Search in sources :

Example 1 with ManagedEntity

use of org.hibernate.engine.spi.ManagedEntity in project hibernate-orm by hibernate.

the class EntityEntryContext method clear.

/**
	 * Clear this context of all managed entities
	 */
public void clear() {
    dirty = true;
    ManagedEntity node = head;
    while (node != null) {
        final ManagedEntity nextNode = node.$$_hibernate_getNextManagedEntity();
        node.$$_hibernate_setEntityEntry(null);
        node.$$_hibernate_setPreviousManagedEntity(null);
        node.$$_hibernate_setNextManagedEntity(null);
        node = nextNode;
    }
    if (immutableManagedEntityXref != null) {
        immutableManagedEntityXref.clear();
    }
    if (nonEnhancedEntityXref != null) {
        nonEnhancedEntityXref.clear();
    }
    head = null;
    tail = null;
    count = 0;
    reentrantSafeEntries = null;
}
Also used : ManagedEntity(org.hibernate.engine.spi.ManagedEntity)

Example 2 with ManagedEntity

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

Example 3 with ManagedEntity

use of org.hibernate.engine.spi.ManagedEntity in project hibernate-orm by hibernate.

the class EntityEntryContext method getAssociatedManagedEntity.

private ManagedEntity getAssociatedManagedEntity(Object entity) {
    if (ManagedEntity.class.isInstance(entity)) {
        final ManagedEntity managedEntity = (ManagedEntity) entity;
        if (managedEntity.$$_hibernate_getEntityEntry() == null) {
            // it is not associated
            return null;
        }
        final AbstractEntityEntry entityEntry = (AbstractEntityEntry) managedEntity.$$_hibernate_getEntityEntry();
        if (entityEntry.getPersister().isMutable()) {
            return entityEntry.getPersistenceContext() == persistenceContext ? // it is associated
            managedEntity : null;
        } else {
            // holder will be returned.
            return immutableManagedEntityXref != null ? immutableManagedEntityXref.get(managedEntity) : null;
        }
    } else {
        return nonEnhancedEntityXref != null ? nonEnhancedEntityXref.get(entity) : null;
    }
}
Also used : ManagedEntity(org.hibernate.engine.spi.ManagedEntity)

Example 4 with ManagedEntity

use of org.hibernate.engine.spi.ManagedEntity in project hibernate-orm by hibernate.

the class EntityEntryContext method reentrantSafeEntityEntries.

/**
	 * The main bugaboo with IdentityMap that warranted this class in the first place.
	 *
	 * Return an array of all the entity/EntityEntry pairs in this context.  The array is to make sure
	 * that the iterators built off of it are safe from concurrency/reentrancy
	 *
	 * @return The safe array
	 */
public Map.Entry<Object, EntityEntry>[] reentrantSafeEntityEntries() {
    if (dirty) {
        reentrantSafeEntries = new EntityEntryCrossRefImpl[count];
        int i = 0;
        ManagedEntity managedEntity = head;
        while (managedEntity != null) {
            reentrantSafeEntries[i++] = new EntityEntryCrossRefImpl(managedEntity.$$_hibernate_getEntityInstance(), managedEntity.$$_hibernate_getEntityEntry());
            managedEntity = managedEntity.$$_hibernate_getNextManagedEntity();
        }
        dirty = false;
    }
    return reentrantSafeEntries;
}
Also used : ManagedEntity(org.hibernate.engine.spi.ManagedEntity)

Example 5 with ManagedEntity

use of org.hibernate.engine.spi.ManagedEntity in project hibernate-orm by hibernate.

the class DefaultLoadEventListener method makeEntityCircularReferenceSafe.

private void makeEntityCircularReferenceSafe(ReferenceCacheEntryImpl referenceCacheEntry, EventSource session, Object entity, EntityKey entityKey) {
    // make it circular-reference safe
    final StatefulPersistenceContext statefulPersistenceContext = (StatefulPersistenceContext) session.getPersistenceContext();
    if ((entity instanceof ManagedEntity)) {
        statefulPersistenceContext.addReferenceEntry(entity, Status.READ_ONLY);
    } else {
        TwoPhaseLoad.addUninitializedCachedEntity(entityKey, entity, referenceCacheEntry.getSubclassPersister(), LockMode.NONE, referenceCacheEntry.getVersion(), session);
    }
    statefulPersistenceContext.initializeNonLazyCollections();
}
Also used : ManagedEntity(org.hibernate.engine.spi.ManagedEntity) StatefulPersistenceContext(org.hibernate.engine.internal.StatefulPersistenceContext)

Aggregations

ManagedEntity (org.hibernate.engine.spi.ManagedEntity)11 EntityEntry (org.hibernate.engine.spi.EntityEntry)2 Session (org.hibernate.Session)1 StatefulPersistenceContext (org.hibernate.engine.internal.StatefulPersistenceContext)1 PersistentAttributeInterceptable (org.hibernate.engine.spi.PersistentAttributeInterceptable)1