Skip to content

Commit 46d502a

Browse files
committed
Revise query operations in Template API.
Introduce QueryOperations as central abstraction for all query functionality to delegate to StatementFactory and handle RowMapper creation. Encapsulate Deduplicate functionality from Template API, move projection introspection into StatementFactory as it is used from there mostly. Closes #1610
1 parent ee24bf2 commit 46d502a

File tree

10 files changed

+981
-756
lines changed

10 files changed

+981
-756
lines changed

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/AsyncCassandraTemplate.java

Lines changed: 57 additions & 114 deletions
Large diffs are not rendered by default.

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraTemplate.java

Lines changed: 123 additions & 234 deletions
Large diffs are not rendered by default.

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/EntityOperations.java

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,16 @@
1616
package org.springframework.data.cassandra.core;
1717

1818
import org.jspecify.annotations.Nullable;
19+
1920
import org.springframework.core.convert.ConversionService;
2021
import org.springframework.data.cassandra.core.convert.CassandraConverter;
2122
import org.springframework.data.cassandra.core.cql.util.StatementBuilder;
2223
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
2324
import org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty;
24-
import org.springframework.data.convert.CustomConversions;
2525
import org.springframework.data.mapping.PersistentPropertyAccessor;
2626
import org.springframework.data.mapping.context.MappingContext;
2727
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
28-
import org.springframework.data.projection.EntityProjection;
29-
import org.springframework.data.projection.EntityProjectionIntrospector;
30-
import org.springframework.data.projection.ProjectionFactory;
3128
import org.springframework.util.Assert;
32-
import org.springframework.util.ClassUtils;
3329

3430
import com.datastax.oss.driver.api.core.CqlIdentifier;
3531
import com.datastax.oss.driver.api.querybuilder.condition.Condition;
@@ -49,19 +45,9 @@
4945
class EntityOperations {
5046

5147
private final MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext;
52-
private final EntityProjectionIntrospector introspector;
5348

5449
EntityOperations(CassandraConverter converter) {
55-
this(converter.getMappingContext(), converter.getCustomConversions(), converter.getProjectionFactory());
56-
}
57-
58-
EntityOperations(MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> context,
59-
CustomConversions conversions, ProjectionFactory projectionFactory) {
60-
this.mappingContext = context;
61-
this.introspector = EntityProjectionIntrospector.create(projectionFactory,
62-
EntityProjectionIntrospector.ProjectionPredicate.typeHierarchy()
63-
.and(((target, underlyingType) -> !conversions.isSimpleType(target))),
64-
context);
50+
this.mappingContext = converter.getMappingContext();
6551
}
6652

6753
/**
@@ -92,41 +78,6 @@ public <T> AdaptibleEntity<T> forEntity(T entity, ConversionService conversionSe
9278
return AdaptibleMappedEntity.of(entity, getMappingContext(), conversionService);
9379
}
9480

95-
/**
96-
* Returns the {@link MappingContext} used by this entity data access operations class to access mapping meta-data
97-
* used to store (map) object to Cassandra tables.
98-
*
99-
* @return the {@link MappingContext} used by this entity data access operations class.
100-
* @see org.springframework.data.cassandra.core.mapping.CassandraMappingContext
101-
*/
102-
CassandraPersistentEntity<?> getRequiredPersistentEntity(Class<?> entityClass) {
103-
return getMappingContext().getRequiredPersistentEntity(ClassUtils.getUserClass(entityClass));
104-
}
105-
106-
/**
107-
* Returns the table name to which the entity shall be persisted.
108-
*
109-
* @param entityClass entity class, must not be {@literal null}.
110-
* @return the table name to which the entity shall be persisted.
111-
*/
112-
CqlIdentifier getTableName(Class<?> entityClass) {
113-
return getRequiredPersistentEntity(entityClass).getTableName();
114-
}
115-
116-
/**
117-
* Introspect the given {@link Class result type} in the context of the {@link Class entity type} whether the returned
118-
* type is a projection and what property paths are participating in the projection.
119-
*
120-
* @param resultType the type to project on. Must not be {@literal null}.
121-
* @param entityType the source domain type. Must not be {@literal null}.
122-
* @return the introspection result.
123-
* @since 3.4
124-
* @see EntityProjectionIntrospector#introspect(Class, Class)
125-
*/
126-
public <M, D> EntityProjection<M, D> introspectProjection(Class<M> resultType, Class<D> entityType) {
127-
return introspector.introspect(resultType, entityType);
128-
}
129-
13081
protected MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> getMappingContext() {
13182
return this.mappingContext;
13283
}

0 commit comments

Comments
 (0)