20
20
import java .util .Collection ;
21
21
import java .util .Collections ;
22
22
import java .util .List ;
23
+ import java .util .Objects ;
23
24
import software .amazon .awssdk .annotations .NotThreadSafe ;
24
25
import software .amazon .awssdk .annotations .SdkPublicApi ;
25
26
import software .amazon .awssdk .annotations .ThreadSafe ;
26
27
import software .amazon .awssdk .enhanced .dynamodb .DynamoDbEnhancedClient ;
28
+ import software .amazon .awssdk .services .dynamodb .model .BatchWriteItemRequest ;
29
+ import software .amazon .awssdk .services .dynamodb .model .ReturnConsumedCapacity ;
30
+ import software .amazon .awssdk .services .dynamodb .model .ReturnItemCollectionMetrics ;
27
31
28
32
/**
29
33
* Defines parameters used for the batchWriteItem() operation (such as
30
34
* {@link DynamoDbEnhancedClient#batchWriteItem(BatchWriteItemEnhancedRequest)}).
31
35
* <p>
32
- * A request contains references to keys for delete actions and items for put actions,
33
- * organized into one {@link WriteBatch} object per accessed table.
36
+ * A request contains references to keys for delete actions and items for put actions, organized into one {@link WriteBatch}
37
+ * object per accessed table.
34
38
*/
35
39
@ SdkPublicApi
36
40
@ ThreadSafe
37
41
public final class BatchWriteItemEnhancedRequest {
38
42
39
43
private final List <WriteBatch > writeBatches ;
44
+ private final String returnConsumedCapacity ;
45
+ private final String returnItemCollectionMetrics ;
40
46
41
47
private BatchWriteItemEnhancedRequest (Builder builder ) {
42
48
this .writeBatches = getListIfExist (builder .writeBatches );
49
+ this .returnConsumedCapacity = builder .returnConsumedCapacity ;
50
+ this .returnItemCollectionMetrics = builder .returnItemCollectionMetrics ;
43
51
}
44
52
45
53
/**
@@ -50,10 +58,50 @@ public static Builder builder() {
50
58
}
51
59
52
60
/**
53
- * Returns a builder initialized with all existing values on the request object.
61
+ * @return a builder with all existing values set
54
62
*/
55
63
public Builder toBuilder () {
56
- return new Builder ().writeBatches (writeBatches );
64
+ return builder ().writeBatches (writeBatches )
65
+ .returnConsumedCapacity (returnConsumedCapacity )
66
+ .returnItemCollectionMetrics (returnItemCollectionMetrics );
67
+ }
68
+
69
+ /**
70
+ * Whether to return the capacity consumed by this operation.
71
+ *
72
+ * @see BatchWriteItemEnhancedRequest#returnConsumedCapacity()
73
+ */
74
+ public ReturnConsumedCapacity returnConsumedCapacity () {
75
+ return ReturnConsumedCapacity .fromValue (returnConsumedCapacity );
76
+ }
77
+
78
+ /**
79
+ * Whether to return the capacity consumed by this operation.
80
+ * <p>
81
+ * Similar to {@link #returnConsumedCapacity()} but return the value as a string. This is useful in situations where the value
82
+ * is not defined in {@link ReturnConsumedCapacity}.
83
+ */
84
+ public String returnConsumedCapacityAsString () {
85
+ return returnConsumedCapacity ;
86
+ }
87
+
88
+ /**
89
+ * Whether to return the item collection metrics.
90
+ *
91
+ * @see BatchWriteItemRequest#returnItemCollectionMetrics()
92
+ */
93
+ public ReturnItemCollectionMetrics returnItemCollectionMetrics () {
94
+ return ReturnItemCollectionMetrics .fromValue (returnItemCollectionMetrics );
95
+ }
96
+
97
+ /**
98
+ * Whether to return the item collection metrics.
99
+ * <p>
100
+ * Similar to {@link #returnItemCollectionMetrics()} but return the value as a string. This is useful in situations where the
101
+ * value is not defined in {@link ReturnItemCollectionMetrics}.
102
+ */
103
+ public String returnItemCollectionMetricsAsString () {
104
+ return returnItemCollectionMetrics ;
57
105
}
58
106
59
107
/**
@@ -71,15 +119,18 @@ public boolean equals(Object o) {
71
119
if (o == null || getClass () != o .getClass ()) {
72
120
return false ;
73
121
}
74
-
75
122
BatchWriteItemEnhancedRequest that = (BatchWriteItemEnhancedRequest ) o ;
76
-
77
- return writeBatches != null ? writeBatches .equals (that .writeBatches ) : that .writeBatches == null ;
123
+ return Objects .equals (writeBatches , that .writeBatches ) &&
124
+ Objects .equals (returnConsumedCapacity , that .returnConsumedCapacity ) &&
125
+ Objects .equals (returnItemCollectionMetrics , that .returnItemCollectionMetrics );
78
126
}
79
127
80
128
@ Override
81
129
public int hashCode () {
82
- return writeBatches != null ? writeBatches .hashCode () : 0 ;
130
+ int result = writeBatches != null ? writeBatches .hashCode () : 0 ;
131
+ result = 31 * result + (returnConsumedCapacity != null ? returnConsumedCapacity .hashCode () : 0 );
132
+ result = 31 * result + (returnItemCollectionMetrics != null ? returnItemCollectionMetrics .hashCode () : 0 );
133
+ return result ;
83
134
}
84
135
85
136
private static List <WriteBatch > getListIfExist (List <WriteBatch > writeBatches ) {
@@ -92,10 +143,54 @@ private static List<WriteBatch> getListIfExist(List<WriteBatch> writeBatches) {
92
143
@ NotThreadSafe
93
144
public static final class Builder {
94
145
private List <WriteBatch > writeBatches ;
146
+ private String returnConsumedCapacity ;
147
+ private String returnItemCollectionMetrics ;
95
148
96
149
private Builder () {
97
150
}
98
151
152
+ /**
153
+ * Sets the ConsumedCapacity via ReturnConsumedCapacity object
154
+ *
155
+ * @see Builder#returnConsumedCapacity(ReturnConsumedCapacity)
156
+ */
157
+ public Builder returnConsumedCapacity (ReturnConsumedCapacity returnConsumedCapacity ) {
158
+ this .returnConsumedCapacity = returnConsumedCapacity == null ? null : returnConsumedCapacity .toString ();
159
+ return this ;
160
+ }
161
+
162
+ /**
163
+ * Sets the ConsumedCapacity via String.
164
+ *
165
+ * @see Builder#returnConsumedCapacity(String)
166
+ */
167
+ public Builder returnConsumedCapacity (String returnConsumedCapacity ) {
168
+ this .returnConsumedCapacity = returnConsumedCapacity ;
169
+ return this ;
170
+ }
171
+
172
+ /**
173
+ * Sets the item collection metrics.
174
+ *
175
+ * @see BatchWriteItemEnhancedRequest.Builder#returnItemCollectionMetrics(ReturnItemCollectionMetrics)
176
+ */
177
+ public BatchWriteItemEnhancedRequest .Builder returnItemCollectionMetrics (ReturnItemCollectionMetrics
178
+ returnItemCollectionMetrics ) {
179
+ this .returnItemCollectionMetrics = returnItemCollectionMetrics == null ? null :
180
+ returnItemCollectionMetrics .toString ();
181
+ return this ;
182
+ }
183
+
184
+ /**
185
+ * Sets the item collection metrics.
186
+ *
187
+ * @see BatchWriteItemEnhancedRequest.Builder#returnItemCollectionMetrics(String)
188
+ */
189
+ public BatchWriteItemEnhancedRequest .Builder returnItemCollectionMetrics (String returnItemCollectionMetrics ) {
190
+ this .returnItemCollectionMetrics = returnItemCollectionMetrics ;
191
+ return this ;
192
+ }
193
+
99
194
/**
100
195
* Sets a collection of write batches to use in the batchWriteItem operation.
101
196
*
@@ -119,8 +214,8 @@ public Builder writeBatches(WriteBatch... writeBatches) {
119
214
}
120
215
121
216
/**
122
- * Adds a write batch to the collection of batches on this builder.
123
- * If this is the first batch, the method creates a new list.
217
+ * Adds a write batch to the collection of batches on this builder. If this is the first batch, the method creates a new
218
+ * list.
124
219
*
125
220
* @param writeBatch a single write batch
126
221
* @return a builder of this type
0 commit comments