@@ -292,43 +292,6 @@ public void autogenerateKey_onVersionedRecord_setOnPrimaryKey_performsUuidGenera
292292 }
293293 }
294294
295- @ Test
296- public void autogenerateKey_withUpdateBehaviorOnPrimaryKey_preservesKeyOnUpdate () {
297- String tableName = getConcreteTableName ("autogen-pk-update-behavior" );
298- DynamoDbEnhancedClient client = DynamoDbEnhancedClient .builder ()
299- .dynamoDbClient (getDynamoDbClient ())
300- .extensions (AutoGeneratedKeyExtension .builder ().build ())
301- .build ();
302-
303- TableSchema <PrimaryKeyWithUpdateBehaviorBean > schema = TableSchema .fromBean (PrimaryKeyWithUpdateBehaviorBean .class );
304- DynamoDbTable <PrimaryKeyWithUpdateBehaviorBean > table = client .table (tableName , schema );
305-
306- try {
307- table .createTable (r -> r .provisionedThroughput (getDefaultProvisionedThroughput ()));
308-
309- // First put - should generate UUID for primary key
310- PrimaryKeyWithUpdateBehaviorBean bean = new PrimaryKeyWithUpdateBehaviorBean ();
311- bean .setPayload ("initial" );
312- table .putItem (bean );
313-
314- PrimaryKeyWithUpdateBehaviorBean afterPut = table .scan ().items ().stream ().findFirst ()
315- .orElseThrow (() -> new AssertionError ("No record found" ));
316- String generatedId = afterPut .getId ();
317- assertValidUuid (generatedId );
318- assertEquals ("initial" , afterPut .getPayload ());
319-
320- // Update - should preserve the generated primary key due to WRITE_IF_NOT_EXISTS
321- afterPut .setPayload ("updated" );
322- table .updateItem (afterPut );
323-
324- PrimaryKeyWithUpdateBehaviorBean afterUpdate = table .getItem (r -> r .key (k -> k .partitionValue (generatedId )));
325- assertThat (afterUpdate .getId ()).isEqualTo (generatedId ); // Key preserved
326- assertEquals ("updated" , afterUpdate .getPayload ());
327- } finally {
328- deleteTableByName (tableName );
329- }
330- }
331-
332295 /**
333296 * - createdKey: GSI SK + @DynamoDbAutoGeneratedKey annotation (UpdateBehaviour is WRITE_IF_NOT_EXISTS)
334297 * - lastUpdatedKey: GSI PK + @DynamoDbAutoGeneratedKey annotation (UpdateBehaviour is WRITE_ALWAYS - default value)
@@ -570,31 +533,6 @@ public void setPayload(String payload) {
570533 }
571534 }
572535
573- @ DynamoDbBean
574- public static class PrimaryKeyWithUpdateBehaviorBean {
575- private String id ;
576- private String payload ;
577-
578- @ DynamoDbPartitionKey
579- @ DynamoDbAutoGeneratedKey
580- @ DynamoDbUpdateBehavior (UpdateBehavior .WRITE_IF_NOT_EXISTS )
581- public String getId () {
582- return id ;
583- }
584-
585- public void setId (String id ) {
586- this .id = id ;
587- }
588-
589- public String getPayload () {
590- return payload ;
591- }
592-
593- public void setPayload (String payload ) {
594- this .payload = payload ;
595- }
596- }
597-
598536 private void deleteTableByName (String tableName ) {
599537 getDynamoDbClient ().deleteTable (b -> b .tableName (tableName ));
600538 }
0 commit comments