//TODO support "multi table" entities
final boolean[] tableUpdateNeeded = getTableUpdateNeeded( dirtyFields, hasDirtyCollection );
final int span = getTableSpan();
final boolean[] propsToUpdate;
EntityEntry entry = session.getPersistenceContext().getEntry( object );
// Ensure that an immutable or non-modifiable entity is not being updated unless it is
// in the process of being deleted.
if ( entry == null && ! isMutable() ) {
throw new IllegalStateException( "Updating immutable entity that is not in session yet!" );
}
//we always use a dynamicUpdate model for Infinispan
if ( (
//getEntityMetamodel().isDynamicUpdate() &&
dirtyFields != null ) ) {
propsToUpdate = getPropertiesToUpdate( dirtyFields, hasDirtyCollection );
// don't need to check laziness (dirty checking algorithm handles that)
}
else if ( ! isModifiableEntity( entry ) ) {
//TODO does that apply to OGM?
// We need to generate UPDATE SQL when a non-modifiable entity (e.g., read-only or immutable)
// needs:
// - to have references to transient entities set to null before being deleted
// - to have version incremented do to a "dirty" association
// If dirtyFields == null, then that means that there are no dirty properties to
// to be updated; an empty array for the dirty fields needs to be passed to
// getPropertiesToUpdate() instead of null.
propsToUpdate = getPropertiesToUpdate(
( dirtyFields == null ? ArrayHelper.EMPTY_INT_ARRAY : dirtyFields ),
hasDirtyCollection
);
// don't need to check laziness (dirty checking algorithm handles that)
}
else {
// For the case of dynamic-update="false", or no snapshot, we update all properties
//TODO handle lazy
propsToUpdate = getPropertyUpdateability( object );
}
final SessionFactoryImplementor factory = getFactory();
if ( log.isTraceEnabled() ) {
log.trace( "Updating entity: " + MessageHelper.infoString( this, id, factory ) );
if ( isVersioned() ) {
log.trace( "Existing version: " + oldVersion + " -> New version: " + fields[getVersionProperty()] );
}
}
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() );