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);
}
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);
}
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;
}
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);
}
}
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);
}
}
Aggregations