updatePS = database.prepareUpdateEntityStatement( connection );
removePS = database.prepareRemoveEntityStatement( connection );
for( EntityState state : states )
{
EntityStatus status = state.status();
DefaultEntityState defState = ( (SQLEntityState) state ).getDefaultEntityState();
Long entityPK = ( (SQLEntityState) state ).getEntityPK();
if( EntityStatus.REMOVED.equals( status ) )
{
database.populateRemoveEntityStatement( removePS, entityPK, state.identity() );
removePS.addBatch();
}
else
{
StringWriter writer = new StringWriter();
writeEntityState( defState, writer, unitofwork.identity() );
writer.flush();
if( EntityStatus.UPDATED.equals( status ) )
{
Long entityOptimisticLock = ( (SQLEntityState) state ).getEntityOptimisticLock();
database.populateUpdateEntityStatement( updatePS, entityPK, entityOptimisticLock,
defState.identity(), writer.toString(),
unitofwork.currentTime() );
updatePS.addBatch();
}
else if( EntityStatus.NEW.equals( status ) )
{
database.populateInsertEntityStatement( insertPS, defState.identity(),
writer.toString(), unitofwork.currentTime() );
insertPS.addBatch();
}
}
}