List of usage examples for org.hibernate.service.spi SessionFactoryServiceRegistry getService
<R extends Service> R getService(Class<R> serviceRole);
From source file:com.github.javarch.persistence.orm.hibernate.spi.JavarchEventListenerIntegrator.java
License:Apache License
@Override public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { LOG.info("Adicionando eventos customizados ao EventListenerRegistry."); EventListenerRegistry registry = serviceRegistry.getService(EventListenerRegistry.class); registry.getEventListenerGroup(EventType.PRE_INSERT).appendListener(new PreInsertEventListener()); registry.getEventListenerGroup(EventType.PRE_UPDATE).appendListener(new PreUpdateEventListener()); }
From source file:com.googlecode.hibernate.audit.listener.AuditListener.java
License:Open Source License
public void initialize(SessionFactoryImplementor sessionFactory, Metadata metadata, SessionFactoryServiceRegistry serviceRegistry) { try {//ww w . j a va 2 s . c o m recordEmptyCollectionsOnInsert = serviceRegistry.getService(ConfigurationService.class).getSetting( HibernateAudit.AUDIT_RECORD_EMPTY_COLLECTIONS_ON_INSERT_PROPERTY, StandardConverters.BOOLEAN, true); auditConfiguration = ConfigurationHolder.getAuditConfiguration(sessionFactory); if (auditConfiguration == null) { Version.touch(); auditConfiguration = new AuditConfiguration(sessionFactory, metadata); processDynamicUpdate(metadata, serviceRegistry); ConfigurationHolder.putAuditConfiguration(sessionFactory, auditConfiguration); processAuditConfigurationObserver(serviceRegistry); } } catch (RuntimeException e) { if (log.isErrorEnabled()) { log.error( "RuntimeExcpetion occured during AuditListener initialization, will re-throw the exception", e); } throw e; } }
From source file:com.googlecode.hibernate.audit.listener.AuditListener.java
License:Open Source License
private void processDynamicUpdate(Metadata metadata, SessionFactoryServiceRegistry serviceRegistry) { if (serviceRegistry.getService(ConfigurationService.class).getSetting( HibernateAudit.AUDIT_SET_DYNAMIC_UPDATE_FOR_AUDITED_MODEL_PROPERTY, StandardConverters.BOOLEAN, false)) {/*from ww w . ja v a 2s. co m*/ for (PersistentClass persistentClass : metadata.getEntityBindings()) { persistentClass.setDynamicUpdate(true); if (log.isInfoEnabled()) { log.info("Set dynamic-update to true for entity: " + persistentClass.getEntityName()); } } } }
From source file:com.googlecode.hibernate.audit.listener.AuditListener.java
License:Open Source License
private void processAuditConfigurationObserver(SessionFactoryServiceRegistry serviceRegistry) { String observerClazzProperty = serviceRegistry.getService(ConfigurationService.class) .getSetting(HibernateAudit.AUDIT_CONFIGURATION_OBSERVER_PROPERTY, StandardConverters.STRING, null); if (observerClazzProperty != null) { ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); Class observerClazz = null; try {//from w w w. j ava2 s. co m observerClazz = contextClassLoader.loadClass(observerClazzProperty); } catch (ClassNotFoundException ignored) { } try { if (observerClazz == null) { observerClazz = AuditListener.class.forName(observerClazzProperty); } } catch (ClassNotFoundException e) { throw new HibernateException( "Unable to find audit configuration observer class:" + observerClazzProperty, e); } try { AuditConfigurationObserver observer = (AuditConfigurationObserver) observerClazz.newInstance(); observer.auditConfigurationCreated(auditConfiguration); } catch (InstantiationException e) { throw new HibernateException( "Unable to instantiate audit configuration observer from class:" + observerClazzProperty, e); } catch (IllegalAccessException e) { throw new HibernateException( "Unable to instantiate audit configuration observer from class:" + observerClazzProperty, e); } catch (ClassCastException e) { throw new HibernateException("Audit configuration observer class:" + observerClazzProperty + " should implement " + AuditConfigurationObserver.class.getName(), e); } } }
From source file:es.logongas.ix3.dao.impl.rules.IntegratorImplRuleEngine.java
License:Apache License
@Override public void integrate(Configuration c, SessionFactoryImplementor sfi, SessionFactoryServiceRegistry sfsr) { final EventListenerRegistry eventListenerRegistry = sfsr.getService(EventListenerRegistry.class); prependListeners(eventListenerRegistry); }
From source file:es.logongas.ix3.dao.impl.rules.IntegratorImplRuleEngine.java
License:Apache License
@Override public void integrate(MetadataImplementor mi, SessionFactoryImplementor sfi, SessionFactoryServiceRegistry sfsr) { final EventListenerRegistry eventListenerRegistry = sfsr.getService(EventListenerRegistry.class); prependListeners(eventListenerRegistry); }
From source file:org.apereo.portal.utils.jdbc.DelayedValidationQueryResolverImpl.java
License:Apache License
@Override public void setConfiguration(String persistenceUnit, HibernateConfiguration hibernateConfiguration) { final SessionFactoryServiceRegistry serviceRegistry = hibernateConfiguration.getServiceRegistry(); synchronized (this.delayedDataSources) { this.dialectResolver = serviceRegistry.getService(DialectResolver.class); for (final Tuple<DataSource, ValidationQueryRegistrationHandler> delayedDataSource : this.delayedDataSources) { final String validationQuery = this.getValidationQuery(delayedDataSource.first); delayedDataSource.second.setValidationQuery(validationQuery); }/*ww w. j a v a 2 s.c om*/ this.delayedDataSources.clear(); } }
From source file:org.audit4j.integration.hibernate.bootstrap.Audit4jIntegrator.java
License:Apache License
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();//from ww w .j a va2 s . c om 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)); }
From source file:org.cgiar.ccafs.marlo.config.MyIntegrator.java
License:Open Source License
@Override public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService(EventListenerRegistry.class); HibernateAuditLogListener hibernateAuditLogListener = new HibernateAuditLogListener(); AuditColumnHibernateListener auditColumnHibernateListener = new AuditColumnHibernateListener(); eventListenerRegistry.prependListeners(EventType.POST_UPDATE, hibernateAuditLogListener); eventListenerRegistry.prependListeners(EventType.POST_INSERT, hibernateAuditLogListener); eventListenerRegistry.prependListeners(EventType.POST_DELETE, hibernateAuditLogListener); eventListenerRegistry.prependListeners(EventType.FLUSH, hibernateAuditLogListener); eventListenerRegistry.prependListeners(EventType.PRE_INSERT, auditColumnHibernateListener); eventListenerRegistry.prependListeners(EventType.PRE_UPDATE, auditColumnHibernateListener); LOG.debug("Finished registering Hibernate Event Listeners"); }
From source file:org.codehaus.groovy.grails.orm.hibernate.EventListenerIntegrator.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" }) public void integrate(Configuration config, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { EventListenerRegistry listenerRegistry = serviceRegistry.getService(EventListenerRegistry.class); if (eventListeners != null) { for (Map.Entry<String, Object> entry : eventListeners.entrySet()) { EventType type = EventType.resolveEventTypeByName(entry.getKey()); Object listenerObject = entry.getValue(); if (listenerObject instanceof Collection) { appendListeners(listenerRegistry, type, (Collection) listenerObject); } else if (listenerObject != null) { appendListeners(listenerRegistry, type, Collections.singleton(listenerObject)); }//from www .jav a 2 s . c om } } if (hibernateEventListeners != null && hibernateEventListeners.getListenerMap() != null) { Map<String, Object> listenerMap = hibernateEventListeners.getListenerMap(); for (EventType<?> type : TYPES) { appendListeners(listenerRegistry, type, listenerMap); } } // register workaround for GRAILS-8988 (do nullability checks for inserts in last PreInsertEventListener) ClosureEventTriggeringInterceptor.addNullabilityCheckerPreInsertEventListener(listenerRegistry); }