Skip to content

Commit a9a3919

Browse files
committed
#330 - Adapt to Criteria objects in Spring Data Relational.
1 parent dbe935c commit a9a3919

26 files changed

+208
-479
lines changed

Diff for: src/main/java/org/springframework/data/r2dbc/core/DatabaseClient.java

+19-9
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
import org.springframework.data.domain.Sort;
3535
import org.springframework.data.projection.ProjectionFactory;
3636
import org.springframework.data.r2dbc.mapping.SettableValue;
37-
import org.springframework.data.r2dbc.query.Criteria;
3837
import org.springframework.data.r2dbc.query.Update;
3938
import org.springframework.data.r2dbc.support.R2dbcExceptionTranslator;
39+
import org.springframework.data.relational.core.query.CriteriaDefinition;
4040
import org.springframework.data.relational.core.sql.SqlIdentifier;
4141
import org.springframework.util.Assert;
4242

@@ -529,11 +529,11 @@ default S project(String... selectedFields) {
529529
S project(SqlIdentifier... selectedFields);
530530

531531
/**
532-
* Configure a filter {@link Criteria}.
532+
* Configure a filter {@link CriteriaDefinition}.
533533
*
534534
* @param criteria must not be {@literal null}.
535535
*/
536-
S matching(Criteria criteria);
536+
S matching(CriteriaDefinition criteria);
537537

538538
/**
539539
* Configure {@link Sort}.
@@ -705,8 +705,18 @@ interface GenericUpdateSpec {
705705
* Specify an {@link Update} object containing assignments.
706706
*
707707
* @param update must not be {@literal null}.
708+
* @deprecated since 1.1, use {@link #using(org.springframework.data.relational.core.query.Update)}.
708709
*/
710+
@Deprecated
709711
UpdateMatchingSpec using(Update update);
712+
713+
/**
714+
* Specify an {@link Update} object containing assignments.
715+
*
716+
* @param update must not be {@literal null}.
717+
* @since 1.1
718+
*/
719+
UpdateMatchingSpec using(org.springframework.data.relational.core.query.Update update);
710720
}
711721

712722
/**
@@ -750,11 +760,11 @@ default TypedUpdateSpec<T> table(String tableName) {
750760
interface UpdateMatchingSpec extends UpdateSpec {
751761

752762
/**
753-
* Configure a filter {@link Criteria}.
763+
* Configure a filter {@link CriteriaDefinition}.
754764
*
755765
* @param criteria must not be {@literal null}.
756766
*/
757-
UpdateSpec matching(Criteria criteria);
767+
UpdateSpec matching(CriteriaDefinition criteria);
758768
}
759769

760770
/**
@@ -801,11 +811,11 @@ default TypedDeleteSpec<T> table(String tableName) {
801811
TypedDeleteSpec<T> table(SqlIdentifier tableName);
802812

803813
/**
804-
* Configure a filter {@link Criteria}.
814+
* Configure a filter {@link CriteriaDefinition}.
805815
*
806816
* @param criteria must not be {@literal null}.
807817
*/
808-
DeleteSpec matching(Criteria criteria);
818+
DeleteSpec matching(CriteriaDefinition criteria);
809819
}
810820

811821
/**
@@ -814,11 +824,11 @@ default TypedDeleteSpec<T> table(String tableName) {
814824
interface DeleteMatchingSpec extends DeleteSpec {
815825

816826
/**
817-
* Configure a filter {@link Criteria}.
827+
* Configure a filter {@link CriteriaDefinition}.
818828
*
819829
* @param criteria must not be {@literal null}.
820830
*/
821-
DeleteSpec matching(Criteria criteria);
831+
DeleteSpec matching(CriteriaDefinition criteria);
822832
}
823833

824834
/**

Diff for: src/main/java/org/springframework/data/r2dbc/core/DefaultDatabaseClient.java

+35-19
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import org.springframework.data.r2dbc.query.Criteria;
6161
import org.springframework.data.r2dbc.query.Update;
6262
import org.springframework.data.r2dbc.support.R2dbcExceptionTranslator;
63+
import org.springframework.data.relational.core.query.CriteriaDefinition;
6364
import org.springframework.data.relational.core.sql.SqlIdentifier;
6465
import org.springframework.lang.Nullable;
6566
import org.springframework.util.Assert;
@@ -683,7 +684,7 @@ private abstract class DefaultSelectSpecSupport {
683684

684685
final SqlIdentifier table;
685686
final List<SqlIdentifier> projectedFields;
686-
final @Nullable Criteria criteria;
687+
final @Nullable CriteriaDefinition criteria;
687688
final Sort sort;
688689
final Pageable page;
689690

@@ -698,7 +699,8 @@ private abstract class DefaultSelectSpecSupport {
698699
this.page = Pageable.unpaged();
699700
}
700701

701-
DefaultSelectSpecSupport(SqlIdentifier table, List<SqlIdentifier> projectedFields, @Nullable Criteria criteria,
702+
DefaultSelectSpecSupport(SqlIdentifier table, List<SqlIdentifier> projectedFields,
703+
@Nullable CriteriaDefinition criteria,
702704
Sort sort, Pageable page) {
703705
this.table = table;
704706
this.projectedFields = projectedFields;
@@ -717,7 +719,7 @@ public DefaultSelectSpecSupport project(SqlIdentifier... selectedFields) {
717719
return createInstance(this.table, projectedFields, this.criteria, this.sort, this.page);
718720
}
719721

720-
public DefaultSelectSpecSupport where(Criteria whereCriteria) {
722+
public DefaultSelectSpecSupport where(CriteriaDefinition whereCriteria) {
721723

722724
Assert.notNull(whereCriteria, "Criteria must not be null!");
723725

@@ -753,12 +755,13 @@ <R> FetchSpec<R> execute(PreparedOperation<?> preparedOperation, BiFunction<Row,
753755
}
754756

755757
protected abstract DefaultSelectSpecSupport createInstance(SqlIdentifier table, List<SqlIdentifier> projectedFields,
756-
@Nullable Criteria criteria, Sort sort, Pageable page);
758+
@Nullable CriteriaDefinition criteria, Sort sort, Pageable page);
757759
}
758760

759761
private class DefaultGenericSelectSpec extends DefaultSelectSpecSupport implements GenericSelectSpec {
760762

761-
DefaultGenericSelectSpec(SqlIdentifier table, List<SqlIdentifier> projectedFields, @Nullable Criteria criteria,
763+
DefaultGenericSelectSpec(SqlIdentifier table, List<SqlIdentifier> projectedFields,
764+
@Nullable CriteriaDefinition criteria,
762765
Sort sort, Pageable page) {
763766
super(table, projectedFields, criteria, sort, page);
764767
}
@@ -806,7 +809,7 @@ public DefaultGenericSelectSpec project(SqlIdentifier... selectedFields) {
806809
}
807810

808811
@Override
809-
public DefaultGenericSelectSpec matching(Criteria criteria) {
812+
public DefaultGenericSelectSpec matching(CriteriaDefinition criteria) {
810813
return (DefaultGenericSelectSpec) super.where(criteria);
811814
}
812815

@@ -842,7 +845,7 @@ private <R> FetchSpec<R> exchange(BiFunction<Row, RowMetadata, R> mappingFunctio
842845

843846
@Override
844847
protected DefaultGenericSelectSpec createInstance(SqlIdentifier table, List<SqlIdentifier> projectedFields,
845-
@Nullable Criteria criteria, Sort sort, Pageable page) {
848+
@Nullable CriteriaDefinition criteria, Sort sort, Pageable page) {
846849
return new DefaultGenericSelectSpec(table, projectedFields, criteria, sort, page);
847850
}
848851
}
@@ -864,7 +867,8 @@ private class DefaultTypedSelectSpec<T> extends DefaultSelectSpecSupport impleme
864867
this.mappingFunction = dataAccessStrategy.getRowMapper(typeToRead);
865868
}
866869

867-
DefaultTypedSelectSpec(SqlIdentifier table, List<SqlIdentifier> projectedFields, @Nullable Criteria criteria,
870+
DefaultTypedSelectSpec(SqlIdentifier table, List<SqlIdentifier> projectedFields,
871+
@Nullable CriteriaDefinition criteria,
868872
Sort sort, Pageable page, Class<T> typeToRead, BiFunction<Row, RowMetadata, T> mappingFunction) {
869873

870874
super(table, projectedFields, criteria, sort, page);
@@ -912,7 +916,7 @@ public DefaultTypedSelectSpec<T> project(SqlIdentifier... selectedFields) {
912916
}
913917

914918
@Override
915-
public DefaultTypedSelectSpec<T> matching(Criteria criteria) {
919+
public DefaultTypedSelectSpec<T> matching(CriteriaDefinition criteria) {
916920
return (DefaultTypedSelectSpec<T>) super.where(criteria);
917921
}
918922

@@ -956,7 +960,7 @@ private <R> FetchSpec<R> exchange(BiFunction<Row, RowMetadata, R> mappingFunctio
956960

957961
@Override
958962
protected DefaultTypedSelectSpec<T> createInstance(SqlIdentifier table, List<SqlIdentifier> projectedFields,
959-
@Nullable Criteria criteria, Sort sort, Pageable page) {
963+
@Nullable CriteriaDefinition criteria, Sort sort, Pageable page) {
960964
return new DefaultTypedSelectSpec<>(table, projectedFields, criteria, sort, page, this.typeToRead,
961965
this.mappingFunction);
962966
}
@@ -1204,11 +1208,12 @@ class DefaultGenericUpdateSpec implements GenericUpdateSpec, UpdateMatchingSpec
12041208

12051209
private final @Nullable Class<?> typeToUpdate;
12061210
private final @Nullable SqlIdentifier table;
1207-
private final @Nullable Update assignments;
1208-
private final @Nullable Criteria where;
1211+
private final @Nullable org.springframework.data.relational.core.query.Update assignments;
1212+
private final @Nullable CriteriaDefinition where;
12091213

12101214
DefaultGenericUpdateSpec(@Nullable Class<?> typeToUpdate, @Nullable SqlIdentifier table,
1211-
@Nullable Update assignments, @Nullable Criteria where) {
1215+
@Nullable org.springframework.data.relational.core.query.Update assignments,
1216+
@Nullable CriteriaDefinition where) {
12121217
this.typeToUpdate = typeToUpdate;
12131218
this.table = table;
12141219
this.assignments = assignments;
@@ -1220,11 +1225,20 @@ public UpdateMatchingSpec using(Update update) {
12201225

12211226
Assert.notNull(update, "Update must not be null");
12221227

1228+
return new DefaultGenericUpdateSpec(this.typeToUpdate, this.table,
1229+
org.springframework.data.relational.core.query.Update.from(update.getAssignments()), this.where);
1230+
}
1231+
1232+
@Override
1233+
public UpdateMatchingSpec using(org.springframework.data.relational.core.query.Update update) {
1234+
1235+
Assert.notNull(update, "Update must not be null");
1236+
12231237
return new DefaultGenericUpdateSpec(this.typeToUpdate, this.table, update, this.where);
12241238
}
12251239

12261240
@Override
1227-
public UpdateSpec matching(Criteria criteria) {
1241+
public UpdateSpec matching(CriteriaDefinition criteria) {
12281242

12291243
Assert.notNull(criteria, "Criteria must not be null");
12301244

@@ -1333,11 +1347,12 @@ private UpdatedRowsFetchSpec exchange(SqlIdentifier table) {
13331347
}
13341348
Object id = columns.remove(ids.get(0)); // do not update the Id column.
13351349

1336-
Update update = null;
1350+
org.springframework.data.relational.core.query.Update update = null;
13371351

13381352
for (SqlIdentifier column : columns.keySet()) {
13391353
if (update == null) {
1340-
update = Update.update(dataAccessStrategy.toSql(column), columns.get(column));
1354+
update = org.springframework.data.relational.core.query.Update.update(dataAccessStrategy.toSql(column),
1355+
columns.get(column));
13411356
} else {
13421357
update = update.set(dataAccessStrategy.toSql(column), columns.get(column));
13431358
}
@@ -1376,16 +1391,17 @@ class DefaultDeleteSpec<T> implements DeleteMatchingSpec, TypedDeleteSpec<T> {
13761391

13771392
private final @Nullable Class<T> typeToDelete;
13781393
private final @Nullable SqlIdentifier table;
1379-
private final @Nullable Criteria where;
1394+
private final @Nullable CriteriaDefinition where;
13801395

1381-
DefaultDeleteSpec(@Nullable Class<T> typeToDelete, @Nullable SqlIdentifier table, @Nullable Criteria where) {
1396+
DefaultDeleteSpec(@Nullable Class<T> typeToDelete, @Nullable SqlIdentifier table,
1397+
@Nullable CriteriaDefinition where) {
13821398
this.typeToDelete = typeToDelete;
13831399
this.table = table;
13841400
this.where = where;
13851401
}
13861402

13871403
@Override
1388-
public DeleteSpec matching(Criteria criteria) {
1404+
public DeleteSpec matching(CriteriaDefinition criteria) {
13891405

13901406
Assert.notNull(criteria, "Criteria must not be null!");
13911407

Diff for: src/main/java/org/springframework/data/r2dbc/core/DefaultStatementMapper.java

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
* Default {@link StatementMapper} implementation.
4040
*
4141
* @author Mark Paluch
42+
* @author Roman Chigvintsev
4243
*/
4344
class DefaultStatementMapper implements StatementMapper {
4445

Diff for: src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityOperations.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
import org.springframework.dao.DataAccessException;
2222
import org.springframework.dao.TransientDataAccessResourceException;
23-
import org.springframework.data.r2dbc.query.Query;
24-
import org.springframework.data.r2dbc.query.Update;
23+
import org.springframework.data.relational.core.query.Query;
24+
import org.springframework.data.relational.core.query.Update;
2525

2626
/**
2727
* Interface specifying a basic set of reactive R2DBC operations using entities. Implemented by

Diff for: src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@
3737
import org.springframework.data.mapping.context.MappingContext;
3838
import org.springframework.data.projection.ProjectionInformation;
3939
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
40-
import org.springframework.data.r2dbc.query.Criteria;
41-
import org.springframework.data.r2dbc.query.Query;
42-
import org.springframework.data.r2dbc.query.Update;
4340
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
4441
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
42+
import org.springframework.data.relational.core.query.Criteria;
43+
import org.springframework.data.relational.core.query.CriteriaDefinition;
44+
import org.springframework.data.relational.core.query.Query;
45+
import org.springframework.data.relational.core.query.Update;
4546
import org.springframework.data.relational.core.sql.Expression;
4647
import org.springframework.data.relational.core.sql.Functions;
4748
import org.springframework.data.relational.core.sql.SqlIdentifier;
@@ -181,7 +182,7 @@ Mono<Long> doCount(Query query, Class<?> entityClass, SqlIdentifier tableName) {
181182
return spec.withProjection(Functions.count(table.column(entity.getRequiredIdProperty().getColumnName())));
182183
});
183184

184-
Optional<Criteria> criteria = query.getCriteria();
185+
Optional<CriteriaDefinition> criteria = query.getCriteria();
185186
if (criteria.isPresent()) {
186187
selectSpec = criteria.map(selectSpec::withCriteria).orElse(selectSpec);
187188
}
@@ -220,7 +221,7 @@ Mono<Boolean> doExists(Query query, Class<?> entityClass, SqlIdentifier tableNam
220221
.withProjection(columnName) //
221222
.limit(1);
222223

223-
Optional<Criteria> criteria = query.getCriteria();
224+
Optional<CriteriaDefinition> criteria = query.getCriteria();
224225
if (criteria.isPresent()) {
225226
selectSpec = criteria.map(selectSpec::withCriteria).orElse(selectSpec);
226227
}
@@ -266,7 +267,7 @@ <T> RowsFetchSpec<T> doSelect(Query query, Class<?> entityClass, SqlIdentifier t
266267
selectSpec = selectSpec.withSort(query.getSort());
267268
}
268269

269-
Optional<Criteria> criteria = query.getCriteria();
270+
Optional<CriteriaDefinition> criteria = query.getCriteria();
270271
if (criteria.isPresent()) {
271272
selectSpec = criteria.map(selectSpec::withCriteria).orElse(selectSpec);
272273
}
@@ -314,7 +315,7 @@ Mono<Integer> doUpdate(Query query, Update update, Class<?> entityClass, SqlIden
314315
StatementMapper.UpdateSpec selectSpec = statementMapper //
315316
.createUpdate(tableName, update);
316317

317-
Optional<Criteria> criteria = query.getCriteria();
318+
Optional<CriteriaDefinition> criteria = query.getCriteria();
318319
if (criteria.isPresent()) {
319320
selectSpec = criteria.map(selectSpec::withCriteria).orElse(selectSpec);
320321
}
@@ -343,7 +344,7 @@ Mono<Integer> doDelete(Query query, Class<?> entityClass, SqlIdentifier tableNam
343344
StatementMapper.DeleteSpec selectSpec = statementMapper //
344345
.createDelete(tableName);
345346

346-
Optional<Criteria> criteria = query.getCriteria();
347+
Optional<CriteriaDefinition> criteria = query.getCriteria();
347348
if (criteria.isPresent()) {
348349
selectSpec = criteria.map(selectSpec::withCriteria).orElse(selectSpec);
349350
}

Diff for: src/main/java/org/springframework/data/r2dbc/core/ReactiveDeleteOperation.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import reactor.core.publisher.Mono;
1919

20-
import org.springframework.data.r2dbc.query.Query;
20+
import org.springframework.data.relational.core.query.Query;
2121
import org.springframework.data.relational.core.sql.SqlIdentifier;
2222

2323
/**

Diff for: src/main/java/org/springframework/data/r2dbc/core/ReactiveDeleteOperationSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import reactor.core.publisher.Mono;
1919

20-
import org.springframework.data.r2dbc.query.Query;
20+
import org.springframework.data.relational.core.query.Query;
2121
import org.springframework.data.relational.core.sql.SqlIdentifier;
2222
import org.springframework.lang.Nullable;
2323
import org.springframework.util.Assert;

Diff for: src/main/java/org/springframework/data/r2dbc/core/ReactiveSelectOperation.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import reactor.core.publisher.Flux;
1919
import reactor.core.publisher.Mono;
2020

21-
import org.springframework.data.r2dbc.query.Query;
21+
import org.springframework.data.relational.core.query.Query;
2222
import org.springframework.data.relational.core.sql.SqlIdentifier;
2323

2424
/**

Diff for: src/main/java/org/springframework/data/r2dbc/core/ReactiveSelectOperationSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import reactor.core.publisher.Flux;
1919
import reactor.core.publisher.Mono;
2020

21-
import org.springframework.data.r2dbc.query.Query;
21+
import org.springframework.data.relational.core.query.Query;
2222
import org.springframework.data.relational.core.sql.SqlIdentifier;
2323
import org.springframework.lang.Nullable;
2424
import org.springframework.util.Assert;

Diff for: src/main/java/org/springframework/data/r2dbc/core/ReactiveUpdateOperation.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import reactor.core.publisher.Mono;
1919

20-
import org.springframework.data.r2dbc.query.Query;
21-
import org.springframework.data.r2dbc.query.Update;
20+
import org.springframework.data.relational.core.query.Query;
21+
import org.springframework.data.relational.core.query.Update;
2222
import org.springframework.data.relational.core.sql.SqlIdentifier;
2323

2424
/**

Diff for: src/main/java/org/springframework/data/r2dbc/core/ReactiveUpdateOperationSupport.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import reactor.core.publisher.Mono;
1919

20-
import org.springframework.data.r2dbc.query.Query;
21-
import org.springframework.data.r2dbc.query.Update;
20+
import org.springframework.data.relational.core.query.Query;
21+
import org.springframework.data.relational.core.query.Update;
2222
import org.springframework.data.relational.core.sql.SqlIdentifier;
2323
import org.springframework.lang.Nullable;
2424
import org.springframework.util.Assert;

0 commit comments

Comments
 (0)