DATACASS-389 - Adapt to API changes in Spring Data Commons.

This commit is contained in:
Mark Paluch
2017-03-23 11:23:11 +01:00
parent 83a64f316e
commit c9bb49fad4
8 changed files with 41 additions and 44 deletions

View File

@@ -254,8 +254,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
PropertyValueProvider<CassandraPersistentProperty> propertyProvider) {
return instantiators.getInstantiatorFor(entity).createInstance(entity,
new PersistentEntityParameterValueProvider<>(entity, propertyProvider,
Optional.empty()));
new PersistentEntityParameterValueProvider<>(entity, propertyProvider, Optional.empty()));
}
/* (non-Javadoc)
@@ -837,8 +836,8 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
.getPersistentEntity(property.getActualType()).filter(CassandraPersistentEntity::isUserDefinedType);
if (persistentEntity.isPresent() && obj.filter(it -> it instanceof UDTValue).isPresent()) {
persistentEntity
.map(cassandraPersistentEntity -> obj.map(it -> readEntityFromUdt(cassandraPersistentEntity, (UDTValue) it)));
return persistentEntity.flatMap(
cassandraPersistentEntity -> obj.map(it -> (T) readEntityFromUdt(cassandraPersistentEntity, (UDTValue) it)));
}
return obj.flatMap(it -> Optional.of((T) getPotentiallyConvertedSimpleRead(it, property.getType())));

View File

@@ -32,7 +32,6 @@ import org.springframework.cassandra.core.WriteOptions;
import org.springframework.cassandra.core.cql.CqlIdentifier;
import org.springframework.cassandra.core.session.DefaultSessionFactory;
import org.springframework.cassandra.core.session.SessionFactory;
import org.springframework.cassandra.core.util.CollectionUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.data.cassandra.convert.CassandraConverter;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
@@ -79,8 +78,8 @@ public class CassandraTemplate implements CassandraOperations {
private final CqlOperations cqlOperations;
/**
* Creates an instance of {@link CassandraTemplate} initialized with the given {@link Session}
* and a default {@link MappingCassandraConverter}.
* Creates an instance of {@link CassandraTemplate} initialized with the given {@link Session} and a default
* {@link MappingCassandraConverter}.
*
* @param session {@link Session} used to interact with Cassandra; must not be {@literal null}.
* @see CassandraConverter
@@ -91,12 +90,12 @@ public class CassandraTemplate implements CassandraOperations {
}
/**
* Creates an instance of {@link CassandraTemplate} initialized with the given {@link Session}
* and {@link CassandraConverter}.
* Creates an instance of {@link CassandraTemplate} initialized with the given {@link Session} and
* {@link CassandraConverter}.
*
* @param session {@link Session} used to interact with Cassandra; must not be {@literal null}.
* @param converter {@link CassandraConverter} used to convert between Java and Cassandra types;
* must not be {@literal null}.
* @param converter {@link CassandraConverter} used to convert between Java and Cassandra types; must not be
* {@literal null}.
* @see CassandraConverter
* @see Session
*/
@@ -105,12 +104,12 @@ public class CassandraTemplate implements CassandraOperations {
}
/**
* Creates an instance of {@link CassandraTemplate} initialized with the given {@link SessionFactory}
* and {@link CassandraConverter}.
* Creates an instance of {@link CassandraTemplate} initialized with the given {@link SessionFactory} and
* {@link CassandraConverter}.
*
* @param sessionFactory {@link SessionFactory} used to interact with Cassandra; must not be {@literal null}.
* @param converter {@link CassandraConverter} used to convert between Java and Cassandra types;
* must not be {@literal null}.
* @param converter {@link CassandraConverter} used to convert between Java and Cassandra types; must not be
* {@literal null}.
* @see CassandraConverter
* @see SessionFactory
*/
@@ -119,12 +118,12 @@ public class CassandraTemplate implements CassandraOperations {
}
/**
* Creates an instance of {@link CassandraTemplate} initialized with the given {@link CqlOperations}
* and {@link CassandraConverter}.
* Creates an instance of {@link CassandraTemplate} initialized with the given {@link CqlOperations} and
* {@link CassandraConverter}.
*
* @param cqlOperations {@link CqlOperations} used to interact with Cassandra; must not be {@literal null}.
* @param converter {@link CassandraConverter} used to convert between Java and Cassandra types;
* must not be {@literal null}.
* @param converter {@link CassandraConverter} used to convert between Java and Cassandra types; must not be
* {@literal null}.
* @see CassandraConverter
* @see Session
*/
@@ -330,8 +329,7 @@ public class CassandraTemplate implements CassandraOperations {
Assert.notNull(entity, "Entity must not be null");
Insert insert = QueryUtils.createInsertQuery(getTableName(entity.getClass()).toCql(),
entity, options, converter);
Insert insert = QueryUtils.createInsertQuery(getTableName(entity.getClass()).toCql(), entity, options, converter);
return cqlOperations.execute(new StatementCallback<>(insert, entity));
}
@@ -354,8 +352,7 @@ public class CassandraTemplate implements CassandraOperations {
Assert.notNull(entity, "Entity must not be null");
Update update = QueryUtils.createUpdateQuery(getTableName(entity.getClass()).toCql(),
entity, options, converter);
Update update = QueryUtils.createUpdateQuery(getTableName(entity.getClass()).toCql(), entity, options, converter);
return cqlOperations.execute(new StatementCallback<>(update, entity));
}
@@ -378,8 +375,7 @@ public class CassandraTemplate implements CassandraOperations {
Assert.notNull(entity, "Entity must not be null");
Delete delete = QueryUtils.createDeleteQuery(getTableName(entity.getClass()).toCql(),
entity, options, converter);
Delete delete = QueryUtils.createDeleteQuery(getTableName(entity.getClass()).toCql(), entity, options, converter);
return cqlOperations.execute(new StatementCallback<>(delete, entity));
}

View File

@@ -459,7 +459,12 @@ public class BasicCassandraMappingContext
Optional<CassandraPersistentEntity<?>> persistentEntity = getPersistentEntity(property.getActualType());
if (persistentEntity.filter(CassandraPersistentEntity::isUserDefinedType).isPresent()) {
return persistentEntity.get().getUserType();
Optional<DataType> dataType = persistentEntity.map(it -> getUserDataType(property, dataTypeProvider, it));
if (dataType.isPresent()) {
return dataType.get();
}
}
if (customConversions.hasCustomWriteTarget(property.getType())) {

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.repository.cdi;
import java.lang.annotation.Annotation;
@@ -50,8 +49,8 @@ public class CassandraRepositoryBean<T> extends CdiRepositoryBean<T> {
* implementations {@link CustomRepositoryImplementationDetector}, can be {@literal null}.
*/
public CassandraRepositoryBean(Bean<CassandraOperations> operations, Set<Annotation> qualifiers,
Class<T> repositoryType, BeanManager beanManager, Optional<CustomRepositoryImplementationDetector> detector) {
super(qualifiers, repositoryType, beanManager, detector);
Class<T> repositoryType, BeanManager beanManager, CustomRepositoryImplementationDetector detector) {
super(qualifiers, repositoryType, beanManager, Optional.of(detector));
Assert.notNull(operations, "Cannot create repository with 'null' for CassandraOperations.");
this.cassandraOperationsBean = operations;
@@ -64,14 +63,14 @@ public class CassandraRepositoryBean<T> extends CdiRepositoryBean<T> {
@Override
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType,
Optional<Object> customImplementation) {
CassandraOperations cassandraOperations = getDependencyInstance(cassandraOperationsBean, CassandraOperations.class);
if (customImplementation.isPresent()) {
return new CassandraRepositoryFactory(cassandraOperations).getRepository(repositoryType,
customImplementation.get());
}
CassandraRepositoryFactory factory = new CassandraRepositoryFactory(cassandraOperations);
return new CassandraRepositoryFactory(cassandraOperations).getRepository(repositoryType);
return customImplementation //
.map(o -> factory.getRepository(repositoryType, o)) //
.orElseGet(() -> factory.getRepository(repositoryType));
}
@Override

View File

@@ -16,7 +16,6 @@
package org.springframework.data.cassandra.repository.cdi;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
@@ -51,6 +50,7 @@ public class CassandraRepositoryExtension extends CdiRepositoryExtensionSupport
*/
@SuppressWarnings("unchecked")
<T> void processBean(@Observes ProcessBean<T> processBean) {
Bean<T> bean = processBean.getBean();
bean.getTypes().stream() //
.filter(type -> type instanceof Class<?> && CassandraOperations.class.isAssignableFrom((Class<?>) type)) //
@@ -88,12 +88,12 @@ public class CassandraRepositoryExtension extends CdiRepositoryExtensionSupport
private <T> CdiRepositoryBean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers,
BeanManager beanManager) {
Bean<CassandraOperations> cassandraOperationsBean = Optional.ofNullable(this.cassandraOperationsMap.get(qualifiers)).orElseThrow(() -> new UnsatisfiedResolutionException(String.format("Unable to resolve a bean for '%s' with qualifiers %s.",
CassandraOperations.class.getName(), qualifiers)));
Bean<CassandraOperations> cassandraOperationsBean = Optional.ofNullable(this.cassandraOperationsMap.get(qualifiers))
.orElseThrow(() -> new UnsatisfiedResolutionException(String.format(
"Unable to resolve a bean for '%s' with qualifiers %s.", CassandraOperations.class.getName(), qualifiers)));
return new CassandraRepositoryBean<>(cassandraOperationsBean, qualifiers, repositoryType, beanManager,
Optional.of(getCustomImplementationDetector()));
getCustomImplementationDetector());
}
}

View File

@@ -100,7 +100,6 @@ public abstract class AbstractCassandraQuery implements RepositoryQuery {
CassandraParameterAccessor parameterAccessor = new ConvertingParameterAccessor(template.getConverter(),
new CassandraParametersParameterAccessor(queryMethod, parameters));
// FIXME: Use ResultProcessor#withDynamicProjection(ParameterAccessor) when available
ResultProcessor resultProcessor = queryMethod.getResultProcessor().withDynamicProjection(parameterAccessor);
String query = createQuery(parameterAccessor);

View File

@@ -99,7 +99,6 @@ public abstract class AbstractReactiveCassandraQuery implements RepositoryQuery
String query = createQuery(convertingParameterAccessor);
// FIXME: Use ResultProcessor#withDynamicProjection(ParameterAccessor) when available
ResultProcessor resultProcessor = method.getResultProcessor().withDynamicProjection(convertingParameterAccessor);
ReactiveCassandraQueryExecution queryExecution = getExecution(

View File

@@ -266,7 +266,7 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
Optional<Person> loaded = repository.findOne(dave.getId());
assertThat(loaded).isPresent();
assertThat(loaded).isEmpty();
}
@Test // DATACASS-396
@@ -276,7 +276,7 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
Optional<Person> loaded = repository.findOne(dave.getId());
assertThat(loaded).isPresent();
assertThat(loaded).isEmpty();
}
@Test // DATACASS-396
@@ -286,7 +286,7 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
Optional<Person> loaded = repository.findOne(boyd.getId());
assertThat(loaded).isPresent();
assertThat(loaded).isEmpty();
}
interface PersonRepostitory extends TypedIdCassandraRepository<Person, String> {}