for ( int j = 0; j < span; j++ ) {
// Now update only the tables with dirty properties (and the table with the version number)
if ( tableUpdateNeeded[j] ) {
final EntityKey key = EntityKeyBuilder.fromPersister( this, id, session );
Tuple resultset = null;
if ( mightRequireInverseAssociationManagement || usesNonAtomicOptimisticLocking ) {
resultset = gridDialect.getTuple( key, getTupleContext() );
}
else {
OgmEntityEntryState extraState = entry.getExtraState( OgmEntityEntryState.class );
if ( extraState != null ) {
resultset = extraState.getTuple();
}
if ( resultset == null ) {
resultset = gridDialect.getTuple( key, getTupleContext() );
}
}
final boolean useVersion = j == 0 && isVersioned();
resultset = createNewResultSetIfNull( key, resultset, id, session );
final EntityMetamodel entityMetamodel = getEntityMetamodel();
if ( usesNonAtomicOptimisticLocking ) {
// Write any appropriate versioning conditional parameters
if ( useVersion && entityMetamodel.getOptimisticLockStyle() == OptimisticLockStyle.VERSION ) {
if ( checkVersion( propsToUpdate ) ) {
checkVersionAndRaiseSOSE( id, oldVersion, session, resultset );
}
}
else if ( isAllOrDirtyOptLocking() && oldFields != null ) {
boolean[] versionability = getPropertyVersionability(); //TODO: is this really necessary????
boolean[] includeOldField = entityMetamodel.getOptimisticLockStyle() == OptimisticLockStyle.ALL
? getPropertyUpdateability()
: propsToUpdate;
//TODO do a diff on the properties value from resultset and the dirty value
GridType[] types = gridPropertyTypes;
for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) {
boolean include = includeOldField[i] &&
isPropertyOfTable( i, j ) &&
versionability[i]; //TODO: is this really necessary????
if ( include ) {
final GridType type = types[i];
//FIXME what do do with settable?
boolean[] settable = type.toColumnNullness( oldFields[i], factory );
final Object snapshotValue = type.nullSafeGet(
resultset, getPropertyColumnNames( i ), session, object
);
if ( !type.isEqual( oldFields[i], snapshotValue, factory ) ) {
raiseStaleObjectStateException( id );
}
}
}
}
}
if ( mightRequireInverseAssociationManagement ) {
removeFromInverseAssociations( resultset, j, id, session );
}
dehydrate( resultset, fields, propsToUpdate, j, id, session );
// TODO OGM-616 Also use this facet for "all columns" optimistic locking strategy
if ( isVersioned() && optimisticLockingAwareGridDialect != null ) {
Tuple oldVersionTuple = new Tuple();
oldVersionTuple.put( getVersionColumnName(), oldVersion );
boolean success = optimisticLockingAwareGridDialect.updateTupleWithOptimisticLock( key, oldVersionTuple, resultset, getTupleContext() );
if ( !success ) {
raiseStaleObjectStateException( id );