org.hibernate.event.spi.PreLoadEvent Java Examples
The following examples show how to use
org.hibernate.event.spi.PreLoadEvent.
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: AbstractRowReader.java From lams with GNU General Public License v2.0 | 6 votes |
private void performTwoPhaseLoad( PreLoadEvent preLoadEvent, ResultSetProcessingContextImpl context, List<HydratedEntityRegistration> hydratedEntityRegistrations) { final int numberOfHydratedObjects = hydratedEntityRegistrations == null ? 0 : hydratedEntityRegistrations.size(); log.tracev( "Total objects hydrated: {0}", numberOfHydratedObjects ); if ( hydratedEntityRegistrations == null ) { return; } for ( HydratedEntityRegistration registration : hydratedEntityRegistrations ) { TwoPhaseLoad.initializeEntity( registration.getInstance(), context.isReadOnly(), context.getSession(), preLoadEvent ); } }
Example #2
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 #3
Source File: DefaultPreLoadEventListener.java From lams with GNU General Public License v2.0 | 5 votes |
public void onPreLoad(PreLoadEvent event) { EntityPersister persister = event.getPersister(); event.getSession() .getInterceptor() .onLoad( event.getEntity(), event.getId(), event.getState(), persister.getPropertyNames(), persister.getPropertyTypes() ); }
Example #4
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 ) ); }
Example #5
Source File: JaccPreLoadEventListener.java From lams with GNU General Public License v2.0 | 4 votes |
public void onPreLoad(PreLoadEvent event) { performSecurityCheck( event.getSession(), event, PermissibleAction.READ ); }
Example #6
Source File: ClosureEventTriggeringInterceptor.java From gorm-hibernate5 with Apache License 2.0 | 4 votes |
public void onPreLoad(PreLoadEvent hibernateEvent) { org.grails.datastore.mapping.engine.event.PreLoadEvent grailsEvent = new org.grails.datastore.mapping.engine.event.PreLoadEvent( this.datastore, hibernateEvent.getEntity()); publishEvent(hibernateEvent, grailsEvent); }
Example #7
Source File: TwoPhaseLoad.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Perform the second step of 2-phase load. Fully initialize the entity * instance. * <p/> * After processing a JDBC result set, we "resolve" all the associations * between the entities which were instantiated and had their state * "hydrated" into an array * * @param entity The entity being loaded * @param readOnly Is the entity being loaded as read-only * @param session The Session * @param preLoadEvent The (re-used) pre-load event */ public static void initializeEntity( final Object entity, final boolean readOnly, final SharedSessionContractImplementor session, final PreLoadEvent preLoadEvent) { final PersistenceContext persistenceContext = session.getPersistenceContext(); final EntityEntry entityEntry = persistenceContext.getEntry( entity ); if ( entityEntry == null ) { throw new AssertionFailure( "possible non-threadsafe access to the session" ); } doInitializeEntity( entity, entityEntry, readOnly, session, preLoadEvent ); }