@ Override public void update ( Object entity ) { if ( entity == null ) { throw new IllegalArgumentException ( "'entity' must not be [" + entity + "]" ) ; } assertTransactional ( ) ; List < Log > logs = transaction . get ( ) . logs ( ) ; if ( logs . isEmpty ( ) ) { throw new IllegalStateException ( "Log [" + Log . Operation . UPDATE + "] is not allowed: previous operation must be [" + Log . Operation . GET + "]" ) ; } for ( int i = logs . size ( ) - 1 ; i >= 0 ; i -- ) { Log log = logs . get ( i ) ; if ( keyValue ( entity ) . equals ( keyValue ( log . entity ( ) ) ) ) { if ( log . operation ( ) == Log . Operation . GET ) { break ; } else { throw new IllegalStateException ( "Log [" + log . operation ( ) + "] -> [" + Log . Operation . UPDATE + "] is not allowed: previous operation must be [" + Log . Operation . GET + "]" ) ; } } } Transaction tx = transaction . get ( ) . transaction ( ) ; datastore . put ( tx , Translation . toEntities ( entity ) ) ; Log log = new Log ( logs . size ( ) + 1 , Log . Operation . UPDATE , entity ) ; log . state ( State . UNCOMMITTED ) ; logs . add ( log ) ; }
Updates the entity in the datastore with the specified one . This method must be invoked under a transaction .