DATACASS-85 - WIP - Verifier

This commit is contained in:
David T Webb
2014-02-07 10:39:28 -05:00
parent c68c73628b
commit 646dc0d1b3
4 changed files with 141 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2012 the original author or authors.
* Copyright 2011-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import org.springframework.data.cassandra.util.CassandraNamingUtils;
import org.springframework.data.mapping.Association;
import org.springframework.data.mapping.AssociationHandler;
import org.springframework.data.mapping.model.BasicPersistentEntity;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.util.TypeInformation;
import org.springframework.expression.Expression;
import org.springframework.expression.ParserContext;
@@ -102,4 +103,11 @@ public class BasicCassandraPersistentEntity<T> extends BasicPersistentEntity<T,
Assert.hasText(tableName);
this.tableName = tableName;
}
@Override
public void verify() throws MappingException {
super.verify();
CassandraPersistentEntityMetadataVerifier verifier = new DefaultCassandraPersistentEntityMetadataVerifier();
verifier.verify(this);
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2011-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.mapping;
import org.springframework.data.mapping.model.MappingException;
/**
* Interface for Cassandra Persistent Entity Mapping Verification.
*
* @author David Webb
*/
public interface CassandraPersistentEntityMetadataVerifier {
/**
* Performs verification on the Persistent Entity to ensure all markers and marker combinations are valid.
*
* @param entity
*/
void verify(CassandraPersistentEntity<?> entity) throws MappingException;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2012 the original author or authors.
* Copyright 2011-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import com.datastax.driver.core.DataType;
*
* @author Alex Shvid
* @author Matthew T. Adams
* @author David T. Webb
*/
public interface CassandraPersistentProperty extends PersistentProperty<CassandraPersistentProperty> {

View File

@@ -0,0 +1,96 @@
/*
* Copyright 2011-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.mapping;
import java.util.ArrayList;
import java.util.List;
import org.springframework.data.mapping.PropertyHandler;
import org.springframework.data.mapping.model.MappingException;
/**
* Default implementation for Cassandra Persistent Entity Verification. Ensures that annotated Persistent Entities will
* map properly to a Cassandra Table.
*
* @author Matthew T Adams
* @author David Webb
*/
public class DefaultCassandraPersistentEntityMetadataVerifier implements CassandraPersistentEntityMetadataVerifier {
@Override
public void verify(CassandraPersistentEntity<?> entity) throws MappingException {
boolean todo = true;
if (todo) {
return;
}
// TODO
final List<CassandraPersistentProperty> idProperties = new ArrayList<CassandraPersistentProperty>();
final List<CassandraPersistentProperty> compositePrimaryKeys = new ArrayList<CassandraPersistentProperty>();
final List<CassandraPersistentProperty> primaryKeyColumns = new ArrayList<CassandraPersistentProperty>();
entity.doWithProperties(new PropertyHandler<CassandraPersistentProperty>() {
@Override
public void doWithPersistentProperty(CassandraPersistentProperty p) {
if (p.isIdProperty()) {
idProperties.add(p);
} else if (p.isCompositePrimaryKey()) {
compositePrimaryKeys.add(p);
} else if (p.isPrimaryKeyColumn()) {
primaryKeyColumns.add(p);
}
}
});
// TODO Outline Rules needed
// TODO PK Combinations
// TODO Index, potential verify against TableMetaData...DO NOT CREATE INDEX.
// TODO - Uncomment once Matt merges this support
/*
if (entity.isCompositePrimaryKey()) {
if (primaryKeyColumns.size() == 0) {
throw new IllegalStateException(String.format(
"composite primary key type [%s] has no fields annotated with @%s", entity.getType().getName(),
PrimaryKeyColumn.class.getSimpleName()));
}
// there can also be no @PrimaryKey or @Id fields that aren't composite primary keys themselves
for (CassandraPersistentProperty p : idProperties) {
if (!p.getType().isAnnotationPresent(PrimaryKeyClass.class)) {
throw new IllegalStateException(String.format(
"composite primary key type [%s] property [%s] can only be a composite primary key type itself", entity
.getType().getName(), p.getName()));
}
}
return;
}
// else it's not a composite primary key class
}*/
}
}