DATACASS-91 - added test that searches multiple packages
This commit is contained in:
@@ -123,7 +123,7 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
|
||||
Assert.notNull(type);
|
||||
Assert.notNull(id);
|
||||
|
||||
CassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(type);
|
||||
CassandraPersistentEntity<?> entity = mappingContext.getPersistentEntity(type);
|
||||
|
||||
Select select = QueryBuilder.select().countAll().from(entity.getTableName());
|
||||
appendIdCriteria(select.where(), entity, id);
|
||||
@@ -152,9 +152,9 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
|
||||
Assert.notNull(type);
|
||||
Assert.notNull(id);
|
||||
|
||||
CassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(type);
|
||||
CassandraPersistentEntity<?> entity = mappingContext.getPersistentEntity(type);
|
||||
|
||||
Delete delete = QueryBuilder.delete().all().from(entity.getTableName());
|
||||
Delete delete = QueryBuilder.delete().from(entity.getTableName());
|
||||
appendIdCriteria(delete.where(), entity, id);
|
||||
|
||||
execute(delete.getQueryString());
|
||||
@@ -192,7 +192,7 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
|
||||
|
||||
@Override
|
||||
public String getTableName(Class<?> type) {
|
||||
return mappingContext.getRequiredPersistentEntity(type).getTableName();
|
||||
return mappingContext.getPersistentEntity(type).getTableName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -252,7 +252,7 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
|
||||
@Override
|
||||
public <T> List<T> selectBySimpleIds(Class<T> type, Iterable<?> ids) {
|
||||
|
||||
CassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(type);
|
||||
CassandraPersistentEntity<?> entity = mappingContext.getPersistentEntity(type);
|
||||
|
||||
if (entity.getIdProperty().isCompositePrimaryKey()) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.springframework.context.expression.BeanFactoryResolver;
|
||||
import org.springframework.data.cassandra.util.CassandraNamingUtils;
|
||||
import org.springframework.data.mapping.Association;
|
||||
import org.springframework.data.mapping.AssociationHandler;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PropertyHandler;
|
||||
import org.springframework.data.mapping.model.BasicPersistentEntity;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
@@ -57,24 +57,4 @@ public interface CassandraMappingContext extends
|
||||
* @param table May not be null.
|
||||
*/
|
||||
boolean usesTable(TableMetadata table);
|
||||
|
||||
/**
|
||||
* Returns the {@link CassandraPersistentEntity} for the given type. If it doesn't exist, this method throws
|
||||
* {@link IllegalArgumentException}.
|
||||
*
|
||||
* @param type The Java type of the persistent entity.
|
||||
* @return The {@link CassandraPersistentEntity} describing the persistent Java type.
|
||||
* @throws IllegalArgumentException if the persistent entity is unknown
|
||||
*/
|
||||
public CassandraPersistentEntity<?> getRequiredPersistentEntity(Class<?> type);
|
||||
|
||||
/**
|
||||
* Returns the {@link CassandraPersistentEntity} for the given type. If it doesn't exist, this method throws
|
||||
* {@link IllegalArgumentException}.
|
||||
*
|
||||
* @param type The {@link TypeInformation} of the persistent entity.
|
||||
* @return The {@link CassandraPersistentEntity} describing the persistent Java type.
|
||||
* @throws IllegalArgumentException if the persistent entity is unknown
|
||||
*/
|
||||
public CassandraPersistentEntity<?> getRequiredPersistentEntity(TypeInformation<?> type);
|
||||
}
|
||||
|
||||
@@ -198,31 +198,6 @@ public class DefaultCassandraMappingContext extends
|
||||
return spec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CassandraPersistentEntity<?> getRequiredPersistentEntity(Class<?> type) {
|
||||
|
||||
CassandraPersistentEntity<?> entity = getPersistentEntity(type);
|
||||
|
||||
if (entity == null) {
|
||||
throw new IllegalArgumentException(String.format("no persistence metadata found for type [%s]", type.getName()));
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CassandraPersistentEntity<?> getRequiredPersistentEntity(TypeInformation<?> type) {
|
||||
|
||||
CassandraPersistentEntity<?> entity = getPersistentEntity(type);
|
||||
|
||||
if (entity == null) {
|
||||
throw new IllegalArgumentException(String.format("no persistence metadata found for type [%s]",
|
||||
type.getActualType()));
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public void setMapping(Mapping mapping) {
|
||||
|
||||
Assert.notNull(mapping);
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.springframework.data.cassandra.test.integration.mappingcontext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.cassandra.mapping.CassandraPersistentEntity;
|
||||
import org.springframework.data.cassandra.mapping.DefaultCassandraMappingContext;
|
||||
|
||||
public class MappingContextIntegrationTests {
|
||||
|
||||
public static class Transient {
|
||||
}
|
||||
|
||||
@Test
|
||||
// TODO: (expected = MappingException.class)
|
||||
public void testGetPersistentEntityOfTransientType() {
|
||||
|
||||
// TODO: when entity verification is added (DATACASS-85), this should throw a MappingException
|
||||
|
||||
DefaultCassandraMappingContext ctx = new DefaultCassandraMappingContext();
|
||||
CassandraPersistentEntity<?> entity = ctx.getPersistentEntity(Transient.class);
|
||||
|
||||
// TODO: remove following lines after DATACASS-85
|
||||
assertNotNull(entity);
|
||||
assertEquals(Transient.class.getSimpleName().toLowerCase(), entity.getTableName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.springframework.data.cassandra.test.integration.multipackagescanning;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.cassandra.config.CassandraEntityClassScanner;
|
||||
import org.springframework.data.cassandra.mapping.CassandraPersistentEntity;
|
||||
import org.springframework.data.cassandra.mapping.DefaultCassandraMappingContext;
|
||||
import org.springframework.data.cassandra.test.integration.multipackagescanning.first.First;
|
||||
import org.springframework.data.cassandra.test.integration.multipackagescanning.second.Second;
|
||||
import org.springframework.data.cassandra.test.integration.multipackagescanning.third.Third;
|
||||
|
||||
public class MultipackageScanningIntegrationTests {
|
||||
|
||||
DefaultCassandraMappingContext mapping;
|
||||
String pkg = getClass().getPackage().getName();
|
||||
|
||||
@Before
|
||||
public void before() throws ClassNotFoundException {
|
||||
|
||||
mapping = new DefaultCassandraMappingContext();
|
||||
mapping.setInitialEntitySet(CassandraEntityClassScanner.scan(pkg + ".first", pkg + ".second"));
|
||||
|
||||
mapping.initialize();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Collection<CassandraPersistentEntity<?>> entities = mapping.getPersistentEntities();
|
||||
|
||||
Collection<Class<?>> types = new HashSet<Class<?>>(entities.size());
|
||||
for (CassandraPersistentEntity<?> entity : entities) {
|
||||
types.add(entity.getType());
|
||||
}
|
||||
|
||||
assertTrue(types.contains(First.class));
|
||||
assertTrue(types.contains(Second.class));
|
||||
assertFalse(types.contains(Third.class));
|
||||
assertFalse(types.contains(Top.class));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.springframework.data.cassandra.test.integration.multipackagescanning;
|
||||
|
||||
import org.springframework.data.cassandra.mapping.PrimaryKey;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
|
||||
@Table
|
||||
public class Top {
|
||||
|
||||
@PrimaryKey
|
||||
String key;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.springframework.data.cassandra.test.integration.multipackagescanning.first;
|
||||
|
||||
import org.springframework.data.cassandra.mapping.PrimaryKey;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
|
||||
@Table
|
||||
public class First {
|
||||
|
||||
@PrimaryKey
|
||||
String key;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.springframework.data.cassandra.test.integration.multipackagescanning.second;
|
||||
|
||||
import org.springframework.data.cassandra.mapping.PrimaryKey;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
|
||||
@Table
|
||||
public class Second {
|
||||
|
||||
@PrimaryKey
|
||||
String key;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.springframework.data.cassandra.test.integration.multipackagescanning.third;
|
||||
|
||||
import org.springframework.data.cassandra.mapping.PrimaryKey;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
|
||||
@Table
|
||||
public class Third {
|
||||
|
||||
@PrimaryKey
|
||||
String key;
|
||||
}
|
||||
Reference in New Issue
Block a user