15
15
*/
16
16
package org .springframework .data .r2dbc .core ;
17
17
18
- import io .r2dbc .spi .Connection ;
19
- import io .r2dbc .spi .ConnectionFactory ;
20
- import io .r2dbc .spi .R2dbcException ;
21
- import io .r2dbc .spi .Result ;
22
- import io .r2dbc .spi .Row ;
23
- import io .r2dbc .spi .RowMetadata ;
24
- import io .r2dbc .spi .Statement ;
25
- import lombok .RequiredArgsConstructor ;
26
- import reactor .core .publisher .Flux ;
27
- import reactor .core .publisher .Mono ;
28
-
29
18
import java .lang .reflect .InvocationHandler ;
30
19
import java .lang .reflect .InvocationTargetException ;
31
20
import java .lang .reflect .Method ;
42
31
import java .util .function .Supplier ;
43
32
import java .util .stream .Collectors ;
44
33
34
+ import io .r2dbc .spi .Connection ;
35
+ import io .r2dbc .spi .ConnectionFactory ;
36
+ import io .r2dbc .spi .R2dbcException ;
37
+ import io .r2dbc .spi .Result ;
38
+ import io .r2dbc .spi .Row ;
39
+ import io .r2dbc .spi .RowMetadata ;
40
+ import io .r2dbc .spi .Statement ;
45
41
import org .apache .commons .logging .Log ;
46
42
import org .apache .commons .logging .LogFactory ;
47
43
import org .reactivestreams .Publisher ;
44
+ import reactor .core .publisher .Flux ;
45
+ import reactor .core .publisher .Mono ;
48
46
49
47
import org .springframework .dao .DataAccessException ;
50
48
import org .springframework .dao .InvalidDataAccessApiUsageException ;
@@ -305,7 +303,6 @@ private static void bindByIndex(Statement statement, Map<Integer, SettableValue>
305
303
/**
306
304
* Base class for {@link DatabaseClient.GenericExecuteSpec} implementations.
307
305
*/
308
- @ RequiredArgsConstructor
309
306
class ExecuteSpecSupport {
310
307
311
308
final Map <Integer , SettableValue > byIndex ;
@@ -319,6 +316,13 @@ class ExecuteSpecSupport {
319
316
this .sqlSupplier = sqlSupplier ;
320
317
}
321
318
319
+ ExecuteSpecSupport (Map <Integer , SettableValue > byIndex , Map <String , SettableValue > byName ,
320
+ Supplier <String > sqlSupplier ) {
321
+ this .byIndex = byIndex ;
322
+ this .byName = byName ;
323
+ this .sqlSupplier = sqlSupplier ;
324
+ }
325
+
322
326
<T > FetchSpec <T > exchange (Supplier <String > sqlSupplier , BiFunction <Row , RowMetadata , T > mappingFunction ) {
323
327
324
328
String sql = getRequiredSql (sqlSupplier );
@@ -630,7 +634,6 @@ public <T> TypedSelectSpec<T> from(Class<T> table) {
630
634
/**
631
635
* Base class for {@link DatabaseClient.GenericExecuteSpec} implementations.
632
636
*/
633
- @ RequiredArgsConstructor
634
637
private abstract class DefaultSelectSpecSupport {
635
638
636
639
final String table ;
@@ -650,6 +653,14 @@ private abstract class DefaultSelectSpecSupport {
650
653
this .page = Pageable .unpaged ();
651
654
}
652
655
656
+ DefaultSelectSpecSupport (String table , List <String > projectedFields , Criteria criteria , Sort sort , Pageable page ) {
657
+ this .table = table ;
658
+ this .projectedFields = projectedFields ;
659
+ this .criteria = criteria ;
660
+ this .sort = sort ;
661
+ this .page = page ;
662
+ }
663
+
653
664
public DefaultSelectSpecSupport project (String ... selectedFields ) {
654
665
Assert .notNull (selectedFields , "Projection fields must not be null!" );
655
666
@@ -789,7 +800,7 @@ private class DefaultTypedSelectSpec<T> extends DefaultSelectSpecSupport impleme
789
800
private final @ Nullable Class <T > typeToRead ;
790
801
private final BiFunction <Row , RowMetadata , T > mappingFunction ;
791
802
792
- DefaultTypedSelectSpec (Class <T > typeToRead ) {
803
+ DefaultTypedSelectSpec (@ Nullable Class <T > typeToRead ) {
793
804
794
805
super (dataAccessStrategy .getTableName (typeToRead ));
795
806
@@ -798,7 +809,7 @@ private class DefaultTypedSelectSpec<T> extends DefaultSelectSpecSupport impleme
798
809
}
799
810
800
811
DefaultTypedSelectSpec (String table , List <String > projectedFields , Criteria criteria , Sort sort , Pageable page ,
801
- Class <T > typeToRead , BiFunction <Row , RowMetadata , T > mappingFunction ) {
812
+ @ Nullable Class <T > typeToRead , BiFunction <Row , RowMetadata , T > mappingFunction ) {
802
813
803
814
super (table , projectedFields , criteria , sort , page );
804
815
@@ -905,13 +916,19 @@ public <T> TypedInsertSpec<T> into(Class<T> table) {
905
916
/**
906
917
* Default implementation of {@link DatabaseClient.GenericInsertSpec}.
907
918
*/
908
- @ RequiredArgsConstructor
909
919
class DefaultGenericInsertSpec <T > implements GenericInsertSpec <T > {
910
920
911
921
private final String table ;
912
922
private final Map <String , SettableValue > byName ;
913
923
private final BiFunction <Row , RowMetadata , T > mappingFunction ;
914
924
925
+ DefaultGenericInsertSpec (String table , Map <String , SettableValue > byName ,
926
+ BiFunction <Row , RowMetadata , T > mappingFunction ) {
927
+ this .table = table ;
928
+ this .byName = byName ;
929
+ this .mappingFunction = mappingFunction ;
930
+ }
931
+
915
932
@ Override
916
933
public GenericInsertSpec <T > value (String field , Object value ) {
917
934
@@ -988,7 +1005,6 @@ private <R> FetchSpec<R> exchange(BiFunction<Row, RowMetadata, R> mappingFunctio
988
1005
/**
989
1006
* Default implementation of {@link DatabaseClient.TypedInsertSpec}.
990
1007
*/
991
- @ RequiredArgsConstructor
992
1008
class DefaultTypedInsertSpec <T , R > implements TypedInsertSpec <T >, InsertSpec <R > {
993
1009
994
1010
private final Class <?> typeToInsert ;
@@ -1004,6 +1020,14 @@ class DefaultTypedInsertSpec<T, R> implements TypedInsertSpec<T>, InsertSpec<R>
1004
1020
this .mappingFunction = mappingFunction ;
1005
1021
}
1006
1022
1023
+ DefaultTypedInsertSpec (Class <?> typeToInsert , String table , Publisher <T > objectToInsert ,
1024
+ BiFunction <Row , RowMetadata , R > mappingFunction ) {
1025
+ this .typeToInsert = typeToInsert ;
1026
+ this .table = table ;
1027
+ this .objectToInsert = objectToInsert ;
1028
+ this .mappingFunction = mappingFunction ;
1029
+ }
1030
+
1007
1031
@ Override
1008
1032
public TypedInsertSpec <T > table (String tableName ) {
1009
1033
@@ -1118,14 +1142,21 @@ public <T> TypedUpdateSpec<T> table(Class<T> table) {
1118
1142
}
1119
1143
}
1120
1144
1121
- @ RequiredArgsConstructor
1122
1145
class DefaultGenericUpdateSpec implements GenericUpdateSpec , UpdateMatchingSpec {
1123
1146
1124
1147
private final @ Nullable Class <?> typeToUpdate ;
1125
1148
private final @ Nullable String table ;
1126
1149
private final Update assignments ;
1127
1150
private final Criteria where ;
1128
1151
1152
+ DefaultGenericUpdateSpec (@ Nullable Class <?> typeToUpdate , @ Nullable String table , Update assignments ,
1153
+ Criteria where ) {
1154
+ this .typeToUpdate = typeToUpdate ;
1155
+ this .table = table ;
1156
+ this .assignments = assignments ;
1157
+ this .where = where ;
1158
+ }
1159
+
1129
1160
@ Override
1130
1161
public UpdateMatchingSpec using (Update update ) {
1131
1162
@@ -1181,13 +1212,18 @@ private UpdatedRowsFetchSpec exchange(String table) {
1181
1212
}
1182
1213
}
1183
1214
1184
- @ RequiredArgsConstructor
1185
1215
class DefaultTypedUpdateSpec <T > implements TypedUpdateSpec <T >, UpdateSpec {
1186
1216
1187
1217
private final @ Nullable Class <T > typeToUpdate ;
1188
1218
private final @ Nullable String table ;
1189
1219
private final T objectToUpdate ;
1190
1220
1221
+ DefaultTypedUpdateSpec (@ Nullable Class <T > typeToUpdate , @ Nullable String table , T objectToUpdate ) {
1222
+ this .typeToUpdate = typeToUpdate ;
1223
+ this .table = table ;
1224
+ this .objectToUpdate = objectToUpdate ;
1225
+ }
1226
+
1191
1227
@ Override
1192
1228
public UpdateSpec using (T objectToUpdate ) {
1193
1229
@@ -1270,13 +1306,18 @@ public <T> DefaultDeleteSpec<T> from(Class<T> table) {
1270
1306
/**
1271
1307
* Default implementation of {@link DatabaseClient.TypedInsertSpec}.
1272
1308
*/
1273
- @ RequiredArgsConstructor
1274
1309
class DefaultDeleteSpec <T > implements DeleteMatchingSpec , TypedDeleteSpec <T > {
1275
1310
1276
1311
private final @ Nullable Class <T > typeToDelete ;
1277
1312
private final @ Nullable String table ;
1278
1313
private final Criteria where ;
1279
1314
1315
+ DefaultDeleteSpec (@ Nullable Class <T > typeToDelete , @ Nullable String table , Criteria where ) {
1316
+ this .typeToDelete = typeToDelete ;
1317
+ this .table = table ;
1318
+ this .where = where ;
1319
+ }
1320
+
1280
1321
@ Override
1281
1322
public DeleteSpec matching (Criteria criteria ) {
1282
1323
@@ -1483,14 +1524,18 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
1483
1524
/**
1484
1525
* Holder for a connection that makes sure the close action is invoked atomically only once.
1485
1526
*/
1486
- @ RequiredArgsConstructor
1487
1527
static class ConnectionCloseHolder extends AtomicBoolean {
1488
1528
1489
1529
private static final long serialVersionUID = -8994138383301201380L ;
1490
1530
1491
1531
final Connection connection ;
1492
1532
final Function <Connection , Publisher <Void >> closeFunction ;
1493
1533
1534
+ ConnectionCloseHolder (Connection connection , Function <Connection , Publisher <Void >> closeFunction ) {
1535
+ this .connection = connection ;
1536
+ this .closeFunction = closeFunction ;
1537
+ }
1538
+
1494
1539
Mono <Void > close () {
1495
1540
1496
1541
return Mono .defer (() -> {
@@ -1504,11 +1549,14 @@ Mono<Void> close() {
1504
1549
}
1505
1550
}
1506
1551
1507
- @ RequiredArgsConstructor
1508
1552
static class StatementWrapper implements BindTarget {
1509
1553
1510
1554
final Statement statement ;
1511
1555
1556
+ StatementWrapper (Statement statement ) {
1557
+ this .statement = statement ;
1558
+ }
1559
+
1512
1560
@ Override
1513
1561
public void bind (Object identifier , Object value ) {
1514
1562
this .statement .bind (identifier , value );
0 commit comments