1919import com .amazonaws .services .dynamodbv2 .model .ComparisonOperator ;
2020import org .socialsignin .spring .data .dynamodb .core .DynamoDBOperations ;
2121import org .socialsignin .spring .data .dynamodb .query .Query ;
22+ import org .socialsignin .spring .data .dynamodb .repository .ExpressionAttribute ;
2223import org .socialsignin .spring .data .dynamodb .repository .QueryConstants ;
2324import org .socialsignin .spring .data .dynamodb .repository .support .DynamoDBEntityInformation ;
2425import org .socialsignin .spring .data .dynamodb .repository .support .DynamoDBIdIsHashAndRangeKeyEntityInformation ;
2526import org .springframework .data .mapping .PropertyPath ;
27+ import org .springframework .data .repository .query .Parameter ;
2628import org .springframework .data .repository .query .ParameterAccessor ;
29+ import org .springframework .data .repository .query .ParametersParameterAccessor ;
2730import org .springframework .data .repository .query .parser .AbstractQueryCreator ;
2831import org .springframework .data .repository .query .parser .Part ;
2932import org .springframework .data .repository .query .parser .Part .IgnoreCaseType ;
3033import org .springframework .data .repository .query .parser .PartTree ;
3134import org .springframework .util .Assert ;
3235import org .springframework .util .ClassUtils ;
3336import org .springframework .util .ObjectUtils ;
37+ import org .springframework .util .StringUtils ;
3438
3539import java .util .Arrays ;
40+ import java .util .HashMap ;
3641import java .util .Iterator ;
42+ import java .util .Map ;
3743import java .util .Optional ;
3844
3945/**
@@ -48,35 +54,71 @@ public abstract class AbstractDynamoDBQueryCreator<T, ID, R>
4854 protected final DynamoDBOperations dynamoDBOperations ;
4955 protected final Optional <String > projection ;
5056 protected final Optional <Integer > limit ;
57+ protected final Optional <String > filterExpression ;
58+ protected final ExpressionAttribute [] expressionAttributeNames ;
59+ protected final ExpressionAttribute [] expressionAttributeValues ;
60+ protected final Map <String , String > mappedExpressionValues = new HashMap <>();
5161 protected final QueryConstants .ConsistentReadMode consistentReads ;
5262
5363 public AbstractDynamoDBQueryCreator (PartTree tree , DynamoDBEntityInformation <T , ID > entityMetadata ,
54- Optional <String > projection , Optional <Integer > limitResults , QueryConstants .ConsistentReadMode consistentReads , DynamoDBOperations dynamoDBOperations ) {
64+ Optional <String > projection , Optional <Integer > limitResults , QueryConstants .ConsistentReadMode consistentReads ,
65+ Optional <String > filterExpression , ExpressionAttribute [] names , ExpressionAttribute [] values , DynamoDBOperations dynamoDBOperations ) {
5566 super (tree );
5667 this .entityMetadata = entityMetadata ;
5768 this .projection = projection ;
5869 this .limit = limitResults ;
5970 this .consistentReads = consistentReads ;
71+ this .filterExpression = filterExpression ;
72+ if (names != null ) {
73+ this .expressionAttributeNames = names .clone ();
74+ } else {
75+ this .expressionAttributeNames = null ;
76+ }
77+ if (values != null ) {
78+ this .expressionAttributeValues = values .clone ();
79+ } else {
80+ this .expressionAttributeValues = null ;
81+ }
6082 this .dynamoDBOperations = dynamoDBOperations ;
6183 }
6284
6385 public AbstractDynamoDBQueryCreator (PartTree tree , ParameterAccessor parameterAccessor ,
6486 DynamoDBEntityInformation <T , ID > entityMetadata , Optional <String > projection ,
65- Optional <Integer > limitResults , QueryConstants .ConsistentReadMode consistentReads , DynamoDBOperations dynamoDBOperations ) {
87+ Optional <Integer > limitResults , QueryConstants .ConsistentReadMode consistentReads , Optional < String > filterExpression , ExpressionAttribute [] names , ExpressionAttribute [] values , DynamoDBOperations dynamoDBOperations ) {
6688 super (tree , parameterAccessor );
6789 this .entityMetadata = entityMetadata ;
6890 this .projection = projection ;
6991 this .limit = limitResults ;
92+ this .filterExpression = filterExpression ;
7093 this .consistentReads = consistentReads ;
94+ if (names != null ) {
95+ this .expressionAttributeNames = names .clone ();
96+ } else {
97+ this .expressionAttributeNames = null ;
98+ }
99+ if (values != null ) {
100+ this .expressionAttributeValues = values .clone ();
101+ for (ExpressionAttribute value : expressionAttributeValues ) {
102+ if (!StringUtils .isEmpty (value .parameterName ())) {
103+ for (Parameter p : ((ParametersParameterAccessor )parameterAccessor ).getParameters ()) {
104+ if (p .getName ().isPresent () && p .getName ().get ().equals (value .parameterName ())) {
105+ mappedExpressionValues .put (value .parameterName (), (String ) parameterAccessor .getBindableValue (p .getIndex ()));
106+ }
107+ }
108+ }
109+ }
110+ } else {
111+ this .expressionAttributeValues = null ;
112+ }
71113 this .dynamoDBOperations = dynamoDBOperations ;
72114 }
73115
74116 @ Override
75117 protected DynamoDBQueryCriteria <T , ID > create (Part part , Iterator <Object > iterator ) {
76118 final DynamoDBMapperTableModel <T > tableModel = dynamoDBOperations .getTableModel (entityMetadata .getJavaType ());
77119 DynamoDBQueryCriteria <T , ID > criteria = entityMetadata .isRangeKeyAware ()
78- ? new DynamoDBEntityWithHashAndRangeKeyCriteria <T , ID >(
79- (DynamoDBIdIsHashAndRangeKeyEntityInformation <T , ID >) entityMetadata , tableModel )
120+ ? new DynamoDBEntityWithHashAndRangeKeyCriteria <>(
121+ (DynamoDBIdIsHashAndRangeKeyEntityInformation <T , ID >) entityMetadata , tableModel )
80122 : new DynamoDBEntityWithHashKeyOnlyCriteria <>(entityMetadata , tableModel );
81123 return addCriteria (criteria , part , iterator );
82124 }
@@ -90,7 +132,7 @@ protected DynamoDBQueryCriteria<T, ID> addCriteria(DynamoDBQueryCriteria<T, ID>
90132
91133 PropertyPath leafNodePropertyPath = part .getProperty ().getLeafProperty ();
92134 String leafNodePropertyName = leafNodePropertyPath .toDotPath ();
93- if (leafNodePropertyName .indexOf ("." ) != - 1 ) {
135+ if (leafNodePropertyName .contains ("." )) {
94136 int index = leafNodePropertyName .lastIndexOf ("." );
95137 leafNodePropertyName = leafNodePropertyName .substring (index );
96138 }
0 commit comments