15
15
*/
16
16
package org .socialsignin .spring .data .dynamodb .repository .query ;
17
17
18
- import java .io .Serializable ;
19
- import java .util .ArrayList ;
20
- import java .util .Arrays ;
21
- import java .util .HashMap ;
22
- import java .util .HashSet ;
23
- import java .util .List ;
24
- import java .util .Map ;
25
- import java .util .Map .Entry ;
26
- import java .util .Set ;
27
-
18
+ import com .amazonaws .services .dynamodbv2 .datamodeling .DynamoDBMapperTableModel ;
19
+ import com .amazonaws .services .dynamodbv2 .datamodeling .DynamoDBQueryExpression ;
20
+ import com .amazonaws .services .dynamodbv2 .datamodeling .DynamoDBScanExpression ;
21
+ import com .amazonaws .services .dynamodbv2 .model .ComparisonOperator ;
22
+ import com .amazonaws .services .dynamodbv2 .model .Condition ;
23
+ import com .amazonaws .services .dynamodbv2 .model .QueryRequest ;
28
24
import org .socialsignin .spring .data .dynamodb .core .DynamoDBOperations ;
29
25
import org .socialsignin .spring .data .dynamodb .query .CountByHashAndRangeKeyQuery ;
30
26
import org .socialsignin .spring .data .dynamodb .query .MultipleEntityQueryExpressionQuery ;
38
34
import org .socialsignin .spring .data .dynamodb .repository .support .DynamoDBIdIsHashAndRangeKeyEntityInformation ;
39
35
import org .springframework .util .Assert ;
40
36
41
- import com .amazonaws .services .dynamodbv2 .datamodeling .DynamoDBMapperTableModel ;
42
- import com .amazonaws .services .dynamodbv2 .datamodeling .DynamoDBQueryExpression ;
43
- import com .amazonaws .services .dynamodbv2 .datamodeling .DynamoDBScanExpression ;
44
- import com .amazonaws .services .dynamodbv2 .model .ComparisonOperator ;
45
- import com .amazonaws .services .dynamodbv2 .model .Condition ;
46
- import com .amazonaws .services .dynamodbv2 .model .QueryRequest ;
37
+ import java .util .ArrayList ;
38
+ import java .util .Arrays ;
39
+ import java .util .HashMap ;
40
+ import java .util .HashSet ;
41
+ import java .util .List ;
42
+ import java .util .Map ;
43
+ import java .util .Map .Entry ;
44
+ import java .util .Set ;
47
45
48
46
/**
49
47
* @author Michael Lavelle
50
48
*/
51
- public class DynamoDBEntityWithHashAndRangeKeyCriteria <T , ID extends Serializable > extends AbstractDynamoDBQueryCriteria <T , ID > {
49
+ public class DynamoDBEntityWithHashAndRangeKeyCriteria <T , ID > extends AbstractDynamoDBQueryCriteria <T , ID > {
52
50
53
51
private Object rangeKeyAttributeValue ;
54
52
private Object rangeKeyPropertyValue ;
@@ -75,14 +73,14 @@ public DynamoDBEntityWithHashAndRangeKeyCriteria(
75
73
this .rangeKeyPropertyName = entityInformation .getRangeKeyPropertyName ();
76
74
this .indexRangeKeyPropertyNames = entityInformation .getIndexRangeKeyPropertyNames ();
77
75
if (indexRangeKeyPropertyNames == null ) {
78
- indexRangeKeyPropertyNames = new HashSet <String >();
76
+ indexRangeKeyPropertyNames = new HashSet <>();
79
77
}
80
78
this .entityInformation = entityInformation ;
81
79
82
80
}
83
81
84
82
public Set <String > getIndexRangeKeyAttributeNames () {
85
- Set <String > indexRangeKeyAttributeNames = new HashSet <String >();
83
+ Set <String > indexRangeKeyAttributeNames = new HashSet <>();
86
84
for (String indexRangeKeyPropertyName : indexRangeKeyPropertyNames ) {
87
85
indexRangeKeyAttributeNames .add (getAttributeName (indexRangeKeyPropertyName ));
88
86
}
@@ -102,12 +100,12 @@ protected boolean isRangeKeySpecified() {
102
100
}
103
101
104
102
protected Query <T > buildSingleEntityLoadQuery (DynamoDBOperations dynamoDBOperations ) {
105
- return new SingleEntityLoadByHashAndRangeKeyQuery <T >(dynamoDBOperations , entityInformation .getJavaType (),
103
+ return new SingleEntityLoadByHashAndRangeKeyQuery <>(dynamoDBOperations , entityInformation .getJavaType (),
106
104
getHashKeyPropertyValue (), getRangeKeyPropertyValue ());
107
105
}
108
106
109
107
protected Query <Long > buildSingleEntityCountQuery (DynamoDBOperations dynamoDBOperations ) {
110
- return new CountByHashAndRangeKeyQuery <T >(dynamoDBOperations , entityInformation .getJavaType (),
108
+ return new CountByHashAndRangeKeyQuery <>(dynamoDBOperations , entityInformation .getJavaType (),
111
109
getHashKeyPropertyValue (), getRangeKeyPropertyValue ());
112
110
}
113
111
@@ -146,7 +144,7 @@ public DynamoDBQueryExpression<T> buildQueryExpression() {
146
144
if (isHashKeySpecified ()) {
147
145
T hashKeyPrototype = entityInformation .getHashKeyPropotypeEntityForHashKey (getHashKeyPropertyValue ());
148
146
queryExpression .withHashKeyValues (hashKeyPrototype );
149
- queryExpression .withRangeKeyConditions (new HashMap <String , Condition >());
147
+ queryExpression .withRangeKeyConditions (new HashMap <>());
150
148
}
151
149
152
150
if (isRangeKeySpecified () && !isApplicableForGlobalSecondaryIndex ()) {
@@ -160,7 +158,7 @@ public DynamoDBQueryExpression<T> buildQueryExpression() {
160
158
161
159
Entry <String , List <Condition >> singlePropertyConditions = propertyConditions .entrySet ().iterator ().next ();
162
160
163
- List <String > allowedSortProperties = new ArrayList <String >();
161
+ List <String > allowedSortProperties = new ArrayList <>();
164
162
for (Entry <String , List <Condition >> singlePropertyCondition : propertyConditions .entrySet ()) {
165
163
if (entityInformation .getGlobalSecondaryIndexNamesByPropertyName ().keySet ()
166
164
.contains (singlePropertyCondition .getKey ())) {
@@ -332,9 +330,8 @@ public boolean isApplicableForQuery() {
332
330
333
331
public DynamoDBScanExpression buildScanExpression () {
334
332
335
- if (sort != null ) {
336
- throw new UnsupportedOperationException ("Sort not supported for scan expressions" );
337
- }
333
+ ensureNoSort ();
334
+
338
335
DynamoDBScanExpression scanExpression = new DynamoDBScanExpression ();
339
336
if (isHashKeySpecified ()) {
340
337
scanExpression .addFilterCondition (
0 commit comments