Skip to content

Commit 0e1e594

Browse files
committed
Explore returning Search Results.
Closes #1573
1 parent 1b0a4da commit 0e1e594

26 files changed

+892
-144
lines changed

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

+15-14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.stream.Stream;
2121

2222
import org.jspecify.annotations.Nullable;
23+
2324
import org.springframework.dao.DataAccessException;
2425
import org.springframework.data.cassandra.core.convert.CassandraConverter;
2526
import org.springframework.data.cassandra.core.cql.CqlOperations;
@@ -92,7 +93,7 @@ default CassandraBatchOperations batchOps() {
9293
/**
9394
* The table name used for the specified class by this template.
9495
*
95-
* @param entityClass The entity type must not be {@literal null}.
96+
* @param entityClass the entity type must not be {@literal null}.
9697
* @return the {@link CqlIdentifier}
9798
*/
9899
CqlIdentifier getTableName(Class<?> entityClass);
@@ -105,7 +106,7 @@ default CassandraBatchOperations batchOps() {
105106
* Execute a {@code SELECT} query and convert the resulting items to a {@link List} of entities.
106107
*
107108
* @param cql must not be {@literal null}.
108-
* @param entityClass The entity type must not be {@literal null}.
109+
* @param entityClass the entity type must not be {@literal null}.
109110
* @return the converted results
110111
* @throws DataAccessException if there is any problem executing the query.
111112
*/
@@ -129,7 +130,7 @@ default CassandraBatchOperations batchOps() {
129130
* Execute a {@code SELECT} query and convert the resulting item to an entity.
130131
*
131132
* @param cql must not be {@literal null}.
132-
* @param entityClass The entity type must not be {@literal null}.
133+
* @param entityClass the entity type must not be {@literal null}.
133134
* @return the converted object or {@literal null}.
134135
* @throws DataAccessException if there is any problem executing the query.
135136
*/
@@ -154,7 +155,7 @@ default CassandraBatchOperations batchOps() {
154155
* Execute a {@code SELECT} query and convert the resulting items to a {@link List} of entities.
155156
*
156157
* @param statement must not be {@literal null}.
157-
* @param entityClass The entity type must not be {@literal null}.
158+
* @param entityClass the entity type must not be {@literal null}.
158159
* @return the converted results
159160
* @throws DataAccessException if there is any problem executing the query.
160161
*/
@@ -165,7 +166,7 @@ default CassandraBatchOperations batchOps() {
165166
* query translates the effective {@link Statement#getPageSize()} to the page size.
166167
*
167168
* @param statement the CQL statement, must not be {@literal null}.
168-
* @param entityClass The entity type must not be {@literal null}.
169+
* @param entityClass the entity type must not be {@literal null}.
169170
* @return the converted results
170171
* @throws DataAccessException if there is any problem executing the query.
171172
* @since 2.0
@@ -190,7 +191,7 @@ default CassandraBatchOperations batchOps() {
190191
* Execute a {@code SELECT} query and convert the resulting item to an entity.
191192
*
192193
* @param statement must not be {@literal null}.
193-
* @param entityClass The entity type must not be {@literal null}.
194+
* @param entityClass the entity type must not be {@literal null}.
194195
* @return the converted object or {@literal null}.
195196
* @throws DataAccessException if there is any problem executing the query.
196197
*/
@@ -204,7 +205,7 @@ default CassandraBatchOperations batchOps() {
204205
* Execute a {@code SELECT} query and convert the resulting items to a {@link List} of entities.
205206
*
206207
* @param query must not be {@literal null}.
207-
* @param entityClass The entity type must not be {@literal null}.
208+
* @param entityClass the entity type must not be {@literal null}.
208209
* @return the converted results
209210
* @throws DataAccessException if there is any problem executing the query.
210211
* @since 2.0
@@ -215,7 +216,7 @@ default CassandraBatchOperations batchOps() {
215216
* Execute a {@code SELECT} query with paging and convert the result set to a {@link Slice} of entities.
216217
*
217218
* @param query the query object used to create a CQL statement, must not be {@literal null}.
218-
* @param entityClass The entity type must not be {@literal null}.
219+
* @param entityClass the entity type must not be {@literal null}.
219220
* @return the converted results
220221
* @throws DataAccessException if there is any problem executing the query.
221222
* @since 2.0
@@ -241,7 +242,7 @@ default CassandraBatchOperations batchOps() {
241242
* Execute a {@code SELECT} query and convert the resulting item to an entity.
242243
*
243244
* @param query must not be {@literal null}.
244-
* @param entityClass The entity type must not be {@literal null}.
245+
* @param entityClass the entity type must not be {@literal null}.
245246
* @return the converted object or {@literal null}.
246247
* @throws DataAccessException if there is any problem executing the query.
247248
* @since 2.0
@@ -253,7 +254,7 @@ default CassandraBatchOperations batchOps() {
253254
*
254255
* @param query must not be {@literal null}.
255256
* @param update must not be {@literal null}.
256-
* @param entityClass The entity type must not be {@literal null}.
257+
* @param entityClass the entity type must not be {@literal null}.
257258
* @throws DataAccessException if there is any problem executing the query.
258259
*/
259260
boolean update(Query query, Update update, Class<?> entityClass) throws DataAccessException;
@@ -262,7 +263,7 @@ default CassandraBatchOperations batchOps() {
262263
* Remove entities (rows)/columns from the table by {@link Query}.
263264
*
264265
* @param query must not be {@literal null}.
265-
* @param entityClass The entity type must not be {@literal null}.
266+
* @param entityClass the entity type must not be {@literal null}.
266267
* @throws DataAccessException if there is any problem executing the query.
267268
*/
268269
boolean delete(Query query, Class<?> entityClass) throws DataAccessException;
@@ -322,7 +323,7 @@ default CassandraBatchOperations batchOps() {
322323
* @param id the Id value. For single primary keys it's the plain value. For composite primary keys either the
323324
* {@link org.springframework.data.cassandra.core.mapping.PrimaryKeyClass} or
324325
* {@link org.springframework.data.cassandra.core.mapping.MapId}. Must not be {@literal null}.
325-
* @param entityClass The entity type must not be {@literal null}.
326+
* @param entityClass the entity type must not be {@literal null}.
326327
* @return the converted object or {@literal null}.
327328
* @throws DataAccessException if there is any problem executing the query.
328329
*/
@@ -407,15 +408,15 @@ default WriteResult delete(Object entity, DeleteOptions options) throws DataAcce
407408
* @param id the Id value. For single primary keys it's the plain value. For composite primary keys either the
408409
* {@link org.springframework.data.cassandra.core.mapping.PrimaryKeyClass} or
409410
* {@link org.springframework.data.cassandra.core.mapping.MapId}. Must not be {@literal null}.
410-
* @param entityClass The entity type must not be {@literal null}.
411+
* @param entityClass the entity type must not be {@literal null}.
411412
* @throws DataAccessException if there is any problem executing the query.
412413
*/
413414
boolean deleteById(Object id, Class<?> entityClass) throws DataAccessException;
414415

415416
/**
416417
* Execute a {@code TRUNCATE} query to remove all entities of a given class.
417418
*
418-
* @param entityClass The entity type must not be {@literal null}.
419+
* @param entityClass the entity type must not be {@literal null}.
419420
* @throws DataAccessException if there is any problem executing the query.
420421
*/
421422
void truncate(Class<?> entityClass) throws DataAccessException;

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ public <T> List<T> select(Statement<?> statement, Class<T> entityClass) {
354354
Assert.notNull(statement, "Statement must not be null");
355355
Assert.notNull(entityClass, "Entity type must not be null");
356356

357-
return doSelect(statement, entityClass, getTableName(entityClass), entityClass, QueryResultConverter.entity());
357+
return doSelect(statement, entityClass, EntityQueryUtils.getTableName(statement), entityClass,
358+
QueryResultConverter.entity());
358359
}
359360

360361
<T, R> List<R> doSelect(Statement<?> statement, Class<?> entityClass, CqlIdentifier tableName, Class<T> returnType,

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -767,12 +767,11 @@ private static com.datastax.oss.driver.api.querybuilder.select.Selector getSelec
767767
.stream().map(param -> {
768768

769769
if (param instanceof ColumnSelector s) {
770-
771-
return com.datastax.oss.driver.api.querybuilder.select.Selector.column(s.getExpression());
770+
return com.datastax.oss.driver.api.querybuilder.select.Selector.column(s.getIdentifier());
772771
}
773772

774773
if (param instanceof CqlIdentifier i) {
775-
return com.datastax.oss.driver.api.querybuilder.select.Selector.column(i.toString());
774+
return com.datastax.oss.driver.api.querybuilder.select.Selector.column(i);
776775
}
777776

778777
return new SimpleSelector(param.toString());

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

-27
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,9 @@ static Collection<Object> getConvertersToRegister() {
7373

7474
converters.add(VectorToFloatArrayConverter.INSTANCE);
7575
converters.add(VectorToDoubleArrayConverter.INSTANCE);
76-
converters.add(VectorToFloatListConverter.INSTANCE);
7776

7877
converters.add(FloatArrayToVectorConverter.INSTANCE);
7978
converters.add(DoubleArrayToVectorConverter.INSTANCE);
80-
converters.add(NumberListToVectorConverter.INSTANCE);
8179

8280
converters.add(VectorToCqlVectorConverter.INSTANCE);
8381
converters.add(CqlVectorToVectorConverter.INSTANCE);
@@ -307,17 +305,6 @@ public CqlVector<Float> convert(float[] source) {
307305
}
308306
}
309307

310-
@ReadingConverter
311-
public enum NumberListToVectorConverter implements Converter<List<Number>, CqlVector<Number>> {
312-
313-
INSTANCE;
314-
315-
@Override
316-
public CqlVector<Number> convert(List<Number> source) {
317-
return CqlVector.newInstance(source);
318-
}
319-
}
320-
321308
@ReadingConverter
322309
public enum VectorToFloatArrayConverter implements Converter<CqlVector<Number>, float[]> {
323310

@@ -348,18 +335,4 @@ public double[] convert(CqlVector<Number> source) {
348335
}
349336
}
350337

351-
@ReadingConverter
352-
public enum VectorToFloatListConverter implements Converter<CqlVector<Number>, List<Float>> {
353-
354-
INSTANCE;
355-
356-
@Override
357-
public List<Float> convert(CqlVector<Number> source) {
358-
List<Float> values = new ArrayList<>(source.size());
359-
for (int i = 0; i < source.size(); i++) {
360-
values.add(source.get(i).floatValue());
361-
}
362-
return values;
363-
}
364-
}
365338
}

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public List<Selector> getMappedSelectors(Columns columns, CassandraPersistentEnt
199199

200200
Field field = createPropertyField(entity, column);
201201

202-
columns.getSelector(column).ifPresent(selector -> {
202+
columns.getSelector(column).forEach(selector -> {
203203

204204
List<CqlIdentifier> mappedColumnNames = getCqlIdentifier(column, field);
205205

@@ -301,8 +301,12 @@ public List<CqlIdentifier> getMappedColumnNames(Columns columns, CassandraPersis
301301
Field field = createPropertyField(entity, column);
302302
field.getProperty().ifPresent(seen::add);
303303

304-
columns.getSelector(column).filter(selector -> selector instanceof ColumnSelector)
305-
.ifPresent(columnSelector -> columnNames.addAll(getCqlIdentifier(column, field)));
304+
columns.getSelector(column).forEach(columnSelector -> {
305+
306+
if (columnSelector instanceof ColumnSelector) {
307+
columnNames.addAll(getCqlIdentifier(column, field));
308+
}
309+
});
306310
}
307311

308312
if (columns.isEmpty()) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public Optional<CqlIdentifier> getCqlIdentifier() {
169169

170170
@Override
171171
public String toCql() {
172-
return this.cqlIdentifier.toString();
172+
return this.cqlIdentifier.asInternal();
173173
}
174174

175175
@Override

0 commit comments

Comments
 (0)