Search in sources :

Example 11 with ManagedEntity

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

the class EntityEntryContext method deserialize.

/**
	 * JDK serialization hook for deserializing
	 *
	 * @param ois The stream to read ourselves from
	 * @param rtn The persistence context we belong to
	 *
	 * @return The deserialized EntityEntryContext
	 *
	 * @throws IOException Indicates an IO exception accessing the given stream
	 * @throws ClassNotFoundException Problem reading stream data
	 */
public static EntityEntryContext deserialize(ObjectInputStream ois, StatefulPersistenceContext rtn) throws IOException, ClassNotFoundException {
    final int count = ois.readInt();
    log.tracef("Starting deserialization of [%s] EntityEntry entries", count);
    final EntityEntryContext context = new EntityEntryContext(rtn);
    context.count = count;
    context.dirty = true;
    if (count == 0) {
        return context;
    }
    ManagedEntity previous = null;
    for (int i = 0; i < count; i++) {
        final boolean isEnhanced = ois.readBoolean();
        final Object entity = ois.readObject();
        //Call deserialize method dynamically via reflection
        final int numChars = ois.readInt();
        final char[] entityEntryClassNameArr = new char[numChars];
        for (int j = 0; j < numChars; j++) {
            entityEntryClassNameArr[j] = ois.readChar();
        }
        final EntityEntry entry = deserializeEntityEntry(entityEntryClassNameArr, ois, rtn);
        final ManagedEntity managedEntity;
        if (isEnhanced) {
            if (entry.getPersister().isMutable()) {
                managedEntity = (ManagedEntity) entity;
            } else {
                managedEntity = new ImmutableManagedEntityHolder((ManagedEntity) entity);
                if (context.immutableManagedEntityXref == null) {
                    context.immutableManagedEntityXref = new IdentityHashMap<ManagedEntity, ImmutableManagedEntityHolder>();
                }
                context.immutableManagedEntityXref.put((ManagedEntity) entity, (ImmutableManagedEntityHolder) managedEntity);
            }
        } else {
            managedEntity = new ManagedEntityImpl(entity);
            if (context.nonEnhancedEntityXref == null) {
                context.nonEnhancedEntityXref = new IdentityHashMap<Object, ManagedEntity>();
            }
            context.nonEnhancedEntityXref.put(entity, managedEntity);
        }
        managedEntity.$$_hibernate_setEntityEntry(entry);
        if (previous == null) {
            context.head = managedEntity;
        } else {
            previous.$$_hibernate_setNextManagedEntity(managedEntity);
            managedEntity.$$_hibernate_setPreviousManagedEntity(previous);
        }
        previous = managedEntity;
    }
    context.tail = previous;
    return context;
}
Also used : ManagedEntity(org.hibernate.engine.spi.ManagedEntity) EntityEntry(org.hibernate.engine.spi.EntityEntry)

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