HHH-6144 - Introduce ServiceRegistryBuilder

This commit is contained in:
Steve Ebersole 2011-04-20 15:58:10 -05:00
parent bd82732dee
commit 53e0439880
73 changed files with 468 additions and 330 deletions

View File

@ -38,8 +38,8 @@ import org.hibernate.event.EventType;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.service.event.spi.EventListenerGroup;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerGroup;
import org.hibernate.event.service.spi.EventListenerRegistry;
/**
* Any action relating to insert/update/delete of a collection

View File

@ -35,7 +35,7 @@ import org.hibernate.event.PostCollectionRecreateEventListener;
import org.hibernate.event.PreCollectionRecreateEvent;
import org.hibernate.event.PreCollectionRecreateEventListener;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.service.event.spi.EventListenerGroup;
import org.hibernate.event.service.spi.EventListenerGroup;
public final class CollectionRecreateAction extends CollectionAction {

View File

@ -35,7 +35,7 @@ import org.hibernate.event.PostCollectionRemoveEventListener;
import org.hibernate.event.PreCollectionRemoveEvent;
import org.hibernate.event.PreCollectionRemoveEventListener;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.service.event.spi.EventListenerGroup;
import org.hibernate.event.service.spi.EventListenerGroup;
public final class CollectionRemoveAction extends CollectionAction {

View File

@ -29,17 +29,14 @@ import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.collection.PersistentCollection;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.event.EventSource;
import org.hibernate.event.EventType;
import org.hibernate.event.PostCollectionUpdateEvent;
import org.hibernate.event.PostCollectionUpdateEventListener;
import org.hibernate.event.PreCollectionRemoveEvent;
import org.hibernate.event.PreCollectionRemoveEventListener;
import org.hibernate.event.PreCollectionUpdateEvent;
import org.hibernate.event.PreCollectionUpdateEventListener;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.service.event.spi.EventListenerGroup;
import org.hibernate.event.service.spi.EventListenerGroup;
public final class CollectionUpdateAction extends CollectionAction {

View File

@ -35,8 +35,8 @@ import org.hibernate.event.EventType;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.service.event.spi.EventListenerGroup;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerGroup;
import org.hibernate.event.service.spi.EventListenerRegistry;
/**
* Base class for actions relating to insert/update/delete of an entity

View File

@ -32,14 +32,13 @@ import org.hibernate.cache.access.SoftLock;
import org.hibernate.engine.EntityEntry;
import org.hibernate.engine.PersistenceContext;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.event.EventSource;
import org.hibernate.event.EventType;
import org.hibernate.event.PostDeleteEvent;
import org.hibernate.event.PostDeleteEventListener;
import org.hibernate.event.PreDeleteEvent;
import org.hibernate.event.PreDeleteEventListener;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.service.event.spi.EventListenerGroup;
import org.hibernate.event.service.spi.EventListenerGroup;
public final class EntityDeleteAction extends EntityAction {
private final Object version;

View File

@ -36,7 +36,7 @@ import org.hibernate.event.PostInsertEventListener;
import org.hibernate.event.PreInsertEvent;
import org.hibernate.event.PreInsertEventListener;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.service.event.spi.EventListenerGroup;
import org.hibernate.event.service.spi.EventListenerGroup;
public final class EntityIdentityInsertAction extends EntityAction {

View File

@ -33,15 +33,13 @@ import org.hibernate.engine.EntityEntry;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.Versioning;
import org.hibernate.event.EventSource;
import org.hibernate.event.EventType;
import org.hibernate.event.PostInsertEvent;
import org.hibernate.event.PostInsertEventListener;
import org.hibernate.event.PreInsertEvent;
import org.hibernate.event.PreInsertEventListener;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.service.event.spi.EventListenerGroup;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerGroup;
public final class EntityInsertAction extends EntityAction {

View File

@ -42,7 +42,7 @@ import org.hibernate.event.PostUpdateEventListener;
import org.hibernate.event.PreUpdateEvent;
import org.hibernate.event.PreUpdateEventListener;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.service.event.spi.EventListenerGroup;
import org.hibernate.event.service.spi.EventListenerGroup;
import org.hibernate.type.TypeHelper;
public final class EntityUpdateAction extends EntityAction {

View File

@ -35,8 +35,8 @@ import org.hibernate.event.PreLoadEvent;
import org.hibernate.event.PreLoadEventListener;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.service.event.spi.EventListenerGroup;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerGroup;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.type.TypeHelper;
/**

View File

@ -130,6 +130,7 @@ import org.hibernate.mapping.UniqueKey;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.secure.JACCConfiguration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.tool.hbm2ddl.DatabaseMetadata;
import org.hibernate.tool.hbm2ddl.IndexMetadata;
@ -1744,7 +1745,7 @@ public class Configuration implements Serializable {
public SessionFactory buildSessionFactory() throws HibernateException {
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
final ServiceRegistry serviceRegistry = new BasicServiceRegistryImpl( properties );
final ServiceRegistry serviceRegistry = new ServiceRegistryBuilder( properties ).buildServiceRegistry();
setSessionFactoryObserver(
new SessionFactoryObserver() {
@Override

View File

@ -33,14 +33,14 @@ import java.util.Set;
import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.spi.Integrator;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
/**

View File

@ -23,7 +23,7 @@
*/
package org.hibernate.cfg.beanvalidation;
import org.hibernate.service.event.spi.DuplicationStrategy;
import org.hibernate.event.service.spi.DuplicationStrategy;
/**
* @author Steve Ebersole

View File

@ -57,7 +57,7 @@ import org.hibernate.mapping.Component;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.SingleTableSubclass;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerRegistry;
/**
* @author Emmanuel Bernard

View File

@ -36,11 +36,11 @@ import org.hibernate.event.PostCollectionUpdateEventListener;
import org.hibernate.event.PostDeleteEventListener;
import org.hibernate.event.PostInsertEventListener;
import org.hibernate.event.PostUpdateEventListener;
import org.hibernate.spi.Integrator;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.event.spi.DuplicationStrategy;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.DuplicationStrategy;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
/**

View File

@ -44,8 +44,8 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.property.BackrefPropertyAccessor;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.service.event.spi.EventListenerGroup;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerGroup;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.type.Type;
import org.hibernate.type.TypeHelper;

View File

@ -56,8 +56,8 @@ import org.hibernate.internal.util.collections.IdentityMap;
import org.hibernate.internal.util.collections.LazyIterator;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.Printer;
import org.hibernate.service.event.spi.EventListenerGroup;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerGroup;
import org.hibernate.event.service.spi.EventListenerRegistry;
/**
* A convenience base class for listeners whose functionality results in flushing.

View File

@ -55,7 +55,7 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.type.EmbeddedComponentType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;

View File

@ -21,9 +21,8 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.service.event.internal;
package org.hibernate.event.service.internal;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
@ -32,9 +31,9 @@ import java.util.ListIterator;
import java.util.Set;
import org.hibernate.event.EventType;
import org.hibernate.service.event.spi.DuplicationStrategy;
import org.hibernate.service.event.spi.EventListenerGroup;
import org.hibernate.service.event.spi.EventListenerRegistrationException;
import org.hibernate.event.service.spi.DuplicationStrategy;
import org.hibernate.event.service.spi.EventListenerGroup;
import org.hibernate.event.service.spi.EventListenerRegistrationException;
/**
* @author Steve Ebersole

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.service.event.internal;
package org.hibernate.event.service.internal;
import java.lang.reflect.Array;
import java.util.Collections;
@ -29,9 +29,6 @@ import java.util.HashMap;
import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.event.EventListenerRegistration;
import org.hibernate.event.EventType;
import org.hibernate.event.def.DefaultAutoFlushEventListener;
import org.hibernate.event.def.DefaultDeleteEventListener;
@ -52,11 +49,9 @@ import org.hibernate.event.def.DefaultReplicateEventListener;
import org.hibernate.event.def.DefaultSaveEventListener;
import org.hibernate.event.def.DefaultSaveOrUpdateEventListener;
import org.hibernate.event.def.DefaultUpdateEventListener;
import org.hibernate.service.event.spi.DuplicationStrategy;
import org.hibernate.service.event.spi.EventListenerRegistrationException;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.StandardServiceInitiators.EventListenerRegistrationService;
import org.hibernate.event.service.spi.DuplicationStrategy;
import org.hibernate.event.service.spi.EventListenerRegistrationException;
import org.hibernate.event.service.spi.EventListenerRegistry;
import static org.hibernate.event.EventType.AUTO_FLUSH;
import static org.hibernate.event.EventType.DELETE;
@ -425,20 +420,4 @@ public class EventListenerRegistryImpl implements EventListenerRegistry {
map.put( type, listeners );
}
public static EventListenerRegistryImpl buildEventListenerRegistry(
SessionFactoryImplementor sessionFactory,
Configuration configuration,
ServiceRegistryImplementor serviceRegistry) {
final EventListenerRegistryImpl registry = new EventListenerRegistryImpl();
final EventListenerRegistrationService registrationService = serviceRegistry.getService(
EventListenerRegistrationService.class
);
for ( EventListenerRegistration registration : registrationService.getEventListenerRegistrations() ) {
registration.apply( registry, configuration, configuration.getProperties(), serviceRegistry );
}
return registry;
}
}

View File

@ -21,11 +21,11 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.service.event.internal;
package org.hibernate.event.service.internal;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.SessionFactoryServiceInitiator;
@ -47,7 +47,7 @@ public class EventListenerServiceInitiator implements SessionFactoryServiceIniti
SessionFactoryImplementor sessionFactory,
Configuration configuration,
ServiceRegistryImplementor registry) {
return EventListenerRegistryImpl.buildEventListenerRegistry( sessionFactory, configuration, registry );
return new EventListenerRegistryImpl();
}
}

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.service.event.spi;
package org.hibernate.event.service.spi;
/**
* Defines listener duplication checking strategy, both in terms of when a duplication is detected (see

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.service.event.spi;
package org.hibernate.event.service.spi;
import java.io.Serializable;

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.service.event.spi;
package org.hibernate.event.service.spi;
import org.hibernate.HibernateException;

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.service.event.spi;
package org.hibernate.event.service.spi;
import java.io.Serializable;

View File

@ -39,10 +39,8 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@ -56,7 +54,6 @@ import org.hibernate.EmptyInterceptor;
import org.hibernate.EntityMode;
import org.hibernate.EntityNameResolver;
import org.hibernate.HibernateException;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.Interceptor;
import org.hibernate.MappingException;
import org.hibernate.ObjectNotFoundException;
@ -80,8 +77,6 @@ import org.hibernate.cache.impl.CacheDataDescriptionImpl;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.Settings;
import org.hibernate.cfg.beanvalidation.BeanValidationIntegrator;
import org.hibernate.cfg.search.HibernateSearchIntegrator;
import org.hibernate.context.CurrentSessionContext;
import org.hibernate.context.JTASessionContext;
import org.hibernate.context.ManagedSessionContext;
@ -107,6 +102,8 @@ import org.hibernate.exception.SQLExceptionConverter;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.UUIDGenerator;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.internal.util.collections.EmptyIterator;
@ -123,12 +120,12 @@ import org.hibernate.persister.spi.PersisterFactory;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.service.jta.platform.spi.JtaPlatform;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.hibernate.service.spi.SessionFactoryServiceRegistryFactory;
import org.hibernate.spi.Integrator;
import org.hibernate.stat.Statistics;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.tool.hbm2ddl.SchemaExport;
@ -260,7 +257,7 @@ public final class SessionFactoryImpl
final IntegratorObserver integratorObserver = new IntegratorObserver();
this.observer.addObserver( integratorObserver );
for ( Integrator integrator : locateIntegrators( this.serviceRegistry ) ) {
for ( Integrator integrator : serviceRegistry.getService( IntegratorService.class ).getIntegrators() ) {
integrator.integrate( cfg, this, this.serviceRegistry );
integratorObserver.integrators.add( integrator );
}
@ -503,20 +500,6 @@ public final class SessionFactoryImpl
this.observer.sessionFactoryCreated( this );
}
private Iterable<Integrator> locateIntegrators(ServiceRegistryImplementor serviceRegistry) {
List<Integrator> integrators = new ArrayList<Integrator>();
// todo : Envers needs to be handled by discovery to be because it is in a separate project
integrators.add( new BeanValidationIntegrator() );
integrators.add( new HibernateSearchIntegrator() );
for ( Integrator integrator : ServiceLoader.load( Integrator.class ) ) {
integrators.add( integrator );
}
return integrators;
}
public Session openSession() throws HibernateException {
return withOptions().openSession();
}

View File

@ -141,8 +141,8 @@ import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import org.hibernate.service.event.spi.EventListenerGroup;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerGroup;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.stat.SessionStatistics;
import org.hibernate.stat.internal.SessionStatisticsImpl;
import org.hibernate.type.SerializationException;

View File

@ -0,0 +1,66 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.integrator.internal;
import java.util.LinkedHashSet;
import java.util.ServiceLoader;
import org.hibernate.cfg.beanvalidation.BeanValidationIntegrator;
import org.hibernate.cfg.search.HibernateSearchIntegrator;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.service.spi.ServiceRegistryImplementor;
/**
* @author Steve Ebersole
*/
public class IntegratorServiceImpl implements IntegratorService {
private final ServiceRegistryImplementor serviceRegistry;
private LinkedHashSet<Integrator> integrators = new LinkedHashSet<Integrator>();
public IntegratorServiceImpl(ServiceRegistryImplementor serviceRegistry) {
this.serviceRegistry = serviceRegistry;
// Standard integrators nameable from here. Envers and JPA, for example, need to be handled by discovery
// because in separate project/jars
integrators.add( new BeanValidationIntegrator() );
integrators.add( new HibernateSearchIntegrator() );
}
@Override
public void addIntegrator(Integrator integrator) {
integrators.add( integrator );
}
@Override
public Iterable<Integrator> getIntegrators() {
LinkedHashSet<Integrator> integrators = new LinkedHashSet<Integrator>();
integrators.addAll( this.integrators );
for ( Integrator integrator : ServiceLoader.load( Integrator.class ) ) {
integrators.add( integrator );
}
return integrators;
}
}

View File

@ -21,25 +21,27 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.event;
package org.hibernate.integrator.internal;
import java.util.Map;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.service.spi.BasicServiceInitiator;
import org.hibernate.service.spi.ServiceRegistryImplementor;
/**
* Contract for performing event listener registration. This is completely a work in progress for now. The
* expectation is that this gets tied in with the "service locator" pattern defined by HHH-5562
*
* @author Steve Ebersole
*/
public interface EventListenerRegistration {
public void apply(
EventListenerRegistry eventListenerRegistry,
Configuration configuration,
Map<?, ?> configValues,
ServiceRegistryImplementor serviceRegistry
);
public class IntegratorServiceInitiator implements BasicServiceInitiator<IntegratorService> {
public static final IntegratorServiceInitiator INSTANCE = new IntegratorServiceInitiator();
@Override
public Class<IntegratorService> getServiceInitiated() {
return IntegratorService.class;
}
@Override
public IntegratorService initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
return new IntegratorServiceImpl( registry );
}
}

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.spi;
package org.hibernate.integrator.spi;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.SessionFactoryImplementor;

View File

@ -0,0 +1,47 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.integrator.spi;
import org.hibernate.service.Service;
/**
* @author Steve Ebersole
*/
public interface IntegratorService extends Service {
/**
* Manually add an integrator. Added integrators supplement the set of discovered ones.
* <p/>
* This is mostly an internal contract used between modules.
*
* @param integrator The integrator
*/
public void addIntegrator(Integrator integrator);
/**
* Retrieve all integrators.
*
* @return All integrators.
*/
public Iterable<Integrator> getIntegrators();
}

View File

@ -1,19 +1,21 @@
//$Id: HibernateService.java 6100 2005-03-17 10:48:03Z turin42 $
package org.hibernate.jmx;
import javax.naming.InitialContext;
import java.util.Map;
import java.util.Properties;
import javax.naming.InitialContext;
import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.ExternalSessionFactoryConfig;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.jndi.JndiHelper;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.jboss.logging.Logger;
/**
@ -59,9 +61,11 @@ public class HibernateService extends ExternalSessionFactoryConfig implements Hi
}
SessionFactory buildSessionFactory() throws HibernateException {
LOG.startingServiceAtJndiName(boundName);
LOG.serviceProperties(properties);
return buildConfiguration().buildSessionFactory(new BasicServiceRegistryImpl(properties));
LOG.startingServiceAtJndiName( boundName );
LOG.serviceProperties( properties );
return buildConfiguration().buildSessionFactory(
new ServiceRegistryBuilder( properties ).buildServiceRegistry()
);
}
@Override

View File

@ -0,0 +1,71 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.internal.ProvidedService;
import org.hibernate.service.spi.BasicServiceInitiator;
/**
* @author Steve Ebersole
*/
public class ServiceRegistryBuilder {
private final Map configurationValues;
private final List<BasicServiceInitiator> initiators = standardInitiatorList();
private final List<ProvidedService> services = new ArrayList<ProvidedService>();
public ServiceRegistryBuilder() {
this( new HashMap() );
}
public ServiceRegistryBuilder(Map configurationValues) {
this.configurationValues = configurationValues;
}
private static List<BasicServiceInitiator> standardInitiatorList() {
final List<BasicServiceInitiator> initiators = new ArrayList<BasicServiceInitiator>();
initiators.addAll( StandardServiceInitiators.LIST );
return initiators;
}
public ServiceRegistryBuilder addInitiator(BasicServiceInitiator initiator) {
initiators.add( initiator );
return this;
}
@SuppressWarnings( {"unchecked"})
public ServiceRegistryBuilder addService(final Class serviceRole, final Service service) {
services.add( new ProvidedService( serviceRole, service ) );
return this;
}
public BasicServiceRegistry buildServiceRegistry() {
return new BasicServiceRegistryImpl( initiators, services, configurationValues );
}
}

View File

@ -26,12 +26,11 @@ package org.hibernate.service;
import org.hibernate.engine.jdbc.batch.internal.BatchBuilderInitiator;
import org.hibernate.engine.jdbc.internal.JdbcServicesInitiator;
import org.hibernate.engine.transaction.internal.TransactionFactoryInitiator;
import org.hibernate.event.EventListenerRegistration;
import org.hibernate.persister.internal.PersisterClassResolverInitiator;
import org.hibernate.persister.internal.PersisterFactoryInitiator;
import org.hibernate.service.classloading.internal.ClassLoaderServiceInitiator;
import org.hibernate.integrator.internal.IntegratorServiceInitiator;
import org.hibernate.service.internal.SessionFactoryServiceRegistryFactoryInitiator;
import org.hibernate.service.event.internal.EventListenerServiceInitiator;
import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator;
import org.hibernate.service.jdbc.connections.internal.MultiTenantConnectionProviderInitiator;
import org.hibernate.service.jdbc.dialect.internal.DialectFactoryInitiator;
@ -40,11 +39,9 @@ import org.hibernate.service.jmx.internal.JmxServiceInitiator;
import org.hibernate.service.jndi.internal.JndiServiceInitiator;
import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator;
import org.hibernate.service.spi.BasicServiceInitiator;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author Steve Ebersole
@ -73,50 +70,9 @@ public class StandardServiceInitiators {
serviceInitiators.add( TransactionFactoryInitiator.INSTANCE );
serviceInitiators.add( SessionFactoryServiceRegistryFactoryInitiator.INSTANCE );
serviceInitiators.add( EventListenerRegistrationServiceInitiator.INSTANCE );
serviceInitiators.add( IntegratorServiceInitiator.INSTANCE );
return serviceInitiators;
}
// todo : completely temporary. See HHH-5562 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* Acts as a service in the basic registry to which users/integrators can attach things that perform event listener
* registration. The event listeners live in the SessionFactory registry, but it has access to the basic registry.
* So when it starts up, it looks in the basic registry for this service and does the requested registrations.
*/
public static interface EventListenerRegistrationService extends Service {
public void attachEventListenerRegistration(EventListenerRegistration registration);
public Iterable<EventListenerRegistration> getEventListenerRegistrations();
}
public static class EventListenerRegistrationServiceImpl implements EventListenerRegistrationService {
private List<EventListenerRegistration> registrations = new ArrayList<EventListenerRegistration>();
@Override
public void attachEventListenerRegistration(EventListenerRegistration registration) {
registrations.add( registration );
}
@Override
public Iterable<EventListenerRegistration> getEventListenerRegistrations() {
return registrations;
}
}
public static class EventListenerRegistrationServiceInitiator implements BasicServiceInitiator<EventListenerRegistrationService> {
public static final EventListenerRegistrationServiceInitiator INSTANCE = new EventListenerRegistrationServiceInitiator();
@Override
public Class<EventListenerRegistrationService> getServiceInitiated() {
return EventListenerRegistrationService.class;
}
@Override
public EventListenerRegistrationService initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
return new EventListenerRegistrationServiceImpl();
}
}
}

View File

@ -26,7 +26,7 @@ package org.hibernate.service;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.service.event.internal.EventListenerServiceInitiator;
import org.hibernate.event.service.internal.EventListenerServiceInitiator;
import org.hibernate.service.spi.SessionFactoryServiceInitiator;
import org.hibernate.stat.internal.StatisticsInitiator;

View File

@ -32,7 +32,6 @@ import org.jboss.logging.Logger;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.service.BasicServiceRegistry;
import org.hibernate.service.Service;
import org.hibernate.service.StandardServiceInitiators;
import org.hibernate.service.UnknownServiceException;
import org.hibernate.service.spi.BasicServiceInitiator;
import org.hibernate.service.spi.Configurable;
@ -50,19 +49,25 @@ public class BasicServiceRegistryImpl extends AbstractServiceRegistryImpl implem
private final Map<Class,BasicServiceInitiator> serviceInitiatorMap;
private final Map configurationValues;
public BasicServiceRegistryImpl(Map configurationValues) {
this( StandardServiceInitiators.LIST, configurationValues );
}
@SuppressWarnings( {"unchecked"})
public BasicServiceRegistryImpl(List<BasicServiceInitiator> serviceInitiators, Map configurationValues) {
public BasicServiceRegistryImpl(
List<BasicServiceInitiator> serviceInitiators,
List<ProvidedService> providedServices,
Map configurationValues) {
super();
this.serviceInitiatorMap = toMap( serviceInitiators );
this.configurationValues = configurationValues;
this.serviceInitiatorMap = toMap( serviceInitiators );
for ( BasicServiceInitiator initiator : serviceInitiatorMap.values() ) {
// create the bindings up front to help identify to which registry services belong
createServiceBinding( initiator.getServiceInitiated() );
}
for ( ProvidedService providedService : providedServices ) {
ServiceBinding binding = locateOrCreateServiceBinding( providedService.getServiceRole(), false );
binding.setTarget( providedService.getService() );
}
}
/**
@ -133,4 +138,5 @@ public class BasicServiceRegistryImpl extends AbstractServiceRegistryImpl implem
( (Configurable) service ).configure( configurationValues );
}
}
}

View File

@ -21,27 +21,27 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.service.event.internal;
import org.hibernate.event.EventType;
import org.hibernate.service.event.spi.EventListenerRegistry;
package org.hibernate.service.internal;
/**
* Helper for handling various aspects of event listeners. Temporary because generally speaking this is legacy stuff
* that should change as we move forward
* A service provided as-is.
*
* @author Steve Ebersole
*/
public class TemporaryListenerHelper {
public static interface ListenerProcessor {
public void processListener(Object listener);
public class ProvidedService<T> {
private final Class<T> serviceRole;
private final T service;
public ProvidedService(Class<T> serviceRole, T service) {
this.serviceRole = serviceRole;
this.service = service;
}
public static void processListeners(EventListenerRegistry registryRegistry, ListenerProcessor processer) {
for ( EventType eventType : EventType.values() ) {
for ( Object listener : registryRegistry.getEventListenerGroup( eventType ).listeners() ) {
processer.processListener( listener );
}
}
public Class<T> getServiceRole() {
return serviceRole;
}
public T getService() {
return service;
}
}

View File

@ -23,13 +23,10 @@
*/
package org.hibernate.service.internal;
import java.util.List;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.service.Service;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.SessionFactoryServiceInitiator;
import org.hibernate.service.spi.SessionFactoryServiceRegistryFactory;
/**

View File

@ -23,8 +23,6 @@
*/
package org.hibernate.service.spi;
import java.util.List;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.service.Service;

View File

@ -56,6 +56,7 @@ import org.hibernate.internal.util.ConfigHelper;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
@ -460,7 +461,7 @@ public class SchemaExport {
private static BasicServiceRegistryImpl createServiceRegistry(Properties properties) {
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
return new BasicServiceRegistryImpl( properties );
return (BasicServiceRegistryImpl) new ServiceRegistryBuilder( properties ).buildServiceRegistry();
}
public static void main(String[] args) {

View File

@ -50,6 +50,7 @@ import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
/**
@ -109,7 +110,7 @@ public class SchemaUpdate {
private static BasicServiceRegistryImpl createServiceRegistry(Properties properties) {
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
return new BasicServiceRegistryImpl( properties );
return (BasicServiceRegistryImpl) new ServiceRegistryBuilder( properties ).buildServiceRegistry();
}
public static void main(String[] args) {

View File

@ -40,6 +40,7 @@ import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
/**
@ -78,7 +79,7 @@ public class SchemaValidator {
private static BasicServiceRegistryImpl createServiceRegistry(Properties properties) {
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
return new BasicServiceRegistryImpl( properties );
return (BasicServiceRegistryImpl) new ServiceRegistryBuilder( properties ).buildServiceRegistry();
}
public static void main(String[] args) {

View File

@ -51,7 +51,7 @@ import org.hibernate.property.Getter;
import org.hibernate.property.Setter;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.ProxyFactory;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.tuple.Instantiator;
import org.hibernate.tuple.StandardProperty;
import org.hibernate.tuple.VersionProperty;

View File

@ -23,16 +23,15 @@
*/
package org.hibernate.metamodel.binding;
import java.util.Collections;
import org.hibernate.metamodel.relational.Column;
import org.hibernate.service.BasicServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.metamodel.relational.Column;
import org.hibernate.service.BasicServiceRegistry;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static junit.framework.Assert.assertNotNull;
@ -51,7 +50,7 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
@Before
public void setUp() {
serviceRegistry = new BasicServiceRegistryImpl( Collections.emptyMap() );
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder().buildServiceRegistry();
}
@After

View File

@ -25,14 +25,13 @@ package org.hibernate.metamodel.binding;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import org.jboss.jandex.Index;
import org.jboss.jandex.Indexer;
import org.hibernate.metamodel.source.MetadataSources;
import org.hibernate.metamodel.source.internal.MetadataImpl;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.ServiceRegistryBuilder;
import org.junit.Test;
@ -61,7 +60,7 @@ public class BasicAnnotationBindingTests extends AbstractBasicBindingTests {
public EntityBinding buildSimpleEntityBinding() {
Index index = indexForClass( SimpleEntity.class );
MetadataImpl metadata = (MetadataImpl) new MetadataSources( new BasicServiceRegistryImpl( Collections.emptyMap() ) ).buildMetadata();
MetadataImpl metadata = (MetadataImpl) new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() ).buildMetadata();
metadata.getAnnotationBinder().bindMappedClasses( index );
return metadata.getEntityBinding( SimpleEntity.class.getSimpleName() );
@ -69,7 +68,7 @@ public class BasicAnnotationBindingTests extends AbstractBasicBindingTests {
public EntityBinding buildSimpleVersionedEntityBinding() {
Index index = indexForClass( SimpleEntity.class );
MetadataImpl metadata = (MetadataImpl) new MetadataSources( new BasicServiceRegistryImpl( Collections.emptyMap() ) ).buildMetadata();
MetadataImpl metadata = (MetadataImpl) new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() ).buildMetadata();
metadata.getAnnotationBinder().bindMappedClasses( index );
return metadata.getEntityBinding( SimpleVersionedEntity.class.getSimpleName() );

View File

@ -1,12 +1,8 @@
package org.hibernate.metamodel.source.annotations.global;
import java.util.Collections;
import java.util.Iterator;
import org.jboss.jandex.Index;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.MappingException;
import org.hibernate.annotations.FetchMode;
@ -15,8 +11,14 @@ import org.hibernate.annotations.FetchProfiles;
import org.hibernate.metamodel.source.MetadataSources;
import org.hibernate.metamodel.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.source.internal.MetadataImpl;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static junit.framework.Assert.fail;
@ -34,7 +36,7 @@ public class FetchProfileBinderTest extends BaseUnitTestCase {
@Before
public void setUp() {
serviceRegistry = new BasicServiceRegistryImpl( Collections.emptyMap() );
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder().buildServiceRegistry();
service = serviceRegistry.getService( ClassLoaderService.class );
meta = (MetadataImpl) new MetadataSources( serviceRegistry ).buildMetadata();
}

View File

@ -21,6 +21,7 @@ import org.junit.Test;
import org.hibernate.AnnotationException;
import org.hibernate.metamodel.source.annotations.ConfiguredClass;
import org.hibernate.metamodel.source.annotations.ConfiguredClassHierarchy;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.testing.junit4.BaseUnitTestCase;
@ -39,7 +40,7 @@ public class ConfiguredClassHierarchyBuilderTest extends BaseUnitTestCase {
@Before
public void setUp() {
serviceRegistry = new BasicServiceRegistryImpl( Collections.emptyMap() );
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder().buildServiceRegistry();
service = serviceRegistry.getService( ClassLoaderService.class );
}

View File

@ -8,6 +8,7 @@ import org.junit.Test;
import org.hibernate.metamodel.source.MetadataSources;
import org.hibernate.metamodel.source.internal.MetadataImpl;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.testing.junit4.BaseUnitTestCase;
@ -17,7 +18,7 @@ import org.hibernate.testing.junit4.BaseUnitTestCase;
public class OrmXmlParserTests extends BaseUnitTestCase {
@Test
public void testSingleOrmXml() {
MetadataImpl metadata = (MetadataImpl) new MetadataSources( new BasicServiceRegistryImpl( Collections.emptyMap() ) ).buildMetadata();
MetadataImpl metadata = (MetadataImpl) new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() ).buildMetadata();
OrmXmlParser parser = new OrmXmlParser( metadata );
Set<String> xmlFiles = new HashSet<String>();
xmlFiles.add( "org/hibernate/metamodel/source/annotations/xml/orm.xml" );
@ -26,7 +27,7 @@ public class OrmXmlParserTests extends BaseUnitTestCase {
@Test
public void testOrmXmlWithOldSchema() {
MetadataImpl metadata = (MetadataImpl) new MetadataSources( new BasicServiceRegistryImpl( Collections.emptyMap() ) ).buildMetadata();
MetadataImpl metadata = (MetadataImpl) new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() ).buildMetadata();
OrmXmlParser parser = new OrmXmlParser( metadata );
Set<String> xmlFiles = new HashSet<String>();
xmlFiles.add( "org/hibernate/metamodel/source/annotations/xml/orm-star.xml" );

View File

@ -45,7 +45,7 @@ import org.hibernate.event.PreCollectionRemoveEventListener;
import org.hibernate.event.PreCollectionUpdateEvent;
import org.hibernate.event.PreCollectionUpdateEventListener;
import org.hibernate.event.def.DefaultInitializeCollectionEventListener;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerRegistry;
/**
* @author Gail Badner

View File

@ -22,23 +22,24 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.events;
import java.util.Map;
import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.event.DeleteEvent;
import org.hibernate.event.DeleteEventListener;
import org.hibernate.event.Destructible;
import org.hibernate.event.EventListenerRegistration;
import org.hibernate.event.EventType;
import org.hibernate.event.Initializable;
import org.hibernate.service.StandardServiceInitiators;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.hibernate.integrator.spi.Integrator;
import org.junit.Test;
@ -68,15 +69,21 @@ public class CallbackTest extends BaseCoreFunctionalTestCase {
@Override
protected void applyServices(BasicServiceRegistryImpl serviceRegistry) {
super.applyServices( serviceRegistry );
serviceRegistry.getService( StandardServiceInitiators.EventListenerRegistrationService.class ).attachEventListenerRegistration(
new EventListenerRegistration() {
serviceRegistry.getService( IntegratorService.class ).addIntegrator(
new Integrator() {
@Override
public void apply(
EventListenerRegistry eventListenerRegistry,
public void integrate(
Configuration configuration,
Map<?, ?> configValues,
ServiceRegistryImplementor serviceRegistry) {
eventListenerRegistry.setListeners( EventType.DELETE, listener );
SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) {
serviceRegistry.getService( EventListenerRegistry.class ).setListeners(
EventType.DELETE, listener
);
}
@Override
public void disintegrate(
SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
}
}
);

View File

@ -23,16 +23,15 @@
*/
package org.hibernate.test.flush;
import java.util.Map;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.event.EventListenerRegistration;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.event.EventType;
import org.hibernate.service.StandardServiceInitiators;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.hibernate.integrator.spi.Integrator;
import org.junit.Test;
@ -53,15 +52,21 @@ public class TestCollectionInitializingDuringFlush extends BaseCoreFunctionalTes
@Override
protected void applyServices(BasicServiceRegistryImpl serviceRegistry) {
super.applyServices( serviceRegistry );
serviceRegistry.getService( StandardServiceInitiators.EventListenerRegistrationService.class ).attachEventListenerRegistration(
new EventListenerRegistration() {
serviceRegistry.getService( IntegratorService.class ).addIntegrator(
new Integrator() {
@Override
public void apply(
EventListenerRegistry eventListenerRegistry,
public void integrate(
Configuration configuration,
Map<?, ?> configValues,
ServiceRegistryImplementor serviceRegistry) {
eventListenerRegistry.getEventListenerGroup( EventType.PRE_UPDATE ).appendListener( new InitializingPreUpdateEventListener() );
SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) {
serviceRegistry.getService( EventListenerRegistry.class )
.getEventListenerGroup( EventType.PRE_UPDATE )
.appendListener( new InitializingPreUpdateEventListener() );
}
@Override
public void disintegrate(
SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
}
}
);

View File

@ -41,7 +41,7 @@ import org.hibernate.engine.transaction.spi.TransactionContext;
import org.hibernate.engine.transaction.spi.TransactionImplementor;
import org.hibernate.jdbc.Expectation;
import org.hibernate.jdbc.Expectations;
import org.hibernate.service.StandardServiceInitiators;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.junit.After;
@ -68,10 +68,8 @@ public class BatchingTest extends BaseUnitTestCase implements BatchKey {
@Before
public void setUp() throws Exception {
serviceRegistry = new BasicServiceRegistryImpl(
StandardServiceInitiators.LIST,
ConnectionProviderBuilder.getConnectionProviderProperties()
);
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder( ConnectionProviderBuilder.getConnectionProviderProperties() )
.buildServiceRegistry();
}
@After

View File

@ -25,13 +25,12 @@ package org.hibernate.test.jpa;
import javax.persistence.EntityNotFoundException;
import java.io.Serializable;
import java.util.Map;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.CascadingAction;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.event.AutoFlushEventListener;
import org.hibernate.event.EventListenerRegistration;
import org.hibernate.event.EventType;
import org.hibernate.event.FlushEntityEventListener;
import org.hibernate.event.FlushEventListener;
@ -40,12 +39,13 @@ import org.hibernate.event.def.DefaultAutoFlushEventListener;
import org.hibernate.event.def.DefaultFlushEntityEventListener;
import org.hibernate.event.def.DefaultFlushEventListener;
import org.hibernate.event.def.DefaultPersistEventListener;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.internal.util.collections.IdentityMap;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.service.StandardServiceInitiators;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
@ -71,20 +71,27 @@ public abstract class AbstractJPATest extends BaseCoreFunctionalTestCase {
@Override
protected void applyServices(BasicServiceRegistryImpl serviceRegistry) {
super.applyServices( serviceRegistry );
serviceRegistry.getService( StandardServiceInitiators.EventListenerRegistrationService.class ).attachEventListenerRegistration(
new EventListenerRegistration() {
serviceRegistry.getService( IntegratorService.class ).addIntegrator(
new Integrator() {
@Override
public void apply(
EventListenerRegistry eventListenerRegistry,
public void integrate(
Configuration configuration,
Map<?, ?> configValues,
ServiceRegistryImplementor serviceRegistry) {
SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) {
EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
eventListenerRegistry.setListeners( EventType.PERSIST, buildPersistEventListeners() );
eventListenerRegistry.setListeners( EventType.PERSIST_ONFLUSH, buildPersisOnFlushEventListeners() );
eventListenerRegistry.setListeners(
EventType.PERSIST_ONFLUSH, buildPersisOnFlushEventListeners()
);
eventListenerRegistry.setListeners( EventType.AUTO_FLUSH, buildAutoFlushEventListeners() );
eventListenerRegistry.setListeners( EventType.FLUSH, buildFlushEventListeners() );
eventListenerRegistry.setListeners( EventType.FLUSH_ENTITY, buildFlushEntityEventListeners() );
}
@Override
public void disintegrate(
SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
}
}
);
}

View File

@ -23,21 +23,20 @@
*/
package org.hibernate.test.keymanytoone.bidir.component;
import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.event.EventListenerRegistration;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.event.EventType;
import org.hibernate.event.LoadEvent;
import org.hibernate.event.LoadEventListener;
import org.hibernate.event.def.DefaultLoadEventListener;
import org.hibernate.service.StandardServiceInitiators;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.hibernate.integrator.spi.Integrator;
import org.junit.Test;
@ -65,16 +64,21 @@ public class EagerKeyManyToOneTest extends BaseCoreFunctionalTestCase {
protected void applyServices(BasicServiceRegistryImpl serviceRegistry) {
super.applyServices( serviceRegistry );
// (they are different service registries!)
serviceRegistry.getService( StandardServiceInitiators.EventListenerRegistrationService.class ).attachEventListenerRegistration(
new EventListenerRegistration() {
serviceRegistry.getService( IntegratorService.class ).addIntegrator(
new Integrator() {
@Override
public void apply(
EventListenerRegistry eventListenerRegistry,
public void integrate(
Configuration configuration,
Map<?, ?> configValues,
ServiceRegistryImplementor serviceRegistry) {
eventListenerRegistry.prependListeners( EventType.LOAD, new CustomLoadListener() );
SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) {
serviceRegistry.getService( EventListenerRegistry.class ).prependListeners(
EventType.LOAD, new CustomLoadListener()
);
}
@Override
public void disintegrate(
SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
}
}
);

View File

@ -29,14 +29,12 @@ import java.sql.SQLException;
import org.hibernate.HibernateException;
import org.hibernate.MultiTenancyStrategy;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cache.HashtableCacheProvider;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.RootClass;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
import org.hibernate.service.jdbc.connections.spi.AbstractMultiTenantConnectionProvider;
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
@ -152,8 +150,9 @@ public class SchemaBasedMultiTenancyTest extends BaseUnitTestCase {
false // do not *just* perform the create
);
serviceRegistry = new BasicServiceRegistryImpl( cfg.getProperties() );
serviceRegistry.registerService( MultiTenantConnectionProvider.class, multiTenantConnectionProvider );
serviceRegistry = (ServiceRegistryImplementor) new ServiceRegistryBuilder( cfg.getProperties() )
.addService( MultiTenantConnectionProvider.class, multiTenantConnectionProvider )
.buildServiceRegistry();
sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
}

View File

@ -32,6 +32,7 @@ import static org.junit.Assert.assertTrue;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
import org.hibernate.service.jdbc.connections.internal.UserSuppliedConnectionProviderImpl;
@ -46,7 +47,9 @@ import org.hibernate.testing.junit4.BaseUnitTestCase;
public class ServiceBootstrappingTest extends BaseUnitTestCase {
@Test
public void testBasicBuild() {
BasicServiceRegistryImpl serviceRegistry = new BasicServiceRegistryImpl( ConnectionProviderBuilder.getConnectionProviderProperties() );
BasicServiceRegistryImpl serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder(
ConnectionProviderBuilder.getConnectionProviderProperties()
).buildServiceRegistry();
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
assertTrue( jdbcServices.getDialect() instanceof H2Dialect );
@ -61,7 +64,8 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase {
Properties props = ConnectionProviderBuilder.getConnectionProviderProperties();
props.put( Environment.SHOW_SQL, "true" );
BasicServiceRegistryImpl serviceRegistry = new BasicServiceRegistryImpl( props );
BasicServiceRegistryImpl serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder( props ).buildServiceRegistry();
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
assertTrue( jdbcServices.getDialect() instanceof H2Dialect );
@ -75,7 +79,7 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase {
public void testBuildWithServiceOverride() {
Properties props = ConnectionProviderBuilder.getConnectionProviderProperties();
BasicServiceRegistryImpl serviceRegistry = new BasicServiceRegistryImpl( props );
BasicServiceRegistryImpl serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder( props ).buildServiceRegistry();
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
assertTrue( jdbcServices.getDialect() instanceof H2Dialect );

View File

@ -33,23 +33,24 @@ import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
import org.hibernate.engine.transaction.spi.TransactionContext;
import org.hibernate.engine.transaction.spi.TransactionImplementor;
import org.hibernate.service.StandardServiceInitiators;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.env.ConnectionProviderBuilder;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.test.common.JournalingTransactionObserver;
import org.hibernate.test.common.TransactionContextImpl;
import org.hibernate.test.common.TransactionEnvironmentImpl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.testing.env.ConnectionProviderBuilder;
import org.hibernate.test.common.JournalingTransactionObserver;
import org.hibernate.test.common.TransactionContextImpl;
import org.hibernate.test.common.TransactionEnvironmentImpl;
/**
* @author Steve Ebersole
*/
@ -58,10 +59,8 @@ public class TestExpectedUsage extends BaseUnitTestCase {
@Before
public void setUp() throws Exception {
serviceRegistry = new BasicServiceRegistryImpl(
StandardServiceInitiators.LIST,
ConnectionProviderBuilder.getConnectionProviderProperties()
);
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder( ConnectionProviderBuilder.getConnectionProviderProperties() )
.buildServiceRegistry();
}
@After

View File

@ -36,6 +36,7 @@ import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
import org.hibernate.engine.transaction.internal.jta.JtaTransactionFactory;
import org.hibernate.engine.transaction.spi.TransactionContext;
import org.hibernate.engine.transaction.spi.TransactionImplementor;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.ServiceProxy;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.jta.platform.spi.JtaPlatform;
@ -71,7 +72,7 @@ public class BasicDrivingTest extends BaseUnitTestCase {
configValues.putAll( ConnectionProviderBuilder.getConnectionProviderProperties() );
configValues.put( Environment.TRANSACTION_STRATEGY, JtaTransactionFactory.class.getName() );
TestingJtaBootstrap.prepare( configValues );
serviceRegistry = new BasicServiceRegistryImpl( configValues );
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder( configValues ).buildServiceRegistry();
}
@After

View File

@ -38,7 +38,7 @@ import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
import org.hibernate.engine.transaction.spi.TransactionContext;
import org.hibernate.engine.transaction.spi.TransactionImplementor;
import org.hibernate.service.StandardServiceInitiators;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.internal.ServiceProxy;
import org.hibernate.service.jta.platform.spi.JtaPlatform;
@ -71,10 +71,9 @@ public class ManagedDrivingTest extends BaseUnitTestCase {
public void setUp() throws Exception {
Map configValues = new HashMap();
TestingJtaBootstrap.prepare( configValues );
// configValues.putAll( ConnectionProviderBuilder.getConnectionProviderProperties() );
configValues.put( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
serviceRegistry = new BasicServiceRegistryImpl( StandardServiceInitiators.LIST, configValues );
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder( configValues ).buildServiceRegistry();
}
@After

View File

@ -75,7 +75,7 @@ import org.hibernate.cfg.NamingStrategy;
import org.hibernate.cfg.annotations.reflection.XMLContext;
import org.hibernate.cfg.beanvalidation.BeanValidationIntegrator;
import org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider;
import org.hibernate.ejb.event.JpaEventListenerRegistration;
import org.hibernate.ejb.event.JpaIntegrator;
import org.hibernate.ejb.instrument.InterceptFieldClassFileTransformer;
import org.hibernate.ejb.internal.EntityManagerMessageLogger;
import org.hibernate.ejb.packaging.JarVisitorFactory;
@ -90,6 +90,7 @@ import org.hibernate.ejb.util.NamingHelper;
import org.hibernate.engine.FilterDefinition;
import org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory;
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.CollectionHelper;
@ -101,8 +102,7 @@ import org.hibernate.mapping.PersistentClass;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.secure.JACCConfiguration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.StandardServiceInitiators;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl;
/**
@ -872,7 +872,7 @@ public class Ejb3Configuration implements Serializable, Referenceable {
}
public EntityManagerFactory buildEntityManagerFactory() {
return buildEntityManagerFactory( new BasicServiceRegistryImpl( cfg.getProperties() ) );
return buildEntityManagerFactory( new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry() );
}
public EntityManagerFactory buildEntityManagerFactory(ServiceRegistry serviceRegistry) {
@ -886,9 +886,7 @@ public class Ejb3Configuration implements Serializable, Referenceable {
try {
configure( (Properties)null, null );
NamingHelper.bind(this);
// todo : temporary -> HHH-5562
serviceRegistry.getService( StandardServiceInitiators.EventListenerRegistrationService.class )
.attachEventListenerRegistration( new JpaEventListenerRegistration() );
serviceRegistry.getService( IntegratorService.class ).addIntegrator( new JpaIntegrator() );
return new EntityManagerFactoryImpl(
transactionType,
discardOnClose,

View File

@ -31,8 +31,9 @@ import org.hibernate.MappingException;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.cfg.Configuration;
import org.hibernate.ejb.AvailableSettings;
import org.hibernate.event.EventListenerRegistration;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.event.EventType;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.secure.JACCPreDeleteEventListener;
import org.hibernate.secure.JACCPreInsertEventListener;
@ -40,19 +41,18 @@ import org.hibernate.secure.JACCPreLoadEventListener;
import org.hibernate.secure.JACCPreUpdateEventListener;
import org.hibernate.secure.JACCSecurityListener;
import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.event.spi.DuplicationStrategy;
import org.hibernate.service.event.spi.EventListenerGroup;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.DuplicationStrategy;
import org.hibernate.event.service.spi.EventListenerGroup;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
/**
* Prepare the HEM-specific event listeners.
*
* @todo : make this into Integrator per HHH-5562 ??
*
* @author Steve Ebersole
*/
public class JpaEventListenerRegistration implements EventListenerRegistration {
public class JpaIntegrator implements Integrator {
private static final DuplicationStrategy JPA_DUPLICATION_STRATEGY = new DuplicationStrategy() {
@Override
public boolean areMatch(Object listener, Object original) {
@ -81,12 +81,13 @@ public class JpaEventListenerRegistration implements EventListenerRegistration {
@Override
@SuppressWarnings( {"unchecked"})
public void apply(
EventListenerRegistry eventListenerRegistry,
public void integrate(
Configuration configuration,
Map<?, ?> configValues,
ServiceRegistryImplementor serviceRegistry) {
boolean isSecurityEnabled = configValues.containsKey( AvailableSettings.JACC_ENABLED );
SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) {
final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
boolean isSecurityEnabled = configuration.getProperties().containsKey( AvailableSettings.JACC_ENABLED );
eventListenerRegistry.addDuplicationStrategy( JPA_DUPLICATION_STRATEGY );
eventListenerRegistry.addDuplicationStrategy( JACC_DUPLICATION_STRATEGY );
@ -116,7 +117,7 @@ public class JpaEventListenerRegistration implements EventListenerRegistration {
eventListenerRegistry.prependListeners( EventType.POST_LOAD, new EJB3PostLoadEventListener() );
eventListenerRegistry.prependListeners( EventType.POST_UPDATE, new EJB3PostUpdateEventListener() );
for ( Map.Entry<?,?> entry : configValues.entrySet() ) {
for ( Map.Entry<?,?> entry : configuration.getProperties().entrySet() ) {
if ( ! String.class.isInstance( entry.getKey() ) ) {
continue;
}
@ -127,14 +128,11 @@ public class JpaEventListenerRegistration implements EventListenerRegistration {
final String eventTypeName = propertyName.substring( AvailableSettings.EVENT_LISTENER_PREFIX.length() + 1 );
final EventType eventType = EventType.resolveEventTypeByName( eventTypeName );
final EventListenerGroup eventListenerGroup = eventListenerRegistry.getEventListenerGroup( eventType );
eventListenerGroup.clear();
for ( String listenerImpl : ( (String) entry.getValue() ).split( " ," ) ) {
eventListenerGroup.appendListener( instantiate( listenerImpl, serviceRegistry ) );
}
}
// todo : we may need to account for callback handlers previously set (shared across EMFs)
final EntityCallbackHandler callbackHandler = new EntityCallbackHandler();
Iterator classes = configuration.getClassMappings();
ReflectionManager reflectionManager = configuration.getReflectionManager();
@ -162,6 +160,10 @@ public class JpaEventListenerRegistration implements EventListenerRegistration {
}
}
@Override
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
}
private Object instantiate(String listenerImpl, ServiceRegistryImplementor serviceRegistry) {
try {
return serviceRegistry.getService( ClassLoaderService.class ).classForName( listenerImpl ).newInstance();

View File

@ -42,6 +42,7 @@ import org.hibernate.dialect.Dialect;
import org.hibernate.ejb.AvailableSettings;
import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.junit.After;
@ -203,7 +204,7 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa
properties.putAll( configuration.getProperties() );
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
return new BasicServiceRegistryImpl( properties );
return (BasicServiceRegistryImpl) new ServiceRegistryBuilder( properties ).buildServiceRegistry();
}
@SuppressWarnings( {"UnusedParameters"})

View File

@ -58,7 +58,7 @@ import org.hibernate.ejb.test.pack.various.Seat;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.event.EventType;
import org.hibernate.internal.util.ConfigHelper;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.stat.Statistics;
import org.junit.Test;

View File

@ -32,7 +32,7 @@ import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.reader.AuditReaderImpl;
import org.hibernate.event.EventType;
import org.hibernate.event.PostInsertEventListener;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerRegistry;
/**
* @author Adam Warski (adam at warski dot org)

View File

@ -30,9 +30,9 @@ import org.hibernate.cfg.Configuration;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.event.EventType;
import org.hibernate.spi.Integrator;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
/**

View File

@ -23,7 +23,7 @@
*/
package org.hibernate.envers.event;
import org.hibernate.service.event.spi.DuplicationStrategy;
import org.hibernate.event.service.spi.DuplicationStrategy;
/**
* Event listener duplication strategy for envers

View File

@ -28,6 +28,7 @@ import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.envers.AuditReader;
import org.hibernate.envers.AuditReaderFactory;
import org.hibernate.envers.event.EnversIntegrator;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.testing.AfterClassOnce;
import org.hibernate.testing.BeforeClassOnce;
@ -97,7 +98,7 @@ public abstract class AbstractEntityTest extends AbstractEnversTest {
configure( cfg );
serviceRegistry = new BasicServiceRegistryImpl(configValues);
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder( configValues ).buildServiceRegistry();
emf = cfg.buildEntityManagerFactory( serviceRegistry );

View File

@ -34,6 +34,8 @@ import org.hibernate.cache.Region;
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
import org.hibernate.cache.infinispan.util.CacheAdapter;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.junit.Test;
@ -79,7 +81,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
private void evictOrRemoveTest() throws Exception {
Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
new BasicServiceRegistryImpl( cfg.getProperties() ),
new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry(),
cfg,
getCacheTestSupport()
);
@ -96,7 +98,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
cfg = createConfiguration();
regionFactory = CacheTestUtil.startRegionFactory(
new BasicServiceRegistryImpl( cfg.getProperties() ),
new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry(),
cfg,
getCacheTestSupport()
);
@ -142,7 +144,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
private void evictOrRemoveAllTest(String configName) throws Exception {
Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
new BasicServiceRegistryImpl( cfg.getProperties() ),
new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry(),
cfg,
getCacheTestSupport()
);
@ -160,7 +162,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
cfg = createConfiguration();
regionFactory = CacheTestUtil.startRegionFactory(
new BasicServiceRegistryImpl( cfg.getProperties() ),
new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry(),
cfg,
getCacheTestSupport()
);

View File

@ -32,6 +32,7 @@ import org.hibernate.cache.infinispan.collection.CollectionRegionImpl;
import org.hibernate.cache.infinispan.entity.EntityRegionImpl;
import org.hibernate.cache.infinispan.util.FlagAdapter;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.test.cache.infinispan.util.CacheTestUtil;
@ -108,7 +109,7 @@ public class NodeEnvironment {
}
public void prepare() throws Exception {
serviceRegistry = new BasicServiceRegistryImpl( configuration.getProperties() );
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder( configuration.getProperties() ).buildServiceRegistry();
regionFactory = CacheTestUtil.startRegionFactory( serviceRegistry, configuration );
}

View File

@ -42,6 +42,7 @@ import org.hibernate.cache.infinispan.InfinispanRegionFactory;
import org.hibernate.cache.infinispan.util.CacheAdapter;
import org.hibernate.cache.infinispan.util.CacheAdapterImpl;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import junit.framework.AssertionFailedError;
@ -89,7 +90,7 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
private void putDoesNotBlockGetTest() throws Exception {
Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
new BasicServiceRegistryImpl( cfg.getProperties() ),
new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry(),
cfg,
getCacheTestSupport()
);
@ -189,7 +190,7 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
private void getDoesNotBlockPutTest() throws Exception {
Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
new BasicServiceRegistryImpl( cfg.getProperties() ),
new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry(),
cfg,
getCacheTestSupport()
);

View File

@ -48,6 +48,7 @@ import org.hibernate.cache.infinispan.util.CacheAdapter;
import org.hibernate.cache.infinispan.util.CacheAdapterImpl;
import org.hibernate.cache.infinispan.util.FlagAdapter;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.test.cache.infinispan.AbstractGeneralDataRegionTestCase;
@ -82,7 +83,7 @@ public class TimestampsRegionImplTestCase extends AbstractGeneralDataRegionTestC
public void testClearTimestampsRegionInIsolated() throws Exception {
Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
new BasicServiceRegistryImpl( cfg.getProperties() ),
new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry(),
cfg,
getCacheTestSupport()
);
@ -91,7 +92,7 @@ public class TimestampsRegionImplTestCase extends AbstractGeneralDataRegionTestC
Configuration cfg2 = createConfiguration();
InfinispanRegionFactory regionFactory2 = CacheTestUtil.startRegionFactory(
new BasicServiceRegistryImpl( cfg.getProperties() ),
new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry(),
cfg2,
getCacheTestSupport()
);

View File

@ -44,7 +44,7 @@ public class ServiceRegistryBuilder {
properties.putAll( serviceRegistryConfig );
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
return new BasicServiceRegistryImpl( properties );
return (BasicServiceRegistryImpl) new org.hibernate.service.ServiceRegistryBuilder( properties ).buildServiceRegistry();
}
public static void destroy(ServiceRegistry serviceRegistry) {

View File

@ -248,7 +248,7 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
properties.putAll( configuration.getProperties() );
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
BasicServiceRegistryImpl serviceRegistry = new BasicServiceRegistryImpl( properties );
BasicServiceRegistryImpl serviceRegistry = (BasicServiceRegistryImpl) new org.hibernate.service.ServiceRegistryBuilder( properties ).buildServiceRegistry();
applyServices( serviceRegistry );
return serviceRegistry;
}