use of org.hibernate.engine.spi.EntityEntry in project hibernate-orm by hibernate.
the class PessimisticForceIncrementLockingStrategy method lock.
@Override
public void lock(Serializable id, Object version, Object object, int timeout, SharedSessionContractImplementor session) {
if (!lockable.isVersioned()) {
throw new HibernateException("[" + lockMode + "] not supported for non-versioned entities [" + lockable.getEntityName() + "]");
}
final EntityEntry entry = session.getPersistenceContext().getEntry(object);
final EntityPersister persister = entry.getPersister();
final Object nextVersion = persister.forceVersionIncrement(entry.getId(), entry.getVersion(), session);
entry.forceLocked(object, nextVersion);
}
use of org.hibernate.engine.spi.EntityEntry in project hibernate-orm by hibernate.
the class OptimisticForceIncrementLockingStrategy method lock.
@Override
public void lock(Serializable id, Object version, Object object, int timeout, SharedSessionContractImplementor session) {
if (!lockable.isVersioned()) {
throw new HibernateException("[" + lockMode + "] not supported for non-versioned entities [" + lockable.getEntityName() + "]");
}
final EntityEntry entry = session.getPersistenceContext().getEntry(object);
// Register the EntityIncrementVersionProcess action to run just prior to transaction commit.
((EventSource) session).getActionQueue().registerProcess(new EntityIncrementVersionProcess(object, entry));
}
use of org.hibernate.engine.spi.EntityEntry in project hibernate-orm by hibernate.
the class EntityEntryContext method removeEntityEntry.
/**
* Remove an entity from the context, returning the EntityEntry which was associated with it
*
* @param entity The entity to remove
*
* @return Tjee EntityEntry
*/
public EntityEntry removeEntityEntry(Object entity) {
// locate a ManagedEntity for the entity, but only if it is associated with the same PersistenceContext.
// no need to check if the entity is a ManagedEntity that is associated with a different PersistenceContext
final ManagedEntity managedEntity = getAssociatedManagedEntity(entity);
if (managedEntity == null) {
// not associated with this EntityEntryContext, so nothing to do.
return null;
}
dirty = true;
if (ImmutableManagedEntityHolder.class.isInstance(managedEntity)) {
assert entity == ((ImmutableManagedEntityHolder) managedEntity).managedEntity;
immutableManagedEntityXref.remove((ManagedEntity) entity);
} else if (!ManagedEntity.class.isInstance(entity)) {
nonEnhancedEntityXref.remove(entity);
}
// prepare for re-linking...
final ManagedEntity previous = managedEntity.$$_hibernate_getPreviousManagedEntity();
final ManagedEntity next = managedEntity.$$_hibernate_getNextManagedEntity();
managedEntity.$$_hibernate_setPreviousManagedEntity(null);
managedEntity.$$_hibernate_setNextManagedEntity(null);
// re-link
count--;
if (count == 0) {
// handle as a special case...
head = null;
tail = null;
assert previous == null;
assert next == null;
} else {
// otherwise, previous or next (or both) should be non-null
if (previous == null) {
// we are removing head
assert managedEntity == head;
head = next;
} else {
previous.$$_hibernate_setNextManagedEntity(next);
}
if (next == null) {
// we are removing tail
assert managedEntity == tail;
tail = previous;
} else {
next.$$_hibernate_setPreviousManagedEntity(previous);
}
}
// finally clean out the ManagedEntity and return the associated EntityEntry
final EntityEntry theEntityEntry = managedEntity.$$_hibernate_getEntityEntry();
managedEntity.$$_hibernate_setEntityEntry(null);
return theEntityEntry;
}
use of org.hibernate.engine.spi.EntityEntry in project hibernate-orm by hibernate.
the class StatefulPersistenceContext method setEntityReadOnly.
private void setEntityReadOnly(Object entity, boolean readOnly) {
final EntityEntry entry = getEntry(entity);
if (entry == null) {
throw new TransientObjectException("Instance was not associated with this persistence context");
}
entry.setReadOnly(readOnly, entity);
hasNonReadOnlyEntities = hasNonReadOnlyEntities || !readOnly;
}
use of org.hibernate.engine.spi.EntityEntry in project hibernate-orm by hibernate.
the class StatefulPersistenceContext method replaceDelayedEntityIdentityInsertKeys.
@Override
public void replaceDelayedEntityIdentityInsertKeys(EntityKey oldKey, Serializable generatedId) {
final Object entity = entitiesByKey.remove(oldKey);
final EntityEntry oldEntry = entityEntryContext.removeEntityEntry(entity);
parentsByChild.clear();
final EntityKey newKey = session.generateEntityKey(generatedId, oldEntry.getPersister());
addEntity(newKey, entity);
addEntry(entity, oldEntry.getStatus(), oldEntry.getLoadedState(), oldEntry.getRowId(), generatedId, oldEntry.getVersion(), oldEntry.getLockMode(), oldEntry.isExistsInDatabase(), oldEntry.getPersister(), oldEntry.isBeingReplicated());
}
Aggregations