org.hibernate.event.spi.PreLoadEventListener Java Examples
The following examples show how to use
org.hibernate.event.spi.PreLoadEventListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardCacheEntryImpl.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Assemble the previously disassembled state represented by this entry into the given entity instance. * * Additionally manages the PreLoadEvent callbacks. * * @param instance The entity instance * @param id The entity identifier * @param persister The entity persister * @param interceptor (currently unused) * @param session The session * * @return The assembled state * * @throws HibernateException Indicates a problem performing assembly or calling the PreLoadEventListeners. * * @see org.hibernate.type.Type#assemble * @see org.hibernate.type.Type#disassemble */ public Object[] assemble( final Object instance, final Serializable id, final EntityPersister persister, final Interceptor interceptor, final EventSource session) throws HibernateException { if ( !persister.getEntityName().equals( subclass ) ) { throw new AssertionFailure( "Tried to assemble a different subclass instance" ); } //assembled state gets put in a new array (we read from cache by value!) final Object[] state = TypeHelper.assemble( disassembledState, persister.getPropertyTypes(), session, instance ); //persister.setIdentifier(instance, id); //before calling interceptor, for consistency with normal load //TODO: reuse the PreLoadEvent final PreLoadEvent preLoadEvent = new PreLoadEvent( session ) .setEntity( instance ) .setState( state ) .setId( id ) .setPersister( persister ); final EventListenerGroup<PreLoadEventListener> listenerGroup = session .getFactory() .getServiceRegistry() .getService( EventListenerRegistry.class ) .getEventListenerGroup( EventType.PRE_LOAD ); for ( PreLoadEventListener listener : listenerGroup.listeners() ) { listener.onPreLoad( preLoadEvent ); } persister.setPropertyValues( instance, state ); return state; }
Example #2
Source File: ReactiveResultSetProcessor.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 4 votes |
@SuppressWarnings("unchecked") default CompletionStage<Void> initializeEntity( final Object entity, final boolean readOnly, final SharedSessionContractImplementor session, final PreLoadEvent preLoadEvent, Iterable<PreLoadEventListener> listeners) { final PersistenceContext persistenceContext = session.getPersistenceContext(); final EntityEntry entityEntry = persistenceContext.getEntry(entity); if (entityEntry == null) { throw new AssertionFailure("possible non-threadsafe access to the session"); } TwoPhaseLoad.initializeEntityEntryLoadedState( entity, entityEntry, session, (entityType, value, session1, owner, overridingEager) -> entityType.isEager( overridingEager ) ? ((ReactiveSession) session1).reactiveGet( entityType.getReturnedClass(), (Serializable) value ) : entityType.resolve(value, session1, owner, overridingEager) ); CompletionStage<Void> stage = CompletionStages.nullFuture(); final Object[] hydratedState = entityEntry.getLoadedState(); for ( int i = 0 ; i < hydratedState.length ; i++ ) { if ( hydratedState[ i ] instanceof CompletionStage ) { final int iConstant = i; stage = stage.thenCompose( v -> (CompletionStage<Object>) hydratedState[ iConstant ] ) .thenAccept( initializedEntity -> hydratedState[ iConstant ] = initializedEntity ); } } return stage.thenAccept( v -> TwoPhaseLoad.initializeEntityFromEntityEntryLoadedState( entity, entityEntry, readOnly, session, preLoadEvent, listeners ) ); }