private Map < String , AttributeValueUpdate > transformAttributeUpdates ( Class < ? > clazz , Key objectKey , Map < String , AttributeValueUpdate > updateValues ) { Map < String , AttributeValue > item = convertToItem ( updateValues ) ; boolean hashKeyAdded = false ; boolean rangeKeyAdded = false ; String hashKey = reflector . getAttributeName ( reflector . getHashKeyGetter ( clazz ) ) ; if ( ! item . containsKey ( hashKey ) ) { item . put ( hashKey , objectKey . getHashKeyElement ( ) ) ; hashKeyAdded = true ; } String rangeKey = null ; Method rangeKeyGetter = reflector . getRangeKeyGetter ( clazz ) ; if ( rangeKeyGetter != null ) { rangeKey = reflector . getAttributeName ( rangeKeyGetter ) ; if ( ! item . containsKey ( rangeKey ) ) { item . put ( rangeKey , objectKey . getRangeKeyElement ( ) ) ; rangeKeyAdded = true ; } } item = transformAttributes ( clazz , item ) ; // Remove the keys if we added them before. if ( hashKeyAdded ) { item . remove ( hashKey ) ; } if ( rangeKeyAdded ) { item . remove ( rangeKey ) ; } for ( String key : item . keySet ( ) ) { if ( updateValues . containsKey ( key ) ) { updateValues . get ( key ) . getValue ( ) . withB ( item . get ( key ) . getB ( ) ) . withBS ( item . get ( key ) . getBS ( ) ) . withN ( item . get ( key ) . getN ( ) ) . withNS ( item . get ( key ) . getNS ( ) ) . withS ( item . get ( key ) . getS ( ) ) . withSS ( item . get ( key ) . getSS ( ) ) ; } else { updateValues . put ( key , new AttributeValueUpdate ( item . get ( key ) , "PUT" ) ) ; } } return updateValues ; }
A transformation expects to see all values including keys when determining the transformation therefore we must insert them if they are not already present . However we must remove the keys prior to actual storage as this method is called when updating DynamoDB which does not permit the modification of key attributes as part of an update call .