@@ -283,6 +283,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <R> R project(EntityProjection<R, ?> projection, Row row) {
|
||||
|
||||
if (!projection.isProjection()) {
|
||||
@@ -665,7 +666,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
? getMappingContext().getRequiredPersistentEntity(compositeIdProperty)
|
||||
: entity;
|
||||
|
||||
writeWhere(MapId.class.cast(id), sink, whereEntity);
|
||||
writeWhere((MapId) id, sink, whereEntity);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -725,18 +726,6 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
}
|
||||
}
|
||||
|
||||
private void writeWhere(ConvertingPropertyAccessor<?> accessor, Where sink, CassandraPersistentEntity<?> entity) {
|
||||
|
||||
Assert.isTrue(entity.isCompositePrimaryKey(),
|
||||
() -> String.format("Entity [%s] is not a composite primary key", entity.getName()));
|
||||
|
||||
for (CassandraPersistentProperty property : entity) {
|
||||
TypeCodec<Object> codec = getCodec(property);
|
||||
Object value = accessor.getProperty(property, codec.getJavaType().getRawType());
|
||||
sink.put(property.getRequiredColumnName(), value);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeTupleValue(ConvertingPropertyAccessor<?> propertyAccessor, TupleValue tupleValue,
|
||||
CassandraPersistentEntity<?> entity) {
|
||||
|
||||
@@ -863,7 +852,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
*/
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T getWriteValue(CassandraPersistentProperty property, ConvertingPropertyAccessor propertyAccessor) {
|
||||
private <T> T getWriteValue(CassandraPersistentProperty property, ConvertingPropertyAccessor<?> propertyAccessor) {
|
||||
|
||||
ColumnType cassandraTypeDescriptor = cassandraTypeResolver.resolve(property);
|
||||
|
||||
@@ -914,7 +903,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
return writeMapInternal((Map<Object, Object>) value, columnType);
|
||||
}
|
||||
|
||||
TypeInformation<?> type = TypeInformation.of((Class) value.getClass());
|
||||
TypeInformation<?> type = TypeInformation.of((Class<?>) value.getClass());
|
||||
TypeInformation<?> actualType = type.getRequiredActualType();
|
||||
BasicCassandraPersistentEntity<?> entity = getMappingContext().getPersistentEntity(actualType.getType());
|
||||
|
||||
@@ -989,7 +978,6 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
* @param requestedTargetType must not be {@literal null}.
|
||||
* @see org.springframework.data.cassandra.core.mapping.CassandraType
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
private Object getPotentiallyConvertedSimpleValue(@Nullable Object value, @Nullable Class<?> requestedTargetType) {
|
||||
|
||||
@@ -1237,7 +1225,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
* Extension of {@link SpELExpressionParameterValueProvider} to recursively trigger value conversion on the raw
|
||||
* resolved SpEL value.
|
||||
*/
|
||||
private class ConverterAwareSpELExpressionParameterValueProvider
|
||||
private static class ConverterAwareSpELExpressionParameterValueProvider
|
||||
extends SpELExpressionParameterValueProvider<CassandraPersistentProperty> {
|
||||
|
||||
private final ConversionContext context;
|
||||
@@ -1450,16 +1438,8 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
}
|
||||
}
|
||||
|
||||
private static class PropertyTranslatingPropertyAccessor<T> implements PersistentPropertyAccessor<T> {
|
||||
|
||||
private final PersistentPropertyAccessor<T> delegate;
|
||||
private final PersistentPropertyTranslator propertyTranslator;
|
||||
|
||||
private PropertyTranslatingPropertyAccessor(PersistentPropertyAccessor<T> delegate,
|
||||
PersistentPropertyTranslator propertyTranslator) {
|
||||
this.delegate = delegate;
|
||||
this.propertyTranslator = propertyTranslator;
|
||||
}
|
||||
private record PropertyTranslatingPropertyAccessor<T> (PersistentPropertyAccessor<T> delegate,
|
||||
PersistentPropertyTranslator propertyTranslator) implements PersistentPropertyAccessor<T> {
|
||||
|
||||
static <T> PersistentPropertyAccessor<T> create(PersistentPropertyAccessor<T> delegate,
|
||||
PersistentPropertyTranslator propertyTranslator) {
|
||||
@@ -1549,7 +1529,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
|
||||
@Override
|
||||
public void setProperty(PersistentProperty<?> persistentProperty, Object o) {
|
||||
public void setProperty(PersistentProperty<?> persistentProperty, @Nullable Object o) {
|
||||
map.put(persistentProperty.getName(), o);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@ package org.springframework.data.cassandra.repository.query;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.cassandra.core.CassandraOperations;
|
||||
import org.springframework.data.cassandra.core.convert.CassandraConverter;
|
||||
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
|
||||
import org.springframework.data.cassandra.repository.query.CassandraQueryExecution.CollectionExecution;
|
||||
import org.springframework.data.cassandra.repository.query.CassandraQueryExecution.ExistsExecution;
|
||||
import org.springframework.data.cassandra.repository.query.CassandraQueryExecution.ResultProcessingConverter;
|
||||
@@ -31,7 +29,6 @@ import org.springframework.data.repository.query.ParameterAccessor;
|
||||
import org.springframework.data.repository.query.RepositoryQuery;
|
||||
import org.springframework.data.repository.query.ResultProcessor;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
|
||||
import com.datastax.oss.driver.api.core.cql.Statement;
|
||||
@@ -56,7 +53,7 @@ public abstract class AbstractCassandraQuery extends CassandraRepositoryQuerySup
|
||||
*/
|
||||
public AbstractCassandraQuery(CassandraQueryMethod queryMethod, CassandraOperations operations) {
|
||||
|
||||
super(queryMethod, toMappingContext(operations));
|
||||
super(queryMethod, operations.getConverter().getMappingContext());
|
||||
|
||||
this.operations = operations;
|
||||
}
|
||||
@@ -81,7 +78,7 @@ public abstract class AbstractCassandraQuery extends CassandraRepositoryQuerySup
|
||||
Statement<?> statement = createQuery(parameterAccessor);
|
||||
|
||||
CassandraQueryExecution queryExecution = getExecution(parameterAccessor,
|
||||
new ResultProcessingConverter(resultProcessor, toMappingContext(getOperations()), getEntityInstantiators()));
|
||||
new ResultProcessingConverter(resultProcessor, getMappingContext(), getEntityInstantiators()));
|
||||
|
||||
Class<?> resultType = resolveResultType(resultProcessor);
|
||||
|
||||
@@ -170,14 +167,4 @@ public abstract class AbstractCassandraQuery extends CassandraRepositoryQuerySup
|
||||
*/
|
||||
protected abstract boolean isModifyingQuery();
|
||||
|
||||
private static CassandraConverter toConverter(CassandraOperations operations) {
|
||||
|
||||
Assert.notNull(operations, "CassandraOperations must not be null");
|
||||
|
||||
return operations.getConverter();
|
||||
}
|
||||
|
||||
private static CassandraMappingContext toMappingContext(CassandraOperations operations) {
|
||||
return toConverter(operations).getMappingContext();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@ import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.cassandra.ReactiveResultSet;
|
||||
import org.springframework.data.cassandra.core.CassandraOperations;
|
||||
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
|
||||
import org.springframework.data.cassandra.core.convert.CassandraConverter;
|
||||
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
|
||||
import org.springframework.data.cassandra.repository.query.ReactiveCassandraQueryExecution.CollectionExecution;
|
||||
import org.springframework.data.cassandra.repository.query.ReactiveCassandraQueryExecution.ExistsExecution;
|
||||
import org.springframework.data.cassandra.repository.query.ReactiveCassandraQueryExecution.ResultProcessingConverter;
|
||||
@@ -33,7 +31,6 @@ import org.springframework.data.cassandra.repository.query.ReactiveCassandraQuer
|
||||
import org.springframework.data.repository.query.ParameterAccessor;
|
||||
import org.springframework.data.repository.query.RepositoryQuery;
|
||||
import org.springframework.data.repository.query.ResultProcessor;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
|
||||
|
||||
@@ -58,7 +55,7 @@ public abstract class AbstractReactiveCassandraQuery extends CassandraRepository
|
||||
*/
|
||||
public AbstractReactiveCassandraQuery(ReactiveCassandraQueryMethod method, ReactiveCassandraOperations operations) {
|
||||
|
||||
super(method, getRequiredMappingContext(operations));
|
||||
super(method, operations.getConverter().getMappingContext());
|
||||
|
||||
this.operations = operations;
|
||||
}
|
||||
@@ -83,8 +80,8 @@ public abstract class AbstractReactiveCassandraQuery extends CassandraRepository
|
||||
|
||||
Mono<SimpleStatement> statement = createQuery(parameterAccessor);
|
||||
ResultProcessor resultProcessor = getQueryMethod().getResultProcessor().withDynamicProjection(parameterAccessor);
|
||||
ReactiveCassandraQueryExecution queryExecution = getExecution(parameterAccessor, new ResultProcessingConverter(
|
||||
resultProcessor, getRequiredMappingContext(getReactiveCassandraOperations()), getEntityInstantiators()));
|
||||
ReactiveCassandraQueryExecution queryExecution = getExecution(parameterAccessor,
|
||||
new ResultProcessingConverter(resultProcessor, getMappingContext(), getEntityInstantiators()));
|
||||
|
||||
Class<?> resultType = resolveResultType(resultProcessor);
|
||||
|
||||
@@ -94,7 +91,7 @@ public abstract class AbstractReactiveCassandraQuery extends CassandraRepository
|
||||
private Class<?> resolveResultType(ResultProcessor resultProcessor) {
|
||||
|
||||
CassandraReturnedType returnedType = new CassandraReturnedType(resultProcessor.getReturnedType(),
|
||||
getRequiredConverter(getReactiveCassandraOperations()).getCustomConversions());
|
||||
getReactiveCassandraOperations().getConverter().getCustomConversions());
|
||||
|
||||
return returnedType.getResultType();
|
||||
}
|
||||
@@ -173,14 +170,4 @@ public abstract class AbstractReactiveCassandraQuery extends CassandraRepository
|
||||
*/
|
||||
protected abstract boolean isModifyingQuery();
|
||||
|
||||
private static CassandraConverter getRequiredConverter(ReactiveCassandraOperations operations) {
|
||||
|
||||
Assert.notNull(operations, "ReactiveCassandraOperations must not be null");
|
||||
|
||||
return operations.getConverter();
|
||||
}
|
||||
|
||||
private static CassandraMappingContext getRequiredMappingContext(ReactiveCassandraOperations operations) {
|
||||
return getRequiredConverter(operations).getMappingContext();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ public abstract class CassandraRepositoryQuerySupport implements RepositoryQuery
|
||||
|
||||
private final QueryStatementCreator queryStatementCreator;
|
||||
|
||||
private final MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext;
|
||||
|
||||
/**
|
||||
* Create a new {@link AbstractCassandraQuery} from the given {@link CassandraQueryMethod} and
|
||||
* {@link CassandraOperations}.
|
||||
@@ -78,6 +80,7 @@ public abstract class CassandraRepositoryQuerySupport implements RepositoryQuery
|
||||
this.queryMethod = queryMethod;
|
||||
this.instantiators = new EntityInstantiators();
|
||||
this.queryStatementCreator = new QueryStatementCreator(queryMethod, mappingContext);
|
||||
this.mappingContext = mappingContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,6 +96,10 @@ public abstract class CassandraRepositoryQuerySupport implements RepositoryQuery
|
||||
return this.queryStatementCreator;
|
||||
}
|
||||
|
||||
protected MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> getMappingContext() {
|
||||
return mappingContext;
|
||||
}
|
||||
|
||||
class CassandraReturnedType {
|
||||
|
||||
private final ReturnedType returnedType;
|
||||
|
||||
Reference in New Issue
Block a user