Package org.hibernate.event

Examples of org.hibernate.event.EventListeners


        sessionFactoryObserver
      );
  }

  private EventListeners getInitializedEventListeners() {
    EventListeners result = (EventListeners) eventListeners.shallowCopy();
    result.initializeListeners( this );
    return result;
  }
View Full Code Here


    propertyReferences = new ArrayList();
    secondPasses = new ArrayList();
    interceptor = EmptyInterceptor.INSTANCE;
    properties = Environment.getProperties();
    entityResolver = XMLHelper.DEFAULT_DTD_RESOLVER;
    eventListeners = new EventListeners();
    filterDefinitions = new HashMap();
//    extendsQueue = new ArrayList();
    extendsQueue = new HashMap();
    auxiliaryDatabaseObjects = new ArrayList();
    tableNameBinding = new HashMap();
View Full Code Here

        getInitializedEventListeners()
      );
  }

  private EventListeners getInitializedEventListeners() {
    EventListeners result = (EventListeners) eventListeners.shallowCopy();
    result.initializeListeners( this );
    return result;
  }
View Full Code Here

    propertyReferences = new ArrayList();
    secondPasses = new ArrayList();
    interceptor = EmptyInterceptor.INSTANCE;
    properties = Environment.getProperties();
    entityResolver = XMLHelper.DEFAULT_DTD_RESOLVER;
    eventListeners = new EventListeners();
    filterDefinitions = new HashMap();
//    extendsQueue = new ArrayList();
    extendsQueue = new HashMap();
    auxiliaryDatabaseObjects = new ArrayList();
    tableNameBinding = new HashMap();
View Full Code Here

        sessionFactoryObserver
      );
  }

  private EventListeners getInitializedEventListeners() {
    EventListeners result = (EventListeners) eventListeners.shallowCopy();
    result.initializeListeners( this );
    return result;
  }
View Full Code Here

          throw new MappingException( "entity class not found: " + clazz.getNodeName(), e );
        }
      }
    }

    EventListeners listenerConfig = configuration.getEventListeners();

    BeanInfo beanInfo = null;
    try {
      beanInfo = Introspector.getBeanInfo( listenerConfig.getClass(), Object.class );
      PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
      try {
        for (int i = 0, max = pds.length; i < max; i++) {
          final Object listeners = pds[i].getReadMethod().invoke( listenerConfig, READER_METHOD_ARGS );
          if ( listeners == null ) {
View Full Code Here

  private Ejb3Configuration configuration;
  private boolean isSecurity;

  public EventListenerConfigurator(Ejb3Configuration configuration) {
    this.configuration = configuration;
    EventListeners listenerConfig = configuration.getEventListeners();

    //Action event
    //EJB3-specific ops listeners
    listenerConfig.setFlushEventListeners( new FlushEventListener[] { EJB3FlushEventListener.INSTANCE } );
    //EJB3-specific ops listeners
    listenerConfig.setAutoFlushEventListeners( new AutoFlushEventListener[] { EJB3AutoFlushEventListener.INSTANCE } );
    listenerConfig.setDeleteEventListeners( new DeleteEventListener[] { new EJB3DeleteEventListener() } );
    listenerConfig.setFlushEntityEventListeners(
        new FlushEntityEventListener[] { new EJB3FlushEntityEventListener() }
    );
    listenerConfig.setMergeEventListeners( new MergeEventListener[] { new EJB3MergeEventListener() } );
    listenerConfig.setPersistEventListeners( new PersistEventListener[] { new EJB3PersistEventListener() } );
    listenerConfig.setPersistOnFlushEventListeners(
        new PersistEventListener[] { new EJB3PersistOnFlushEventListener() }
    );
    listenerConfig.setSaveEventListeners( new SaveOrUpdateEventListener[] { new EJB3SaveEventListener() } );
    listenerConfig.setSaveOrUpdateEventListeners(
        new SaveOrUpdateEventListener[] { new EJB3SaveOrUpdateEventListener() }
    );

    //Pre events
    listenerConfig.setPreInsertEventListeners(
        new PreInsertEventListener[] {
            new JACCPreInsertEventListener(),
        }
    );
    listenerConfig.setPreUpdateEventListeners(
        new PreUpdateEventListener[] {
            new JACCPreUpdateEventListener(),
        }
    );
    listenerConfig.setPreDeleteEventListeners(
        new PreDeleteEventListener[] {
            new JACCPreDeleteEventListener()
        }
    );

    //Add the default Hibernate Core PreLoadEventListener
    //TODO shouldn't we read the value from getPreLoadEventListeners and add JACC?
    //probably a better thing to do as it allows cfg.xml config but this is a big change and need more thoughts
    listenerConfig.setPreLoadEventListeners(
        new PreLoadEventListener[] {
            new DefaultPreLoadEventListener(),
            new JACCPreLoadEventListener()
        }
    );

    //post events
    listenerConfig.setPostDeleteEventListeners(
        new PostDeleteEventListener[] { new EJB3PostDeleteEventListener() }
    );
    listenerConfig.setPostInsertEventListeners(
        new PostInsertEventListener[] { new EJB3PostInsertEventListener() }
    );
    //Add the default Hibernate Core PostLoadEventListener
    //TODO shouldn't we read the value from getPostLoadEventListeners
    //probably a better thing to do as it allows cfg.xml config but this is a big change and need more thoughts
    listenerConfig.setPostLoadEventListeners(
        new PostLoadEventListener[] { new EJB3PostLoadEventListener(), new DefaultPostLoadEventListener() }
    );
   
    EJB3PostUpdateEventListener postUpdateEventListener = new EJB3PostUpdateEventListener();
    listenerConfig.setPostUpdateEventListeners(
        new PostUpdateEventListener[] { postUpdateEventListener }
    );
   
// EJB-288 - registration of post collection listeners. Commented out due to problem
// of duplicated callbacks. See Jira.
View Full Code Here


  public void testListeners() throws Exception {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory( "manager1", new HashMap() );
    EntityManager em = emf.createEntityManager();
    EventListeners eventListeners = ( (SessionImplementor) em.getDelegate() ).getListeners();
    assertEquals(
        "Explicit pre-insert event through hibernate.ejb.event.pre-insert does not work",
        eventListeners.getPreInsertEventListeners().length,
        eventListeners.getPreUpdateEventListeners().length + 1 );

    em.close();
    emf.close();
  }
View Full Code Here

  private Ejb3Configuration configuration;
  private boolean isSecurity;

  public EventListenerConfigurator(Ejb3Configuration configuration) {
    this.configuration = configuration;
    EventListeners listenerConfig = configuration.getEventListeners();

    //Action event
    //EJB3-specific ops listeners
    listenerConfig.setFlushEventListeners( new FlushEventListener[] { EJB3FlushEventListener.INSTANCE } );
    //EJB3-specific ops listeners
    listenerConfig.setAutoFlushEventListeners( new AutoFlushEventListener[] { EJB3AutoFlushEventListener.INSTANCE } );
    listenerConfig.setDeleteEventListeners( new DeleteEventListener[] { new EJB3DeleteEventListener() } );
    listenerConfig.setFlushEntityEventListeners(
        new FlushEntityEventListener[] { new EJB3FlushEntityEventListener() }
    );
    listenerConfig.setMergeEventListeners( new MergeEventListener[] { new EJB3MergeEventListener() } );
    listenerConfig.setPersistEventListeners( new PersistEventListener[] { new EJB3PersistEventListener() } );
    listenerConfig.setPersistOnFlushEventListeners(
        new PersistEventListener[] { new EJB3PersistOnFlushEventListener() }
    );
    listenerConfig.setSaveEventListeners( new SaveOrUpdateEventListener[] { new EJB3SaveEventListener() } );
    listenerConfig.setSaveOrUpdateEventListeners(
        new SaveOrUpdateEventListener[] { new EJB3SaveOrUpdateEventListener() }
    );

    //Pre events
    listenerConfig.setPreInsertEventListeners(
        new PreInsertEventListener[] {
            new JACCPreInsertEventListener(),
        }
    );
    listenerConfig.setPreUpdateEventListeners(
        new PreUpdateEventListener[] {
            new JACCPreUpdateEventListener(),
        }
    );
    listenerConfig.setPreDeleteEventListeners(
        new PreDeleteEventListener[] {
            new JACCPreDeleteEventListener()
        }
    );

    //Add the default Hibernate Core PreLoadEventListener
    //TODO shouldn't we read the value from getPreLoadEventListeners and add JACC?
    //probably a better thing to do as it allows cfg.xml config but this is a big change and need more thoughts
    listenerConfig.setPreLoadEventListeners(
        new PreLoadEventListener[] {
            new DefaultPreLoadEventListener(),
            new JACCPreLoadEventListener()
        }
    );

    //post events
    listenerConfig.setPostDeleteEventListeners(
        new PostDeleteEventListener[] { new EJB3PostDeleteEventListener() }
    );
    listenerConfig.setPostInsertEventListeners(
        new PostInsertEventListener[] { new EJB3PostInsertEventListener() }
    );
    //Add the default Hibernate Core PostLoadEventListener
    //TODO shouldn't we read the value from getPostLoadEventListeners
    //probably a better thing to do as it allows cfg.xml config but this is a big change and need more thoughts
    listenerConfig.setPostLoadEventListeners(
        new PostLoadEventListener[] { new EJB3PostLoadEventListener(), new DefaultPostLoadEventListener() }
    );
   
    EJB3PostUpdateEventListener postUpdateEventListener = new EJB3PostUpdateEventListener();
    listenerConfig.setPostUpdateEventListeners(
        new PostUpdateEventListener[] { postUpdateEventListener }
    );
   
// EJB-288 - registration of post collection listeners. Commented out due to problem
// of duplicated callbacks. See Jira.
View Full Code Here

          throw new MappingException( "entity class not found: " + clazz.getNodeName(), e );
        }
      }
    }

    EventListeners listenerConfig = configuration.getEventListeners();

    BeanInfo beanInfo = null;
    try {
      beanInfo = Introspector.getBeanInfo( listenerConfig.getClass(), Object.class );
      PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
      try {
        for (int i = 0, max = pds.length; i < max; i++) {
          final Object listeners = pds[i].getReadMethod().invoke( listenerConfig, READER_METHOD_ARGS );
          if ( listeners == null ) {
            throw new HibernateException( "Listener [" + pds[i].getName() + "] was null" );
          }
          if ( listeners instanceof Object[] ) {
            int securityListenersNbr = 0;
            Object[] listenersArray = (Object[]) listeners;
            for (Object listener : listenersArray) {
              if ( listener != null && listener instanceof CallbackHandlerConsumer ) {
                ( (CallbackHandlerConsumer) listener ).setCallbackHandler( callbackHandler );
              }
              if ( listener != null && listener instanceof JACCSecurityListener ) {
                if ( !isSecurity ) {
                  securityListenersNbr++;
                }
              }
            }
            if ( !isSecurity ) {
              Class clazz = pds[i].getReadMethod().getReturnType().getComponentType();
              Object newArray = Array.newInstance( clazz, listenersArray.length - securityListenersNbr );
              int index = 0;
              for (Object listener : listenersArray) {
                if ( !( listener != null && listener instanceof JACCSecurityListener ) ) {
                  Array.set( newArray, index++, listener );
                }
              }
              pds[i].getWriteMethod().invoke( listenerConfig, newArray );
            }
          }
        }
      }
      catch (HibernateException e) {
        throw e;
      }
      catch (Throwable t) {
        throw new HibernateException( "Unable to validate listener config", t );
      }
    }
    catch (Exception t) {
      throw new HibernateException( "Unable to copy listeners", t );
    }
    finally {
      if ( beanInfo != null ) {
        // release the jdk internal caches everytime to ensure this
        // plays nicely with destroyable class-loaders
        Introspector.flushFromCaches( listenerConfig.getClass() );
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.hibernate.event.EventListeners

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.