Search in sources :

Example 6 with Status

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);
}
Also used : Status(org.hibernate.engine.spi.Status)

Example 7 with Status

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;
}
Also used : Status(org.hibernate.engine.spi.Status) EntityEntry(org.hibernate.engine.spi.EntityEntry)

Example 8 with Status

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;
}
Also used : Status(org.hibernate.engine.spi.Status) EntityPersister(org.hibernate.persister.entity.EntityPersister) EntityEntry(org.hibernate.engine.spi.EntityEntry) SessionImplementor(org.hibernate.engine.spi.SessionImplementor)

Example 9 with Status

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);
        }
    }
}
Also used : Status(org.hibernate.engine.spi.Status) EntityEntry(org.hibernate.engine.spi.EntityEntry) Map(java.util.Map) IdentityMap(org.hibernate.internal.util.collections.IdentityMap) IdentityHashMap(java.util.IdentityHashMap)

Example 10 with Status

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);
    }
}
Also used : Status(org.hibernate.engine.spi.Status)

Aggregations

Status (org.hibernate.engine.spi.Status)11 EntityEntry (org.hibernate.engine.spi.EntityEntry)6 EntityPersister (org.hibernate.persister.entity.EntityPersister)5 EventSource (org.hibernate.event.spi.EventSource)3 IdentityHashMap (java.util.IdentityHashMap)2 Map (java.util.Map)2 IdentityMap (org.hibernate.internal.util.collections.IdentityMap)2 AssertionFailure (org.hibernate.AssertionFailure)1 EntityUpdateAction (org.hibernate.action.internal.EntityUpdateAction)1 CascadePoint (org.hibernate.engine.internal.CascadePoint)1 Nullability (org.hibernate.engine.internal.Nullability)1 CollectionEntry (org.hibernate.engine.spi.CollectionEntry)1 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)1 FlushEntityEvent (org.hibernate.event.spi.FlushEntityEvent)1 FlushEntityEventListener (org.hibernate.event.spi.FlushEntityEventListener)1 Type (org.hibernate.type.Type)1