log.trace( "Existing version: " + oldVersion + " -> New version: " + fields[getVersionProperty()] );
}
}
final Cache<EntityKey, Map<String, Object>> entityCache = GridMetadataManagerHelper.getEntityCache( gridManager );
final GridDialect gridDialect = gridManager.getGridDialect();
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 = new EntityKeyBuilder().entityPersister( this ).id(id).getKey();
Map<String, Object> resultset = gridDialect.getTuple( key, entityCache );
final boolean useVersion = j == 0 && isVersioned();
resultset = createNewResultSetIfNull( key, entityCache, resultset, id, session );
final EntityMetamodel entityMetamodel = getEntityMetamodel();
// Write any appropriate versioning conditional parameters
if ( useVersion && Versioning.OPTIMISTIC_LOCK_VERSION == entityMetamodel.getOptimisticLockMode() ) {
if ( checkVersion( propsToUpdate ) ) {
checkVersionAndRaiseSOSE( id, oldVersion, session, resultset );
}
}
else if ( entityMetamodel.getOptimisticLockMode() > Versioning.OPTIMISTIC_LOCK_VERSION && oldFields != null ) {
boolean[] versionability = getPropertyVersionability(); //TODO: is this really necessary????
boolean[] includeOldField = entityMetamodel.getOptimisticLockMode() == Versioning.OPTIMISTIC_LOCK_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
);
comparePropertyAndRaiseSOSE(
id,
oldFields[i],
factory,
!type.isEqual( oldFields, snapshotValue, EntityMode.POJO, factory )
);
}
}
}
//dehydrate
dehydrate(resultset, fields, propsToUpdate, getPropertyColumnUpdateable(), j, id, session );
gridDialect.updateTuple( resultset, key, entityCache );
}
}
}