1616package org .eclipse .jnosql .databases .dynamodb .communication ;
1717
1818import org .eclipse .jnosql .communication .Settings ;
19- import org .eclipse .jnosql .communication .document . DocumentDeleteQuery ;
20- import org .eclipse .jnosql .communication .document . DocumentEntity ;
21- import org .eclipse .jnosql .communication .document . DocumentQuery ;
19+ import org .eclipse .jnosql .communication .semistructured . CommunicationEntity ;
20+ import org .eclipse .jnosql .communication .semistructured . DeleteQuery ;
21+ import org .eclipse .jnosql .communication .semistructured . SelectQuery ;
2222import software .amazon .awssdk .services .dynamodb .DynamoDbClient ;
2323import software .amazon .awssdk .services .dynamodb .model .AttributeDefinition ;
2424import software .amazon .awssdk .services .dynamodb .model .AttributeValue ;
6060import static java .util .Objects .requireNonNull ;
6161import static org .eclipse .jnosql .databases .dynamodb .communication .DynamoDBConverter .entityAttributeName ;
6262import static org .eclipse .jnosql .databases .dynamodb .communication .DynamoDBConverter .toAttributeValue ;
63- import static org .eclipse .jnosql .databases .dynamodb .communication .DynamoDBConverter .toDocumentEntity ;
63+ import static org .eclipse .jnosql .databases .dynamodb .communication .DynamoDBConverter .toCommunicationEntity ;
6464import static org .eclipse .jnosql .databases .dynamodb .communication .DynamoDBConverter .toItem ;
6565import static org .eclipse .jnosql .databases .dynamodb .communication .DynamoDBConverter .toItemUpdate ;
6666
67- public class DefaultDynamoDBDocumentManager implements DynamoDBDocumentManager {
67+ public class DefaultDynamoDBDatabaseManager implements DynamoDBDatabaseManager {
6868
6969 private final String database ;
7070
@@ -76,7 +76,7 @@ public class DefaultDynamoDBDocumentManager implements DynamoDBDocumentManager {
7676
7777 private final ConcurrentHashMap <String , DescribeTableResponse > tables = new ConcurrentHashMap <>();
7878
79- public DefaultDynamoDBDocumentManager (String database , DynamoDbClient dynamoDbClient , Settings settings ) {
79+ public DefaultDynamoDBDatabaseManager (String database , DynamoDbClient dynamoDbClient , Settings settings ) {
8080 this .settings = settings ;
8181 this .database = database ;
8282 this .dynamoDbClient = dynamoDbClient ;
@@ -96,7 +96,7 @@ public String name() {
9696 }
9797
9898 @ Override
99- public DocumentEntity insert (DocumentEntity documentEntity ) {
99+ public CommunicationEntity insert (CommunicationEntity documentEntity ) {
100100 requireNonNull (documentEntity , "documentEntity is required" );
101101 dynamoDbClient ().putItem (PutItemRequest .builder ()
102102 .tableName (createTableIfNeeded (documentEntity .name ()).table ().tableName ())
@@ -189,23 +189,23 @@ private String getEntityAttributeName() {
189189 }
190190
191191 @ Override
192- public DocumentEntity insert (DocumentEntity documentEntity , Duration ttl ) {
192+ public CommunicationEntity insert (CommunicationEntity documentEntity , Duration ttl ) {
193193 requireNonNull (documentEntity , "documentEntity is required" );
194194 requireNonNull (ttl , "ttl is required" );
195195 documentEntity .add (getTTLAttributeName (documentEntity .name ()).get (), Instant .now ().plus (ttl ).truncatedTo (ChronoUnit .SECONDS ));
196196 return insert (documentEntity );
197197 }
198198
199199 @ Override
200- public Iterable <DocumentEntity > insert (Iterable <DocumentEntity > entities ) {
200+ public Iterable <CommunicationEntity > insert (Iterable <CommunicationEntity > entities ) {
201201 requireNonNull (entities , "entities are required" );
202202 return StreamSupport .stream (entities .spliterator (), false )
203203 .map (this ::insert )
204204 .toList ();
205205 }
206206
207207 @ Override
208- public Iterable <DocumentEntity > insert (Iterable <DocumentEntity > entities , Duration ttl ) {
208+ public Iterable <CommunicationEntity > insert (Iterable <CommunicationEntity > entities , Duration ttl ) {
209209 requireNonNull (entities , "entities is required" );
210210 requireNonNull (ttl , "ttl is required" );
211211 return StreamSupport .stream (entities .spliterator (), false )
@@ -214,7 +214,7 @@ public Iterable<DocumentEntity> insert(Iterable<DocumentEntity> entities, Durati
214214 }
215215
216216 @ Override
217- public DocumentEntity update (DocumentEntity documentEntity ) {
217+ public CommunicationEntity update (CommunicationEntity documentEntity ) {
218218 requireNonNull (documentEntity , "entity is required" );
219219 Map <String , AttributeValue > itemKey = getItemKey (documentEntity );
220220 Map <String , AttributeValueUpdate > attributeUpdates = asItemToUpdate (documentEntity );
@@ -227,7 +227,7 @@ public DocumentEntity update(DocumentEntity documentEntity) {
227227 return documentEntity ;
228228 }
229229
230- private Map <String , AttributeValue > getItemKey (DocumentEntity documentEntity ) {
230+ private Map <String , AttributeValue > getItemKey (CommunicationEntity documentEntity ) {
231231 DescribeTableResponse describeTableResponse = this .tables .computeIfAbsent (documentEntity .name (), this ::getDescribeTableResponse );
232232 Map <String , AttributeValue > itemKey = describeTableResponse
233233 .table ()
@@ -243,47 +243,48 @@ private Map<String, AttributeValue> getItemKey(DocumentEntity documentEntity) {
243243 return itemKey ;
244244 }
245245
246- private Map <String , AttributeValueUpdate > asItemToUpdate (DocumentEntity documentEntity ) {
246+ private Map <String , AttributeValueUpdate > asItemToUpdate (CommunicationEntity documentEntity ) {
247247 return toItemUpdate (this ::resolveEntityNameAttributeName , documentEntity );
248248 }
249249
250250 @ Override
251- public Iterable <DocumentEntity > update (Iterable <DocumentEntity > entities ) {
251+ public Iterable <CommunicationEntity > update (Iterable <CommunicationEntity > entities ) {
252252 requireNonNull (entities , "entities is required" );
253253 return StreamSupport .stream (entities .spliterator (), false )
254254 .map (this ::update )
255255 .toList ();
256256 }
257257
258258 @ Override
259- public void delete (DocumentDeleteQuery documentDeleteQuery ) {
260- Objects .requireNonNull (documentDeleteQuery , "documentDeleteQuery is required" );
259+ public void delete (DeleteQuery deleteQuery ) {
260+ Objects .requireNonNull (deleteQuery , "deleteQuery is required" );
261261
262- List <String > primaryKeys = getDescribeTableResponse (documentDeleteQuery .name ())
262+ List <String > primaryKeys = getDescribeTableResponse (deleteQuery .name ())
263263 .table ()
264264 .keySchema ()
265265 .stream ()
266266 .map (KeySchemaElement ::attributeName ).toList ();
267267
268- DocumentQuery .DocumentQueryBuilder selectQueryBuilder = DocumentQuery .builder ()
268+
269+ var selectQueryBuilder = SelectQuery .builder ()
269270 .select (primaryKeys .toArray (new String [0 ]))
270- .from (documentDeleteQuery .name ());
271+ .from (deleteQuery .name ());
271272
272- documentDeleteQuery .condition ().ifPresent (selectQueryBuilder ::where );
273+ deleteQuery .condition ().ifPresent (selectQueryBuilder ::where );
273274
274275 select (selectQueryBuilder .build ()).forEach (
275276 documentEntity ->
276277 dynamoDbClient ().deleteItem (DeleteItemRequest .builder ()
277- .tableName (documentDeleteQuery .name ())
278+ .tableName (deleteQuery .name ())
278279 .key (getItemKey (documentEntity ))
279280 .build ()));
280281 }
281282
282283 @ Override
283- public Stream <DocumentEntity > select (DocumentQuery documentQuery ) {
284- Objects .requireNonNull (documentQuery , "documentQuery is required" );
284+ public Stream <CommunicationEntity > select (SelectQuery query ) {
285+ Objects .requireNonNull (query , "query is required" );
285286 DynamoDBQuery dynamoDBQuery = DynamoDBQuery
286- .builderOf (documentQuery .name (), getEntityAttributeName (), documentQuery )
287+ .builderOf (query .name (), getEntityAttributeName (), query )
287288 .get ();
288289
289290 ScanRequest .Builder selectRequest = ScanRequest .builder ()
@@ -298,7 +299,7 @@ public Stream<DocumentEntity> select(DocumentQuery documentQuery) {
298299 return StreamSupport
299300 .stream (dynamoDbClient ().scanPaginator (selectRequest .build ()).spliterator (), false )
300301 .flatMap (scanResponse -> scanResponse .items ().stream ()
301- .map (item -> toDocumentEntity (this ::resolveEntityNameAttributeName , item )));
302+ .map (item -> toCommunicationEntity (this ::resolveEntityNameAttributeName , item )));
302303 }
303304
304305 @ Override
@@ -319,29 +320,24 @@ public void close() {
319320 }
320321
321322 @ Override
322- public Stream <DocumentEntity > partiQL (String query ) {
323- return partiQL (query ,new Object [0 ]);
324- }
325-
326- @ Override
327- public Stream <DocumentEntity > partiQL (String query , Object ... params ) {
323+ public Stream <CommunicationEntity > partiQL (String query , Object ... params ) {
328324 Objects .requireNonNull (query , "query is required" );
329325 List <AttributeValue > parameters = Stream .of (params ).map (DynamoDBConverter ::toAttributeValue ).toList ();
330326 ExecuteStatementResponse executeStatementResponse = dynamoDbClient ()
331327 .executeStatement (ExecuteStatementRequest .builder ()
332328 .statement (query )
333329 .parameters (parameters )
334330 .build ());
335- List <DocumentEntity > result = new LinkedList <>();
336- executeStatementResponse .items ().forEach (item -> result .add (toDocumentEntity (this ::resolveEntityNameAttributeName , item )));
331+ List <CommunicationEntity > result = new LinkedList <>();
332+ executeStatementResponse .items ().forEach (item -> result .add (toCommunicationEntity (this ::resolveEntityNameAttributeName , item )));
337333 while (executeStatementResponse .nextToken () != null ) {
338334 executeStatementResponse = dynamoDbClient ()
339335 .executeStatement (ExecuteStatementRequest .builder ()
340336 .statement (query )
341337 .parameters (parameters )
342338 .nextToken (executeStatementResponse .nextToken ())
343339 .build ());
344- executeStatementResponse .items ().forEach (item -> result .add (toDocumentEntity (this ::resolveEntityNameAttributeName , item )));
340+ executeStatementResponse .items ().forEach (item -> result .add (toCommunicationEntity (this ::resolveEntityNameAttributeName , item )));
345341 }
346342 return result .stream ();
347343 }
0 commit comments