1515 */
1616package org .springframework .data .r2dbc .core ;
1717
18- import java .util .ArrayList ;
19- import java .util .Arrays ;
20- import java .util .Collection ;
21- import java .util .Collections ;
22- import java .util .LinkedHashMap ;
23- import java .util .List ;
24- import java .util .Map ;
18+ import java .util .*;
2519import java .util .function .BiFunction ;
2620import java .util .function .Supplier ;
2721import java .util .stream .Collectors ;
3327import org .springframework .data .relational .core .query .Criteria ;
3428import org .springframework .data .relational .core .query .CriteriaDefinition ;
3529import org .springframework .data .relational .core .sql .Expression ;
30+ import org .springframework .data .relational .core .sql .LockMode ;
3631import org .springframework .data .relational .core .sql .SqlIdentifier ;
3732import org .springframework .data .relational .core .sql .Table ;
3833import org .springframework .data .relational .core .sql .render .RenderContext ;
5348 * @author Mark Paluch
5449 * @author Roman Chigvintsev
5550 * @author Mingyuan Wu
51+ * @author Diego Krupitza
5652 */
5753public interface StatementMapper {
5854
@@ -227,9 +223,10 @@ class SelectSpec {
227223 private final long offset ;
228224 private final int limit ;
229225 private final boolean distinct ;
226+ private final LockMode lockMode ;
230227
231228 protected SelectSpec (Table table , List <String > projectedFields , List <Expression > selectList ,
232- @ Nullable CriteriaDefinition criteria , Sort sort , int limit , long offset , boolean distinct ) {
229+ @ Nullable CriteriaDefinition criteria , Sort sort , int limit , long offset , boolean distinct , LockMode lockMode ) {
233230 this .table = table ;
234231 this .projectedFields = projectedFields ;
235232 this .selectList = selectList ;
@@ -238,6 +235,7 @@ protected SelectSpec(Table table, List<String> projectedFields, List<Expression>
238235 this .offset = offset ;
239236 this .limit = limit ;
240237 this .distinct = distinct ;
238+ this .lockMode = lockMode ;
241239 }
242240
243241 /**
@@ -262,7 +260,7 @@ public static SelectSpec create(SqlIdentifier table) {
262260 List <String > projectedFields = Collections .emptyList ();
263261 List <Expression > selectList = Collections .emptyList ();
264262 return new SelectSpec (Table .create (table ), projectedFields , selectList , Criteria .empty (), Sort .unsorted (), -1 , -1 ,
265- false );
263+ false , null );
266264 }
267265
268266 public SelectSpec doWithTable (BiFunction <Table , SelectSpec , SelectSpec > function ) {
@@ -304,7 +302,7 @@ public SelectSpec withProjection(Expression... expressions) {
304302 selectList .addAll (Arrays .asList (expressions ));
305303
306304 return new SelectSpec (this .table , projectedFields , selectList , this .criteria , this .sort , this .limit , this .offset ,
307- this .distinct );
305+ this .distinct , this . lockMode );
308306 }
309307
310308 /**
@@ -320,7 +318,7 @@ public SelectSpec withProjection(Collection<Expression> projectedFields) {
320318 selectList .addAll (projectedFields );
321319
322320 return new SelectSpec (this .table , this .projectedFields , selectList , this .criteria , this .sort , this .limit ,
323- this .offset , this .distinct );
321+ this .offset , this .distinct , this . lockMode );
324322 }
325323
326324 /**
@@ -331,7 +329,7 @@ public SelectSpec withProjection(Collection<Expression> projectedFields) {
331329 */
332330 public SelectSpec withCriteria (CriteriaDefinition criteria ) {
333331 return new SelectSpec (this .table , this .projectedFields , this .selectList , criteria , this .sort , this .limit ,
334- this .offset , this .distinct );
332+ this .offset , this .distinct , this . lockMode );
335333 }
336334
337335 /**
@@ -344,11 +342,11 @@ public SelectSpec withSort(Sort sort) {
344342
345343 if (sort .isSorted ()) {
346344 return new SelectSpec (this .table , this .projectedFields , this .selectList , this .criteria , sort , this .limit ,
347- this .offset , this .distinct );
345+ this .offset , this .distinct , this . lockMode );
348346 }
349347
350348 return new SelectSpec (this .table , this .projectedFields , this .selectList , this .criteria , this .sort , this .limit ,
351- this .offset , this .distinct );
349+ this .offset , this .distinct , this . lockMode );
352350 }
353351
354352 /**
@@ -364,11 +362,11 @@ public SelectSpec withPage(Pageable page) {
364362 Sort sort = page .getSort ();
365363
366364 return new SelectSpec (this .table , this .projectedFields , this .selectList , this .criteria ,
367- sort .isSorted () ? sort : this .sort , page .getPageSize (), page .getOffset (), this .distinct );
365+ sort .isSorted () ? sort : this .sort , page .getPageSize (), page .getOffset (), this .distinct , this . lockMode );
368366 }
369367
370368 return new SelectSpec (this .table , this .projectedFields , this .selectList , this .criteria , this .sort , this .limit ,
371- this .offset , this .distinct );
369+ this .offset , this .distinct , this . lockMode );
372370 }
373371
374372 /**
@@ -379,7 +377,7 @@ public SelectSpec withPage(Pageable page) {
379377 */
380378 public SelectSpec offset (long offset ) {
381379 return new SelectSpec (this .table , this .projectedFields , this .selectList , this .criteria , this .sort , this .limit ,
382- offset , this .distinct );
380+ offset , this .distinct , this . lockMode );
383381 }
384382
385383 /**
@@ -390,7 +388,7 @@ public SelectSpec offset(long offset) {
390388 */
391389 public SelectSpec limit (int limit ) {
392390 return new SelectSpec (this .table , this .projectedFields , this .selectList , this .criteria , this .sort , limit ,
393- this .offset , this .distinct );
391+ this .offset , this .distinct , this . lockMode );
394392 }
395393
396394 /**
@@ -400,7 +398,28 @@ public SelectSpec limit(int limit) {
400398 */
401399 public SelectSpec distinct () {
402400 return new SelectSpec (this .table , this .projectedFields , this .selectList , this .criteria , this .sort , limit ,
403- this .offset , true );
401+ this .offset , true , this .lockMode );
402+ }
403+
404+ /**
405+ * Associate a lock mode with the select and create a new {@link SelectSpec}.
406+ *
407+ * @param lockMode the {@link LockMode} we want to use. This might be null
408+ * @return the {@link SelectSpec}.
409+ */
410+ public SelectSpec lock (LockMode lockMode ) {
411+ return new SelectSpec (this .table , this .projectedFields , this .selectList , this .criteria , this .sort , limit ,
412+ this .offset , this .distinct , lockMode );
413+ }
414+
415+ /**
416+ * The used lockmode
417+ *
418+ * @return might be null if no lockmode defined.
419+ */
420+ @ Nullable
421+ public LockMode getLock () {
422+ return this .lockMode ;
404423 }
405424
406425 public Table getTable () {
@@ -440,6 +459,7 @@ public int getLimit() {
440459 public boolean isDistinct () {
441460 return this .distinct ;
442461 }
462+
443463 }
444464
445465 /**
0 commit comments