HHH-5765 - Replaced ServiceRegistryHolder with ServiceRegistryBuilder

This commit is contained in:
Steve Ebersole 2011-02-21 23:41:17 -06:00
parent 3ba07b3f18
commit 39d2d53968
30 changed files with 388 additions and 403 deletions

View File

@ -24,36 +24,38 @@
*/ */
package org.hibernate.dialect.resolver; package org.hibernate.dialect.resolver;
import java.util.Properties;
import java.sql.Connection;
import junit.framework.TestSuite;
import junit.framework.TestCase;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.dialect.HSQLDialect; import org.hibernate.cfg.Environment;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.DerbyDialect;
import org.hibernate.dialect.IngresDialect;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.dialect.InformixDialect;
import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.DerbyDialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.InformixDialect;
import org.hibernate.dialect.IngresDialect;
import org.hibernate.dialect.Mocks;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.Oracle10gDialect;
import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.Oracle8iDialect;
import org.hibernate.dialect.Oracle9iDialect; import org.hibernate.dialect.Oracle9iDialect;
import org.hibernate.dialect.Oracle10gDialect; import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.TestingDialects; import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.dialect.Mocks;
import org.hibernate.dialect.SybaseASE15Dialect; import org.hibernate.dialect.SybaseASE15Dialect;
import org.hibernate.dialect.SybaseAnywhereDialect; import org.hibernate.dialect.SybaseAnywhereDialect;
import org.hibernate.cfg.Environment; import org.hibernate.dialect.TestingDialects;
import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl; import org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl;
import org.hibernate.service.jdbc.dialect.internal.DialectResolverSet; import org.hibernate.service.jdbc.dialect.internal.DialectResolverSet;
import org.hibernate.service.jdbc.dialect.internal.StandardDialectResolver; import org.hibernate.service.jdbc.dialect.internal.StandardDialectResolver;
import org.hibernate.service.jdbc.dialect.spi.DialectResolver; import org.hibernate.service.jdbc.dialect.spi.DialectResolver;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import java.sql.Connection;
import java.util.Properties;
/** /**
* TODO : javadoc * TODO : javadoc
@ -61,19 +63,19 @@ import org.hibernate.test.common.ServiceRegistryHolder;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class DialectFactoryTest extends TestCase { public class DialectFactoryTest extends TestCase {
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
public DialectFactoryTest(String name) { public DialectFactoryTest(String name) {
super( name ); super( name );
} }
protected void setUp() { protected void setUp() {
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
} }
protected void tearDown() { protected void tearDown() {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
@ -124,7 +126,7 @@ public class DialectFactoryTest extends TestCase {
private DialectFactoryImpl getDialectFactoryImpl(DialectResolver dialectResolver) { private DialectFactoryImpl getDialectFactoryImpl(DialectResolver dialectResolver) {
DialectFactoryImpl dialectFactoryImpl = new DialectFactoryImpl(); DialectFactoryImpl dialectFactoryImpl = new DialectFactoryImpl();
dialectFactoryImpl.setClassLoaderService( serviceRegistryHolder.getClassLoaderService() ); dialectFactoryImpl.setClassLoaderService( serviceRegistry.getService( ClassLoaderService.class ) );
dialectFactoryImpl.setDialectResolver( dialectResolver ); dialectFactoryImpl.setDialectResolver( dialectResolver );
return dialectFactoryImpl; return dialectFactoryImpl;
} }

View File

@ -44,7 +44,8 @@ import org.hibernate.impl.SessionImpl;
import org.hibernate.jdbc.Work; import org.hibernate.jdbc.Work;
import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject; import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject;
import org.hibernate.TestingDatabaseInfo; import org.hibernate.TestingDatabaseInfo;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
/** /**
* I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this * I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this
@ -57,7 +58,7 @@ public class SequenceHiLoGeneratorNoIncrementTest extends TestCase {
private static final String TEST_SEQUENCE = "test_sequence"; private static final String TEST_SEQUENCE = "test_sequence";
private Configuration cfg; private Configuration cfg;
ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
private SessionFactoryImplementor sessionFactory; private SessionFactoryImplementor sessionFactory;
private SequenceHiLoGenerator generator; private SequenceHiLoGenerator generator;
@ -97,8 +98,8 @@ public class SequenceHiLoGeneratorNoIncrementTest extends TestCase {
) )
); );
serviceRegistryHolder = new ServiceRegistryHolder( cfg.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
} }
@Override @Override
@ -106,8 +107,8 @@ public class SequenceHiLoGeneratorNoIncrementTest extends TestCase {
if ( sessionFactory != null ) { if ( sessionFactory != null ) {
sessionFactory.close(); sessionFactory.close();
} }
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
super.tearDown(); super.tearDown();
} }

View File

@ -23,12 +23,6 @@
*/ */
package org.hibernate.id; package org.hibernate.id;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
@ -44,7 +38,14 @@ import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.impl.SessionImpl; import org.hibernate.impl.SessionImpl;
import org.hibernate.jdbc.Work; import org.hibernate.jdbc.Work;
import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject; import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
/** /**
* I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this * I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this
@ -57,7 +58,7 @@ public class SequenceHiLoGeneratorTest extends TestCase {
private static final String TEST_SEQUENCE = "test_sequence"; private static final String TEST_SEQUENCE = "test_sequence";
private Configuration cfg; private Configuration cfg;
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
private SessionFactoryImplementor sessionFactory; private SessionFactoryImplementor sessionFactory;
private SequenceHiLoGenerator generator; private SequenceHiLoGenerator generator;
@ -96,10 +97,8 @@ public class SequenceHiLoGeneratorTest extends TestCase {
generator.sqlDropStrings( dialect )[0] generator.sqlDropStrings( dialect )[0]
) )
); );
serviceRegistryHolder = new ServiceRegistryHolder( cfg.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
sessionFactory =
(SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
} }
@Override @Override
@ -107,8 +106,8 @@ public class SequenceHiLoGeneratorTest extends TestCase {
if ( sessionFactory != null ) { if ( sessionFactory != null ) {
sessionFactory.close(); sessionFactory.close();
} }
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
super.tearDown(); super.tearDown();
} }

View File

@ -23,12 +23,6 @@
*/ */
package org.hibernate.id; package org.hibernate.id;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
@ -44,7 +38,14 @@ import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.impl.SessionImpl; import org.hibernate.impl.SessionImpl;
import org.hibernate.jdbc.Work; import org.hibernate.jdbc.Work;
import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject; import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
/** /**
* I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this * I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this
@ -58,7 +59,7 @@ public class TableHiLoGeneratorTest extends TestCase {
private static final String GEN_COLUMN = TableHiLoGenerator.DEFAULT_COLUMN_NAME; private static final String GEN_COLUMN = TableHiLoGenerator.DEFAULT_COLUMN_NAME;
private Configuration cfg; private Configuration cfg;
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
private SessionFactoryImplementor sessionFactory; private SessionFactoryImplementor sessionFactory;
private TableHiLoGenerator generator; private TableHiLoGenerator generator;
@ -106,9 +107,8 @@ public class TableHiLoGeneratorTest extends TestCase {
) )
); );
serviceRegistryHolder = new ServiceRegistryHolder( cfg.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
sessionFactory = sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
(SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
} }
@Override @Override
@ -116,8 +116,8 @@ public class TableHiLoGeneratorTest extends TestCase {
if ( sessionFactory != null ) { if ( sessionFactory != null ) {
sessionFactory.close(); sessionFactory.close();
} }
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
super.tearDown(); super.tearDown();

View File

@ -28,7 +28,8 @@ import junit.framework.TestCase;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.H2Dialect;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
/** /**
* TODO : javadoc * TODO : javadoc
@ -38,10 +39,10 @@ import org.hibernate.test.common.ServiceRegistryHolder;
public class SubclassProxyInterfaceTest extends TestCase { public class SubclassProxyInterfaceTest extends TestCase {
public void testSubclassProxyInterfaces() { public void testSubclassProxyInterfaces() {
final Configuration cfg = new Configuration() final Configuration cfg = new Configuration()
.setProperty( Environment.DIALECT, H2Dialect.class.getName() ); .setProperty( Environment.DIALECT, H2Dialect.class.getName() )
cfg.addClass( Person.class ); .addClass( Person.class );
ServiceRegistryHolder serviceRegistryHolder = new ServiceRegistryHolder( cfg.getProperties() ); ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ).close(); cfg.buildSessionFactory( serviceRegistry ).close();
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }

View File

@ -2,29 +2,28 @@
package org.hibernate.test.annotations; package org.hibernate.test.annotations;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.Query; import org.hibernate.Query;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class ConfigurationTest extends junit.framework.TestCase { public class ConfigurationTest extends junit.framework.TestCase {
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
protected void setUp() { protected void setUp() {
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
} }
protected void tearDown() { protected void tearDown() {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
@ -32,7 +31,7 @@ public class ConfigurationTest extends junit.framework.TestCase {
AnnotationConfiguration cfg = new AnnotationConfiguration(); AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" ); cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
SessionFactory sf = cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); SessionFactory sf = cfg.buildSessionFactory( serviceRegistry );
assertNotNull( sf ); assertNotNull( sf );
Session s = sf.openSession(); Session s = sf.openSession();
Transaction tx = s.beginTransaction(); Transaction tx = s.beginTransaction();
@ -50,7 +49,7 @@ public class ConfigurationTest extends junit.framework.TestCase {
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" ); cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
cfg.setProperty( AnnotationConfiguration.ARTEFACT_PROCESSING_ORDER, "class" ); cfg.setProperty( AnnotationConfiguration.ARTEFACT_PROCESSING_ORDER, "class" );
SessionFactory sf = cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); SessionFactory sf = cfg.buildSessionFactory( serviceRegistry );
assertNotNull( sf ); assertNotNull( sf );
Session s = sf.openSession(); Session s = sf.openSession();
Transaction tx = s.beginTransaction(); Transaction tx = s.beginTransaction();
@ -74,7 +73,7 @@ public class ConfigurationTest extends junit.framework.TestCase {
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" ); cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
cfg.addAnnotatedClass( Boat.class ); cfg.addAnnotatedClass( Boat.class );
SessionFactory sf = cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); SessionFactory sf = cfg.buildSessionFactory( serviceRegistry );
assertNotNull( sf ); assertNotNull( sf );
Session s = sf.openSession(); Session s = sf.openSession();
s.getTransaction().begin(); s.getTransaction().begin();
@ -100,7 +99,7 @@ public class ConfigurationTest extends junit.framework.TestCase {
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
cfg.setProperty( AnnotationConfiguration.ARTEFACT_PROCESSING_ORDER, "class, hbm" ); cfg.setProperty( AnnotationConfiguration.ARTEFACT_PROCESSING_ORDER, "class, hbm" );
cfg.addAnnotatedClass( Boat.class ); cfg.addAnnotatedClass( Boat.class );
SessionFactory sf = cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); SessionFactory sf = cfg.buildSessionFactory( serviceRegistry );
assertNotNull( sf ); assertNotNull( sf );
Session s = sf.openSession(); Session s = sf.openSession();
s.getTransaction().begin(); s.getTransaction().begin();
@ -124,7 +123,7 @@ public class ConfigurationTest extends junit.framework.TestCase {
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" ); cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.addClass( Ferry.class ); cfg.addClass( Ferry.class );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
SessionFactory sf = cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); SessionFactory sf = cfg.buildSessionFactory( serviceRegistry );
assertNotNull( sf ); assertNotNull( sf );
Session s = sf.openSession(); Session s = sf.openSession();
Transaction tx = s.beginTransaction(); Transaction tx = s.beginTransaction();
@ -142,7 +141,7 @@ public class ConfigurationTest extends junit.framework.TestCase {
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" ); cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.addAnnotatedClass( Port.class ); cfg.addAnnotatedClass( Port.class );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
SessionFactory sf = cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); SessionFactory sf = cfg.buildSessionFactory( serviceRegistry );
assertNotNull( sf ); assertNotNull( sf );
Session s = sf.openSession(); Session s = sf.openSession();
Transaction tx = s.beginTransaction(); Transaction tx = s.beginTransaction();

View File

@ -2,10 +2,10 @@
package org.hibernate.test.annotations; package org.hibernate.test.annotations;
import org.hibernate.AnnotationException; import org.hibernate.AnnotationException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
@ -15,18 +15,18 @@ public class SafeMappingTest extends junit.framework.TestCase {
AnnotationConfiguration cfg = new AnnotationConfiguration(); AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass( IncorrectEntity.class ); cfg.addAnnotatedClass( IncorrectEntity.class );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
ServiceRegistryHolder serviceRegistryHolder = null; ServiceRegistry serviceRegistry = null;
try { try {
serviceRegistryHolder = new ServiceRegistryHolder( cfg.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
SessionFactory sf = cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); cfg.buildSessionFactory( serviceRegistry );
fail( "Entity wo id should fail" ); fail( "Entity wo id should fail" );
} }
catch (AnnotationException e) { catch (AnnotationException e) {
//success //success
} }
finally { finally {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
} }

View File

@ -1,14 +1,16 @@
//$Id$ //$Id$
package org.hibernate.test.annotations; package org.hibernate.test.annotations;
import java.util.Properties;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import java.util.Properties;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
@ -31,22 +33,25 @@ public class SecuredBindingTest extends TestCase {
ac.setProperties( p ); ac.setProperties( p );
ac.addAnnotatedClass( Plane.class ); ac.addAnnotatedClass( Plane.class );
SessionFactory sf; SessionFactory sf;
ServiceRegistryHolder serviceRegistryHolder = null; ServiceRegistry serviceRegistry = null;
try { try {
serviceRegistryHolder = new ServiceRegistryHolder( p ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( p );
sf = ac.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); sf = ac.buildSessionFactory( serviceRegistry );
try {
sf.close();
}
catch (Exception ignore) {
}
fail( "Driver property overriding should work" ); fail( "Driver property overriding should work" );
sf.close();
} }
catch (HibernateException he) { catch (HibernateException he) {
//success //success
} }
finally { finally {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
} }
} }

View File

@ -24,8 +24,6 @@
*/ */
package org.hibernate.test.annotations; package org.hibernate.test.annotations;
import java.io.InputStream;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Interceptor; import org.hibernate.Interceptor;
import org.hibernate.Session; import org.hibernate.Session;
@ -33,9 +31,10 @@ import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.test.common.ServiceRegistryHolder;
import org.hibernate.testing.junit.functional.annotations.HibernateTestCase; import org.hibernate.testing.junit.functional.annotations.HibernateTestCase;
import java.io.InputStream;
/** /**
* A base class for all annotation tests. * A base class for all annotation tests.
* *

View File

@ -33,7 +33,8 @@ import org.hibernate.cfg.Environment;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.property.BasicPropertyAccessor; import org.hibernate.property.BasicPropertyAccessor;
import org.hibernate.property.DirectPropertyAccessor; import org.hibernate.property.DirectPropertyAccessor;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.tuple.entity.PojoEntityTuplizer; import org.hibernate.tuple.entity.PojoEntityTuplizer;
@ -45,15 +46,15 @@ import org.hibernate.tuple.entity.PojoEntityTuplizer;
*/ */
public class AccessMappingTest extends TestCase { public class AccessMappingTest extends TestCase {
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
protected void setUp() { protected void setUp() {
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
} }
protected void tearDown() { protected void tearDown() {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
@ -62,7 +63,7 @@ public class AccessMappingTest extends TestCase {
cfg.addAnnotatedClass( Course1.class ); cfg.addAnnotatedClass( Course1.class );
cfg.addAnnotatedClass( Student.class ); cfg.addAnnotatedClass( Student.class );
try { try {
cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); cfg.buildSessionFactory( serviceRegistry );
fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." ); fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." );
} }
catch ( MappingException e ) { catch ( MappingException e ) {
@ -75,7 +76,7 @@ public class AccessMappingTest extends TestCase {
Class<?> classUnderTest = Course6.class; Class<?> classUnderTest = Course6.class;
cfg.addAnnotatedClass( classUnderTest ); cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class ); cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() ) EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel(); .getEntityMetamodel();
PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO ); PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO );
@ -90,7 +91,7 @@ public class AccessMappingTest extends TestCase {
Class<?> classUnderTest = Course7.class; Class<?> classUnderTest = Course7.class;
cfg.addAnnotatedClass( classUnderTest ); cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class ); cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() ) EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel(); .getEntityMetamodel();
PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO ); PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO );
@ -105,7 +106,7 @@ public class AccessMappingTest extends TestCase {
Class<?> classUnderTest = Course2.class; Class<?> classUnderTest = Course2.class;
cfg.addAnnotatedClass( classUnderTest ); cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class ); cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() ) EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel(); .getEntityMetamodel();
PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO ); PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO );
@ -120,7 +121,7 @@ public class AccessMappingTest extends TestCase {
cfg.addAnnotatedClass( Course4.class ); cfg.addAnnotatedClass( Course4.class );
cfg.addAnnotatedClass( Student.class ); cfg.addAnnotatedClass( Student.class );
try { try {
cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); cfg.buildSessionFactory( serviceRegistry );
fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." ); fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." );
} }
catch ( MappingException e ) { catch ( MappingException e ) {
@ -133,7 +134,7 @@ public class AccessMappingTest extends TestCase {
Class<?> classUnderTest = Course3.class; Class<?> classUnderTest = Course3.class;
cfg.addAnnotatedClass( classUnderTest ); cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class ); cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() ) EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel(); .getEntityMetamodel();
PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO ); PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO );
@ -153,7 +154,7 @@ public class AccessMappingTest extends TestCase {
Class<?> classUnderTest = Course5.class; Class<?> classUnderTest = Course5.class;
cfg.addAnnotatedClass( classUnderTest ); cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class ); cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() ) EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel(); .getEntityMetamodel();
PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO ); PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO );
@ -174,7 +175,7 @@ public class AccessMappingTest extends TestCase {
cfg.addAnnotatedClass( classUnderTest ); cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Person.class ); cfg.addAnnotatedClass( Person.class );
cfg.addAnnotatedClass( Being.class ); cfg.addAnnotatedClass( Being.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() ) EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel(); .getEntityMetamodel();
PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO ); PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO );
@ -189,7 +190,7 @@ public class AccessMappingTest extends TestCase {
cfg.addAnnotatedClass( Horse.class ); cfg.addAnnotatedClass( Horse.class );
cfg.addAnnotatedClass( Animal.class ); cfg.addAnnotatedClass( Animal.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityMetamodel metaModel = factory.getEntityPersister( Animal.class.getName() ) EntityMetamodel metaModel = factory.getEntityPersister( Animal.class.getName() )
.getEntityMetamodel(); .getEntityMetamodel();
PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO ); PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO );
@ -214,6 +215,6 @@ public class AccessMappingTest extends TestCase {
AnnotationConfiguration cfg = new AnnotationConfiguration(); AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass( Course8.class ); cfg.addAnnotatedClass( Course8.class );
cfg.addAnnotatedClass( Student.class ); cfg.addAnnotatedClass( Student.class );
cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); cfg.buildSessionFactory( serviceRegistry );
} }
} }

View File

@ -24,12 +24,6 @@
*/ */
package org.hibernate.test.annotations.access.xml; package org.hibernate.test.annotations.access.xml;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.persistence.AccessType;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.hibernate.EntityMode; import org.hibernate.EntityMode;
@ -38,10 +32,17 @@ import org.hibernate.cfg.Environment;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.property.BasicPropertyAccessor; import org.hibernate.property.BasicPropertyAccessor;
import org.hibernate.property.DirectPropertyAccessor; import org.hibernate.property.DirectPropertyAccessor;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.tuple.entity.PojoEntityTuplizer; import org.hibernate.tuple.entity.PojoEntityTuplizer;
import javax.persistence.AccessType;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/** /**
* Test verifying that it is possible to configure the access type via xml configuration. * Test verifying that it is possible to configure the access type via xml configuration.
@ -50,15 +51,15 @@ import org.hibernate.tuple.entity.PojoEntityTuplizer;
*/ */
public class XmlAccessTest extends TestCase { public class XmlAccessTest extends TestCase {
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
protected void setUp() { protected void setUp() {
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
} }
protected void tearDown() { protected void tearDown() {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
@ -184,7 +185,7 @@ public class XmlAccessTest extends TestCase {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( configFile ); InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( configFile );
cfg.addInputStream( is ); cfg.addInputStream( is );
} }
return ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); return ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
} }
// uses the first getter of the tupelizer for the assertions // uses the first getter of the tupelizer for the assertions

View File

@ -1,19 +1,19 @@
//$Id$ //$Id$
package org.hibernate.test.annotations.backquotes; package org.hibernate.test.annotations.backquotes;
import java.io.PrintWriter;
import java.io.StringWriter;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.PrintWriter;
import java.io.StringWriter;
/** /**
* Testcase for ANN-718 - @JoinTable / @JoinColumn fail when using backquotes in PK field name. * Testcase for ANN-718 - @JoinTable / @JoinColumn fail when using backquotes in PK field name.
* *
@ -24,15 +24,15 @@ public class BackquoteTest extends TestCase {
private Logger log = LoggerFactory.getLogger(BackquoteTest.class); private Logger log = LoggerFactory.getLogger(BackquoteTest.class);
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
protected void setUp() { protected void setUp() {
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
} }
protected void tearDown() { protected void tearDown() {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
@ -41,7 +41,7 @@ public class BackquoteTest extends TestCase {
AnnotationConfiguration config = new AnnotationConfiguration(); AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass(Bug.class); config.addAnnotatedClass(Bug.class);
config.addAnnotatedClass(Category.class); config.addAnnotatedClass(Category.class);
config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); config.buildSessionFactory( serviceRegistry );
} }
catch( Exception e ) { catch( Exception e ) {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
@ -63,7 +63,7 @@ public class BackquoteTest extends TestCase {
AnnotationConfiguration config = new AnnotationConfiguration(); AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass(Printer.class); config.addAnnotatedClass(Printer.class);
config.addAnnotatedClass(PrinterCable.class); config.addAnnotatedClass(PrinterCable.class);
config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); config.buildSessionFactory( serviceRegistry );
fail("expected MappingException to be thrown"); fail("expected MappingException to be thrown");
} }
//we WANT MappingException to be thrown //we WANT MappingException to be thrown

View File

@ -2,10 +2,12 @@
package org.hibernate.test.annotations.duplicatedgenerator; package org.hibernate.test.annotations.duplicatedgenerator;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.hibernate.AnnotationException; import org.hibernate.AnnotationException;
import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
@ -14,22 +16,22 @@ public class DuplicateTest extends TestCase {
public void testDuplicateEntityName() throws Exception { public void testDuplicateEntityName() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration(); AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
ServiceRegistryHolder serviceRegistryHolder = null; ServiceRegistry serviceRegistry = null;
try { try {
cfg.addAnnotatedClass( Flight.class ); cfg.addAnnotatedClass( Flight.class );
cfg.addAnnotatedClass( org.hibernate.test.annotations.Flight.class ); cfg.addAnnotatedClass( org.hibernate.test.annotations.Flight.class );
cfg.addResource( "org/hibernate/test/annotations/orm.xml" ); cfg.addResource( "org/hibernate/test/annotations/orm.xml" );
cfg.addResource( "org/hibernate/test/annotations/duplicatedgenerator/orm.xml" ); cfg.addResource( "org/hibernate/test/annotations/duplicatedgenerator/orm.xml" );
serviceRegistryHolder = new ServiceRegistryHolder( cfg.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); cfg.buildSessionFactory( serviceRegistry );
fail( "Should not be able to map the same entity name twice" ); fail( "Should not be able to map the same entity name twice" );
} }
catch (AnnotationException ae) { catch (AnnotationException ae) {
//success //success
} }
finally { finally {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
} }

View File

@ -25,17 +25,18 @@
*/ */
package org.hibernate.test.annotations.fetchprofile; package org.hibernate.test.annotations.fetchprofile;
import java.io.InputStream;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.InputStream;
/** /**
* Test case for HHH-4812 * Test case for HHH-4812
@ -46,15 +47,15 @@ public class FetchProfileTest extends TestCase {
private Logger log = LoggerFactory.getLogger( FetchProfileTest.class ); private Logger log = LoggerFactory.getLogger( FetchProfileTest.class );
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
protected void setUp() { protected void setUp() {
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
} }
protected void tearDown() { protected void tearDown() {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
@ -65,7 +66,7 @@ public class FetchProfileTest extends TestCase {
config.addAnnotatedClass( SupportTickets.class ); config.addAnnotatedClass( SupportTickets.class );
config.addAnnotatedClass( Country.class ); config.addAnnotatedClass( Country.class );
SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory( SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
serviceRegistryHolder.getServiceRegistry() serviceRegistry
); );
assertTrue( assertTrue(
@ -85,7 +86,7 @@ public class FetchProfileTest extends TestCase {
config.addAnnotatedClass( Country.class ); config.addAnnotatedClass( Country.class );
try { try {
config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); config.buildSessionFactory( serviceRegistry );
fail(); fail();
} }
catch ( MappingException e ) { catch ( MappingException e ) {
@ -100,7 +101,7 @@ public class FetchProfileTest extends TestCase {
config.addAnnotatedClass( Country.class ); config.addAnnotatedClass( Country.class );
try { try {
config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); config.buildSessionFactory( serviceRegistry );
fail(); fail();
} }
catch ( MappingException e ) { catch ( MappingException e ) {
@ -115,7 +116,7 @@ public class FetchProfileTest extends TestCase {
config.addAnnotatedClass( Country.class ); config.addAnnotatedClass( Country.class );
try { try {
config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); config.buildSessionFactory( serviceRegistry );
fail(); fail();
} }
catch ( MappingException e ) { catch ( MappingException e ) {
@ -133,7 +134,7 @@ public class FetchProfileTest extends TestCase {
.getResourceAsStream( "org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml" ); .getResourceAsStream( "org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml" );
config.addInputStream( is ); config.addInputStream( is );
SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory( SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
serviceRegistryHolder.getServiceRegistry() serviceRegistry
); );
assertTrue( assertTrue(
@ -147,7 +148,7 @@ public class FetchProfileTest extends TestCase {
config.addAnnotatedClass( Order.class ); config.addAnnotatedClass( Order.class );
config.addAnnotatedClass( Country.class ); config.addAnnotatedClass( Country.class );
try { try {
config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); config.buildSessionFactory( serviceRegistry );
fail(); fail();
} }
catch ( MappingException e ) { catch ( MappingException e ) {
@ -163,7 +164,7 @@ public class FetchProfileTest extends TestCase {
config.addAnnotatedClass( Country.class ); config.addAnnotatedClass( Country.class );
config.addPackage( Customer.class.getPackage().getName() ); config.addPackage( Customer.class.getPackage().getName() );
SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory( SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
serviceRegistryHolder.getServiceRegistry() serviceRegistry
); );
assertTrue( assertTrue(

View File

@ -1,20 +1,20 @@
// $Id$ // $Id$
package org.hibernate.test.annotations.fkcircularity; package org.hibernate.test.annotations.fkcircularity;
import java.io.PrintWriter;
import java.io.StringWriter;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.dialect.HSQLDialect; import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.SQLServerDialect; import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.PrintWriter;
import java.io.StringWriter;
/** /**
* Test case for ANN-722 and ANN-730. * Test case for ANN-722 and ANN-730.
* *
@ -24,15 +24,15 @@ public class FkCircularityTest extends TestCase {
private Logger log = LoggerFactory.getLogger(FkCircularityTest.class); private Logger log = LoggerFactory.getLogger(FkCircularityTest.class);
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
protected void setUp() { protected void setUp() {
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
} }
protected void tearDown() { protected void tearDown() {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
@ -43,7 +43,7 @@ public class FkCircularityTest extends TestCase {
config.addAnnotatedClass(B.class); config.addAnnotatedClass(B.class);
config.addAnnotatedClass(C.class); config.addAnnotatedClass(C.class);
config.addAnnotatedClass(D.class); config.addAnnotatedClass(D.class);
config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); config.buildSessionFactory( serviceRegistry );
String[] schema = config String[] schema = config
.generateSchemaCreationScript(new SQLServerDialect()); .generateSchemaCreationScript(new SQLServerDialect());
for (String s : schema) { for (String s : schema) {
@ -65,7 +65,7 @@ public class FkCircularityTest extends TestCase {
config.addAnnotatedClass(ClassB.class); config.addAnnotatedClass(ClassB.class);
config.addAnnotatedClass(ClassC.class); config.addAnnotatedClass(ClassC.class);
config.addAnnotatedClass(ClassD.class); config.addAnnotatedClass(ClassD.class);
config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); config.buildSessionFactory( serviceRegistry );
String[] schema = config String[] schema = config
.generateSchemaCreationScript(new HSQLDialect()); .generateSchemaCreationScript(new HSQLDialect());
for (String s : schema) { for (String s : schema) {

View File

@ -1,10 +1,6 @@
// $Id$ // $Id$
package org.hibernate.test.annotations.namingstrategy; package org.hibernate.test.annotations.namingstrategy;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Iterator;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.AnnotationConfiguration;
@ -12,11 +8,15 @@ import org.hibernate.cfg.EJB3NamingStrategy;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.cfg.Mappings; import org.hibernate.cfg.Mappings;
import org.hibernate.mapping.Table; import org.hibernate.mapping.Table;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Iterator;
/** /**
* Test harness for ANN-716. * Test harness for ANN-716.
* *
@ -26,15 +26,15 @@ public class NamingStrategyTest extends TestCase {
private Logger log = LoggerFactory.getLogger(NamingStrategyTest.class); private Logger log = LoggerFactory.getLogger(NamingStrategyTest.class);
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
protected void setUp() { protected void setUp() {
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
} }
protected void tearDown() { protected void tearDown() {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
@ -44,7 +44,7 @@ public class NamingStrategyTest extends TestCase {
config.setNamingStrategy(new DummyNamingStrategy()); config.setNamingStrategy(new DummyNamingStrategy());
config.addAnnotatedClass(Address.class); config.addAnnotatedClass(Address.class);
config.addAnnotatedClass(Person.class); config.addAnnotatedClass(Person.class);
config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); config.buildSessionFactory( serviceRegistry );
} }
catch( Exception e ) { catch( Exception e ) {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
@ -60,7 +60,7 @@ public class NamingStrategyTest extends TestCase {
config.setNamingStrategy(EJB3NamingStrategy.INSTANCE); config.setNamingStrategy(EJB3NamingStrategy.INSTANCE);
config.addAnnotatedClass(A.class); config.addAnnotatedClass(A.class);
config.addAnnotatedClass(AddressEntry.class); config.addAnnotatedClass(AddressEntry.class);
config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); config.buildSessionFactory( serviceRegistry );
Mappings mappings = config.createMappings(); Mappings mappings = config.createMappings();
boolean foundIt = false; boolean foundIt = false;
@ -88,7 +88,7 @@ public class NamingStrategyTest extends TestCase {
AnnotationConfiguration config = new AnnotationConfiguration(); AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass(Address.class); config.addAnnotatedClass(Address.class);
config.addAnnotatedClass(Person.class); config.addAnnotatedClass(Person.class);
config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); config.buildSessionFactory( serviceRegistry );
} }
catch( Exception e ) { catch( Exception e ) {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();

View File

@ -1,11 +1,11 @@
//$Id$ //$Id$
package org.hibernate.test.annotations.onetoone; package org.hibernate.test.annotations.onetoone;
import org.hibernate.AnnotationException;
import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.SessionFactory; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.AnnotationException; import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.test.common.ServiceRegistryHolder;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
@ -16,19 +16,19 @@ public class OneToOneErrorTest extends junit.framework.TestCase {
cfg.addAnnotatedClass( Show.class ) cfg.addAnnotatedClass( Show.class )
.addAnnotatedClass( ShowDescription.class ); .addAnnotatedClass( ShowDescription.class );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
ServiceRegistryHolder serviceRegistryHolder = null; ServiceRegistry serviceRegistry = null;
try { try {
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
SessionFactory sf = cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); cfg.buildSessionFactory( serviceRegistry );
fail( "Wrong mappedBy does not fail property" ); fail( "Wrong mappedBy does not fail property" );
} }
catch (AnnotationException e) { catch (AnnotationException e) {
//success //success
} }
finally { finally {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
} }
} }

View File

@ -6,8 +6,8 @@ import junit.framework.TestCase;
import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.dialect.SQLServerDialect; import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -23,13 +23,13 @@ public class NullablePrimaryKeyTest extends TestCase {
public void testGeneratedSql() { public void testGeneratedSql() {
ServiceRegistryHolder serviceRegistryHolder = null; ServiceRegistry serviceRegistry = null;
try { try {
AnnotationConfiguration config = new AnnotationConfiguration(); AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass(Address.class); config.addAnnotatedClass(Address.class);
config.addAnnotatedClass(Person.class); config.addAnnotatedClass(Person.class);
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); config.buildSessionFactory( serviceRegistry );
String[] schema = config String[] schema = config
.generateSchemaCreationScript(new SQLServerDialect()); .generateSchemaCreationScript(new SQLServerDialect());
for (String s : schema) { for (String s : schema) {
@ -42,8 +42,8 @@ public class NullablePrimaryKeyTest extends TestCase {
fail(e.getMessage()); fail(e.getMessage());
} }
finally { finally {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
} }

View File

@ -21,17 +21,18 @@
*/ */
package org.hibernate.test.cfg; package org.hibernate.test.cfg;
import javax.persistence.Entity;
import javax.persistence.Id;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.hibernate.test.common.ServiceRegistryHolder;
import org.hibernate.testing.junit.UnitTestCase;
import org.hibernate.cfg.Configuration;
import org.hibernate.util.SerializationHelper;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.testing.junit.UnitTestCase;
import org.hibernate.util.SerializationHelper;
import javax.persistence.Entity;
import javax.persistence.Id;
/** /**
* Copied over mostly from ConfigurationPerformanceTest * Copied over mostly from ConfigurationPerformanceTest
@ -105,18 +106,18 @@ public class ConfigurationSerializationTest extends UnitTestCase {
cfg = ( Configuration ) SerializationHelper.deserialize( bytes ); cfg = ( Configuration ) SerializationHelper.deserialize( bytes );
SessionFactory factory = null; SessionFactory factory = null;
ServiceRegistryHolder serviceRegistryHolder = null; ServiceRegistry serviceRegistry = null;
try { try {
serviceRegistryHolder = new ServiceRegistryHolder( cfg.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
// try to build SF // try to build SF
factory = cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry()); factory = cfg.buildSessionFactory( serviceRegistry );
} }
finally { finally {
if ( factory != null ) { if ( factory != null ) {
factory.close(); factory.close();
} }
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
} }

View File

@ -20,12 +20,11 @@
*/ */
package org.hibernate.test.cfg.persister; package org.hibernate.test.cfg.persister;
import junit.framework.TestCase;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.testing.junit.UnitTestCase; import org.hibernate.testing.junit.UnitTestCase;
/** /**
@ -40,9 +39,9 @@ public class PersisterClassProviderTest extends UnitTestCase {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
cfg.addAnnotatedClass( Gate.class ); cfg.addAnnotatedClass( Gate.class );
ServiceRegistryHolder serviceRegistryHolder = new ServiceRegistryHolder( cfg.getProperties() ); ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
//no exception as the GoofyPersisterClassProvider is not set //no exception as the GoofyPersisterClassProvider is not set
SessionFactory sessionFactory = cfg.buildSessionFactory(serviceRegistryHolder.getServiceRegistry()); SessionFactory sessionFactory = cfg.buildSessionFactory( serviceRegistry );
sessionFactory.close(); sessionFactory.close();
@ -50,7 +49,7 @@ public class PersisterClassProviderTest extends UnitTestCase {
cfg.addAnnotatedClass( Gate.class ); cfg.addAnnotatedClass( Gate.class );
cfg.setPersisterClassProvider( new GoofyPersisterClassProvider() ); cfg.setPersisterClassProvider( new GoofyPersisterClassProvider() );
try { try {
sessionFactory = cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); sessionFactory = cfg.buildSessionFactory( serviceRegistry );
sessionFactory.close(); sessionFactory.close();
} }
catch ( MappingException e ) { catch ( MappingException e ) {
@ -66,7 +65,7 @@ public class PersisterClassProviderTest extends UnitTestCase {
cfg.addAnnotatedClass( Window.class ); cfg.addAnnotatedClass( Window.class );
cfg.setPersisterClassProvider( new GoofyPersisterClassProvider() ); cfg.setPersisterClassProvider( new GoofyPersisterClassProvider() );
try { try {
sessionFactory = cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); sessionFactory = cfg.buildSessionFactory( serviceRegistry );
sessionFactory.close(); sessionFactory.close();
} }
catch ( MappingException e ) { catch ( MappingException e ) {
@ -76,8 +75,8 @@ public class PersisterClassProviderTest extends UnitTestCase {
( (GoofyException) e.getCause() ).getValue() ); ( (GoofyException) e.getCause() ).getValue() );
} }
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
} }

View File

@ -3,24 +3,25 @@ package org.hibernate.test.instrument.cases;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public abstract class AbstractExecutable implements Executable { public abstract class AbstractExecutable implements Executable {
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
private SessionFactory factory; private SessionFactory factory;
public final void prepare() { public final void prepare() {
Configuration cfg = new Configuration().setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); Configuration cfg = new Configuration().setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
String[] resources = getResources(); String[] resources = getResources();
for ( int i = 0; i < resources.length; i++ ) { for ( String resource : resources ) {
cfg.addResource( resources[i] ); cfg.addResource( resource );
} }
serviceRegistryHolder = new ServiceRegistryHolder( cfg.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
factory = cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); factory = cfg.buildSessionFactory( serviceRegistry );
} }
public final void complete() { public final void complete() {
@ -29,9 +30,9 @@ public abstract class AbstractExecutable implements Executable {
} }
finally { finally {
factory.close(); factory.close();
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
} }

View File

@ -1,7 +1,7 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc. * distributed under license by Red Hat Inc.
@ -21,58 +21,29 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.common; package org.hibernate.testing;
import org.hibernate.cfg.Environment;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.internal.ServiceRegistryImpl;
import org.hibernate.service.spi.ServiceRegistry;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.jdbc.internal.JdbcServicesImpl;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.internal.ServiceRegistryImpl;
import org.hibernate.service.spi.ServiceRegistry;
/** /**
* @author Gail Badner * @author Steve Ebersole
*/ */
public class ServiceRegistryHolder { public class ServiceRegistryBuilder {
private final ServiceRegistryImpl serviceRegistry; public static ServiceRegistryImpl buildServiceRegistry(Map serviceRegistryConfig) {
private final Properties properties; Properties properties = new Properties();
properties.putAll( serviceRegistryConfig );
public ServiceRegistryHolder(Map props) {
properties = new Properties();
properties.putAll( props );
Environment.verifyProperties( properties ); Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties ); ConfigurationHelper.resolvePlaceHolders( properties );
serviceRegistry = new ServiceRegistryImpl( properties ); return new ServiceRegistryImpl( properties );
properties.putAll( serviceRegistry.getService( JdbcServices.class ).getDialect().getDefaultProperties() );
} }
public Properties getProperties() { public static void destroy(ServiceRegistry serviceRegistry) {
return properties; ( (ServiceRegistryImpl) serviceRegistry ).destroy();
}
public ServiceRegistry getServiceRegistry() {
return serviceRegistry;
}
public JdbcServices getJdbcServices() {
return serviceRegistry.getService( JdbcServices.class );
}
public JdbcServicesImpl getJdbcServicesImpl() {
return ( JdbcServicesImpl ) getJdbcServices();
}
public ClassLoaderService getClassLoaderService() {
return serviceRegistry.getService( ClassLoaderService.class );
}
public void destroy() {
if ( serviceRegistry != null ) {
serviceRegistry.destroy();
}
} }
} }

View File

@ -23,13 +23,6 @@
*/ */
package org.hibernate.testing.junit; package org.hibernate.testing.junit;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -39,7 +32,13 @@ import org.hibernate.cfg.Environment;
import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.service.spi.ServiceRegistry; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.testing.ServiceRegistryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
/** /**
* A basic JUnit {@link junit.framework.TestCase} subclass for * A basic JUnit {@link junit.framework.TestCase} subclass for
@ -51,7 +50,7 @@ public abstract class UnitTestCase extends junit.framework.TestCase {
private static final Logger log = LoggerFactory.getLogger( UnitTestCase.class ); private static final Logger log = LoggerFactory.getLogger( UnitTestCase.class );
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
public UnitTestCase(String string) { public UnitTestCase(String string) {
super( string ); super( string );
@ -90,17 +89,17 @@ public abstract class UnitTestCase extends junit.framework.TestCase {
@Override @Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
serviceRegistryHolder = null; serviceRegistry = null;
} }
} }
protected ServiceRegistry getServiceRegistry() { protected ServiceRegistry getServiceRegistry() {
if ( serviceRegistryHolder == null ) { if ( serviceRegistry == null ) {
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
} }
return serviceRegistryHolder.getServiceRegistry(); return serviceRegistry;
} }
protected JdbcServices getJdbcServices() { protected JdbcServices getJdbcServices() {
@ -124,9 +123,8 @@ public abstract class UnitTestCase extends junit.framework.TestCase {
// additional assertions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // additional assertions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public static void assertElementTypeAssignability(java.util.Collection collection, Class clazz) throws AssertionFailedError { public static void assertElementTypeAssignability(java.util.Collection collection, Class clazz) throws AssertionFailedError {
Iterator itr = collection.iterator(); for ( Object aCollection : collection ) {
while ( itr.hasNext() ) { assertClassAssignability( aCollection.getClass(), clazz );
assertClassAssignability( itr.next().getClass(), clazz );
} }
} }

View File

@ -23,25 +23,25 @@
*/ */
package org.hibernate.testing.junit.functional; package org.hibernate.testing.junit.functional;
import java.util.HashMap; import org.hibernate.SessionFactory;
import java.util.Iterator;
import java.sql.Blob;
import java.sql.Clob;
import java.util.Map;
import org.hibernate.dialect.Dialect;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.cfg.Mappings; import org.hibernate.cfg.Mappings;
import org.hibernate.SessionFactory; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Collection;
import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator; import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator;
import org.hibernate.service.spi.ServiceRegistry; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.testing.ServiceRegistryBuilder;
import java.sql.Blob;
import java.sql.Clob;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/** /**
* {@inheritDoc} * {@inheritDoc}
@ -55,8 +55,8 @@ public class ExecutionEnvironment {
private final ExecutionEnvironment.Settings settings; private final ExecutionEnvironment.Settings settings;
private Map conectionProviderInjectionProperties; private Map conectionProviderInjectionProperties;
private ServiceRegistryHolder serviceRegistryHolder;
private Configuration configuration; private Configuration configuration;
private ServiceRegistry serviceRegistry;
private SessionFactory sessionFactory; private SessionFactory sessionFactory;
private boolean allowRebuild; private boolean allowRebuild;
@ -81,7 +81,7 @@ public class ExecutionEnvironment {
} }
public ServiceRegistry getServiceRegistry() { public ServiceRegistry getServiceRegistry() {
return serviceRegistryHolder.getServiceRegistry(); return serviceRegistry;
} }
public SessionFactory getSessionFactory() { public SessionFactory getSessionFactory() {
@ -117,8 +117,8 @@ public class ExecutionEnvironment {
this.configuration = configuration; this.configuration = configuration;
serviceRegistryHolder = new ServiceRegistryHolder( getServiceRegistryProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( getServiceRegistryProperties() );
sessionFactory = configuration.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); sessionFactory = configuration.buildSessionFactory( serviceRegistry );
settings.afterSessionFactoryBuilt( ( SessionFactoryImplementor ) sessionFactory ); settings.afterSessionFactoryBuilt( ( SessionFactoryImplementor ) sessionFactory );
} }
@ -186,12 +186,11 @@ public class ExecutionEnvironment {
sessionFactory.close(); sessionFactory.close();
sessionFactory = null; sessionFactory = null;
} }
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
serviceRegistryHolder = null;
} }
serviceRegistryHolder = new ServiceRegistryHolder( getServiceRegistryProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( getServiceRegistryProperties() );
sessionFactory = configuration.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); sessionFactory = configuration.buildSessionFactory( serviceRegistry );
settings.afterSessionFactoryBuilt( ( SessionFactoryImplementor ) sessionFactory ); settings.afterSessionFactoryBuilt( ( SessionFactoryImplementor ) sessionFactory );
} }
@ -200,9 +199,9 @@ public class ExecutionEnvironment {
sessionFactory.close(); sessionFactory.close();
sessionFactory = null; sessionFactory = null;
} }
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
serviceRegistryHolder = null; serviceRegistry = null;
} }
configuration = null; configuration = null;
} }

View File

@ -26,16 +26,7 @@
package org.hibernate.testing.junit.functional.annotations; package org.hibernate.testing.junit.functional.annotations;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.sql.Connection;
import java.sql.SQLException;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
@ -43,7 +34,7 @@ import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.jdbc.Work; import org.hibernate.jdbc.Work;
import org.hibernate.service.spi.ServiceRegistry; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.testing.junit.DialectChecks; import org.hibernate.testing.junit.DialectChecks;
import org.hibernate.testing.junit.FailureExpected; import org.hibernate.testing.junit.FailureExpected;
import org.hibernate.testing.junit.RequiresDialect; import org.hibernate.testing.junit.RequiresDialect;
@ -52,6 +43,15 @@ import org.hibernate.testing.junit.SkipForDialect;
import org.hibernate.testing.junit.SkipLog; import org.hibernate.testing.junit.SkipLog;
import org.hibernate.tool.hbm2ddl.SchemaExport; import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.util.StringHelper; import org.hibernate.util.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.sql.Connection;
import java.sql.SQLException;
/** /**
* A base class for all tests. * A base class for all tests.
@ -65,7 +65,7 @@ public abstract class HibernateTestCase extends TestCase {
protected static Configuration cfg; protected static Configuration cfg;
private static Class<?> lastTestClass; private static Class<?> lastTestClass;
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
public HibernateTestCase() { public HibernateTestCase() {
super(); super();
@ -153,10 +153,10 @@ public abstract class HibernateTestCase extends TestCase {
} }
protected ServiceRegistry getServiceRegistry() { protected ServiceRegistry getServiceRegistry() {
if ( serviceRegistryHolder == null ) { if ( serviceRegistry == null ) {
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
} }
return serviceRegistryHolder.getServiceRegistry(); return serviceRegistry;
} }
protected JdbcServices getJdbcServices() { protected JdbcServices getJdbcServices() {
@ -282,9 +282,9 @@ public abstract class HibernateTestCase extends TestCase {
protected abstract void handleUnclosedResources(); protected abstract void handleUnclosedResources();
protected void closeResources() { protected void closeResources() {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
serviceRegistryHolder = null; serviceRegistry = null;
} }
} }

View File

@ -1,8 +1,10 @@
package org.hibernate.envers.test; package org.hibernate.envers.test;
import java.io.File; import org.testng.annotations.AfterClass;
import java.net.URISyntaxException; import org.testng.annotations.BeforeClass;
import java.net.URL; import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.Session; import org.hibernate.Session;
@ -11,12 +13,12 @@ import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.envers.AuditReader; import org.hibernate.envers.AuditReader;
import org.hibernate.envers.AuditReaderFactory; import org.hibernate.envers.AuditReaderFactory;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.testng.annotations.AfterClass; import org.hibernate.testing.ServiceRegistryBuilder;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod; import java.io.File;
import org.testng.annotations.Optional; import java.net.URISyntaxException;
import org.testng.annotations.Parameters; import java.net.URL;
/** /**
* Base class for testing envers with Session when the same session and * Base class for testing envers with Session when the same session and
@ -29,7 +31,7 @@ public abstract class AbstractOneSessionTest {
protected Configuration config; protected Configuration config;
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
private SessionFactory sessionFactory; private SessionFactory sessionFactory;
private Session session ; private Session session ;
private AuditReader auditReader; private AuditReader auditReader;
@ -48,8 +50,8 @@ public abstract class AbstractOneSessionTest {
this.initMappings(); this.initMappings();
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
sessionFactory = config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); sessionFactory = config.buildSessionFactory( serviceRegistry );
} }
protected abstract void initMappings() throws MappingException, URISyntaxException ; protected abstract void initMappings() throws MappingException, URISyntaxException ;
@ -69,9 +71,9 @@ public abstract class AbstractOneSessionTest {
sessionFactory.close(); sessionFactory.close();
} }
finally { finally {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
serviceRegistryHolder = null; serviceRegistry = null;
} }
} }
} }

View File

@ -1,8 +1,10 @@
package org.hibernate.envers.test; package org.hibernate.envers.test;
import java.io.File; import org.testng.annotations.AfterClass;
import java.net.URISyntaxException; import org.testng.annotations.BeforeClass;
import java.net.URL; import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.Session; import org.hibernate.Session;
@ -11,9 +13,12 @@ import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.envers.AuditReader; import org.hibernate.envers.AuditReader;
import org.hibernate.envers.AuditReaderFactory; import org.hibernate.envers.AuditReaderFactory;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.testng.annotations.*; import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
/** /**
* Base class for testing envers with Session. * Base class for testing envers with Session.
@ -24,7 +29,7 @@ import org.testng.annotations.*;
public abstract class AbstractSessionTest { public abstract class AbstractSessionTest {
protected Configuration config; protected Configuration config;
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
private SessionFactory sessionFactory; private SessionFactory sessionFactory;
private Session session ; private Session session ;
private AuditReader auditReader; private AuditReader auditReader;
@ -34,7 +39,7 @@ public abstract class AbstractSessionTest {
@Parameters("auditStrategy") @Parameters("auditStrategy")
public void init(@Optional String auditStrategy) throws URISyntaxException { public void init(@Optional String auditStrategy) throws URISyntaxException {
config = new Configuration(); config = new Configuration();
URL url = Thread.currentThread().getContextClassLoader().getResource(getHibernateConfigurationFileName()); URL url = Thread.currentThread().getContextClassLoader().getResource(getHibernateConfigurationFileName());
config.configure(new File(url.toURI())); config.configure(new File(url.toURI()));
if (auditStrategy != null && !"".equals(auditStrategy)) { if (auditStrategy != null && !"".equals(auditStrategy)) {
@ -43,15 +48,15 @@ public abstract class AbstractSessionTest {
this.initMappings(); this.initMappings();
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
sessionFactory = config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); sessionFactory = config.buildSessionFactory( serviceRegistry );
} }
protected abstract void initMappings() throws MappingException, URISyntaxException ; protected abstract void initMappings() throws MappingException, URISyntaxException ;
protected String getHibernateConfigurationFileName(){ protected String getHibernateConfigurationFileName(){
return "hibernate.test.session-cfg.xml"; return "hibernate.test.session-cfg.xml";
} }
private SessionFactory getSessionFactory(){ private SessionFactory getSessionFactory(){
@ -71,9 +76,9 @@ public abstract class AbstractSessionTest {
sessionFactory.close(); sessionFactory.close();
} }
finally { finally {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
serviceRegistryHolder = null; serviceRegistry = null;
} }
} }
} }

View File

@ -23,23 +23,13 @@
*/ */
package org.hibernate.test.cache.infinispan.collection; package org.hibernate.test.cache.infinispan.collection;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import junit.extensions.TestSetup; import junit.extensions.TestSetup;
import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.infinispan.transaction.tm.BatchModeTransactionManager;
import org.hibernate.cache.CacheDataDescription; import org.hibernate.cache.CacheDataDescription;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.CollectionRegion; import org.hibernate.cache.CollectionRegion;
import org.hibernate.cache.access.AccessType; import org.hibernate.cache.access.AccessType;
import org.hibernate.cache.access.CollectionRegionAccessStrategy; import org.hibernate.cache.access.CollectionRegionAccessStrategy;
@ -50,19 +40,24 @@ import org.hibernate.cache.infinispan.access.TransactionalAccessDelegate;
import org.hibernate.cache.infinispan.collection.CollectionRegionImpl; import org.hibernate.cache.infinispan.collection.CollectionRegionImpl;
import org.hibernate.cache.infinispan.impl.BaseRegion; import org.hibernate.cache.infinispan.impl.BaseRegion;
import org.hibernate.cache.infinispan.util.CacheAdapter; import org.hibernate.cache.infinispan.util.CacheAdapter;
import org.hibernate.cache.infinispan.util.CacheAdapterImpl;
import org.hibernate.cache.infinispan.util.FlagAdapter; import org.hibernate.cache.infinispan.util.FlagAdapter;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.test.cache.infinispan.AbstractNonFunctionalTestCase; import org.hibernate.test.cache.infinispan.AbstractNonFunctionalTestCase;
import org.hibernate.test.cache.infinispan.functional.cluster.DualNodeJtaTransactionManagerImpl; import org.hibernate.test.cache.infinispan.functional.cluster.DualNodeJtaTransactionManagerImpl;
import org.hibernate.test.cache.infinispan.util.CacheTestUtil; import org.hibernate.test.cache.infinispan.util.CacheTestUtil;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.util.ComparableComparator; import org.hibernate.util.ComparableComparator;
import org.infinispan.Cache;
import org.infinispan.transaction.tm.BatchModeTransactionManager;
import javax.transaction.TransactionManager; import javax.transaction.TransactionManager;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
/** /**
* Base class for tests of CollectionRegionAccessStrategy impls. * Base class for tests of CollectionRegionAccessStrategy impls.
@ -524,7 +519,7 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs
private final String configResource; private final String configResource;
private final String configName; private final String configName;
private String preferIPv4Stack; private String preferIPv4Stack;
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
public AccessStrategyTestSetup(Test test, String configName) { public AccessStrategyTestSetup(Test test, String configName) {
this(test, configName, null); this(test, configName, null);
@ -544,17 +539,17 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs
preferIPv4Stack = System.getProperty(PREFER_IPV4STACK); preferIPv4Stack = System.getProperty(PREFER_IPV4STACK);
System.setProperty(PREFER_IPV4STACK, "true"); System.setProperty(PREFER_IPV4STACK, "true");
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
localCfg = createConfiguration(configName, configResource); localCfg = createConfiguration(configName, configResource);
localRegionFactory = CacheTestUtil.startRegionFactory( localRegionFactory = CacheTestUtil.startRegionFactory(
serviceRegistryHolder.getJdbcServicesImpl(), serviceRegistry.getService( JdbcServices.class ),
localCfg localCfg
); );
remoteCfg = createConfiguration(configName, configResource); remoteCfg = createConfiguration(configName, configResource);
remoteRegionFactory = CacheTestUtil.startRegionFactory( remoteRegionFactory = CacheTestUtil.startRegionFactory(
serviceRegistryHolder.getJdbcServicesImpl(), serviceRegistry.getService( JdbcServices.class ),
remoteCfg remoteCfg
); );
} }
@ -578,8 +573,8 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs
remoteRegionFactory.stop(); remoteRegionFactory.stop();
} }
finally { finally {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
} }

View File

@ -23,13 +23,11 @@
*/ */
package org.hibernate.test.cache.infinispan.entity; package org.hibernate.test.cache.infinispan.entity;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import junit.extensions.TestSetup; import junit.extensions.TestSetup;
import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.infinispan.transaction.tm.BatchModeTransactionManager;
import org.hibernate.cache.CacheDataDescription; import org.hibernate.cache.CacheDataDescription;
import org.hibernate.cache.EntityRegion; import org.hibernate.cache.EntityRegion;
@ -42,11 +40,15 @@ import org.hibernate.cache.infinispan.util.CacheAdapter;
import org.hibernate.cache.infinispan.util.FlagAdapter; import org.hibernate.cache.infinispan.util.FlagAdapter;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.test.cache.infinispan.AbstractNonFunctionalTestCase; import org.hibernate.test.cache.infinispan.AbstractNonFunctionalTestCase;
import org.hibernate.test.cache.infinispan.util.CacheTestUtil; import org.hibernate.test.cache.infinispan.util.CacheTestUtil;
import org.hibernate.test.common.ServiceRegistryHolder; import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.util.ComparableComparator; import org.hibernate.util.ComparableComparator;
import org.infinispan.transaction.tm.BatchModeTransactionManager;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/** /**
* Base class for tests of EntityRegionAccessStrategy impls. * Base class for tests of EntityRegionAccessStrategy impls.
@ -639,7 +641,7 @@ public abstract class AbstractEntityRegionAccessStrategyTestCase extends Abstrac
private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack"; private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack";
private final String configName; private final String configName;
private String preferIPv4Stack; private String preferIPv4Stack;
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
public AccessStrategyTestSetup(Test test, String configName) { public AccessStrategyTestSetup(Test test, String configName) {
super(test); super(test);
@ -661,17 +663,17 @@ public abstract class AbstractEntityRegionAccessStrategyTestCase extends Abstrac
preferIPv4Stack = System.getProperty(PREFER_IPV4STACK); preferIPv4Stack = System.getProperty(PREFER_IPV4STACK);
System.setProperty(PREFER_IPV4STACK, "true"); System.setProperty(PREFER_IPV4STACK, "true");
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
localCfg = createConfiguration(configName); localCfg = createConfiguration(configName);
localRegionFactory = CacheTestUtil.startRegionFactory( localRegionFactory = CacheTestUtil.startRegionFactory(
serviceRegistryHolder.getJdbcServicesImpl(), serviceRegistry.getService( JdbcServices.class ),
localCfg localCfg
); );
remoteCfg = createConfiguration(configName); remoteCfg = createConfiguration(configName);
remoteRegionFactory = CacheTestUtil.startRegionFactory( remoteRegionFactory = CacheTestUtil.startRegionFactory(
serviceRegistryHolder.getJdbcServicesImpl(), serviceRegistry.getService( JdbcServices.class ),
remoteCfg remoteCfg
); );
} }
@ -688,8 +690,8 @@ public abstract class AbstractEntityRegionAccessStrategyTestCase extends Abstrac
remoteRegionFactory.stop(); remoteRegionFactory.stop();
} }
finally { finally {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
} }

View File

@ -25,16 +25,6 @@ package org.hibernate.test.cache.infinispan.tm;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.enhydra.jdbc.standard.StandardXADataSource; import org.enhydra.jdbc.standard.StandardXADataSource;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.stat.Statistics;
import org.hibernate.test.cache.infinispan.functional.Item;
import org.hibernate.test.common.ServiceRegistryHolder;
import org.infinispan.transaction.lookup.JBossStandaloneJTAManagerLookup; import org.infinispan.transaction.lookup.JBossStandaloneJTAManagerLookup;
import org.infinispan.util.logging.Log; import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory; import org.infinispan.util.logging.LogFactory;
@ -43,6 +33,17 @@ import org.jnp.interfaces.NamingContext;
import org.jnp.server.Main; import org.jnp.server.Main;
import org.jnp.server.NamingServer; import org.jnp.server.NamingServer;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.stat.Statistics;
import org.hibernate.test.cache.infinispan.functional.Item;
import org.hibernate.testing.ServiceRegistryBuilder;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.naming.Name; import javax.naming.Name;
@ -72,12 +73,12 @@ public class JBossStandaloneJtaExampleTest extends TestCase {
private static final JBossStandaloneJTAManagerLookup lookup = new JBossStandaloneJTAManagerLookup(); private static final JBossStandaloneJTAManagerLookup lookup = new JBossStandaloneJTAManagerLookup();
Context ctx; Context ctx;
Main jndiServer; Main jndiServer;
private ServiceRegistryHolder serviceRegistryHolder; private ServiceRegistry serviceRegistry;
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
jndiServer = startJndiServer(); jndiServer = startJndiServer();
ctx = createJndiContext(); ctx = createJndiContext();
bindTransactionManager(); bindTransactionManager();
@ -93,8 +94,8 @@ public class JBossStandaloneJtaExampleTest extends TestCase {
jndiServer.stop(); jndiServer.stop();
} }
finally { finally {
if ( serviceRegistryHolder != null ) { if ( serviceRegistry != null ) {
serviceRegistryHolder.destroy(); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
} }
@ -301,6 +302,6 @@ public class JBossStandaloneJtaExampleTest extends TestCase {
Collection coll = (Collection) iter.next(); Collection coll = (Collection) iter.next();
cfg.setCollectionCacheConcurrencyStrategy(coll.getRole(), "transactional"); cfg.setCollectionCacheConcurrencyStrategy(coll.getRole(), "transactional");
} }
return cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); return cfg.buildSessionFactory( serviceRegistry );
} }
} }