use of org.hibernate.engine.spi.Status in project hibernate-orm by hibernate.
the class AbstractEntityEntry method isModifiableEntity.
@Override
public boolean isModifiableEntity() {
final Status status = getStatus();
final Status previousStatus = getPreviousStatus();
return getPersister().isMutable() && status != Status.READ_ONLY && !(status == Status.DELETED && previousStatus == Status.READ_ONLY);
}
use of org.hibernate.engine.spi.Status in project hibernate-orm by hibernate.
the class DefaultLoadEventListener method createProxyIfNecessary.
/**
* If there is already a corresponding proxy associated with the
* persistence context, return it; otherwise create a proxy, associate it
* with the persistence context, and return the just-created proxy.
*
* @param event The initiating load request event
* @param persister The persister corresponding to the entity to be loaded
* @param keyToLoad The key of the entity to be loaded
* @param options The defined load options
* @param persistenceContext The originating session
*
* @return The created/existing proxy
*/
private Object createProxyIfNecessary(final LoadEvent event, final EntityPersister persister, final EntityKey keyToLoad, final LoadEventListener.LoadType options, final PersistenceContext persistenceContext) {
Object existing = persistenceContext.getEntity(keyToLoad);
if (existing != null) {
// return existing object or initialized proxy (unless deleted)
if (traceEnabled) {
LOG.trace("Entity found in session cache");
}
if (options.isCheckDeleted()) {
EntityEntry entry = persistenceContext.getEntry(existing);
Status status = entry.getStatus();
if (status == Status.DELETED || status == Status.GONE) {
return null;
}
}
return existing;
}
if (traceEnabled) {
LOG.trace("Creating new proxy for entity");
}
// return new uninitialized proxy
Object proxy = persister.createProxy(event.getEntityId(), event.getSession());
persistenceContext.getBatchFetchQueue().addBatchLoadableEntityKey(keyToLoad);
persistenceContext.addProxy(keyToLoad, proxy);
return proxy;
}
use of org.hibernate.engine.spi.Status in project hibernate-orm by hibernate.
the class DefaultLoadEventListener method loadFromSessionCache.
/**
* Attempts to locate the entity in the session-level cache.
* <p/>
* If allowed to return nulls, then if the entity happens to be found in
* the session cache, we check the entity type for proper handling
* of entity hierarchies.
* <p/>
* If checkDeleted was set to true, then if the entity is found in the
* session-level cache, it's current status within the session cache
* is checked to see if it has previously been scheduled for deletion.
*
* @param event The load event
* @param keyToLoad The EntityKey representing the entity to be loaded.
* @param options The load options.
*
* @return The entity from the session-level cache, or null.
*
* @throws HibernateException Generally indicates problems applying a lock-mode.
*/
protected Object loadFromSessionCache(final LoadEvent event, final EntityKey keyToLoad, final LoadEventListener.LoadType options) throws HibernateException {
SessionImplementor session = event.getSession();
Object old = session.getEntityUsingInterceptor(keyToLoad);
if (old != null) {
// this object was already loaded
EntityEntry oldEntry = session.getPersistenceContext().getEntry(old);
if (options.isCheckDeleted()) {
Status status = oldEntry.getStatus();
if (status == Status.DELETED || status == Status.GONE) {
return REMOVED_ENTITY_MARKER;
}
}
if (options.isAllowNulls()) {
final EntityPersister persister = event.getSession().getFactory().getEntityPersister(keyToLoad.getEntityName());
if (!persister.isInstance(old)) {
return INCONSISTENT_RTN_CLASS_MARKER;
}
}
upgradeLock(old, oldEntry, event.getLockOptions(), event.getSession());
}
return old;
}
use of org.hibernate.engine.spi.Status in project hibernate-orm by hibernate.
the class AbstractFlushingEventListener method prepareEntityFlushes.
/**
* process cascade save/update at the start of a flush to discover
* any newly referenced entity that must be passed to saveOrUpdate(),
* and also apply orphan delete
*/
private void prepareEntityFlushes(EventSource session, PersistenceContext persistenceContext) throws HibernateException {
LOG.debug("Processing flush-time cascades");
final Object anything = getAnything();
// safe from concurrent modification because of how concurrentEntries() is implemented on IdentityMap
for (Map.Entry<Object, EntityEntry> me : persistenceContext.reentrantSafeEntityEntries()) {
// for ( Map.Entry me : IdentityMap.concurrentEntries( persistenceContext.getEntityEntries() ) ) {
EntityEntry entry = (EntityEntry) me.getValue();
Status status = entry.getStatus();
if (status == Status.MANAGED || status == Status.SAVING || status == Status.READ_ONLY) {
cascadeOnFlush(session, entry.getPersister(), me.getKey(), anything);
}
}
}
use of org.hibernate.engine.spi.Status in project hibernate-orm by hibernate.
the class AbstractEntityEntry method setStatus.
@Override
public void setStatus(Status status) {
if (status == Status.READ_ONLY) {
// memory optimization
loadedState = null;
}
final Status currentStatus = this.getStatus();
if (currentStatus != status) {
setCompressedValue(EnumState.PREVIOUS_STATUS, currentStatus);
setCompressedValue(EnumState.STATUS, status);
}
}
Aggregations