Search in sources :

Example 21 with EventSource

use of org.hibernate.event.spi.EventSource in project hibernate-orm by hibernate.

the class AbstractRowReader method finishUp.

@Override
public void finishUp(ResultSetProcessingContextImpl context, List<AfterLoadAction> afterLoadActionList) {
    final List<HydratedEntityRegistration> hydratedEntityRegistrations = context.getHydratedEntityRegistrationList();
    // for arrays, we should end the collection load beforeQuery resolving the entities, since the
    // actual array instances are not instantiated during loading
    finishLoadingArrays(context);
    // IMPORTANT: reuse the same event instances for performance!
    final PreLoadEvent preLoadEvent;
    final PostLoadEvent postLoadEvent;
    if (context.getSession().isEventSource()) {
        preLoadEvent = new PreLoadEvent((EventSource) context.getSession());
        postLoadEvent = new PostLoadEvent((EventSource) context.getSession());
    } else {
        preLoadEvent = null;
        postLoadEvent = null;
    }
    // now finish loading the entities (2-phase load)
    performTwoPhaseLoad(preLoadEvent, context, hydratedEntityRegistrations);
    // now we can finalize loading collections
    finishLoadingCollections(context);
    // finally, perform post-load operations
    postLoad(postLoadEvent, context, hydratedEntityRegistrations, afterLoadActionList);
}
Also used : PostLoadEvent(org.hibernate.event.spi.PostLoadEvent) EventSource(org.hibernate.event.spi.EventSource) PreLoadEvent(org.hibernate.event.spi.PreLoadEvent)

Example 22 with EventSource

use of org.hibernate.event.spi.EventSource in project hibernate-orm by hibernate.

the class AuditReaderImpl method getCurrentRevision.

@Override
@SuppressWarnings({ "unchecked" })
public <T> T getCurrentRevision(Class<T> revisionEntityClass, boolean persist) {
    revisionEntityClass = getTargetClassIfProxied(revisionEntityClass);
    if (!(session instanceof EventSource)) {
        throw new IllegalArgumentException("The provided session is not an EventSource!");
    }
    // Obtaining the current audit sync
    final AuditProcess auditProcess = enversService.getAuditProcessManager().get((EventSource) session);
    // And getting the current revision data
    return (T) auditProcess.getCurrentRevisionData(session, persist);
}
Also used : EventSource(org.hibernate.event.spi.EventSource) AuditProcess(org.hibernate.envers.internal.synchronization.AuditProcess)

Example 23 with EventSource

use of org.hibernate.event.spi.EventSource in project hibernate-orm by hibernate.

the class CustomPersister method load.

/**
	 * @see EntityPersister#load(Serializable, Object, LockMode, SharedSessionContractImplementor)
	 */
public Object load(Serializable id, Object optionalObject, LockMode lockMode, SharedSessionContractImplementor session) throws HibernateException {
    // fails when optional object is supplied
    Custom clone = null;
    Custom obj = (Custom) INSTANCES.get(id);
    if (obj != null) {
        clone = (Custom) obj.clone();
        TwoPhaseLoad.addUninitializedEntity(session.generateEntityKey(id, this), clone, this, LockMode.NONE, session);
        TwoPhaseLoad.postHydrate(this, id, new String[] { obj.getName() }, null, clone, LockMode.NONE, session);
        TwoPhaseLoad.initializeEntity(clone, false, session, new PreLoadEvent((EventSource) session));
        TwoPhaseLoad.postLoad(clone, session, new PostLoadEvent((EventSource) session));
    }
    return clone;
}
Also used : PostLoadEvent(org.hibernate.event.spi.PostLoadEvent) EventSource(org.hibernate.event.spi.EventSource) PreLoadEvent(org.hibernate.event.spi.PreLoadEvent)

Example 24 with EventSource

use of org.hibernate.event.spi.EventSource in project hibernate-orm by hibernate.

the class DefaultPersistEventListener method entityIsTransient.

/**
	 * Handle the given create event.
	 *
	 * @param event The save event to be handled.
	 * @param createCache The copy cache of entity instance to merge/copy instance.
	 */
@SuppressWarnings({ "unchecked" })
protected void entityIsTransient(PersistEvent event, Map createCache) {
    LOG.trace("Saving transient instance");
    final EventSource source = event.getSession();
    final Object entity = source.getPersistenceContext().unproxy(event.getObject());
    if (createCache.put(entity, entity) == null) {
        saveWithGeneratedId(entity, event.getEntityName(), createCache, source, false);
    }
}
Also used : EventSource(org.hibernate.event.spi.EventSource)

Example 25 with EventSource

use of org.hibernate.event.spi.EventSource in project hibernate-orm by hibernate.

the class DefaultPersistEventListener method entityIsDeleted.

@SuppressWarnings({ "unchecked" })
private void entityIsDeleted(PersistEvent event, Map createCache) {
    final EventSource source = event.getSession();
    final Object entity = source.getPersistenceContext().unproxy(event.getObject());
    final EntityPersister persister = source.getEntityPersister(event.getEntityName(), entity);
    LOG.tracef("un-scheduling entity deletion [%s]", MessageHelper.infoString(persister, persister.getIdentifier(entity, source), source.getFactory()));
    if (createCache.put(entity, entity) == null) {
        justCascade(createCache, source, entity, persister);
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) EventSource(org.hibernate.event.spi.EventSource)

Aggregations

EventSource (org.hibernate.event.spi.EventSource)36 EntityPersister (org.hibernate.persister.entity.EntityPersister)15 Serializable (java.io.Serializable)10 EntityEntry (org.hibernate.engine.spi.EntityEntry)10 EntityKey (org.hibernate.engine.spi.EntityKey)8 PersistenceContext (org.hibernate.engine.spi.PersistenceContext)7 PostLoadEvent (org.hibernate.event.spi.PostLoadEvent)5 HibernateProxy (org.hibernate.proxy.HibernateProxy)4 AssertionFailure (org.hibernate.AssertionFailure)3 HibernateException (org.hibernate.HibernateException)3 Status (org.hibernate.engine.spi.Status)3 PreLoadEvent (org.hibernate.event.spi.PreLoadEvent)3 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)3 Type (org.hibernate.type.Type)3 TransientObjectException (org.hibernate.TransientObjectException)2 PersistentCollection (org.hibernate.collection.spi.PersistentCollection)2 CascadePoint (org.hibernate.engine.internal.CascadePoint)2 StatefulPersistenceContext (org.hibernate.engine.internal.StatefulPersistenceContext)2 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)2 EventType (org.hibernate.event.spi.EventType)2