@ -15,13 +15,7 @@
@@ -15,13 +15,7 @@
* /
package org.springframework.data.r2dbc.core ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Collection ;
import java.util.Collections ;
import java.util.LinkedHashMap ;
import java.util.List ;
import java.util.Map ;
import java.util.* ;
import java.util.function.BiFunction ;
import java.util.function.Supplier ;
import java.util.stream.Collectors ;
@ -33,6 +27,7 @@ import org.springframework.data.r2dbc.dialect.R2dbcDialect;
@@ -33,6 +27,7 @@ import org.springframework.data.r2dbc.dialect.R2dbcDialect;
import org.springframework.data.relational.core.query.Criteria ;
import org.springframework.data.relational.core.query.CriteriaDefinition ;
import org.springframework.data.relational.core.sql.Expression ;
import org.springframework.data.relational.core.sql.LockMode ;
import org.springframework.data.relational.core.sql.SqlIdentifier ;
import org.springframework.data.relational.core.sql.Table ;
import org.springframework.data.relational.core.sql.render.RenderContext ;
@ -53,6 +48,7 @@ import org.springframework.util.Assert;
@@ -53,6 +48,7 @@ import org.springframework.util.Assert;
* @author Mark Paluch
* @author Roman Chigvintsev
* @author Mingyuan Wu
* @author Diego Krupitza
* /
public interface StatementMapper {
@ -227,9 +223,10 @@ public interface StatementMapper {
@@ -227,9 +223,10 @@ public interface StatementMapper {
private final long offset ;
private final int limit ;
private final boolean distinct ;
private final LockMode lockMode ;
protected SelectSpec ( Table table , List < String > projectedFields , List < Expression > selectList ,
@Nullable CriteriaDefinition criteria , Sort sort , int limit , long offset , boolean distinct ) {
@Nullable CriteriaDefinition criteria , Sort sort , int limit , long offset , boolean distinct , LockMode lockMode ) {
this . table = table ;
this . projectedFields = projectedFields ;
this . selectList = selectList ;
@ -238,6 +235,7 @@ public interface StatementMapper {
@@ -238,6 +235,7 @@ public interface StatementMapper {
this . offset = offset ;
this . limit = limit ;
this . distinct = distinct ;
this . lockMode = lockMode ;
}
/ * *
@ -262,7 +260,7 @@ public interface StatementMapper {
@@ -262,7 +260,7 @@ public interface StatementMapper {
List < String > projectedFields = Collections . emptyList ( ) ;
List < Expression > selectList = Collections . emptyList ( ) ;
return new SelectSpec ( Table . create ( table ) , projectedFields , selectList , Criteria . empty ( ) , Sort . unsorted ( ) , - 1 , - 1 ,
false ) ;
false , null ) ;
}
public SelectSpec doWithTable ( BiFunction < Table , SelectSpec , SelectSpec > function ) {
@ -304,7 +302,7 @@ public interface StatementMapper {
@@ -304,7 +302,7 @@ public interface StatementMapper {
selectList . addAll ( Arrays . asList ( expressions ) ) ;
return new SelectSpec ( this . table , projectedFields , selectList , this . criteria , this . sort , this . limit , this . offset ,
this . distinct ) ;
this . distinct , this . lockMode ) ;
}
/ * *
@ -320,7 +318,7 @@ public interface StatementMapper {
@@ -320,7 +318,7 @@ public interface StatementMapper {
selectList . addAll ( projectedFields ) ;
return new SelectSpec ( this . table , this . projectedFields , selectList , this . criteria , this . sort , this . limit ,
this . offset , this . distinct ) ;
this . offset , this . distinct , this . lockMode ) ;
}
/ * *
@ -331,7 +329,7 @@ public interface StatementMapper {
@@ -331,7 +329,7 @@ public interface StatementMapper {
* /
public SelectSpec withCriteria ( CriteriaDefinition criteria ) {
return new SelectSpec ( this . table , this . projectedFields , this . selectList , criteria , this . sort , this . limit ,
this . offset , this . distinct ) ;
this . offset , this . distinct , this . lockMode ) ;
}
/ * *
@ -344,11 +342,11 @@ public interface StatementMapper {
@@ -344,11 +342,11 @@ public interface StatementMapper {
if ( sort . isSorted ( ) ) {
return new SelectSpec ( this . table , this . projectedFields , this . selectList , this . criteria , sort , this . limit ,
this . offset , this . distinct ) ;
this . offset , this . distinct , this . lockMode ) ;
}
return new SelectSpec ( this . table , this . projectedFields , this . selectList , this . criteria , this . sort , this . limit ,
this . offset , this . distinct ) ;
this . offset , this . distinct , this . lockMode ) ;
}
/ * *
@ -364,11 +362,11 @@ public interface StatementMapper {
@@ -364,11 +362,11 @@ public interface StatementMapper {
Sort sort = page . getSort ( ) ;
return new SelectSpec ( this . table , this . projectedFields , this . selectList , this . criteria ,
sort . isSorted ( ) ? sort : this . sort , page . getPageSize ( ) , page . getOffset ( ) , this . distinct ) ;
sort . isSorted ( ) ? sort : this . sort , page . getPageSize ( ) , page . getOffset ( ) , this . distinct , this . lockMode ) ;
}
return new SelectSpec ( this . table , this . projectedFields , this . selectList , this . criteria , this . sort , this . limit ,
this . offset , this . distinct ) ;
this . offset , this . distinct , this . lockMode ) ;
}
/ * *
@ -379,7 +377,7 @@ public interface StatementMapper {
@@ -379,7 +377,7 @@ public interface StatementMapper {
* /
public SelectSpec offset ( long offset ) {
return new SelectSpec ( this . table , this . projectedFields , this . selectList , this . criteria , this . sort , this . limit ,
offset , this . distinct ) ;
offset , this . distinct , this . lockMode ) ;
}
/ * *
@ -390,7 +388,7 @@ public interface StatementMapper {
@@ -390,7 +388,7 @@ public interface StatementMapper {
* /
public SelectSpec limit ( int limit ) {
return new SelectSpec ( this . table , this . projectedFields , this . selectList , this . criteria , this . sort , limit ,
this . offset , this . distinct ) ;
this . offset , this . distinct , this . lockMode ) ;
}
/ * *
@ -400,7 +398,28 @@ public interface StatementMapper {
@@ -400,7 +398,28 @@ public interface StatementMapper {
* /
public SelectSpec distinct ( ) {
return new SelectSpec ( this . table , this . projectedFields , this . selectList , this . criteria , this . sort , limit ,
this . offset , true ) ;
this . offset , true , this . lockMode ) ;
}
/ * *
* Associate a lock mode with the select and create a new { @link SelectSpec } .
*
* @param lockMode the { @link LockMode } we want to use . This might be null
* @return the { @link SelectSpec } .
* /
public SelectSpec lock ( LockMode lockMode ) {
return new SelectSpec ( this . table , this . projectedFields , this . selectList , this . criteria , this . sort , limit ,
this . offset , this . distinct , lockMode ) ;
}
/ * *
* The used lockmode
*
* @return might be null if no lockmode defined .
* /
@Nullable
public LockMode getLock ( ) {
return this . lockMode ;
}
public Table getTable ( ) {
@ -440,6 +459,7 @@ public interface StatementMapper {
@@ -440,6 +459,7 @@ public interface StatementMapper {
public boolean isDistinct ( ) {
return this . distinct ;
}
}
/ * *