15
15
16
16
package software .amazon .awssdk .enhanced .dynamodb .model ;
17
17
18
+ import java .util .ArrayList ;
19
+ import java .util .Arrays ;
20
+ import java .util .Collection ;
21
+ import java .util .Collections ;
18
22
import java .util .HashMap ;
23
+ import java .util .List ;
19
24
import java .util .Map ;
20
25
import software .amazon .awssdk .annotations .SdkPublicApi ;
21
26
import software .amazon .awssdk .enhanced .dynamodb .DynamoDbAsyncIndex ;
@@ -41,6 +46,7 @@ public final class QueryEnhancedRequest {
41
46
private final Integer limit ;
42
47
private final Boolean consistentRead ;
43
48
private final Expression filterExpression ;
49
+ private final List <String > attributesToProject ;
44
50
45
51
private QueryEnhancedRequest (Builder builder ) {
46
52
this .queryConditional = builder .queryConditional ;
@@ -49,6 +55,9 @@ private QueryEnhancedRequest(Builder builder) {
49
55
this .limit = builder .limit ;
50
56
this .consistentRead = builder .consistentRead ;
51
57
this .filterExpression = builder .filterExpression ;
58
+ this .attributesToProject = builder .attributesToProject != null
59
+ ? Collections .unmodifiableList (builder .attributesToProject )
60
+ : null ;
52
61
}
53
62
54
63
/**
@@ -67,7 +76,8 @@ public Builder toBuilder() {
67
76
.scanIndexForward (scanIndexForward )
68
77
.limit (limit )
69
78
.consistentRead (consistentRead )
70
- .filterExpression (filterExpression );
79
+ .filterExpression (filterExpression )
80
+ .attributesToProject (attributesToProject );
71
81
}
72
82
73
83
/**
@@ -113,6 +123,13 @@ public Expression filterExpression() {
113
123
return filterExpression ;
114
124
}
115
125
126
+ /**
127
+ * Returns the list of projected attributes on this request object, or an null if no projection is specified.
128
+ */
129
+ public List <String > attributesToProject () {
130
+ return attributesToProject ;
131
+ }
132
+
116
133
@ Override
117
134
public boolean equals (Object o ) {
118
135
if (this == o ) {
@@ -142,6 +159,12 @@ public boolean equals(Object o) {
142
159
if (consistentRead != null ? ! consistentRead .equals (query .consistentRead ) : query .consistentRead != null ) {
143
160
return false ;
144
161
}
162
+ if (attributesToProject != null
163
+ ? ! attributesToProject .equals (query .attributesToProject )
164
+ : query .attributesToProject != null
165
+ ) {
166
+ return false ;
167
+ }
145
168
return filterExpression != null ? filterExpression .equals (query .filterExpression ) : query .filterExpression == null ;
146
169
}
147
170
@@ -153,6 +176,7 @@ public int hashCode() {
153
176
result = 31 * result + (limit != null ? limit .hashCode () : 0 );
154
177
result = 31 * result + (consistentRead != null ? consistentRead .hashCode () : 0 );
155
178
result = 31 * result + (filterExpression != null ? filterExpression .hashCode () : 0 );
179
+ result = 31 * result + (attributesToProject != null ? attributesToProject .hashCode () : 0 );
156
180
return result ;
157
181
}
158
182
@@ -168,6 +192,7 @@ public static final class Builder {
168
192
private Integer limit ;
169
193
private Boolean consistentRead ;
170
194
private Expression filterExpression ;
195
+ private List <String > attributesToProject ;
171
196
172
197
private Builder () {
173
198
}
@@ -255,6 +280,73 @@ public Builder filterExpression(Expression filterExpression) {
255
280
return this ;
256
281
}
257
282
283
+ /**
284
+ * <p>
285
+ * Sets a collection of the attribute names to be retrieved from the database. These attributes can include
286
+ * scalars, sets, or elements of a JSON document.
287
+ * </p>
288
+ * <p>
289
+ * If no attribute names are specified, then all attributes will be returned. If any of the requested attributes
290
+ * are not found, they will not appear in the result.
291
+ * </p>
292
+ * <p>
293
+ * For more information, see <a href=
294
+ * "https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.AccessingItemAttributes.html"
295
+ * >Accessing Item Attributes</a> in the <i>Amazon DynamoDB Developer Guide</i>.
296
+ * </p>
297
+ * @param attributesToProject
298
+ * A collection of the attributes names to be retrieved from the database.
299
+ * @return Returns a reference to this object so that method calls can be chained together.
300
+ */
301
+ public Builder attributesToProject (Collection <String > attributesToProject ) {
302
+ this .attributesToProject = attributesToProject != null ? new ArrayList <>(attributesToProject ) : null ;
303
+ return this ;
304
+ }
305
+
306
+ /**
307
+ * <p>
308
+ * Sets one or more attribute names to be retrieved from the database. These attributes can include
309
+ * scalars, sets, or elements of a JSON document.
310
+ * </p>
311
+ * <p>
312
+ * If no attribute names are specified, then all attributes will be returned. If any of the requested attributes
313
+ * are not found, they will not appear in the result.
314
+ * </p>
315
+ * <p>
316
+ * For more information, see <a href=
317
+ * "https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.AccessingItemAttributes.html"
318
+ * >Accessing Item Attributes</a> in the <i>Amazon DynamoDB Developer Guide</i>.
319
+ * </p>
320
+ * @param attributesToProject
321
+ * One or more attributes names to be retrieved from the database.
322
+ * @return Returns a reference to this object so that method calls can be chained together.
323
+ */
324
+ public Builder attributesToProject (String ... attributesToProject ) {
325
+ return attributesToProject (Arrays .asList (attributesToProject ));
326
+ }
327
+
328
+ /**
329
+ * <p>
330
+ * Adds a single attribute name to be retrieved from the database. This attribute can include
331
+ * scalars, sets, or elements of a JSON document.
332
+ * </p>
333
+ * <p>
334
+ * For more information, see <a href=
335
+ * "https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.AccessingItemAttributes.html"
336
+ * >Accessing Item Attributes</a> in the <i>Amazon DynamoDB Developer Guide</i>.
337
+ * </p>
338
+ * @param attributeToProject
339
+ * An additional single attribute name to be retrieved from the database.
340
+ * @return Returns a reference to this object so that method calls can be chained together.
341
+ */
342
+ public Builder addAttributeToProject (String attributeToProject ) {
343
+ if (attributesToProject == null ) {
344
+ attributesToProject = new ArrayList <>();
345
+ }
346
+ attributesToProject .add (attributeToProject );
347
+ return this ;
348
+ }
349
+
258
350
public QueryEnhancedRequest build () {
259
351
return new QueryEnhancedRequest (this );
260
352
}
0 commit comments