diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntity.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntity.java index c0965a4cd..85406f10a 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntity.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntity.java @@ -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 extends BasicPersistentEntity entity) throws MappingException; + +} diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CassandraPersistentProperty.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CassandraPersistentProperty.java index 3fb346fdb..ddae210f4 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CassandraPersistentProperty.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CassandraPersistentProperty.java @@ -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 { diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/DefaultCassandraPersistentEntityMetadataVerifier.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/DefaultCassandraPersistentEntityMetadataVerifier.java new file mode 100644 index 000000000..d1598f7a3 --- /dev/null +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/DefaultCassandraPersistentEntityMetadataVerifier.java @@ -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 idProperties = new ArrayList(); + final List compositePrimaryKeys = new ArrayList(); + final List primaryKeyColumns = new ArrayList(); + + entity.doWithProperties(new PropertyHandler() { + + @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 + + }*/ + + } + +}