Java 类org.hibernate.event.service.spi.EventListenerRegistry 实例源码

项目:lams    文件:TwoPhaseLoad.java   
/**
 * PostLoad cannot occur during initializeEntity, as that call occurs *before*
 * the Set collections are added to the persistence context by Loader.
 * Without the split, LazyInitializationExceptions can occur in the Entity's
 * postLoad if it acts upon the collection.
 *
 * HHH-6043
 * 
 * @param entity The entity
 * @param session The Session
 * @param postLoadEvent The (re-used) post-load event
 */
public static void postLoad(
        final Object entity,
        final SessionImplementor session,
        final PostLoadEvent postLoadEvent) {

    if ( session.isEventSource() ) {
        final PersistenceContext persistenceContext
                = session.getPersistenceContext();
        final EntityEntry entityEntry = persistenceContext.getEntry( entity );

        postLoadEvent.setEntity( entity ).setId( entityEntry.getId() ).setPersister( entityEntry.getPersister() );

        final EventListenerGroup<PostLoadEventListener> listenerGroup = session.getFactory()
                        .getServiceRegistry()
                        .getService( EventListenerRegistry.class )
                        .getEventListenerGroup( EventType.POST_LOAD );
        for ( PostLoadEventListener listener : listenerGroup.listeners() ) {
            listener.onPostLoad( postLoadEvent );
        }
    }
}
项目:spring-data-rest-webhook    文件:EventListenerRegistryAdapter.java   
@PostConstruct
public void registerListeners() {
    // TODO: This method of getting a reference to the SessionFactory (and thereforce the ServiceRegistry) is Deprecated. Find out the right Hibernate 5.2 way to do this.
    EventListenerRegistry registry = entityManagerFactory.getSessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
    if (preInsertEventListeners != null) {
        registry.appendListeners(EventType.PRE_INSERT, preInsertEventListeners.toArray(new PreInsertEventListener[preInsertEventListeners.size()]));
    }
    if (postInsertEventListeners != null) {
        registry.appendListeners(EventType.POST_INSERT, postInsertEventListeners.toArray(new PostInsertEventListener[postInsertEventListeners.size()]));
    }
    if (preUpdateEventListeners != null) {
        registry.appendListeners(EventType.PRE_UPDATE, preUpdateEventListeners.toArray(new PreUpdateEventListener[preUpdateEventListeners.size()]));
    }
    if (postUpdateEventListeners != null) {
        registry.appendListeners(EventType.POST_UPDATE, postUpdateEventListeners.toArray(new PostUpdateEventListener[postUpdateEventListeners.size()]));
    }
    if (preDeleteEventListeners != null) {
        registry.appendListeners(EventType.PRE_DELETE, preDeleteEventListeners.toArray(new PreDeleteEventListener[preDeleteEventListeners.size()]));
    }
    if (postDeleteEventListeners != null) {
        registry.appendListeners(EventType.POST_DELETE, postDeleteEventListeners.toArray(new PostDeleteEventListener[postDeleteEventListeners.size()]));
    }
}
项目:ipf-flow-manager    文件:CustomEventRegistration.java   
@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
    EventListenerRegistry service = serviceRegistry.getService(org.hibernate.event.service.spi.EventListenerRegistry.class);

    StandardPBEStringEncryptor encrypt = new StandardPBEStringEncryptor();
    encrypt.setPassword("test_password");
    RenderedMessageEncryptEventListener encryptListener = new RenderedMessageEncryptEventListener();
    encryptListener.setStringEncryptor(encrypt);

    RenderedMessageDecryptEventListener decryptListener = new RenderedMessageDecryptEventListener();
    decryptListener.setStringEncryptor(encrypt);

    FullTextIndexEventListener fullTextListener = new FullTextIndexEventListener();

    service.appendListeners(EventType.PRE_UPDATE, encryptListener);
    service.prependListeners(EventType.POST_UPDATE, decryptListener);
    service.appendListeners(EventType.PRE_INSERT, encryptListener);
    service.prependListeners(EventType.POST_INSERT, decryptListener);
    service.appendListeners(EventType.POST_LOAD, decryptListener);
}
项目:Audit4j-Hibernate    文件:Audit4jIntegrator.java   
public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory,
        SessionFactoryServiceRegistry serviceRegistry) {
    System.out.println("Integrating......");

    //final AuditService auditService = serviceRegistry.getService(AuditService.class);
    final AuditService auditService = new AuditServiceImpl();
    auditService.init();
    if (!auditService.isInitialized()) {
        throw new InitializationException(
                "Audit4j hibernate integration can not be initialized..");
    }

    // Register listeners..
    final EventListenerRegistry listenerRegistry = serviceRegistry
            .getService(EventListenerRegistry.class);

    listenerRegistry.appendListeners(EventType.POST_INSERT,
            new AuditPostInsertEventListenerImpl(auditService));
    listenerRegistry.appendListeners(EventType.POST_UPDATE,
            new AuditPostUpdateEventListenerImpl(auditService));
    listenerRegistry.appendListeners(EventType.POST_DELETE,
            new AuditPostDeleteEventListenerImpl(auditService));
}
项目:gorm-hibernate5    文件:EventListenerIntegrator.java   
protected <T> void appendListeners(EventListenerRegistry listenerRegistry,
                                   EventType<T> eventType, Collection<T> listeners) {

    EventListenerGroup<T> group = listenerRegistry.getEventListenerGroup(eventType);
    for (T listener : listeners) {
        if (listener != null) {
            if(shouldOverrideListeners(eventType, listener)) {
                // since ClosureEventTriggeringInterceptor extends DefaultSaveOrUpdateEventListener we want to override instead of append the listener here
                // to avoid there being 2 implementations which would impact performance too
                group.clear();
                group.appendListener(listener);
            }
            else {
                group.appendListener(listener);
            }
        }
    }
}
项目:gorm-hibernate5    文件:EventListenerIntegrator.java   
@SuppressWarnings("unchecked")
protected <T> void appendListeners(final EventListenerRegistry listenerRegistry,
                                   final EventType<T> eventType, final Map<String, Object> listeners) {

    Object listener = listeners.get(eventType.eventName());
    if (listener != null) {
        if(shouldOverrideListeners(eventType, listener)) {
            // since ClosureEventTriggeringInterceptor extends DefaultSaveOrUpdateEventListener we want to override instead of append the listener here
            // to avoid there being 2 implementations which would impact performance too
            listenerRegistry.setListeners(eventType, (T) listener);
        }
        else {
            listenerRegistry.appendListeners(eventType, (T)listener);
        }
    }
}
项目:windup-rulesets    文件:MyIntegrator.java   
@Override
public void integrate(org.hibernate.cfg.Configuration configuration,
            org.hibernate.engine.spi.SessionFactoryImplementor sessionFactory,
            org.hibernate.service.spi.SessionFactoryServiceRegistry serviceRegistry) 
{


    final EventListenerRegistry eventRegistry =
        serviceRegistry.getService(EventListenerRegistry.class);

    eventRegistry.prependListeners(EventType.POST_COMMIT_INSERT, listener);

    final AuditConfiguration enversConfiguration = AuditConfiguration.getFor( configuration );
    AuditStrategy auditStrategy = enversConfiguration.getAuditStrategy();

    if (enversConfiguration.getEntCfg().hasAuditedEntities()) {
        listenerRegistry.appendListeners( EventType.POST_DELETE, new EnversPostDeleteEventListenerImpl( enversConfiguration ) );
        listenerRegistry.appendListeners( EventType.POST_INSERT, new EnversPostInsertEventListenerImpl( enversConfiguration ) );
        listenerRegistry.appendListeners( EventType.POST_UPDATE, new EnversPostUpdateEventListenerImpl( enversConfiguration ) );
        listenerRegistry.appendListeners( EventType.POST_COLLECTION_RECREATE, new EnversPostCollectionRecreateEventListenerImpl( enversConfiguration ) );
        listenerRegistry.appendListeners( EventType.PRE_COLLECTION_REMOVE, new EnversPreCollectionRemoveEventListenerImpl( enversConfiguration ) );
        listenerRegistry.appendListeners( EventType.PRE_COLLECTION_UPDATE, new EnversPreCollectionUpdateEventListenerImpl( enversConfiguration ) );
    }

}
项目:debop4j    文件:HibernateTool.java   
/**
 * Register event listener.
 *
 * @param sessionFactory the session factory
 * @param listener       the listener
 * @param eventTypes     the event types
 */
@SuppressWarnings("unchecked")
public static void registerEventListener(SessionFactory sessionFactory, Object listener, EventType... eventTypes) {
    shouldNotBeNull(sessionFactory, "sessionFactory");
    shouldNotBeNull(listener, "listener");


        log.trace("sessionFactory에 event listener를 등록합니다... listener=[{}], eventTypes=[{}]",
                  listener, StringTool.listToString(eventTypes));

    EventListenerRegistry registry =
            ((SessionFactoryImpl) sessionFactory)
                    .getServiceRegistry()
                    .getService(EventListenerRegistry.class);

    for (EventType eventType : eventTypes) {
        try {
            registry.getEventListenerGroup(eventType).appendListener(listener);
        } catch (Exception ignored) {}
    }

}
项目:lams    文件:TypeSafeActivator.java   
@SuppressWarnings( {"UnusedDeclaration"})
public static void applyCallbackListeners(ValidatorFactory validatorFactory, ActivationContext activationContext) {
    final Set<ValidationMode> modes = activationContext.getValidationModes();
    if ( ! ( modes.contains( ValidationMode.CALLBACK ) || modes.contains( ValidationMode.AUTO ) ) ) {
        return;
    }

    // de-activate not-null tracking at the core level when Bean Validation is present unless the user explicitly
    // asks for it
    if ( activationContext.getConfiguration().getProperty( Environment.CHECK_NULLABILITY ) == null ) {
        activationContext.getSessionFactory().getSettings().setCheckNullability( false );
    }

    final BeanValidationEventListener listener = new BeanValidationEventListener(
            validatorFactory,
            activationContext.getConfiguration().getProperties()
    );

    final EventListenerRegistry listenerRegistry = activationContext.getServiceRegistry()
            .getService( EventListenerRegistry.class );

    listenerRegistry.addDuplicationStrategy( DuplicationStrategyImpl.INSTANCE );

    listenerRegistry.appendListeners( EventType.PRE_INSERT, listener );
    listenerRegistry.appendListeners( EventType.PRE_UPDATE, listener );
    listenerRegistry.appendListeners( EventType.PRE_DELETE, listener );

    listener.initialize( activationContext.getConfiguration() );
}
项目:lams    文件:AbstractEntityTuplizer.java   
private static Iterable<PersistEventListener> persistEventListeners(SessionImplementor session) {
    return session
            .getFactory()
            .getServiceRegistry()
            .getService( EventListenerRegistry.class )
            .getEventListenerGroup( EventType.PERSIST )
            .listeners();
}
项目:lams    文件:JaccIntegrator.java   
private void doIntegration(
        Map properties,
        JaccPermissionDeclarations permissionDeclarations,
        SessionFactoryServiceRegistry serviceRegistry) {
    boolean isSecurityEnabled = properties.containsKey( AvailableSettings.JACC_ENABLED );
    if ( ! isSecurityEnabled ) {
        log.debug( "Skipping JACC integration as it was not enabled" );
        return;
    }

    final String contextId = (String) properties.get( AvailableSettings.JACC_CONTEXT_ID );
    if ( contextId == null ) {
        throw new IntegrationException( "JACC context id must be specified" );
    }

    final JaccService jaccService = serviceRegistry.getService( JaccService.class );
    if ( jaccService == null ) {
        throw new IntegrationException( "JaccService was not set up" );
    }

    if ( permissionDeclarations != null ) {
        for ( GrantedPermission declaration : permissionDeclarations.getPermissionDeclarations() ) {
            jaccService.addPermission( declaration );
        }
    }

    final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
    eventListenerRegistry.addDuplicationStrategy( DUPLICATION_STRATEGY );

    eventListenerRegistry.prependListeners( EventType.PRE_DELETE, new JaccPreDeleteEventListener() );
    eventListenerRegistry.prependListeners( EventType.PRE_INSERT, new JaccPreInsertEventListener() );
    eventListenerRegistry.prependListeners( EventType.PRE_UPDATE, new JaccPreUpdateEventListener() );
    eventListenerRegistry.prependListeners( EventType.PRE_LOAD, new JaccPreLoadEventListener() );
}
项目:lams    文件:StandardCacheEntryImpl.java   
/**
 * 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[] assembledProps = 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( assembledProps )
            .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, assembledProps );

    return assembledProps;
}
项目:lams    文件:CollectionCacheInvalidator.java   
private void integrate(SessionFactoryServiceRegistry serviceRegistry, SessionFactoryImplementor sessionFactory) {
    if ( !sessionFactory.getSettings().isAutoEvictCollectionCache() ) {
        // feature is disabled
        return;
    }
    if ( !sessionFactory.getSettings().isSecondLevelCacheEnabled() ) {
        // Nothing to do, if caching is disabled
        return;
    }
    EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
    eventListenerRegistry.appendListeners( EventType.POST_INSERT, this );
    eventListenerRegistry.appendListeners( EventType.POST_DELETE, this );
    eventListenerRegistry.appendListeners( EventType.POST_UPDATE, this );
}
项目:lams    文件:EventListenerServiceInitiator.java   
@Override
public EventListenerRegistry initiateService(
        SessionFactoryImplementor sessionFactory,
        Configuration configuration,
        ServiceRegistryImplementor registry) {
    return new EventListenerRegistryImpl();
}
项目:lams    文件:EventListenerServiceInitiator.java   
@Override
public EventListenerRegistry initiateService(
        SessionFactoryImplementor sessionFactory,
        MetadataImplementor metadata,
        ServiceRegistryImplementor registry) {
    return new EventListenerRegistryImpl();
}
项目:lams    文件:DefaultLoadEventListener.java   
private Iterable<PostLoadEventListener> postLoadEventListeners(EventSource session) {
    return session
            .getFactory()
            .getServiceRegistry()
            .getService( EventListenerRegistry.class )
            .getEventListenerGroup( EventType.POST_LOAD )
            .listeners();
}
项目:lams    文件:AbstractFlushingEventListener.java   
/**
 * 1. detect any dirty entities
 * 2. schedule any entity updates
 * 3. search out any reachable collections
 */
private int flushEntities(final FlushEvent event, final PersistenceContext persistenceContext) throws HibernateException {

    LOG.trace( "Flushing entities and processing referenced collections" );

    final EventSource source = event.getSession();
    final Iterable<FlushEntityEventListener> flushListeners = source.getFactory().getServiceRegistry()
            .getService( EventListenerRegistry.class )
            .getEventListenerGroup( EventType.FLUSH_ENTITY )
            .listeners();

    // Among other things, updateReachables() will recursively load all
    // collections that are moving roles. This might cause entities to
    // be loaded.

    // So this needs to be safe from concurrent modification problems.

    final Map.Entry<Object,EntityEntry>[] entityEntries = persistenceContext.reentrantSafeEntityEntries();
    final int count = entityEntries.length;

    for ( Map.Entry<Object,EntityEntry> me : entityEntries ) {

        // Update the status of the object and if necessary, schedule an update

        EntityEntry entry = me.getValue();
        Status status = entry.getStatus();

        if ( status != Status.LOADING && status != Status.GONE ) {
            final FlushEntityEvent entityEvent = new FlushEntityEvent( source, me.getKey(), entry );
            for ( FlushEntityEventListener listener : flushListeners ) {
                listener.onFlushEntity( entityEvent );
            }
        }
    }

    source.getActionQueue().sortActions();

    return count;
}
项目:lams    文件:EntityAction.java   
protected <T> EventListenerGroup<T> listenerGroup(EventType<T> eventType) {
    return getSession()
            .getFactory()
            .getServiceRegistry()
            .getService( EventListenerRegistry.class )
            .getEventListenerGroup( eventType );
}
项目:lams    文件:CollectionAction.java   
protected <T> EventListenerGroup<T> listenerGroup(EventType<T> eventType) {
    return getSession()
            .getFactory()
            .getServiceRegistry()
            .getService( EventListenerRegistry.class )
            .getEventListenerGroup( eventType );
}
项目:devwars.tv    文件:DatabaseManager.java   
@Override
public void init() {
    boolean testing = Boolean.parseBoolean(System.getProperty("testing"));

    Configuration configuration = new Configuration();
    configuration.configure("hibernate.cfg.xml");
    configuration.setInterceptor(new HibernateInterceptor());

    if (!testing) {
        configuration.setProperty("hibernate.connection.username", Reference.getEnvironmentProperty("db.username"));
        configuration.setProperty("hibernate.connection.password", Reference.getEnvironmentProperty("db.password"));
        String url = "jdbc:mysql://" + Reference.getEnvironmentProperty("db.host") + ":" + Reference.getEnvironmentProperty("db.port") + "/devwars";
        configuration.setProperty("hibernate.connection.url", url);
    } else {
        configuration.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
        configuration.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:testdb");
        configuration.setProperty("hibernate.connection.username", "sa");
        configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    }

    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);

    EventListenerRegistry registry = ((SessionFactoryImpl) DatabaseManager.sessionFactory).getServiceRegistry().getService(EventListenerRegistry.class);

    registry.getEventListenerGroup(EventType.POST_LOAD).appendListener(postLoadEvent ->
    {
        HibernateInterceptor.postLoadAny(postLoadEvent.getEntity());
        HibernateInterceptor.invokeMethodWithAnnotation(postLoadEvent.getEntity(), PostLoad.class);
    });
}
项目:mojito    文件:HibernateEventListenerConfig.java   
@PostConstruct
public void registerListeners() {
    EntityManagerFactoryImpl emf = (EntityManagerFactoryImpl) lcemfb.getNativeEntityManagerFactory();
    SessionFactoryImpl sf = emf.getSessionFactory();
    EventListenerRegistry registry = (EventListenerRegistry)sf.getServiceRegistry().getService(EventListenerRegistry.class);
    registry.getEventListenerGroup(EventType.POST_COMMIT_INSERT).appendListener(entityCrudEventListener);
    registry.getEventListenerGroup(EventType.POST_COMMIT_UPDATE).appendListener(entityCrudEventListener);
    registry.getEventListenerGroup(EventType.POST_COMMIT_DELETE).appendListener(entityCrudEventListener);
}
项目:cibet    文件:CibetIntegrator.java   
@Override
public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory,
      SessionFactoryServiceRegistry serviceRegistry) {
   log.info("start CibetIntegrator");
   final boolean autoRegister = ConfigurationHelper.getBoolean(AUTO_REGISTER, configuration.getProperties(), true);
   if (autoRegister) {
      log.debug("Skipping Cibet Envers listener auto registration");
      return;
   }

   log.info("CibetIntegrator registers Cibet Envers listeners");

   EventListenerRegistry listenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
   listenerRegistry.addDuplicationStrategy(EnversListenerDuplicationStrategy.INSTANCE);

   enversConfiguration = AuditConfiguration.getFor(configuration,
         serviceRegistry.getService(ClassLoaderService.class));

   if (enversConfiguration.getEntCfg().hasAuditedEntities()) {
      listenerRegistry.appendListeners(EventType.POST_DELETE, new CibetPostDeleteEventListener(enversConfiguration));
      listenerRegistry.appendListeners(EventType.POST_INSERT, new CibetPostInsertEventListener(enversConfiguration));
      listenerRegistry.appendListeners(EventType.POST_UPDATE, new CibetPostUpdateEventListener(enversConfiguration));
      listenerRegistry.appendListeners(EventType.POST_COLLECTION_RECREATE,
            new CibetPostCollectionRecreateEventListener(enversConfiguration));
      listenerRegistry.appendListeners(EventType.PRE_COLLECTION_REMOVE,
            new CibetPreCollectionRemoveEventListener(enversConfiguration));
      listenerRegistry.appendListeners(EventType.PRE_COLLECTION_UPDATE,
            new CibetPreCollectionUpdateEventListener(enversConfiguration));
   }
}
项目:dhis2-core    文件:DeletedObjectIntegrator.java   
@Override
public void integrate( Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry )
{
    final EventListenerRegistry registry = serviceRegistry.getService( EventListenerRegistry.class );

    DeletedObjectPostDeleteEventListener listener = new DeletedObjectPostDeleteEventListener();
    registry.appendListeners( EventType.POST_DELETE, listener );
}
项目:bygle-ldp    文件:HibernateListenersConfigurer.java   
@PostConstruct
public void registerListeners() {
    EventListenerRegistry registry = ((SessionFactoryImpl) sessionFactory).getServiceRegistry().getService(EventListenerRegistry.class);
    registry.getEventListenerGroup(EventType.POST_INSERT).appendListener(dbEventInsertListener);
    registry.getEventListenerGroup(EventType.POST_UPDATE).appendListener(dbEventUpdateListener);
    registry.getEventListenerGroup(EventType.POST_DELETE).appendListener(dbEventDeleteListener);
}
项目:UMLS-Terminology-Server    文件:TermServerEnversIntegrator.java   
@Override
public void integrate(Configuration configuration,
  SessionFactoryImplementor sessionFactory,
  SessionFactoryServiceRegistry serviceRegistry) {

  // Avoid custom behavior is autoregister is true
  try {
    if (!"true".equals(ConfigUtility.getConfigProperties()
        .getProperty("hibernate.listeners.envers.autoRegister"))) {

      super.integrate(configuration, sessionFactory, serviceRegistry);

      final AuditConfiguration enversConfiguration =
          AuditConfiguration.getFor(configuration,
              serviceRegistry.getService(ClassLoaderService.class));
      EventListenerRegistry listenerRegistry =
          serviceRegistry.getService(EventListenerRegistry.class);

      listenerRegistry
          .addDuplicationStrategy(EnversListenerDuplicationStrategy.INSTANCE);

      if (enversConfiguration.getEntCfg().hasAuditedEntities()) {
        listenerRegistry.appendListeners(EventType.POST_INSERT,
            new EmptyEnversPostInsertEventListenerImpl(enversConfiguration));
        listenerRegistry.appendListeners(EventType.POST_DELETE,
            new CustomEnversPostDeleteEventListenerImpl(enversConfiguration));
      }
    }
  } catch (Exception e) {
    throw new RuntimeException(e);
  }

}
项目:AgileAlligators    文件:HibernateEventListenerWiring.java   
@PostConstruct
public void registerListeners()
{
    EventListenerRegistry registry = ((SessionFactoryImpl) sessionFactory).getServiceRegistry()
        .getService( EventListenerRegistry.class );

    registry.getEventListenerGroup( EventType.PRE_COLLECTION_UPDATE ).appendListener( preCollectionUpdateEventListener );
    registry.getEventListenerGroup( EventType.POST_COMMIT_UPDATE ).appendListener( postUpdateEventListener );
    registry.getEventListenerGroup( EventType.POST_COMMIT_INSERT ).appendListener( postInsertEventListener );
    registry.getEventListenerGroup( EventType.POST_COMMIT_DELETE ).appendListener( postDeleteEventListener );
}
项目:high-performance-java-persistence    文件:OptimisticLockingChildUpdatesRootVersionTest.java   
@Override
public void integrate(
        Metadata metadata,
        SessionFactoryImplementor sessionFactory,
        SessionFactoryServiceRegistry serviceRegistry) {

    final EventListenerRegistry eventListenerRegistry =
            serviceRegistry.getService( EventListenerRegistry.class );

    eventListenerRegistry.appendListeners(EventType.PERSIST, RootAwareInsertEventListener.INSTANCE);
    eventListenerRegistry.appendListeners(EventType.FLUSH_ENTITY, RootAwareUpdateAndDeleteEventListener.INSTANCE);
}
项目:high-performance-java-persistence    文件:OptimisticLockingBidirectionalChildUpdatesRootVersionTest.java   
@Override
public void integrate(
        Metadata metadata,
        SessionFactoryImplementor sessionFactory,
        SessionFactoryServiceRegistry serviceRegistry) {

    final EventListenerRegistry eventListenerRegistry =
            serviceRegistry.getService( EventListenerRegistry.class );

    eventListenerRegistry.appendListeners( EventType.PERSIST, RootAwareInsertEventListener.INSTANCE);
    eventListenerRegistry.appendListeners( EventType.FLUSH_ENTITY, RootAwareUpdateAndDeleteEventListener.INSTANCE);
}
项目:jspresso-ce    文件:JspressoHibernateIntegrator.java   
/**
 * Appends the {@link LifecyclePostLoadEventListener}.
 * <p>
 * {@inheritDoc}
 */
@Override
public void integrate(Configuration configuration,
    SessionFactoryImplementor sessionFactory,
    SessionFactoryServiceRegistry serviceRegistry) {
  serviceRegistry.getService(EventListenerRegistry.class)
      .getEventListenerGroup(EventType.POST_LOAD)
      .appendListener(postLoadListener);
}
项目:jspresso-ce    文件:JspressoHibernateIntegrator.java   
/**
 * Appends the {@link LifecyclePostLoadEventListener}.
 * <p>
 * {@inheritDoc}
 */
@Override
public void integrate(MetadataImplementor metadata,
    SessionFactoryImplementor sessionFactory,
    SessionFactoryServiceRegistry serviceRegistry) {
  serviceRegistry.getService(EventListenerRegistry.class)
      .getEventListenerGroup(EventType.POST_LOAD)
      .appendListener(postLoadListener);
}
项目:spring-entity-listener    文件:HibernateEntityListenersAdapter.java   
@PostConstruct
public void findMethods() {
    for (Object listener : listeners) {
        findMethodsForListener(listener);
    }

    HibernateEntityManagerFactory hemf = (HibernateEntityManagerFactory) emf;
    SessionFactory sf = hemf.getSessionFactory();
    registry = ((SessionFactoryImpl) sf).getServiceRegistry().getService(EventListenerRegistry.class);
}
项目:spring-entity-listener    文件:HibernateEntityListenersConfigurer.java   
@PostConstruct
public void registerListeners() {
    HibernateEntityManagerFactory hemf = (HibernateEntityManagerFactory) emf;
    SessionFactory sf = hemf.getSessionFactory();
    EventListenerRegistry registry = ((SessionFactoryImpl) sf).getServiceRegistry().getService(
            EventListenerRegistry.class);

    registry.getEventListenerGroup(EventType.PRE_INSERT).appendListener(listener);
    registry.getEventListenerGroup(EventType.POST_COMMIT_INSERT).appendListener(listener);
    registry.getEventListenerGroup(EventType.PRE_UPDATE).appendListener(listener);
    registry.getEventListenerGroup(EventType.POST_COMMIT_UPDATE).appendListener(listener);
    registry.getEventListenerGroup(EventType.PRE_DELETE).appendListener(listener);
    registry.getEventListenerGroup(EventType.POST_COMMIT_DELETE).appendListener(listener);
    registry.getEventListenerGroup(EventType.POST_LOAD).appendListener(listener);
}
项目:ix3    文件:IntegratorImplRuleEngine.java   
private void prependListeners(EventListenerRegistry eventListenerRegistry) {
    eventListenerRegistry.prependListeners(EventType.PRE_INSERT, new EventListenerImplRuleEngine());
    eventListenerRegistry.prependListeners(EventType.PRE_LOAD, new EventListenerImplRuleEngine());
    eventListenerRegistry.prependListeners(EventType.PRE_UPDATE, new EventListenerImplRuleEngine());
    eventListenerRegistry.prependListeners(EventType.PRE_DELETE, new EventListenerImplRuleEngine());
    eventListenerRegistry.prependListeners(EventType.POST_INSERT, new EventListenerImplRuleEngine());
    eventListenerRegistry.prependListeners(EventType.POST_LOAD, new EventListenerImplRuleEngine());
    eventListenerRegistry.prependListeners(EventType.POST_UPDATE, new EventListenerImplRuleEngine());
    eventListenerRegistry.prependListeners(EventType.POST_DELETE, new EventListenerImplRuleEngine());
}
项目:Hibernate-Search-GenericJPA    文件:HibernateSynchronizedUpdateSourceProvider.java   
@Override
public SynchronizedUpdateSource getUpdateSource(
        ExtendedSearchIntegrator searchIntegrator,
        Map<Class<?>, RehashedTypeMetadata> rehashedTypeMetadataPerIndexRoot,
        Map<Class<?>, List<Class<?>>> containedInIndexOf,
        Properties properties,
        EntityManagerFactory emf,
        TransactionManager transactionManager,
        Set<Class<?>> indexRelevantEntities) {
    HibernateEntityManagerFactory hibernateEntityManagerFactory =
            (HibernateEntityManagerFactory) emf;
    SessionFactoryImpl sessionFactory = (SessionFactoryImpl) hibernateEntityManagerFactory.getSessionFactory();
    ServiceRegistry serviceRegistry = sessionFactory.getServiceRegistry();
    EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );

    HibernateUpdateSource updateSource = new HibernateUpdateSource();
    updateSource.initialize( searchIntegrator );

    listenerRegistry.addDuplicationStrategy( new DuplicationStrategyImpl( HibernateUpdateSource.class ) );

    listenerRegistry.appendListeners( EventType.POST_INSERT, updateSource );
    listenerRegistry.appendListeners( EventType.POST_UPDATE, updateSource );
    listenerRegistry.appendListeners( EventType.POST_DELETE, updateSource );
    listenerRegistry.appendListeners( EventType.POST_COLLECTION_RECREATE, updateSource );
    listenerRegistry.appendListeners( EventType.POST_COLLECTION_REMOVE, updateSource );
    listenerRegistry.appendListeners( EventType.POST_COLLECTION_UPDATE, updateSource );

    return updateSource;
}
项目:Hibernate-Search-GenericJPA    文件:EventSourceTransactionContext.java   
private HibernateUpdateSource getIndexWorkFlushEventListener() {
    if ( this.flushListener != null ) {
        //for the "transient" case: might have been nullified.
        return flushListener;
    }
    final Iterable<FlushEventListener> listeners = getService( EventListenerRegistry.class )
            .getEventListenerGroup( EventType.FLUSH ).listeners();
    for ( FlushEventListener listener : listeners ) {
        if ( HibernateUpdateSource.class.isAssignableFrom( listener.getClass() ) ) {
            return (HibernateUpdateSource) listener;
        }
    }
    LOGGER.fine( "FullTextIndexEventListener was not registered as FlushEventListener" );
    return null;
}
项目:jooby    文件:Hbm.java   
/**
 * Register an hibernate event listener. Listener will be created and injected by Guice.
 *
 * @param type Event type.
 * @param listenerType Listener type.
 * @return This module.
 */
@SuppressWarnings("unchecked")
public <T> Hbm onEvent(final EventType<T> type, final Class<? extends T> listenerType) {
  bindings.add(b -> {
    b.bind(listenerType).asEagerSingleton();
  });

  listeners.add((s, r) -> {
    ServiceRegistryImplementor serviceRegistry = s.getServiceRegistry();
    EventListenerRegistry service = serviceRegistry.getService(EventListenerRegistry.class);
    T listener = r.require(listenerType);
    service.appendListeners(type, listener);
  });
  return this;
}
项目:lams    文件:SessionImpl.java   
private <T> EventListenerGroup<T> eventListenerGroup(EventType<T> type) {
    return factory.getServiceRegistry().getService( EventListenerRegistry.class ).getEventListenerGroup( type );
}
项目:lams    文件:EventListenerServiceInitiator.java   
@Override
public Class<EventListenerRegistry> getServiceInitiated() {
    return EventListenerRegistry.class;
}
项目:rpb    文件:HibernateListenerRegistration.java   
private <T> void register(EventType<T> eventType, T t) {
    EventListenerRegistry registry = ((SessionFactoryImpl) sessionFactory).getServiceRegistry().getService(EventListenerRegistry.class);
    log.info("Registering " + t.getClass() + " listener on " + eventType + " events.");
    registry.getEventListenerGroup(eventType).appendListener(t);
}
项目:rpb    文件:HibernateListenerRegistration.java   
private <T> void register(EventType<T> eventType, T t) {
    EventListenerRegistry registry = ((SessionFactoryImpl) sessionFactory).getServiceRegistry().getService(EventListenerRegistry.class);
    log.info("Registering " + t.getClass() + " listener on " + eventType + " events.");
    registry.getEventListenerGroup(eventType).appendListener(t);
}