DATACASS-455 - Refactor BasicCassandraMappingContext to CassandraMappingContext.

Remove CassandraMappingContext interface and replace it with BasicCassandraMappingContext. CassandraPersistentEntity is no longer required to declare MutablePersistentEntity but it's sufficient to implement PersistentEntity. Fall back to MappingContext instead of CassandraMappingContext use where just MappingContext is required.

Reintroduce BasicCassandraMappingContext extending from CassandraMappingContext to reduce breaking changes and ease migration.
This commit is contained in:
Mark Paluch
2017-06-02 13:59:42 +02:00
parent cf2ce9f0cd
commit 820fef2ecd
64 changed files with 681 additions and 826 deletions

View File

@@ -33,7 +33,6 @@ import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.CassandraTemplate;
import org.springframework.data.cassandra.core.convert.CassandraConverter;
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.util.StringUtils;
@@ -45,7 +44,7 @@ import com.datastax.driver.core.Session;
* via their default implementation types:
* <ul>
* <li>{@link CassandraOperations} via {@link CassandraTemplate}</li>
* <li>{@link CassandraMappingContext} via {@link BasicCassandraMappingContext}</li>
* <li>{@link CassandraMappingContext} via {@link CassandraMappingContext}</li>
* <li>{@link CassandraConverter} via {@link MappingCassandraConverter}</li>
* </ul>
* <p/>
@@ -55,8 +54,8 @@ import com.datastax.driver.core.Session;
* when creating a default definition for the {@link CassandraConverter}.
* <p/>
* If a single definition of a required type is present, then it is used. For example, if there is already a
* {@link CassandraMappingContext} definition present, then it will be used in the {@link BasicCassandraMappingContext}
* bean definition.
* {@link CassandraMappingContext} definition present, then it will be used in the {@link CassandraMappingContext} bean
* definition.
* <p/>
* It requires that a single {@link Session} or {@link CassandraSessionFactoryBean} definition be present. As described
* above, multiple {@link Session} definitions, multiple {@link CassandraSessionFactoryBean} definitions, or both a
@@ -154,7 +153,7 @@ public class CassandraMappingBeanFactoryPostProcessor implements BeanFactoryPost
private BeanDefinitionHolder registerDefaultContext(BeanDefinitionRegistry registry) {
BeanDefinitionHolder contextBean = new BeanDefinitionHolder(
BeanDefinitionBuilder.genericBeanDefinition(BasicCassandraMappingContext.class).getBeanDefinition(),
BeanDefinitionBuilder.genericBeanDefinition(CassandraMappingContext.class).getBeanDefinition(),
DefaultBeanNames.CONTEXT);
registry.registerBeanDefinition(contextBean.getBeanName(), contextBean.getBeanDefinition());

View File

@@ -30,7 +30,6 @@ import org.springframework.data.cassandra.core.CassandraAdminTemplate;
import org.springframework.data.cassandra.core.convert.CassandraConverter;
import org.springframework.data.cassandra.core.convert.CassandraCustomConversions;
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver;
import org.springframework.data.cassandra.core.mapping.Table;
@@ -141,7 +140,7 @@ public abstract class AbstractCassandraConfiguration extends AbstractClusterConf
@Bean
public CassandraMappingContext cassandraMapping() throws ClassNotFoundException {
BasicCassandraMappingContext mappingContext = new BasicCassandraMappingContext();
CassandraMappingContext mappingContext = new CassandraMappingContext();
mappingContext.setBeanClassLoader(beanClassLoader);
mappingContext.setInitialEntitySet(getInitialEntitySet());

View File

@@ -29,7 +29,7 @@ import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.data.cassandra.config.CassandraEntityClassScanner;
import org.springframework.data.cassandra.config.DefaultBeanNames;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.EntityMapping;
import org.springframework.data.cassandra.core.mapping.Mapping;
import org.springframework.data.cassandra.core.mapping.PropertyMapping;
@@ -53,7 +53,7 @@ public class CassandraMappingContextParser extends AbstractSingleBeanDefinitionP
*/
@Override
protected Class<?> getBeanClass(Element element) {
return BasicCassandraMappingContext.class;
return CassandraMappingContext.class;
}
/* (non-Javadoc)

View File

@@ -27,6 +27,7 @@ import org.springframework.data.cassandra.core.convert.QueryMapper;
import org.springframework.data.cassandra.core.convert.UpdateMapper;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty;
import org.springframework.data.cassandra.core.query.Query;
import org.springframework.data.cql.core.AsyncCqlOperations;
import org.springframework.data.cql.core.AsyncCqlTemplate;
@@ -39,6 +40,7 @@ import org.springframework.data.cql.core.WriteOptions;
import org.springframework.data.cql.core.session.DefaultSessionFactory;
import org.springframework.data.cql.core.session.SessionFactory;
import org.springframework.data.cql.support.CqlExceptionTranslator;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.concurrent.ListenableFuture;
@@ -69,14 +71,6 @@ import com.datastax.driver.core.querybuilder.Update;
*
* @author Mark Paluch
* @author John Blum
* @see org.springframework.cassandra.core.AsyncCqlOperations
* @see org.springframework.data.cassandra.core.AsyncCassandraOperations
* @see com.datastax.driver.core.querybuilder.Delete
* @see com.datastax.driver.core.querybuilder.Insert
* @see com.datastax.driver.core.querybuilder.QueryBuilder
* @see com.datastax.driver.core.querybuilder.Select
* @see com.datastax.driver.core.querybuilder.Truncate
* @see com.datastax.driver.core.querybuilder.Update
* @since 2.0
*/
public class AsyncCassandraTemplate implements AsyncCassandraOperations {
@@ -85,7 +79,7 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
private final CassandraConverter converter;
private final CassandraMappingContext mappingContext;
private final MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext;
private final CqlExceptionTranslator exceptionTranslator;
@@ -186,9 +180,9 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
* objects to Cassandra tables.
*
* @return the {@link CassandraMappingContext} used by this template.
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext
* @see CassandraMappingContext
*/
protected CassandraMappingContext getMappingContext() {
protected MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> getMappingContext() {
return this.mappingContext;
}

View File

@@ -40,6 +40,7 @@ import org.springframework.data.cql.core.SessionCallback;
import org.springframework.data.cql.core.WriteOptions;
import org.springframework.data.cql.core.session.DefaultSessionFactory;
import org.springframework.data.cql.core.session.SessionFactory;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -75,7 +76,7 @@ public class CassandraTemplate implements CassandraOperations {
private final CassandraConverter converter;
private final CassandraMappingContext mappingContext;
private final MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext;
private final CqlOperations cqlOperations;
@@ -174,9 +175,9 @@ public class CassandraTemplate implements CassandraOperations {
* object to Cassandra tables.
*
* @return the {@link CassandraMappingContext} used by this template.
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext
* @see CassandraMappingContext
*/
protected CassandraMappingContext getMappingContext() {
protected MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> getMappingContext() {
return this.mappingContext;
}

View File

@@ -26,6 +26,7 @@ import org.springframework.data.cassandra.core.convert.QueryMapper;
import org.springframework.data.cassandra.core.convert.UpdateMapper;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty;
import org.springframework.data.cassandra.core.query.Query;
import org.springframework.data.cql.core.CqlIdentifier;
import org.springframework.data.cql.core.CqlProvider;
@@ -38,6 +39,7 @@ import org.springframework.data.cql.core.session.DefaultReactiveSessionFactory;
import org.springframework.data.cql.core.session.ReactiveResultSet;
import org.springframework.data.cql.core.session.ReactiveSession;
import org.springframework.data.cql.core.session.ReactiveSessionFactory;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -66,24 +68,13 @@ import com.datastax.driver.core.querybuilder.Update;
*
* @author Mark Paluch
* @author John Blum
* @see org.springframework.data.cql.core.ReactiveCqlOperations
* @see org.springframework.data.cassandra.core.convert.CassandraConverter
* @see org.springframework.data.cassandra.core.convert.QueryMapper
* @see org.springframework.data.cassandra.core.convert.UpdateMapper
* @see org.springframework.data.cassandra.core.ReactiveCassandraOperations
* @see com.datastax.driver.core.querybuilder.Delete
* @see com.datastax.driver.core.querybuilder.Insert
* @see com.datastax.driver.core.querybuilder.QueryBuilder
* @see com.datastax.driver.core.querybuilder.Select
* @see com.datastax.driver.core.querybuilder.Truncate
* @see com.datastax.driver.core.querybuilder.Update
* @since 2.0
*/
public class ReactiveCassandraTemplate implements ReactiveCassandraOperations {
private final CassandraConverter converter;
private final CassandraMappingContext mappingContext;
private final MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext;
private final ReactiveCqlOperations cqlOperations;
@@ -182,9 +173,9 @@ public class ReactiveCassandraTemplate implements ReactiveCassandraOperations {
* objects to Cassandra tables.
*
* @return the {@link CassandraMappingContext} used by this template.
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext
* @see CassandraMappingContext
*/
protected CassandraMappingContext getMappingContext() {
protected MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> getMappingContext() {
return this.mappingContext;
}

View File

@@ -68,7 +68,7 @@ public abstract class AbstractCassandraConverter implements CassandraConverter,
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.convert.CassandraConverter#getCustomConversions()
* @see org.springframework.data.cassandra.core.convert.CassandraConverter#getCustomConversions()
*/
@Override
public CustomConversions getCustomConversions() {

View File

@@ -70,7 +70,7 @@ public class BasicCassandraRowValueProvider implements CassandraRowValueProvider
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.convert.CassandraRowValueProvider#getRow()
* @see org.springframework.data.cassandra.core.convert.CassandraRowValueProvider#getRow()
*/
@Override
public Row getRow() {
@@ -78,7 +78,7 @@ public class BasicCassandraRowValueProvider implements CassandraRowValueProvider
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.convert.CassandraValueProvider#hasProperty(org.springframework.data.cassandra.mapping.CassandraPersistentProperty)
* @see org.springframework.data.cassandra.core.convert.CassandraValueProvider#hasProperty(org.springframework.data.cassandra.mapping.CassandraPersistentProperty)
*/
@Override
public boolean hasProperty(CassandraPersistentProperty property) {

View File

@@ -78,7 +78,7 @@ public class CassandraUDTValueProvider implements CassandraValueProvider {
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.convert.CassandraValueProvider#hasProperty(org.springframework.data.cassandra.mapping.CassandraPersistentProperty)
* @see org.springframework.data.cassandra.core.convert.CassandraValueProvider#hasProperty(org.springframework.data.cassandra.mapping.CassandraPersistentProperty)
*/
@Override
public boolean hasProperty(CassandraPersistentProperty property) {

View File

@@ -35,7 +35,7 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.core.CollectionFactory;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.BasicCassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty;
@@ -80,12 +80,6 @@ import com.datastax.driver.core.querybuilder.Update;
* @author Mark Paluch
* @author Antoine Toulme
* @author John Blum
* @see org.springframework.beans.factory.InitializingBean
* @see org.springframework.context.ApplicationContextAware
* @see org.springframework.beans.factory.BeanClassLoaderAware
* @see org.springframework.data.convert.EntityConverter
* @see org.springframework.data.convert.EntityReader
* @see org.springframework.data.convert.EntityWriter
*/
public class MappingCassandraConverter extends AbstractCassandraConverter
implements CassandraConverter, ApplicationContextAware, BeanClassLoaderAware {
@@ -99,10 +93,10 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
private SpELContext spELContext;
/**
* Create a new {@link MappingCassandraConverter} with a {@link BasicCassandraMappingContext}.
* Create a new {@link MappingCassandraConverter} with a {@link CassandraMappingContext}.
*/
public MappingCassandraConverter() {
this(new BasicCassandraMappingContext());
this(new CassandraMappingContext());
}
/**
@@ -260,7 +254,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.convert.CassandraConverter#convertToColumnType(java.util.Optional)
* @see org.springframework.data.cassandra.core.convert.CassandraConverter#convertToColumnType(java.util.Optional)
*/
@Override
@SuppressWarnings("unchecked")
@@ -271,7 +265,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.convert.CassandraConverter#convertToColumnType(java.util.Optional, org.springframework.data.util.TypeInformation)
* @see org.springframework.data.cassandra.core.convert.CassandraConverter#convertToColumnType(java.util.Optional, org.springframework.data.util.TypeInformation)
*/
@Override
public <T> Optional<Object> convertToColumnType(Optional<T> obj, TypeInformation<?> typeInformation) {
@@ -732,8 +726,8 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
return Optional.of((O) converted);
}
Optional<CassandraPersistentEntity<?>> optionalUdt = getMappingContext().getPersistentEntity(actualType.getType())
.filter(CassandraPersistentEntity::isUserDefinedType);
Optional<BasicCassandraPersistentEntity<?>> optionalUdt = getMappingContext()
.getPersistentEntity(actualType.getType()).filter(CassandraPersistentEntity::isUserDefinedType);
if (optionalUdt.isPresent()) {
@@ -871,7 +865,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
return obj.map(it -> (T) readCollectionOrArray(property.getTypeInformation(), (Collection) it));
}
Optional<CassandraPersistentEntity<?>> persistentEntity = getMappingContext()
Optional<BasicCassandraPersistentEntity<?>> persistentEntity = getMappingContext()
.getPersistentEntity(property.getActualType()).filter(CassandraPersistentEntity::isUserDefinedType);
if (persistentEntity.isPresent() && obj.filter(it -> it instanceof UDTValue).isPresent()) {
@@ -907,7 +901,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
return getPotentiallyConvertedSimpleRead(items, collectionType);
}
Optional<CassandraPersistentEntity<?>> cassandraPersistentEntity = componentType
Optional<BasicCassandraPersistentEntity<?>> cassandraPersistentEntity = componentType
.flatMap(it -> getMappingContext().getPersistentEntity(it))
.filter(CassandraPersistentEntity::isUserDefinedType);
@@ -945,7 +939,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
private final CassandraValueProvider parent;
/* (non-Javadoc)
* @see org.springframework.data.cassandra.convert.CassandraValueProvider#hasProperty(org.springframework.data.cassandra.mapping.CassandraPersistentProperty)
* @see org.springframework.data.cassandra.core.convert.CassandraValueProvider#hasProperty(org.springframework.data.cassandra.mapping.CassandraPersistentProperty)
*/
@Override
public boolean hasProperty(CassandraPersistentProperty property) {

View File

@@ -56,9 +56,6 @@ import org.springframework.util.Assert;
* @see org.springframework.data.cassandra.core.query.Columns
* @see org.springframework.data.cassandra.core.query.Criteria
* @see org.springframework.data.cassandra.core.query.Filter
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext
* @see org.springframework.data.cassandra.mapping.CassandraPersistentEntity
* @see org.springframework.data.cassandra.mapping.CassandraPersistentProperty
* @see org.springframework.data.domain.Sort
* @see org.springframework.data.mapping.PersistentProperty
* @see org.springframework.data.mapping.PropertyPath
@@ -90,18 +87,17 @@ public class QueryMapper {
* Returns the configured {@link CassandraConverter} used to convert object values into Cassandra column typed values.
*
* @return the configured {@link CassandraConverter}.
* @see org.springframework.data.cassandra.convert.CassandraConverter
* @see org.springframework.data.cassandra.core.convert.CassandraConverter
*/
protected CassandraConverter getConverter() {
return this.converter;
}
/**
* Returns the configured {@link CassandraMappingContext} containing mapping meta-data (persistent entities and
* properties) used to store (map) objects to Cassandra tables (rows/columns).
* Returns the configured {@link MappingContext} containing mapping meta-data (persistent entities and properties)
* used to store (map) objects to Cassandra tables (rows/columns).
*
* @return the configured {@link CassandraMappingContext}.
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext
* @return the configured {@link MappingContext}.
*/
protected CassandraMappingContext getMappingContext() {
return this.mappingContext;

View File

@@ -15,45 +15,7 @@
*/
package org.springframework.data.cassandra.core.mapping;
import static org.springframework.data.cassandra.core.mapping.CassandraSimpleTypeHolder.*;
import static org.springframework.data.cql.core.CqlIdentifier.*;
import static org.springframework.data.cql.core.keyspace.CreateTableSpecification.*;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.data.cassandra.core.convert.CassandraCustomConversions;
import org.springframework.data.cassandra.core.mapping.UserTypeUtil.FrozenLiteralDataType;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.cql.core.CqlIdentifier;
import org.springframework.data.cql.core.keyspace.CreateTableSpecification;
import org.springframework.data.cql.core.keyspace.CreateUserTypeSpecification;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PropertyHandler;
import org.springframework.data.mapping.context.AbstractMappingContext;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.util.Optionals;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.TableMetadata;
import com.datastax.driver.core.UserType;
/**
* Default implementation of a {@link MappingContext} for Cassandra using {@link CassandraPersistentEntity} and
@@ -64,520 +26,7 @@ import com.datastax.driver.core.UserType;
* @author Mark Paluch
* @author John Blum
* @author Jens Schauder
* @deprecated since 2.0. Use {@link CassandraMappingContext}.
*/
public class BasicCassandraMappingContext
extends AbstractMappingContext<CassandraPersistentEntity<?>, CassandraPersistentProperty>
implements CassandraMappingContext, ApplicationContextAware {
private CassandraPersistentEntityMetadataVerifier verifier = new CompositeCassandraPersistentEntityMetadataVerifier();
private CustomConversions customConversions;
private Mapping mapping = new Mapping();
private UserTypeResolver userTypeResolver;
private ApplicationContext context;
private ClassLoader beanClassLoader;
// useful caches
private final Map<Class<?>, CassandraPersistentEntity<?>> entitiesByType = new HashMap<>();
private final Map<CqlIdentifier, Set<CassandraPersistentEntity<?>>> entitySetsByTableName = new HashMap<>();
private final Set<CassandraPersistentEntity<?>> primaryKeyEntities = new HashSet<>();
private final Set<CassandraPersistentEntity<?>> userDefinedTypes = new HashSet<>();
private final Set<CassandraPersistentEntity<?>> tableEntities = new HashSet<>();
/**
* Create a new {@link BasicCassandraMappingContext}.
*/
public BasicCassandraMappingContext() {
setCustomConversions(new CassandraCustomConversions(Collections.EMPTY_LIST));
setSimpleTypeHolder(CassandraSimpleTypeHolder.HOLDER);
}
/* (non-Javadoc)
* @see org.springframework.data.mapping.context.AbstractMappingContext#initialize()
*/
@Override
public void initialize() {
super.initialize();
processMappingOverrides();
}
@SuppressWarnings("all")
protected void processMappingOverrides() {
mapping.getEntityMappings().stream()//
.filter(entityMapping -> entityMapping != null).forEach(entityMapping -> {
String entityClassName = entityMapping.getEntityClassName();
try {
Class<?> entityClass = ClassUtils.forName(entityClassName, beanClassLoader);
CassandraPersistentEntity<?> entity = getRequiredPersistentEntity(entityClass);
String entityTableName = entityMapping.getTableName();
if (StringUtils.hasText(entityTableName)) {
entity.setTableName(cqlId(entityTableName, Boolean.valueOf(entityMapping.getForceQuote())));
}
processMappingOverrides(entity, entityMapping);
} catch (ClassNotFoundException e) {
throw new IllegalStateException(String.format("Unknown persistent entity name [%s]", entityClassName), e);
}
});
}
protected void processMappingOverrides(CassandraPersistentEntity<?> entity, EntityMapping entityMapping) {
entityMapping.getPropertyMappings()
.forEach((key, propertyMapping) -> processMappingOverride(entity, propertyMapping));
}
protected void processMappingOverride(CassandraPersistentEntity<?> entity, PropertyMapping mapping) {
CassandraPersistentProperty property = entity.getRequiredPersistentProperty(mapping.getPropertyName());
boolean forceQuote = Boolean.valueOf(mapping.getForceQuote());
property.setForceQuote(forceQuote);
if (StringUtils.hasText(mapping.getColumnName())) {
property.setColumnName(cqlId(mapping.getColumnName(), forceQuote));
}
}
/* (non-Javadoc)
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.context = applicationContext;
}
public void setBeanClassLoader(ClassLoader beanClassLoader) {
this.beanClassLoader = beanClassLoader;
}
/**
* Sets the {@link CustomConversions}.
*
* @param customConversions must not be {@literal null}.
* @since 1.5
*/
public void setCustomConversions(CustomConversions customConversions) {
Assert.notNull(customConversions, "CustomConversions must not be null");
this.customConversions = customConversions;
}
public void setMapping(Mapping mapping) {
Assert.notNull(mapping, "Mapping must not be null");
this.mapping = mapping;
}
/**
* Sets the {@link UserTypeResolver}.
*
* @param userTypeResolver must not be {@literal null}.
* @since 1.5
*/
public void setUserTypeResolver(UserTypeResolver userTypeResolver) {
Assert.notNull(userTypeResolver, "UserTypeResolver must not be null");
this.userTypeResolver = userTypeResolver;
}
/**
* @param verifier The verifier to set.
*/
@Override
public void setVerifier(CassandraPersistentEntityMetadataVerifier verifier) {
this.verifier = verifier;
}
/**
* @return Returns the verifier.
*/
@SuppressWarnings("unused")
public CassandraPersistentEntityMetadataVerifier getVerifier() {
return verifier;
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext#getNonPrimaryKeyEntities()
*/
@Override
public Collection<CassandraPersistentEntity<?>> getNonPrimaryKeyEntities() {
return getTableEntities();
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext#getPrimaryKeyEntities()
*/
@Override
public Collection<CassandraPersistentEntity<?>> getPrimaryKeyEntities() {
return Collections.unmodifiableSet(primaryKeyEntities);
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext#getTableEntities()
*/
@Override
public Collection<CassandraPersistentEntity<?>> getTableEntities() {
return Collections.unmodifiableCollection(tableEntities);
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext#getUserDefinedTypeEntities()
*/
@Override
public Collection<CassandraPersistentEntity<?>> getUserDefinedTypeEntities() {
return Collections.unmodifiableSet(userDefinedTypes);
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext#getPersistentEntities(boolean)
*/
@Override
public Collection<CassandraPersistentEntity<?>> getPersistentEntities(boolean includePrimaryKeyTypesAndUdts) {
if (includePrimaryKeyTypesAndUdts) {
return super.getPersistentEntities();
}
return getTableEntities();
}
/* (non-Javadoc)
* @see org.springframework.data.mapping.context.AbstractMappingContext#addPersistentEntity(org.springframework.data.util.TypeInformation)
*/
@Override
protected Optional<CassandraPersistentEntity<?>> addPersistentEntity(TypeInformation<?> typeInformation) {
// Prevent conversion types created as CassandraPersistentEntity
Optional<CassandraPersistentEntity<?>> optional = shouldCreatePersistentEntityFor(typeInformation)
? super.addPersistentEntity(typeInformation) : Optional.empty();
optional.ifPresent(entity -> {
if (entity.isUserDefinedType()) {
userDefinedTypes.add(entity);
}
// now do some caching of the entity
Set<CassandraPersistentEntity<?>> entities = entitySetsByTableName.computeIfAbsent(entity.getTableName(),
cqlIdentifier -> new HashSet<>());
entities.add(entity);
if (!entity.isUserDefinedType()) {
if (entity.isCompositePrimaryKey()) {
primaryKeyEntities.add(entity);
}
entity.findAnnotation(Table.class).ifPresent(table -> tableEntities.add(entity));
}
entitiesByType.put(entity.getType(), entity);
});
return optional;
}
/* (non-Javadoc)
* @see org.springframework.data.mapping.context.AbstractMappingContext#shouldCreatePersistentEntityFor(org.springframework.data.util.TypeInformation)
*/
@Override
protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> typeInfo) {
return (!customConversions.hasCustomWriteTarget(typeInfo.getType())
&& super.shouldCreatePersistentEntityFor(typeInfo));
}
/* (non-Javadoc)
* @see org.springframework.data.mapping.context.AbstractMappingContext#createPersistentEntity(org.springframework.data.util.TypeInformation)
*/
@Override
protected <T> CassandraPersistentEntity<T> createPersistentEntity(TypeInformation<T> typeInformation) {
UserDefinedType userDefinedType = AnnotatedElementUtils.findMergedAnnotation(typeInformation.getType(),
UserDefinedType.class);
CassandraPersistentEntity<T> entity;
if (userDefinedType != null) {
entity = new CassandraUserTypePersistentEntity<>(typeInformation, this, verifier, userTypeResolver);
} else {
entity = new BasicCassandraPersistentEntity<>(typeInformation, this, verifier);
}
if (context != null) {
entity.setApplicationContext(context);
}
return entity;
}
/* (non-Javadoc)
* @see org.springframework.data.mapping.context.AbstractMappingContext#createPersistentProperty(java.lang.reflect.Field, java.beans.PropertyDescriptor, org.springframework.data.mapping.model.MutablePersistentEntity, org.springframework.data.mapping.model.SimpleTypeHolder)
*/
@Override
protected CassandraPersistentProperty createPersistentProperty(Property property, CassandraPersistentEntity<?> owner,
SimpleTypeHolder simpleTypeHolder) {
return new BasicCassandraPersistentProperty(property, owner, simpleTypeHolder, userTypeResolver);
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext#usesTable(com.datastax.driver.core.TableMetadata)
*/
@Override
public boolean usesTable(TableMetadata table) {
return entitySetsByTableName.containsKey(cqlId(table.getName()));
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext#usesUserType(com.datastax.driver.core.UserType)
*/
@Override
public boolean usesUserType(final UserType userType) {
CqlIdentifier identifier = CqlIdentifier.cqlId(userType.getTypeName());
return (hasMappedUserType(identifier) || hasReferencedUserType(identifier));
}
private boolean hasReferencedUserType(final CqlIdentifier identifier) {
return getPersistentEntities().stream() //
.flatMap(PersistentEntity::getPersistentProperties) //
.map(it -> it.findAnnotation(CassandraType.class)) //
.filter(Optional::isPresent) //
.flatMap(Optionals::toStream) //
.anyMatch(it -> {
return StringUtils.hasText(it.userTypeName()) //
&& CqlIdentifier.cqlId(it.userTypeName()).equals(identifier);
}); //
}
private boolean hasMappedUserType(CqlIdentifier identifier) {
return userDefinedTypes.stream().map(CassandraPersistentEntity::getTableName).anyMatch(identifier::equals);
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext#getCreateTableSpecificationFor(org.springframework.data.cassandra.mapping.CassandraPersistentEntity)
*/
@Override
public CreateTableSpecification getCreateTableSpecificationFor(CassandraPersistentEntity<?> entity) {
Assert.notNull(entity, "CassandraPersistentEntity must not be null");
final CreateTableSpecification specification = createTable().name(entity.getTableName());
entity.getPersistentProperties().filter(CassandraPersistentProperty::isCompositePrimaryKey).forEach(property -> {
CassandraPersistentEntity<?> primaryKeyEntity = getRequiredPersistentEntity(property.getRawType());
primaryKeyEntity.getPersistentProperties().forEach(primaryKeyProperty -> {
if (primaryKeyProperty.isPartitionKeyColumn()) {
specification.partitionKeyColumn(primaryKeyProperty.getColumnName(), getDataType(primaryKeyProperty));
} else { // it's a cluster column
specification.clusteredKeyColumn(primaryKeyProperty.getColumnName(), getDataType(primaryKeyProperty),
primaryKeyProperty.getPrimaryKeyOrdering());
}
});
});
entity.getPersistentProperties().filter((property) -> !property.isCompositePrimaryKey()).forEach(property -> {
if (property.isIdProperty() || property.isPartitionKeyColumn()) {
specification.partitionKeyColumn(property.getColumnName(),
UserTypeUtil.potentiallyFreeze(getDataType(property)));
} else if (property.isClusterKeyColumn()) {
specification.clusteredKeyColumn(property.getColumnName(),
UserTypeUtil.potentiallyFreeze(getDataType(property)), property.getPrimaryKeyOrdering());
} else {
specification.column(property.getColumnName(), UserTypeUtil.potentiallyFreeze(getDataType(property)));
}
});
if (specification.getPartitionKeyColumns().isEmpty()) {
throw new MappingException(String.format("No partition key columns found in entity [%s]", entity.getType()));
}
return specification;
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext#getCreateUserTypeSpecificationFor(org.springframework.data.cassandra.mapping.CassandraPersistentEntity)
*/
@Override
public CreateUserTypeSpecification getCreateUserTypeSpecificationFor(CassandraPersistentEntity<?> entity) {
Assert.notNull(entity, "CassandraPersistentEntity must not be null");
final CreateUserTypeSpecification specification = CreateUserTypeSpecification.createType(entity.getTableName());
entity.doWithProperties((PropertyHandler<CassandraPersistentProperty>) property -> {
// Use frozen literal to not resolve types from Cassandra.
// At this stage, they might be not created yet.
specification.field(property.getColumnName(),
getDataTypeWithUserTypeFactory(property, DataTypeProvider.FrozenLiteral));
});
if (specification.getFields().isEmpty()) {
throw new MappingException(String.format("No fields in user type [%s]", entity.getType()));
}
return specification;
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext#getDataType(org.springframework.data.cassandra.mapping.CassandraPersistentProperty)
*/
@Override
public DataType getDataType(CassandraPersistentProperty property) {
return getDataTypeWithUserTypeFactory(property, DataTypeProvider.EntityUserType);
}
private DataType getDataTypeWithUserTypeFactory(CassandraPersistentProperty property,
DataTypeProvider dataTypeProvider) {
if (property.isCompositePrimaryKey()) {
return property.getDataType();
}
if (property.findAnnotation(CassandraType.class).isPresent()) {
return property.getDataType();
}
Optional<CassandraPersistentEntity<?>> persistentEntity = getPersistentEntity(property.getActualType());
if (persistentEntity.filter(CassandraPersistentEntity::isUserDefinedType).isPresent()) {
Optional<DataType> dataType = persistentEntity.map(it -> getUserDataType(property, dataTypeProvider, it));
if (dataType.isPresent()) {
return dataType.get();
}
}
return customConversions.getCustomWriteTarget(property.getType()) //
.map(CassandraSimpleTypeHolder::getDataTypeFor) //
.orElseGet(() -> customConversions.getCustomWriteTarget(property.getActualType()) //
.map(it -> {
if (property.isCollectionLike()) {
if (List.class.isAssignableFrom(property.getType())) {
return DataType.list(getDataTypeFor(it));
}
if (Set.class.isAssignableFrom(property.getType())) {
return DataType.set(getDataTypeFor(it));
}
}
return getDataTypeFor(it);
}).orElseGet(property::getDataType)
);
}
private DataType getUserDataType(CassandraPersistentProperty property, DataTypeProvider dataTypeProvider,
CassandraPersistentEntity<?> persistentEntity) {
DataType elementType = dataTypeProvider.getDataType(persistentEntity);
if (property.isCollectionLike()) {
if (Set.class.isAssignableFrom(property.getType())) {
return DataType.set(elementType);
}
if (List.class.isAssignableFrom(property.getType())) {
return DataType.list(elementType);
}
}
if (!property.isCollectionLike() && !property.isMapLike()) {
return elementType;
}
return null;
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext#getDataType(java.lang.Class)
*/
@Override
public DataType getDataType(Class<?> type) {
return customConversions.getCustomWriteTarget(type) //
.map(CassandraSimpleTypeHolder::getDataTypeFor) //
.orElseGet(() -> getDataTypeFor(type));
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext#getExistingPersistentEntity(java.lang.Class)
*/
@Override
public CassandraPersistentEntity<?> getExistingPersistentEntity(Class<?> type) {
CassandraPersistentEntity<?> entity = entitiesByType.get(type);
Assert.notNull(entity, String.format("Unknown persistent type [%s]", type.getName()));
return entity;
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext#contains(java.lang.Class)
*/
@Override
public boolean contains(Class<?> type) {
return entitiesByType.containsKey(type);
}
/**
* @author Jens Schauder
* @since 1.5.1
*/
enum DataTypeProvider {
EntityUserType {
@Override
public DataType getDataType(CassandraPersistentEntity<?> entity) {
return entity.getUserType();
}
},
FrozenLiteral {
@Override
public DataType getDataType(CassandraPersistentEntity<?> entity) {
return new FrozenLiteralDataType(entity.getTableName());
}
};
/**
* Return the data type for the {@link CassandraPersistentEntity}.
*
* @param entity must not be {@literal null}.
* @return
*/
abstract DataType getDataType(CassandraPersistentEntity<?> entity);
}
}
@Deprecated
public class BasicCassandraMappingContext extends CassandraMappingContext {}

View File

@@ -32,6 +32,7 @@ import org.springframework.data.cql.core.CqlIdentifier;
import org.springframework.data.cql.support.exception.UnsupportedCassandraOperationException;
import org.springframework.data.mapping.Association;
import org.springframework.data.mapping.AssociationHandler;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.BasicPersistentEntity;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.util.TypeInformation;
@@ -59,7 +60,7 @@ public class BasicCassandraPersistentEntity<T> extends BasicPersistentEntity<T,
private CassandraPersistentEntityMetadataVerifier verifier = DEFAULT_VERIFIER;
private CassandraMappingContext mappingContext;
private MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext;
private ApplicationContext context;
@@ -84,7 +85,8 @@ public class BasicCassandraPersistentEntity<T> extends BasicPersistentEntity<T,
*
* @param typeInformation
*/
public BasicCassandraPersistentEntity(TypeInformation<T> typeInformation, CassandraMappingContext mappingContext) {
public BasicCassandraPersistentEntity(TypeInformation<T> typeInformation,
MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext) {
this(typeInformation, mappingContext, DEFAULT_VERIFIER);
}
@@ -94,7 +96,8 @@ public class BasicCassandraPersistentEntity<T> extends BasicPersistentEntity<T,
*
* @param typeInformation
*/
public BasicCassandraPersistentEntity(TypeInformation<T> typeInformation, CassandraMappingContext mappingContext,
public BasicCassandraPersistentEntity(TypeInformation<T> typeInformation,
MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext,
CassandraPersistentEntityMetadataVerifier verifier) {
// FIXME: Constructor with comparator, no optionality here
@@ -226,7 +229,7 @@ public class BasicCassandraPersistentEntity<T> extends BasicPersistentEntity<T,
* @see org.springframework.data.cassandra.mapping.CassandraPersistentEntity#getMappingContext()
*/
@Override
public CassandraMappingContext getMappingContext() {
public MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> getMappingContext() {
return mappingContext;
}

View File

@@ -36,6 +36,7 @@ import org.springframework.data.cql.core.CqlIdentifier;
import org.springframework.data.cql.core.Ordering;
import org.springframework.data.cql.core.PrimaryKeyType;
import org.springframework.data.mapping.Association;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.mapping.model.Property;
@@ -326,8 +327,8 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
protected DataType getDataTypeFor(Class<?> javaType) {
Optional<CassandraPersistentEntity<?>> optionalEntity = getOwner().getMappingContext()
.getPersistentEntity(javaType);
Optional<CassandraPersistentEntity<?>> optionalEntity = getOwner().getMappingContext().getPersistentEntity(javaType)
.map(CassandraPersistentEntity.class::cast);
Optional<CassandraPersistentEntity<?>> udtEntity = optionalEntity
.filter(CassandraPersistentEntity::isUserDefinedType);
@@ -493,7 +494,8 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
@Override
public CassandraPersistentEntity<?> getCompositePrimaryKeyEntity() {
CassandraMappingContext mappingContext = getOwner().getMappingContext();
MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext = getOwner()
.getMappingContext();
Assert.state(mappingContext != null, "CassandraMappingContext needed");

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors
* Copyright 2017 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
* 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,
@@ -15,32 +15,220 @@
*/
package org.springframework.data.cassandra.core.mapping;
import java.util.Collection;
import static org.springframework.data.cassandra.core.mapping.CassandraSimpleTypeHolder.*;
import static org.springframework.data.cql.core.CqlIdentifier.*;
import static org.springframework.data.cql.core.keyspace.CreateTableSpecification.*;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.data.cassandra.core.convert.CassandraCustomConversions;
import org.springframework.data.cassandra.core.mapping.UserTypeUtil.FrozenLiteralDataType;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.cql.core.CqlIdentifier;
import org.springframework.data.cql.core.keyspace.CreateTableSpecification;
import org.springframework.data.cql.core.keyspace.CreateUserTypeSpecification;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PropertyHandler;
import org.springframework.data.mapping.context.AbstractMappingContext;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.util.Optionals;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.TableMetadata;
import com.datastax.driver.core.UserType;
/**
* A {@link MappingContext} for Cassandra.
* Default implementation of a {@link MappingContext} for Cassandra using {@link CassandraPersistentEntity} and
* {@link CassandraPersistentProperty} as primary abstractions.
*
* @author Alex Shvid
* @author Matthew T. Adams
* @author Mark Paluch
* @author John Blum
* @author Jens Schauder
*/
public interface CassandraMappingContext
extends MappingContext<CassandraPersistentEntity<?>, CassandraPersistentProperty> {
public class CassandraMappingContext
extends AbstractMappingContext<BasicCassandraPersistentEntity<?>, CassandraPersistentProperty>
implements ApplicationContextAware {
private CassandraPersistentEntityMetadataVerifier verifier = new CompositeCassandraPersistentEntityMetadataVerifier();
private CustomConversions customConversions;
private Mapping mapping = new Mapping();
private UserTypeResolver userTypeResolver;
private ApplicationContext context;
private ClassLoader beanClassLoader;
// useful caches
private final Map<Class<?>, CassandraPersistentEntity<?>> entitiesByType = new HashMap<>();
private final Map<CqlIdentifier, Set<CassandraPersistentEntity<?>>> entitySetsByTableName = new HashMap<>();
private final Set<BasicCassandraPersistentEntity<?>> primaryKeyEntities = new HashSet<>();
private final Set<BasicCassandraPersistentEntity<?>> userDefinedTypes = new HashSet<>();
private final Set<BasicCassandraPersistentEntity<?>> tableEntities = new HashSet<>();
/**
* Returns only those entities that don't represent primary key types.
*
* @see #getPersistentEntities(boolean)
* Create a new {@link CassandraMappingContext}.
*/
public CassandraMappingContext() {
setCustomConversions(new CassandraCustomConversions(Collections.EMPTY_LIST));
setSimpleTypeHolder(CassandraSimpleTypeHolder.HOLDER);
}
/* (non-Javadoc)
* @see org.springframework.data.mapping.context.AbstractMappingContext#initialize()
*/
@Override
Collection<CassandraPersistentEntity<?>> getPersistentEntities();
public void initialize() {
super.initialize();
processMappingOverrides();
}
@SuppressWarnings("all")
protected void processMappingOverrides() {
mapping.getEntityMappings().stream()//
.filter(entityMapping -> entityMapping != null).forEach(entityMapping -> {
String entityClassName = entityMapping.getEntityClassName();
try {
Class<?> entityClass = ClassUtils.forName(entityClassName, beanClassLoader);
CassandraPersistentEntity<?> entity = getRequiredPersistentEntity(entityClass);
String entityTableName = entityMapping.getTableName();
if (StringUtils.hasText(entityTableName)) {
entity.setTableName(cqlId(entityTableName, Boolean.valueOf(entityMapping.getForceQuote())));
}
processMappingOverrides(entity, entityMapping);
} catch (ClassNotFoundException e) {
throw new IllegalStateException(String.format("Unknown persistent entity name [%s]", entityClassName), e);
}
});
}
protected void processMappingOverrides(CassandraPersistentEntity<?> entity, EntityMapping entityMapping) {
entityMapping.getPropertyMappings()
.forEach((key, propertyMapping) -> processMappingOverride(entity, propertyMapping));
}
protected void processMappingOverride(CassandraPersistentEntity<?> entity, PropertyMapping mapping) {
CassandraPersistentProperty property = entity.getRequiredPersistentProperty(mapping.getPropertyName());
boolean forceQuote = Boolean.valueOf(mapping.getForceQuote());
property.setForceQuote(forceQuote);
if (StringUtils.hasText(mapping.getColumnName())) {
property.setColumnName(cqlId(mapping.getColumnName(), forceQuote));
}
}
/* (non-Javadoc)
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.context = applicationContext;
}
public void setBeanClassLoader(ClassLoader beanClassLoader) {
this.beanClassLoader = beanClassLoader;
}
/**
* Sets the {@link CustomConversions}.
*
* @param customConversions must not be {@literal null}.
* @since 1.5
*/
public void setCustomConversions(CustomConversions customConversions) {
Assert.notNull(customConversions, "CustomConversions must not be null");
this.customConversions = customConversions;
}
public void setMapping(Mapping mapping) {
Assert.notNull(mapping, "Mapping must not be null");
this.mapping = mapping;
}
/**
* Sets the {@link UserTypeResolver}.
*
* @param userTypeResolver must not be {@literal null}.
* @since 1.5
*/
public void setUserTypeResolver(UserTypeResolver userTypeResolver) {
Assert.notNull(userTypeResolver, "UserTypeResolver must not be null");
this.userTypeResolver = userTypeResolver;
}
/**
* @param verifier The verifier to set.
*/
public void setVerifier(CassandraPersistentEntityMetadataVerifier verifier) {
this.verifier = verifier;
}
/**
* @return Returns the verifier.
*/
@SuppressWarnings("unused")
public CassandraPersistentEntityMetadataVerifier getVerifier() {
return verifier;
}
/**
* Returns only {@link Table} entities.
*
* @since 1.5
*/
public Collection<BasicCassandraPersistentEntity<?>> getTableEntities() {
return Collections.unmodifiableCollection(tableEntities);
}
/**
* Returns only those entities representing a user defined type.
*
* @see #getPersistentEntities(boolean)
* @since 1.5
*/
public Collection<CassandraPersistentEntity<?>> getUserDefinedTypeEntities() {
return Collections.unmodifiableSet(userDefinedTypes);
}
/**
* Returns all persistent entities or only non-primary-key entities.
@@ -49,53 +237,93 @@ public interface CassandraMappingContext
* primary key types and user-defined types. If {@literal false}, returns only entities that don't represent
* primary key types and no user-defined types.
*/
Collection<CassandraPersistentEntity<?>> getPersistentEntities(boolean includePrimaryKeyTypesAndUdts);
public Collection<BasicCassandraPersistentEntity<?>> getPersistentEntities(boolean includePrimaryKeyTypesAndUdts) {
/**
* Returns only those entities not representing primary key types.
*
* @see #getPersistentEntities(boolean)
* @deprecated as of 1.5, use {@link #getTableEntities()}.
*/
@Deprecated
Collection<CassandraPersistentEntity<?>> getNonPrimaryKeyEntities();
if (includePrimaryKeyTypesAndUdts) {
return super.getPersistentEntities();
}
/**
* Returns only those entities representing primary key types.
*
* @deprecated as of 1.5
*/
@Deprecated
Collection<CassandraPersistentEntity<?>> getPrimaryKeyEntities();
return getTableEntities();
}
/**
* Returns only {@link Table} entities.
*
* @since 1.5
/* (non-Javadoc)
* @see org.springframework.data.mapping.context.AbstractMappingContext#addPersistentEntity(org.springframework.data.util.TypeInformation)
*/
Collection<CassandraPersistentEntity<?>> getTableEntities();
@Override
protected Optional<BasicCassandraPersistentEntity<?>> addPersistentEntity(TypeInformation<?> typeInformation) {
/**
* Returns only those entities representing a user defined type.
*
* @see #getPersistentEntities(boolean)
* @since 1.5
*/
Collection<CassandraPersistentEntity<?>> getUserDefinedTypeEntities();
// Prevent conversion types created as CassandraPersistentEntity
Optional<BasicCassandraPersistentEntity<?>> optional = shouldCreatePersistentEntityFor(typeInformation)
? super.addPersistentEntity(typeInformation) : Optional.empty();
/**
* Returns a {@link CreateTableSpecification} for the given entity, including all mapping information.
*
* @param entity must not be {@literal null}.
*/
CreateTableSpecification getCreateTableSpecificationFor(CassandraPersistentEntity<?> entity);
optional.ifPresent(entity -> {
/**
* Returns a {@link CreateUserTypeSpecification} for the given entity, including all mapping information.
*
* @param entity must not be {@literal null}.
if (entity.isUserDefinedType()) {
userDefinedTypes.add(entity);
}
// now do some caching of the entity
Set<CassandraPersistentEntity<?>> entities = entitySetsByTableName.computeIfAbsent(entity.getTableName(),
cqlIdentifier -> new HashSet<>());
entities.add(entity);
if (!entity.isUserDefinedType()) {
if (entity.isCompositePrimaryKey()) {
primaryKeyEntities.add(entity);
}
entity.findAnnotation(Table.class).ifPresent(table -> tableEntities.add(entity));
}
entitiesByType.put(entity.getType(), entity);
});
return optional;
}
/* (non-Javadoc)
* @see org.springframework.data.mapping.context.AbstractMappingContext#shouldCreatePersistentEntityFor(org.springframework.data.util.TypeInformation)
*/
CreateUserTypeSpecification getCreateUserTypeSpecificationFor(CassandraPersistentEntity<?> entity);
@Override
protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> typeInfo) {
return (!customConversions.hasCustomWriteTarget(typeInfo.getType())
&& super.shouldCreatePersistentEntityFor(typeInfo));
}
/* (non-Javadoc)
* @see org.springframework.data.mapping.context.AbstractMappingContext#createPersistentEntity(org.springframework.data.util.TypeInformation)
*/
@Override
protected <T> BasicCassandraPersistentEntity<T> createPersistentEntity(TypeInformation<T> typeInformation) {
UserDefinedType userDefinedType = AnnotatedElementUtils.findMergedAnnotation(typeInformation.getType(),
UserDefinedType.class);
BasicCassandraPersistentEntity<T> entity;
if (userDefinedType != null) {
entity = new CassandraUserTypePersistentEntity<>(typeInformation, this, verifier, userTypeResolver);
} else {
entity = new BasicCassandraPersistentEntity<>(typeInformation, this, verifier);
}
if (context != null) {
entity.setApplicationContext(context);
}
return entity;
}
/* (non-Javadoc)
* @see org.springframework.data.mapping.context.AbstractMappingContext#createPersistentProperty(java.lang.reflect.Field, java.beans.PropertyDescriptor, org.springframework.data.mapping.model.MutablePersistentEntity, org.springframework.data.mapping.model.SimpleTypeHolder)
*/
@Override
protected CassandraPersistentProperty createPersistentProperty(Property property,
BasicCassandraPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
return new BasicCassandraPersistentProperty(property, owner, simpleTypeHolder, userTypeResolver);
}
/**
* Returns whether this mapping context has any entities mapped to the given table.
@@ -103,7 +331,9 @@ public interface CassandraMappingContext
* @param table must not be {@literal null}.
* @return @return {@literal true} is this {@literal TableMetadata} is used by a mapping.
*/
boolean usesTable(TableMetadata table);
public boolean usesTable(TableMetadata table) {
return entitySetsByTableName.containsKey(cqlId(table.getName()));
}
/**
* Returns whether this mapping context has any entities using the given user type.
@@ -112,27 +342,102 @@ public interface CassandraMappingContext
* @return {@literal true} is this {@literal UserType} is used.
* @since 1.5
*/
boolean usesUserType(UserType userType);
public boolean usesUserType(final UserType userType) {
CqlIdentifier identifier = CqlIdentifier.cqlId(userType.getTypeName());
return (hasMappedUserType(identifier) || hasReferencedUserType(identifier));
}
private boolean hasReferencedUserType(final CqlIdentifier identifier) {
return getPersistentEntities().stream() //
.flatMap(PersistentEntity::getPersistentProperties) //
.map(it -> it.findAnnotation(CassandraType.class)) //
.filter(Optional::isPresent) //
.flatMap(Optionals::toStream) //
.anyMatch(it -> {
return StringUtils.hasText(it.userTypeName()) //
&& CqlIdentifier.cqlId(it.userTypeName()).equals(identifier);
}); //
}
private boolean hasMappedUserType(CqlIdentifier identifier) {
return userDefinedTypes.stream().map(CassandraPersistentEntity::getTableName).anyMatch(identifier::equals);
}
/**
* Returns the existing {@link CassandraPersistentEntity} for the given {@link Class}. If it is not yet known to this
* {@link CassandraMappingContext}, an {@link IllegalArgumentException} is thrown.
* Returns a {@link CreateTableSpecification} for the given entity, including all mapping information.
*
* @param type The class of the existing persistent entity.
* @return The existing persistent entity.
* @param entity must not be {@literal null}.
*/
CassandraPersistentEntity<?> getExistingPersistentEntity(Class<?> type);
public CreateTableSpecification getCreateTableSpecificationFor(CassandraPersistentEntity<?> entity) {
Assert.notNull(entity, "CassandraPersistentEntity must not be null");
final CreateTableSpecification specification = createTable().name(entity.getTableName());
entity.getPersistentProperties().filter(CassandraPersistentProperty::isCompositePrimaryKey).forEach(property -> {
CassandraPersistentEntity<?> primaryKeyEntity = getRequiredPersistentEntity(property.getRawType());
primaryKeyEntity.getPersistentProperties().forEach(primaryKeyProperty -> {
if (primaryKeyProperty.isPartitionKeyColumn()) {
specification.partitionKeyColumn(primaryKeyProperty.getColumnName(), getDataType(primaryKeyProperty));
} else { // it's a cluster column
specification.clusteredKeyColumn(primaryKeyProperty.getColumnName(), getDataType(primaryKeyProperty),
primaryKeyProperty.getPrimaryKeyOrdering());
}
});
});
entity.getPersistentProperties().filter((property) -> !property.isCompositePrimaryKey()).forEach(property -> {
if (property.isIdProperty() || property.isPartitionKeyColumn()) {
specification.partitionKeyColumn(property.getColumnName(),
UserTypeUtil.potentiallyFreeze(getDataType(property)));
} else if (property.isClusterKeyColumn()) {
specification.clusteredKeyColumn(property.getColumnName(),
UserTypeUtil.potentiallyFreeze(getDataType(property)), property.getPrimaryKeyOrdering());
} else {
specification.column(property.getColumnName(), UserTypeUtil.potentiallyFreeze(getDataType(property)));
}
});
if (specification.getPartitionKeyColumns().isEmpty()) {
throw new MappingException(String.format("No partition key columns found in entity [%s]", entity.getType()));
}
return specification;
}
/**
* Returns whether this {@link CassandraMappingContext} already contains a {@link CassandraPersistentEntity} for the
* given type.
* Returns a {@link CreateUserTypeSpecification} for the given entity, including all mapping information.
*
* @param entity must not be {@literal null}.
*/
boolean contains(Class<?> type);
public CreateUserTypeSpecification getCreateUserTypeSpecificationFor(CassandraPersistentEntity<?> entity) {
/**
* Sets a verifier other than the {@link BasicCassandraPersistentEntityMetadataVerifier}
*/
void setVerifier(CassandraPersistentEntityMetadataVerifier verifier);
Assert.notNull(entity, "CassandraPersistentEntity must not be null");
final CreateUserTypeSpecification specification = CreateUserTypeSpecification.createType(entity.getTableName());
entity.doWithProperties((PropertyHandler<CassandraPersistentProperty>) property -> {
// Use frozen literal to not resolve types from Cassandra.
// At this stage, they might be not created yet.
specification.field(property.getColumnName(),
getDataTypeWithUserTypeFactory(property, DataTypeProvider.FrozenLiteral));
});
if (specification.getFields().isEmpty()) {
throw new MappingException(String.format("No fields in user type [%s]", entity.getType()));
}
return specification;
}
/**
* Retrieve the data type of the property. Cassandra {@link DataType types} are determined using simple types and
@@ -144,7 +449,76 @@ public interface CassandraMappingContext
* @see CassandraSimpleTypeHolder
* @since 1.5
*/
DataType getDataType(CassandraPersistentProperty property);
public DataType getDataType(CassandraPersistentProperty property) {
return getDataTypeWithUserTypeFactory(property, DataTypeProvider.EntityUserType);
}
private DataType getDataTypeWithUserTypeFactory(CassandraPersistentProperty property,
DataTypeProvider dataTypeProvider) {
if (property.isCompositePrimaryKey()) {
return property.getDataType();
}
if (property.findAnnotation(CassandraType.class).isPresent()) {
return property.getDataType();
}
Optional<BasicCassandraPersistentEntity<?>> persistentEntity = getPersistentEntity(property.getActualType());
if (persistentEntity.filter(CassandraPersistentEntity::isUserDefinedType).isPresent()) {
Optional<DataType> dataType = persistentEntity.map(it -> getUserDataType(property, dataTypeProvider, it));
if (dataType.isPresent()) {
return dataType.get();
}
}
return customConversions.getCustomWriteTarget(property.getType()) //
.map(CassandraSimpleTypeHolder::getDataTypeFor) //
.orElseGet(() -> customConversions.getCustomWriteTarget(property.getActualType()) //
.map(it -> {
if (property.isCollectionLike()) {
if (List.class.isAssignableFrom(property.getType())) {
return DataType.list(getDataTypeFor(it));
}
if (Set.class.isAssignableFrom(property.getType())) {
return DataType.set(getDataTypeFor(it));
}
}
return getDataTypeFor(it);
}).orElseGet(property::getDataType)
);
}
private DataType getUserDataType(CassandraPersistentProperty property, DataTypeProvider dataTypeProvider,
CassandraPersistentEntity<?> persistentEntity) {
DataType elementType = dataTypeProvider.getDataType(persistentEntity);
if (property.isCollectionLike()) {
if (Set.class.isAssignableFrom(property.getType())) {
return DataType.set(elementType);
}
if (List.class.isAssignableFrom(property.getType())) {
return DataType.list(elementType);
}
}
if (!property.isCollectionLike() && !property.isMapLike()) {
return elementType;
}
return null;
}
/**
* Retrieve the data type based on the given {@code type}. Cassandra {@link DataType types} are determined using
@@ -156,6 +530,49 @@ public interface CassandraMappingContext
* @see CassandraSimpleTypeHolder
* @since 1.5
*/
DataType getDataType(Class<?> type);
public DataType getDataType(Class<?> type) {
return customConversions.getCustomWriteTarget(type) //
.map(CassandraSimpleTypeHolder::getDataTypeFor) //
.orElseGet(() -> getDataTypeFor(type));
}
/**
* Returns whether this {@link CassandraMappingContext} already contains a {@link CassandraPersistentEntity} for the
* given type.
*/
public boolean contains(Class<?> type) {
return entitiesByType.containsKey(type);
}
/**
* @author Jens Schauder
* @since 1.5.1
*/
enum DataTypeProvider {
EntityUserType {
@Override
public DataType getDataType(CassandraPersistentEntity<?> entity) {
return entity.getUserType();
}
},
FrozenLiteral {
@Override
public DataType getDataType(CassandraPersistentEntity<?> entity) {
return new FrozenLiteralDataType(entity.getTableName());
}
};
/**
* Return the data type for the {@link CassandraPersistentEntity}.
*
* @param entity must not be {@literal null}.
* @return
*/
abstract DataType getDataType(CassandraPersistentEntity<?> entity);
}
}

View File

@@ -21,7 +21,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.data.cql.core.CqlIdentifier;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.model.MutablePersistentEntity;
import org.springframework.data.mapping.context.MappingContext;
import com.datastax.driver.core.UserType;
@@ -32,9 +32,8 @@ import com.datastax.driver.core.UserType;
* @author Matthew T. Adams
* @author Mark Paluch
*/
// TODO: Not extend MutablePersistentEntity but rather PersistentEntity.
public interface CassandraPersistentEntity<T>
extends MutablePersistentEntity<T, CassandraPersistentProperty>, ApplicationContextAware {
extends PersistentEntity<T, CassandraPersistentProperty>, ApplicationContextAware {
/**
* Returns whether this entity represents a composite primary key.
@@ -78,7 +77,7 @@ public interface CassandraPersistentEntity<T>
UserType getUserType();
// TODO: Review if that's required or it can be handled in a different way
CassandraMappingContext getMappingContext();
MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> getMappingContext();
ApplicationContext getApplicationContext();
}

View File

@@ -18,6 +18,7 @@ package org.springframework.data.cassandra.core.mapping;
import java.util.Optional;
import org.springframework.data.cql.core.CqlIdentifier;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.Assert;
@@ -48,7 +49,8 @@ public class CassandraUserTypePersistentEntity<T> extends BasicCassandraPersiste
* @param verifier must not be {@literal null}.
* @param resolver must not be {@literal null}.
*/
public CassandraUserTypePersistentEntity(TypeInformation<T> typeInformation, CassandraMappingContext mappingContext,
public CassandraUserTypePersistentEntity(TypeInformation<T> typeInformation,
MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext,
CassandraPersistentEntityMetadataVerifier verifier, UserTypeResolver resolver) {
super(typeInformation, mappingContext, verifier);

View File

@@ -85,7 +85,7 @@ public abstract class AbstractCassandraQuery implements RepositoryQuery {
}
/**
* @deprecated as of 1.5, {@link org.springframework.data.cassandra.mapping.CassandraMappingContext} handles type
* @deprecated as of 1.5, {@link org.springframework.data.cassandra.core.mapping.CassandraMappingContext} handles type
* conversion.
*/
@Deprecated
@@ -95,7 +95,7 @@ public abstract class AbstractCassandraQuery implements RepositoryQuery {
}
/**
* @deprecated as of 1.5, {@link org.springframework.data.cassandra.mapping.CassandraMappingContext} handles type
* @deprecated as of 1.5, {@link org.springframework.data.cassandra.core.mapping.CassandraMappingContext} handles type
* conversion.
*/
@Deprecated
@@ -174,7 +174,7 @@ public abstract class AbstractCassandraQuery implements RepositoryQuery {
* @param declaredReturnType
* @param returnedUnwrappedObjectType
* @return
* @deprecated as of 1.5, {@link org.springframework.data.cassandra.mapping.CassandraMappingContext} handles type
* @deprecated as of 1.5, {@link org.springframework.data.cassandra.core.mapping.CassandraMappingContext} handles type
* conversion.
*/
@Deprecated
@@ -204,7 +204,7 @@ public abstract class AbstractCassandraQuery implements RepositoryQuery {
* @param resultSet
* @param type
* @return
* @deprecated as of 1.5, {@link org.springframework.data.cassandra.mapping.CassandraMappingContext} handles type
* @deprecated as of 1.5, {@link org.springframework.data.cassandra.core.mapping.CassandraMappingContext} handles type
* conversion.
*/
@Deprecated

View File

@@ -51,7 +51,7 @@ class CassandraQueryCreator extends AbstractQueryCreator<Query, CriteriaDefiniti
private static final Logger LOG = LoggerFactory.getLogger(CassandraQueryCreator.class);
private final CassandraMappingContext mappingContext;
private final MappingContext<?, CassandraPersistentProperty> mappingContext;
private final QueryBuilder queryBuilder = new QueryBuilder();
@@ -64,7 +64,7 @@ class CassandraQueryCreator extends AbstractQueryCreator<Query, CriteriaDefiniti
* @param mappingContext must not be {@literal null}.
*/
public CassandraQueryCreator(PartTree tree, CassandraParameterAccessor accessor,
CassandraMappingContext mappingContext) {
MappingContext<?, CassandraPersistentProperty> mappingContext) {
super(tree, accessor);
@@ -74,13 +74,13 @@ class CassandraQueryCreator extends AbstractQueryCreator<Query, CriteriaDefiniti
}
/**
* Returns the {@link CassandraMappingContext} used by this template to access mapping meta-data used to store (map)
* object to Cassandra tables.
* Returns the {@link MappingContext} used by this template to access mapping meta-data used to store (map) object to
* Cassandra tables.
*
* @return the {@link CassandraMappingContext} used by this template.
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext
* @return the {@link MappingContext} used by this template.
* @see CassandraMappingContext
*/
protected CassandraMappingContext getMappingContext() {
protected MappingContext<?, CassandraPersistentProperty> getMappingContext() {
return this.mappingContext;
}

View File

@@ -20,8 +20,10 @@ import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty;
import org.springframework.data.convert.EntityInstantiators;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.repository.query.ResultProcessor;
import org.springframework.data.repository.query.ReturnedType;
import org.springframework.util.ClassUtils;
@@ -144,7 +146,7 @@ interface CassandraQueryExecution {
final class ResultProcessingConverter implements Converter<Object, Object> {
private final @NonNull ResultProcessor processor;
private final @NonNull CassandraMappingContext mappingContext;
private final @NonNull MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext;
private final @NonNull EntityInstantiators instantiators;
/* (non-Javadoc)

View File

@@ -21,9 +21,10 @@ import java.util.Optional;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty;
import org.springframework.data.cassandra.repository.Query;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.QueryMethod;
@@ -47,7 +48,7 @@ public class CassandraQueryMethod extends QueryMethod {
private final Method method;
private final CassandraMappingContext mappingContext;
private final MappingContext<? extends CassandraPersistentEntity<?>, ? extends CassandraPersistentProperty> mappingContext;
private CassandraEntityMetadata<?> entityMetadata;
@@ -60,7 +61,7 @@ public class CassandraQueryMethod extends QueryMethod {
* @param mappingContext must not be {@literal null}.
*/
public CassandraQueryMethod(Method method, RepositoryMetadata repositoryMetadata, ProjectionFactory projectionFactory,
CassandraMappingContext mappingContext) {
MappingContext<? extends CassandraPersistentEntity<?>, ? extends CassandraPersistentProperty> mappingContext) {
super(method, repositoryMetadata, projectionFactory);
@@ -103,7 +104,7 @@ public class CassandraQueryMethod extends QueryMethod {
} else {
Optional<CassandraPersistentEntity<?>> optionalReturnedEntity = mappingContext
.getPersistentEntity(returnedObjectType);
.getPersistentEntity(returnedObjectType).map(CassandraPersistentEntity.class::cast);
CassandraPersistentEntity<?> managedEntity = mappingContext.getRequiredPersistentEntity(domainClass);
CassandraPersistentEntity<?> returnedEntity = optionalReturnedEntity.filter(e -> !e.getType().isInterface())
@@ -115,7 +116,6 @@ public class CassandraQueryMethod extends QueryMethod {
this.entityMetadata = new SimpleCassandraEntityMetadata<>((Class<Object>) returnedEntity.getType(),
collectionEntity);
}
}

View File

@@ -21,7 +21,9 @@ import org.springframework.data.cassandra.core.StatementFactory;
import org.springframework.data.cassandra.core.convert.UpdateMapper;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty;
import org.springframework.data.cassandra.core.query.Query;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.repository.query.QueryCreationException;
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.query.RepositoryQuery;
@@ -37,7 +39,7 @@ import com.datastax.driver.core.Statement;
*/
public class PartTreeCassandraQuery extends AbstractCassandraQuery {
private final CassandraMappingContext mappingContext;
private final MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext;
private final PartTree tree;
@@ -59,13 +61,13 @@ public class PartTreeCassandraQuery extends AbstractCassandraQuery {
}
/**
* Returns the {@link CassandraMappingContext} used by this query to access mapping meta-data used to store (map)
* objects to Cassandra tables.
* Returns the {@link MappingContext} used by this query to access mapping meta-data used to store (map) objects to
* Cassandra tables.
*
* @return the {@link CassandraMappingContext} used by this query.
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext
* @return the {@link MappingContext} used by this query.
* @see CassandraMappingContext
*/
protected CassandraMappingContext getMappingContext() {
protected MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> getMappingContext() {
return this.mappingContext;
}

View File

@@ -20,8 +20,10 @@ import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty;
import org.springframework.data.convert.EntityInstantiators;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.repository.query.ResultProcessor;
import org.springframework.data.repository.query.ReturnedType;
import org.springframework.util.ClassUtils;
@@ -109,7 +111,7 @@ interface ReactiveCassandraQueryExecution {
final class ResultProcessingConverter implements Converter<Object, Object> {
private final @NonNull ResultProcessor processor;
private final @NonNull CassandraMappingContext mappingContext;
private final @NonNull MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext;
private final @NonNull EntityInstantiators instantiators;
/*

View File

@@ -17,8 +17,10 @@ package org.springframework.data.cassandra.repository.query;
import java.lang.reflect.Method;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty;
import org.springframework.data.cassandra.repository.query.CassandraParameters.CassandraParameter;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.util.ReactiveWrapperConverters;
@@ -43,7 +45,7 @@ public class ReactiveCassandraQueryMethod extends CassandraQueryMethod {
* @param mappingContext must not be {@literal null}.
*/
public ReactiveCassandraQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory projectionFactory,
CassandraMappingContext mappingContext) {
MappingContext<? extends CassandraPersistentEntity<?>, ? extends CassandraPersistentProperty> mappingContext) {
super(method, metadata, projectionFactory, mappingContext);

View File

@@ -20,7 +20,9 @@ import org.springframework.data.cassandra.core.StatementFactory;
import org.springframework.data.cassandra.core.convert.UpdateMapper;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty;
import org.springframework.data.cassandra.core.query.Query;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.repository.query.QueryCreationException;
import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.data.repository.query.parser.PartTree;
@@ -35,7 +37,7 @@ import com.datastax.driver.core.Statement;
*/
public class ReactivePartTreeCassandraQuery extends AbstractReactiveCassandraQuery {
private final CassandraMappingContext mappingContext;
private final MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext;
private final PartTree tree;
@@ -59,13 +61,13 @@ public class ReactivePartTreeCassandraQuery extends AbstractReactiveCassandraQue
}
/**
* Returns the {@link CassandraMappingContext} used by this query to access mapping meta-data used to store (map)
* objects to Cassandra tables.
* Returns the {@link MappingContext} used by this query to access mapping meta-data used to store (map) objects to
* Cassandra tables.
*
* @return the {@link CassandraMappingContext} used by this query.
* @see org.springframework.data.cassandra.mapping.CassandraMappingContext
* @return the {@link MappingContext} used by this query.
* @see CassandraMappingContext
*/
protected CassandraMappingContext getMappingContext() {
protected MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> getMappingContext() {
return this.mappingContext;
}

View File

@@ -19,13 +19,14 @@ import java.lang.reflect.Method;
import java.util.Optional;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty;
import org.springframework.data.cassandra.repository.CassandraRepository;
import org.springframework.data.cassandra.repository.query.CassandraEntityInformation;
import org.springframework.data.cassandra.repository.query.CassandraQueryMethod;
import org.springframework.data.cassandra.repository.query.PartTreeCassandraQuery;
import org.springframework.data.cassandra.repository.query.StringBasedCassandraQuery;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.repository.core.NamedQueries;
import org.springframework.data.repository.core.RepositoryInformation;
@@ -51,7 +52,7 @@ public class CassandraRepositoryFactory extends RepositoryFactorySupport {
private static final SpelExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();
private final CassandraMappingContext mappingContext;
private final MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext;
private final CassandraOperations operations;
@@ -113,12 +114,12 @@ public class CassandraRepositoryFactory extends RepositoryFactorySupport {
private final EvaluationContextProvider evaluationContextProvider;
private final CassandraMappingContext mappingContext;
private final MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext;
private final CassandraOperations operations;
CassandraQueryLookupStrategy(CassandraOperations operations, EvaluationContextProvider evaluationContextProvider,
CassandraMappingContext mappingContext) {
MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext) {
this.operations = operations;
this.evaluationContextProvider = evaluationContextProvider;

View File

@@ -19,12 +19,13 @@ import java.lang.reflect.Method;
import java.util.Optional;
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty;
import org.springframework.data.cassandra.repository.query.CassandraEntityInformation;
import org.springframework.data.cassandra.repository.query.ReactiveCassandraQueryMethod;
import org.springframework.data.cassandra.repository.query.ReactivePartTreeCassandraQuery;
import org.springframework.data.cassandra.repository.query.ReactiveStringBasedCassandraQuery;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.repository.core.NamedQueries;
import org.springframework.data.repository.core.RepositoryInformation;
@@ -49,7 +50,7 @@ public class ReactiveCassandraRepositoryFactory extends ReactiveRepositoryFactor
private final ReactiveCassandraOperations operations;
private final CassandraMappingContext mappingContext;
private final MappingContext<? extends CassandraPersistentEntity<?>, ? extends CassandraPersistentProperty> mappingContext;
/**
* Create a new {@link ReactiveCassandraRepositoryFactory} with the given {@link ReactiveCassandraOperations}.
@@ -113,10 +114,11 @@ public class ReactiveCassandraRepositoryFactory extends ReactiveRepositoryFactor
private final EvaluationContextProvider evaluationContextProvider;
private final ReactiveCassandraOperations operations;
private final CassandraMappingContext mappingContext;
private final MappingContext<? extends CassandraPersistentEntity<?>, ? extends CassandraPersistentProperty> mappingContext;
CassandraQueryLookupStrategy(ReactiveCassandraOperations operations,
EvaluationContextProvider evaluationContextProvider, CassandraMappingContext mappingContext) {
EvaluationContextProvider evaluationContextProvider,
MappingContext<? extends CassandraPersistentEntity<?>, ? extends CassandraPersistentProperty> mappingContext) {
this.evaluationContextProvider = evaluationContextProvider;
this.operations = operations;

View File

@@ -766,7 +766,7 @@ Defines a CassandraConverter for getting rich mapping functionality.
<xsd:attribute name="mapping-ref" type="mappingContextRef" use="optional">
<xsd:annotation>
<xsd:documentation
source="org.springframework.data.cassandra.mapping.CassandraMappingContext"><![CDATA[
source="org.springframework.data.cassandra.core.mapping.CassandraMappingContext"><![CDATA[
The reference to a CassandraMappingContext. Will default to 'cassandraMapping'.
]]></xsd:documentation>
</xsd:annotation>

View File

@@ -22,7 +22,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.cassandra.core.CassandraTemplate;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver;
import org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cql.core.CqlTemplate;
@@ -91,7 +91,7 @@ public class CassandraNamespaceIntegrationTests extends AbstractSpringDataEmbedd
@Test // DATACASS-172
public void mappingContextShouldHaveUserTypeResolverConfigured() {
BasicCassandraMappingContext mappingContext = applicationContext.getBean(BasicCassandraMappingContext.class);
CassandraMappingContext mappingContext = applicationContext.getBean(CassandraMappingContext.class);
SimpleUserTypeResolver userTypeResolver = (SimpleUserTypeResolver) ReflectionTestUtils.getField(mappingContext,
"userTypeResolver");

View File

@@ -28,7 +28,7 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.UserDefinedType;
import org.springframework.data.cql.core.CqlOperations;
@@ -44,7 +44,7 @@ public class CassandraPersistentEntitySchemaCreatorUnitTests {
@Mock CassandraAdminOperations adminOperations;
@Mock CqlOperations operations;
BasicCassandraMappingContext context = new BasicCassandraMappingContext();
CassandraMappingContext context = new CassandraMappingContext();
@Before
public void setUp() throws Exception {

View File

@@ -29,7 +29,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.annotation.Id;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.Table;
import org.springframework.data.cassandra.core.mapping.UserDefinedType;
import org.springframework.data.cql.core.CqlIdentifier;
@@ -55,7 +55,7 @@ public class CassandraPersistentEntitySchemaDropperUnitTests {
@Mock TableMetadata person;
@Mock TableMetadata contact;
BasicCassandraMappingContext context = new BasicCassandraMappingContext();
CassandraMappingContext context = new CassandraMappingContext();
// DATACASS-355
@Before

View File

@@ -33,7 +33,7 @@ import org.junit.Test;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.annotation.Id;
import org.springframework.data.cassandra.core.CassandraTemplate;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.Table;
import org.springframework.data.cassandra.repository.support.SchemaTestUtils;
import org.springframework.data.convert.CustomConversions;
@@ -46,7 +46,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Test suite for applying {@link CustomConversions} to {@link MappingCassandraConverter} and
* {@link BasicCassandraMappingContext}.
* {@link CassandraMappingContext}.
*
* @author Mark Paluch
*/
@@ -62,7 +62,7 @@ public class CustomConversionIntegrationTests extends AbstractKeyspaceCreatingIn
converters.add(new PersonWriteConverter());
CustomConversions customConversions = new CassandraCustomConversions(converters);
BasicCassandraMappingContext mappingContext = new BasicCassandraMappingContext();
CassandraMappingContext mappingContext = new CassandraMappingContext();
mappingContext.setCustomConversions(customConversions);
mappingContext.afterPropertiesSet();

View File

@@ -52,7 +52,6 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.core.SpringVersion;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.data.cassandra.RowMockUtil;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraType;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
@@ -105,7 +104,7 @@ public class MappingCassandraConverterUnitTests {
@Before
public void setUp() throws Exception {
mappingContext = new BasicCassandraMappingContext();
mappingContext = new CassandraMappingContext();
mappingCassandraConverter = new MappingCassandraConverter(mappingContext);
mappingCassandraConverter.afterPropertiesSet();

View File

@@ -33,7 +33,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.annotation.Id;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.Column;
import org.springframework.data.cassandra.core.mapping.UserDefinedType;
@@ -65,7 +65,7 @@ import com.datastax.driver.core.UserType;
@RunWith(MockitoJUnitRunner.class)
public class QueryMapperUnitTests {
BasicCassandraMappingContext mappingContext = new BasicCassandraMappingContext();
CassandraMappingContext mappingContext = new CassandraMappingContext();
CassandraPersistentEntity<?> persistentEntity;
MappingCassandraConverter cassandraConverter;
QueryMapper queryMapper;

View File

@@ -29,7 +29,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.annotation.Id;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.Column;
import org.springframework.data.cassandra.core.mapping.UserTypeResolver;
@@ -43,7 +43,7 @@ import org.springframework.data.cassandra.core.query.Update;
@RunWith(MockitoJUnitRunner.class)
public class UpdateMapperUnitTests {
BasicCassandraMappingContext mappingContext = new BasicCassandraMappingContext();
CassandraMappingContext mappingContext = new CassandraMappingContext();
CassandraPersistentEntity<?> persistentEntity;
MappingCassandraConverter cassandraConverter;
UpdateMapper updateMapper;

View File

@@ -34,7 +34,8 @@ import org.springframework.data.mapping.model.MappingException;
public class BasicCassandraPersistentEntityMetadataVerifierUnitTests {
private BasicCassandraPersistentEntityMetadataVerifier verifier = new BasicCassandraPersistentEntityMetadataVerifier();
private BasicCassandraMappingContext context = new BasicCassandraMappingContext();
private CassandraMappingContext context = new CassandraMappingContext();
@Before
public void setUp() throws Exception {

View File

@@ -105,7 +105,7 @@ public class CassandraCompositePrimaryKeyUnitTests {
@Before
public void setup() {
context = new BasicCassandraMappingContext();
context = new CassandraMappingContext();
thing = context.getRequiredPersistentEntity(ClassTypeInformation.from(Thing.class));
key = context.getRequiredPersistentEntity(ClassTypeInformation.from(Key.class));
}

View File

@@ -47,18 +47,17 @@ import com.datastax.driver.core.UDTValue;
import com.datastax.driver.core.UserType;
/**
* Unit tests for {@link BasicCassandraMappingContext}.
* Unit tests for {@link CassandraMappingContext}.
*
* @author Matthew T. Adams
* @author Mark Paluch
*/
public class BasicCassandraMappingContextUnitTests {
public class CassandraMappingContextUnitTests {
BasicCassandraMappingContext mappingContext = new BasicCassandraMappingContext();
CassandraMappingContext mappingContext = new CassandraMappingContext();
@Before
public void before() {
mappingContext.setUserTypeResolver(typeName -> null);
}
@@ -77,10 +76,7 @@ public class BasicCassandraMappingContextUnitTests {
mappingContext.getRequiredPersistentEntity(X.class);
assertThat(mappingContext.getExistingPersistentEntity(X.class)).isNotNull();
assertThat(mappingContext.contains(Y.class)).isFalse();
assertThat(mappingContext.getNonPrimaryKeyEntities()).hasSize(1);
assertThat(mappingContext.getPrimaryKeyEntities()).isEmpty();
assertThat(mappingContext.getUserDefinedTypeEntities()).isEmpty();
assertThat(mappingContext.getTableEntities()).hasSize(1);
assertThat(mappingContext.contains(X.class)).isTrue();
@@ -364,9 +360,6 @@ public class BasicCassandraMappingContextUnitTests {
assertThat(persistentEntity.isUserDefinedType()).isTrue();
assertThat(mappingContext.getExistingPersistentEntity(MappedUdt.class)).isNotNull();
assertThat(mappingContext.getNonPrimaryKeyEntities()).isEmpty();
assertThat(mappingContext.getPrimaryKeyEntities()).isEmpty();
assertThat(mappingContext.getUserDefinedTypeEntities()).hasSize(1);
assertThat(mappingContext.getTableEntities()).hasSize(0);
assertThat(mappingContext.contains(MappedUdt.class)).isTrue();
@@ -375,7 +368,8 @@ public class BasicCassandraMappingContextUnitTests {
@Test // DATACASS-172
public void getNonPrimaryKeyEntitiesShouldNotContainUdt() {
CassandraPersistentEntity<?> existingPersistentEntity = mappingContext.getRequiredPersistentEntity(MappedUdt.class);
BasicCassandraPersistentEntity<?> existingPersistentEntity = mappingContext
.getRequiredPersistentEntity(MappedUdt.class);
assertThat(mappingContext.getTableEntities()).doesNotContain(existingPersistentEntity);
}
@@ -383,7 +377,8 @@ public class BasicCassandraMappingContextUnitTests {
@Test // DATACASS-172, DATACASS-359
public void getPersistentEntitiesShouldContainUdt() {
CassandraPersistentEntity<?> existingPersistentEntity = mappingContext.getRequiredPersistentEntity(MappedUdt.class);
BasicCassandraPersistentEntity<?> existingPersistentEntity = mappingContext
.getRequiredPersistentEntity(MappedUdt.class);
assertThat(mappingContext.getPersistentEntities(true)).contains(existingPersistentEntity);
assertThat(mappingContext.getUserDefinedTypeEntities()).contains(existingPersistentEntity);
@@ -468,8 +463,6 @@ public class BasicCassandraMappingContextUnitTests {
assertThat(e).isInstanceOf(VerifierMappingExceptions.class);
}
assertThat(mappingContext.getNonPrimaryKeyEntities()).isEmpty();
assertThat(mappingContext.getPrimaryKeyEntities()).isEmpty();
assertThat(mappingContext.getUserDefinedTypeEntities()).isEmpty();
assertThat(mappingContext.getTableEntities()).isEmpty();
assertThat(mappingContext.contains(InvalidEntityWithIdAndPrimaryKeyColumn.class)).isFalse();

View File

@@ -28,15 +28,15 @@ import org.springframework.data.cql.core.PrimaryKeyType;
import org.springframework.data.mapping.PropertyHandler;
/**
* Unit tests for {@link BasicCassandraMappingContext}.
* Unit tests for {@link CassandraMappingContext}.
*
* @author David Webb
* @author Mark Paluch
*/
public class BasicCassandraPersistentEntityOrderPropertiesUnitTests {
public class CassandraPersistentEntityOrderPropertiesUnitTests {
private List<CassandraPersistentProperty> expected;
private BasicCassandraMappingContext mappingContext = new BasicCassandraMappingContext();
private CassandraMappingContext mappingContext = new CassandraMappingContext();
@Before
public void init() {}

View File

@@ -176,7 +176,7 @@ public class CassandraPersistentPropertyComparatorUnitTests {
@Test // DATACASS-352
public void columnNameComparisonShouldHonorContract() throws Exception {
BasicCassandraMappingContext context = new BasicCassandraMappingContext();
CassandraMappingContext context = new CassandraMappingContext();
CassandraPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(TwoColumns.class);
CassandraPersistentProperty annotated = persistentEntity.getRequiredPersistentProperty("annotated");

View File

@@ -33,7 +33,7 @@ import org.springframework.data.mapping.model.MappingException;
public class CompositeCassandraPersistentEntityMetadataVerifierUnitTests {
private CompositeCassandraPersistentEntityMetadataVerifier verifier = new CompositeCassandraPersistentEntityMetadataVerifier();
private BasicCassandraMappingContext context = new BasicCassandraMappingContext();
private CassandraMappingContext context = new CassandraMappingContext();
@Before
public void setUp() throws Exception {

View File

@@ -48,14 +48,14 @@ import com.datastax.driver.core.UserType;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Unit tests for {@link BasicCassandraMappingContext} targeted on {@link CreateTableSpecification}.
* Unit tests for {@link CassandraMappingContext} targeted on {@link CreateTableSpecification}.
*
* @author Mark Paluch
* @soundtrack Black Rose - Volbeat
*/
public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
private BasicCassandraMappingContext ctx = new BasicCassandraMappingContext();
private CassandraMappingContext ctx = new CassandraMappingContext();
@Before
public void setUp() throws Exception {

View File

@@ -42,7 +42,7 @@ import com.datastax.driver.core.Session;
import com.datastax.driver.core.UserType;
/**
* Integration tests for creation of UDT types through {@link BasicCassandraMappingContext}.
* Integration tests for creation of UDT types through {@link CassandraMappingContext}.
*
* @author Mark Paluch
*/
@@ -56,7 +56,7 @@ public class CreateUserTypeIntegrationTests extends AbstractSpringDataEmbeddedCa
@Bean
public CassandraMappingContext cassandraMapping() throws ClassNotFoundException {
BasicCassandraMappingContext mappingContext = new BasicCassandraMappingContext();
CassandraMappingContext mappingContext = new CassandraMappingContext();
mappingContext.setInitialEntitySet(new HashSet<>(Arrays.asList(Car.class, Engine.class, Manufacturer.class)));

View File

@@ -27,7 +27,7 @@ import org.springframework.data.cql.core.CqlIdentifier;
import org.springframework.data.cql.core.PrimaryKeyType;
/**
* Unit tests for {@link BasicCassandraMappingContext}.
* Unit tests for {@link CassandraMappingContext}.
*
* @author Matthew T. Adams
* @author Mark Paluch
@@ -39,7 +39,7 @@ public class ForceQuotedPropertiesSimpleUnitTests {
public static final String EXPLICIT_KEY_0 = "TheFirstKeyField";
public static final String EXPLICIT_KEY_1 = "TheSecondKeyField";
CassandraMappingContext context = new BasicCassandraMappingContext();
CassandraMappingContext context = new CassandraMappingContext();
@Test
public void testImplicit() {

View File

@@ -33,7 +33,7 @@ import org.springframework.data.mapping.model.MappingException;
public class PrimaryKeyClassEntityMetadataVerifierUnitTests {
private PrimaryKeyClassEntityMetadataVerifier verifier = new PrimaryKeyClassEntityMetadataVerifier();
private BasicCassandraMappingContext context = new BasicCassandraMappingContext();
private CassandraMappingContext context = new CassandraMappingContext();
@Before
public void setUp() throws Exception {

View File

@@ -23,35 +23,38 @@ import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.cassandra.config.CassandraEntityClassScanner;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty;
import org.springframework.data.cassandra.core.mapping.multipackagescanning.first.First;
import org.springframework.data.cassandra.core.mapping.multipackagescanning.second.Second;
import org.springframework.data.cassandra.core.mapping.multipackagescanning.third.Third;
import org.springframework.data.mapping.context.MappingContext;
/**
* Unit tests for {@link BasicCassandraMappingContext}.
* Unit tests for {@link CassandraMappingContext}.
*
* @author Matthew T. Adams
*/
public class MultipackageScanningUnitTests {
BasicCassandraMappingContext mapping;
MappingContext<? extends CassandraPersistentEntity<?>, ? extends CassandraPersistentProperty> context;
String pkg = getClass().getPackage().getName();
@Before
public void before() throws ClassNotFoundException {
mapping = new BasicCassandraMappingContext();
mapping.setInitialEntitySet(CassandraEntityClassScanner.scan(pkg + ".first", pkg + ".second"));
CassandraMappingContext context = new CassandraMappingContext();
mapping.initialize();
context.setInitialEntitySet(CassandraEntityClassScanner.scan(pkg + ".first", pkg + ".second"));
context.initialize();
this.context = context;
}
@Test
public void test() {
Collection<CassandraPersistentEntity<?>> entities = mapping.getPersistentEntities();
Collection<? extends CassandraPersistentEntity<?>> entities = context.getPersistentEntities();
Collection<Class<?>> types = entities.stream().map(CassandraPersistentEntity::getType).collect(Collectors.toSet());

View File

@@ -28,7 +28,7 @@ import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.CassandraPersistentEntitySchemaCreator;
import org.springframework.data.cassandra.core.CassandraPersistentEntitySchemaDropper;
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver;
import org.springframework.data.cassandra.domain.User;
@@ -63,7 +63,7 @@ class CassandraOperationsProducer {
@ApplicationScoped
public CassandraOperations createCassandraOperations(Cluster cluster) throws Exception {
BasicCassandraMappingContext mappingContext = new BasicCassandraMappingContext();
CassandraMappingContext mappingContext = new CassandraMappingContext();
mappingContext.setUserTypeResolver(new SimpleUserTypeResolver(cluster, KEYSPACE_NAME));
mappingContext.setInitialEntitySet(Collections.singleton(User.class));
mappingContext.afterPropertiesSet();

View File

@@ -27,7 +27,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.data.cassandra.core.ReactiveCassandraTemplate;
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.UserTypeResolver;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.repository.ReactiveCassandraRepository;
@@ -53,7 +53,7 @@ public class ReactiveCassandraRepositoriesRegistrarUnitTests {
@Bean
public ReactiveCassandraTemplate reactiveCassandraTemplate() throws Exception {
BasicCassandraMappingContext mappingContext = new BasicCassandraMappingContext();
CassandraMappingContext mappingContext = new CassandraMappingContext();
mappingContext.setUserTypeResolver(mock(UserTypeResolver.class));
MappingCassandraConverter converter = new MappingCassandraConverter(mappingContext);

View File

@@ -37,7 +37,7 @@ import org.springframework.core.convert.converter.Converter;
import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.core.convert.CassandraCustomConversions;
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraType;
import org.springframework.data.cassandra.domain.AllPossibleTypes;
import org.springframework.data.cassandra.repository.Query;
@@ -82,7 +82,7 @@ public class RepositoryQueryMethodParameterTypesIntegrationTests
@Autowired AllPossibleTypesRepository allPossibleTypesRepository;
@Autowired Session session;
@Autowired BasicCassandraMappingContext mappingContext;
@Autowired CassandraMappingContext mappingContext;
@Autowired MappingCassandraConverter converter;
@Before

View File

@@ -24,7 +24,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraType;
import org.springframework.data.cassandra.domain.AllPossibleTypes;
@@ -48,7 +47,7 @@ public class CassandraParametersParameterAccessorUnitTests {
@Mock ProjectionFactory projectionFactory;
RepositoryMetadata metadata = new DefaultRepositoryMetadata(PossibleRepository.class);
CassandraMappingContext context = new BasicCassandraMappingContext();
CassandraMappingContext context = new CassandraMappingContext();
@Test // DATACASS-296
public void returnsCassandraSimpleType() throws Exception {

View File

@@ -35,7 +35,7 @@ import org.springframework.data.cassandra.core.StatementFactory;
import org.springframework.data.cassandra.core.convert.CassandraConverter;
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.convert.UpdateMapper;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.Column;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
@@ -58,7 +58,7 @@ import com.datastax.driver.core.RegularStatement;
*/
public class CassandraQueryCreatorUnitTests {
BasicCassandraMappingContext context;
CassandraMappingContext context;
CassandraConverter converter;
@Rule public ExpectedException exception = ExpectedException.none();
@@ -66,7 +66,7 @@ public class CassandraQueryCreatorUnitTests {
@Before
public void setUp() throws SecurityException, NoSuchMethodException {
context = new BasicCassandraMappingContext();
context = new CassandraMappingContext();
context.setUserTypeResolver(mock(UserTypeResolver.class));
converter = new MappingCassandraConverter(context);

View File

@@ -22,7 +22,6 @@ import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.domain.User;
import org.springframework.data.projection.ProjectionFactory;
@@ -41,7 +40,7 @@ public class CassandraQueryMethodUnitTests {
@Before
public void setUp() {
context = new BasicCassandraMappingContext();
context = new CassandraMappingContext();
}
@Test // DATACASS-7

View File

@@ -30,7 +30,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty;
import org.springframework.data.cassandra.core.mapping.CassandraType;
import org.springframework.data.cassandra.repository.query.ConvertingParameterAccessor.PotentiallyConvertingIterator;
@@ -57,7 +57,7 @@ public class ConvertingParameterAccessorUnitTests {
@Before
public void setUp() {
this.converter = new MappingCassandraConverter(new BasicCassandraMappingContext());
this.converter = new MappingCassandraConverter(new CassandraMappingContext());
this.converter.afterPropertiesSet();
this.convertingParameterAccessor = new ConvertingParameterAccessor(converter, mockParameterAccessor);
}

View File

@@ -33,7 +33,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.convert.CassandraConverter;
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.UserTypeResolver;
import org.springframework.data.cassandra.domain.AddressType;
import org.springframework.data.cassandra.domain.Group;
@@ -65,13 +65,13 @@ public class PartTreeCassandraQueryUnitTests {
@Mock UserType userTypeMock;
@Mock UDTValue udtValueMock;
BasicCassandraMappingContext mappingContext;
CassandraMappingContext mappingContext;
CassandraConverter converter;
@Before
public void setUp() {
this.mappingContext = new BasicCassandraMappingContext();
this.mappingContext = new CassandraMappingContext();
this.mappingContext.setUserTypeResolver(userTypeResolverMock);
this.converter = new MappingCassandraConverter(mappingContext);

View File

@@ -28,7 +28,6 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraType;
import org.springframework.data.cassandra.domain.AllPossibleTypes;
@@ -55,7 +54,7 @@ public class ReactiveCassandraParameterAccessorUnitTests {
@Mock ProjectionFactory projectionFactory;
RepositoryMetadata metadata = new DefaultRepositoryMetadata(PossibleRepository.class);
CassandraMappingContext context = new BasicCassandraMappingContext();
CassandraMappingContext context = new CassandraMappingContext();
@Test // DATACASS-335
public void returnsCassandraSimpleType() throws Exception {

View File

@@ -25,7 +25,6 @@ import java.lang.reflect.Method;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.projection.ProjectionFactory;
@@ -44,7 +43,7 @@ public class ReactiveCassandraQueryMethodUnitTests {
@Before
public void setUp() {
context = new BasicCassandraMappingContext();
context = new CassandraMappingContext();
}
@Test // DATACASS-335

View File

@@ -33,7 +33,7 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.UserTypeResolver;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.repository.MapIdCassandraRepository;
@@ -55,12 +55,12 @@ public class ReactivePartTreeCassandraQueryUnitTests {
@Mock ReactiveCassandraOperations mockCassandraOperations;
@Mock UserTypeResolver userTypeResolver;
private BasicCassandraMappingContext mappingContext;
private CassandraMappingContext mappingContext;
@Before
public void setUp() {
mappingContext = new BasicCassandraMappingContext();
mappingContext = new CassandraMappingContext();
mappingContext.setUserTypeResolver(userTypeResolver);
when(mockCassandraOperations.getConverter()).thenReturn(new MappingCassandraConverter(mappingContext));

View File

@@ -26,7 +26,7 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.repository.Query;
import org.springframework.data.cql.core.ReactiveCqlOperations;
@@ -69,7 +69,7 @@ public class ReactiveStringBasedCassandraQueryUnitTests {
public void setUp() {
this.metadata = AbstractRepositoryMetadata.getMetadata(SampleRepository.class);
this.converter = new MappingCassandraConverter(new BasicCassandraMappingContext());
this.converter = new MappingCassandraConverter(new CassandraMappingContext());
this.factory = new SpelAwareProxyProjectionFactory();
this.converter.afterPropertiesSet();

View File

@@ -34,7 +34,7 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.UserTypeResolver;
import org.springframework.data.cassandra.domain.AddressType;
import org.springframework.data.cassandra.domain.Person;
@@ -81,7 +81,7 @@ public class StringBasedCassandraQueryUnitTests {
@SuppressWarnings("unchecked")
public void setUp() {
BasicCassandraMappingContext mappingContext = new BasicCassandraMappingContext();
CassandraMappingContext mappingContext = new CassandraMappingContext();
mappingContext.setUserTypeResolver(userTypeResolver);
this.metadata = AbstractRepositoryMetadata.getMetadata(SampleRepository.class);

View File

@@ -37,7 +37,8 @@ public abstract class AbstractSpringDataEmbeddedCassandraIntegrationTest
*/
public void deleteAllEntities() {
Stream<CassandraPersistentEntity<?>> stream = template.getConverter().getMappingContext().getTableEntities()
Stream<? extends CassandraPersistentEntity<?>> stream = template.getConverter().getMappingContext()
.getTableEntities()
.stream();
stream.map(CassandraPersistentEntity::getType).filter(type -> !type.isInterface()).forEach(template::truncate);

View File

@@ -27,8 +27,8 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.cassandra.core.CassandraTemplate;
import org.springframework.data.cassandra.core.convert.CassandraConverter;
import org.springframework.data.cassandra.core.mapping.BasicCassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.repository.query.CassandraEntityInformation;
import org.springframework.data.repository.Repository;
@@ -46,7 +46,7 @@ public class CassandraRepositoryFactoryUnitTests {
@Mock CassandraMappingContext mappingContext;
@Mock CassandraPersistentEntity entity;
@Mock BasicCassandraPersistentEntity entity;
@Mock CassandraTemplate template;

View File

@@ -27,8 +27,8 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.cassandra.core.ReactiveCassandraTemplate;
import org.springframework.data.cassandra.core.convert.CassandraConverter;
import org.springframework.data.cassandra.core.mapping.BasicCassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.repository.query.CassandraEntityInformation;
import org.springframework.data.repository.Repository;
@@ -43,8 +43,11 @@ import org.springframework.data.repository.Repository;
public class ReactiveCassandraRepositoryFactoryUnitTests {
@Mock CassandraConverter converter;
@Mock CassandraMappingContext mappingContext;
@Mock CassandraPersistentEntity entity;
@Mock BasicCassandraPersistentEntity entity;
@Mock ReactiveCassandraTemplate template;
@Before

View File

@@ -32,7 +32,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.annotation.Id;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.UserTypeResolver;
import org.springframework.data.cassandra.domain.Person;
@@ -51,7 +51,7 @@ import com.datastax.driver.core.querybuilder.Insert;
@SuppressWarnings("unchecked")
public class SimpleCassandraRepositoryUnitTests {
BasicCassandraMappingContext mappingContext = new BasicCassandraMappingContext();
CassandraMappingContext mappingContext = new CassandraMappingContext();
MappingCassandraConverter converter = new MappingCassandraConverter(mappingContext);
SimpleCassandraRepository<Object, ? extends Serializable> repository;

View File

@@ -8,6 +8,6 @@
<cass:cluster/>
<bean class="org.springframework.data.cassandra.config.CassandraMappingBeanFactoryPostProcessorUnitTests.MockSessionFactory"/>
<cass:mapping/>
<bean class="org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext"/>
<bean class="org.springframework.data.cassandra.core.mapping.CassandraMappingContext"/>
</beans>