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;
import java.util.Properties;
import java.sql.Connection;
import junit.framework.TestSuite;
import junit.framework.TestCase;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.hibernate.HibernateException;
import org.hibernate.dialect.HSQLDialect;
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.cfg.Environment;
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.Oracle9iDialect;
import org.hibernate.dialect.Oracle10gDialect;
import org.hibernate.dialect.TestingDialects;
import org.hibernate.dialect.Mocks;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.dialect.SybaseASE15Dialect;
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.DialectResolverSet;
import org.hibernate.service.jdbc.dialect.internal.StandardDialectResolver;
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
@ -61,19 +63,19 @@ import org.hibernate.test.common.ServiceRegistryHolder;
* @author Steve Ebersole
*/
public class DialectFactoryTest extends TestCase {
private ServiceRegistryHolder serviceRegistryHolder;
private ServiceRegistry serviceRegistry;
public DialectFactoryTest(String name) {
super( name );
}
protected void setUp() {
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() );
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
}
protected void tearDown() {
if ( serviceRegistryHolder != null ) {
serviceRegistryHolder.destroy();
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
}
@ -124,7 +126,7 @@ public class DialectFactoryTest extends TestCase {
private DialectFactoryImpl getDialectFactoryImpl(DialectResolver dialectResolver) {
DialectFactoryImpl dialectFactoryImpl = new DialectFactoryImpl();
dialectFactoryImpl.setClassLoaderService( serviceRegistryHolder.getClassLoaderService() );
dialectFactoryImpl.setClassLoaderService( serviceRegistry.getService( ClassLoaderService.class ) );
dialectFactoryImpl.setDialectResolver( dialectResolver );
return dialectFactoryImpl;
}

View File

@ -44,7 +44,8 @@ import org.hibernate.impl.SessionImpl;
import org.hibernate.jdbc.Work;
import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject;
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
@ -57,7 +58,7 @@ public class SequenceHiLoGeneratorNoIncrementTest extends TestCase {
private static final String TEST_SEQUENCE = "test_sequence";
private Configuration cfg;
ServiceRegistryHolder serviceRegistryHolder;
private ServiceRegistry serviceRegistry;
private SessionFactoryImplementor sessionFactory;
private SequenceHiLoGenerator generator;
@ -97,8 +98,8 @@ public class SequenceHiLoGeneratorNoIncrementTest extends TestCase {
)
);
serviceRegistryHolder = new ServiceRegistryHolder( cfg.getProperties() );
sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
}
@Override
@ -106,8 +107,8 @@ public class SequenceHiLoGeneratorNoIncrementTest extends TestCase {
if ( sessionFactory != null ) {
sessionFactory.close();
}
if ( serviceRegistryHolder != null ) {
serviceRegistryHolder.destroy();
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
super.tearDown();
}

View File

@ -23,12 +23,6 @@
*/
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 org.hibernate.Hibernate;
@ -44,7 +38,14 @@ import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.impl.SessionImpl;
import org.hibernate.jdbc.Work;
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
@ -57,7 +58,7 @@ public class SequenceHiLoGeneratorTest extends TestCase {
private static final String TEST_SEQUENCE = "test_sequence";
private Configuration cfg;
private ServiceRegistryHolder serviceRegistryHolder;
private ServiceRegistry serviceRegistry;
private SessionFactoryImplementor sessionFactory;
private SequenceHiLoGenerator generator;
@ -96,10 +97,8 @@ public class SequenceHiLoGeneratorTest extends TestCase {
generator.sqlDropStrings( dialect )[0]
)
);
serviceRegistryHolder = new ServiceRegistryHolder( cfg.getProperties() );
sessionFactory =
(SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
}
@Override
@ -107,8 +106,8 @@ public class SequenceHiLoGeneratorTest extends TestCase {
if ( sessionFactory != null ) {
sessionFactory.close();
}
if ( serviceRegistryHolder != null ) {
serviceRegistryHolder.destroy();
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
super.tearDown();
}

View File

@ -23,12 +23,6 @@
*/
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 org.hibernate.Hibernate;
@ -44,7 +38,14 @@ import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.impl.SessionImpl;
import org.hibernate.jdbc.Work;
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
@ -58,7 +59,7 @@ public class TableHiLoGeneratorTest extends TestCase {
private static final String GEN_COLUMN = TableHiLoGenerator.DEFAULT_COLUMN_NAME;
private Configuration cfg;
private ServiceRegistryHolder serviceRegistryHolder;
private ServiceRegistry serviceRegistry;
private SessionFactoryImplementor sessionFactory;
private TableHiLoGenerator generator;
@ -106,9 +107,8 @@ public class TableHiLoGeneratorTest extends TestCase {
)
);
serviceRegistryHolder = new ServiceRegistryHolder( cfg.getProperties() );
sessionFactory =
(SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
}
@Override
@ -116,8 +116,8 @@ public class TableHiLoGeneratorTest extends TestCase {
if ( sessionFactory != null ) {
sessionFactory.close();
}
if ( serviceRegistryHolder != null ) {
serviceRegistryHolder.destroy();
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
super.tearDown();

View File

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

View File

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

View File

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

View File

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

View File

@ -24,8 +24,6 @@
*/
package org.hibernate.test.annotations;
import java.io.InputStream;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.Session;
@ -33,9 +31,10 @@ import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.test.common.ServiceRegistryHolder;
import org.hibernate.testing.junit.functional.annotations.HibernateTestCase;
import java.io.InputStream;
/**
* 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.property.BasicPropertyAccessor;
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.PojoEntityTuplizer;
@ -45,15 +46,15 @@ import org.hibernate.tuple.entity.PojoEntityTuplizer;
*/
public class AccessMappingTest extends TestCase {
private ServiceRegistryHolder serviceRegistryHolder;
private ServiceRegistry serviceRegistry;
protected void setUp() {
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() );
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
}
protected void tearDown() {
if ( serviceRegistryHolder != null ) {
serviceRegistryHolder.destroy();
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
}
@ -62,7 +63,7 @@ public class AccessMappingTest extends TestCase {
cfg.addAnnotatedClass( Course1.class );
cfg.addAnnotatedClass( Student.class );
try {
cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
cfg.buildSessionFactory( serviceRegistry );
fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." );
}
catch ( MappingException e ) {
@ -75,7 +76,7 @@ public class AccessMappingTest extends TestCase {
Class<?> classUnderTest = Course6.class;
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel();
PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO );
@ -90,7 +91,7 @@ public class AccessMappingTest extends TestCase {
Class<?> classUnderTest = Course7.class;
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel();
PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO );
@ -105,7 +106,7 @@ public class AccessMappingTest extends TestCase {
Class<?> classUnderTest = Course2.class;
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel();
PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO );
@ -120,7 +121,7 @@ public class AccessMappingTest extends TestCase {
cfg.addAnnotatedClass( Course4.class );
cfg.addAnnotatedClass( Student.class );
try {
cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
cfg.buildSessionFactory( serviceRegistry );
fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." );
}
catch ( MappingException e ) {
@ -133,7 +134,7 @@ public class AccessMappingTest extends TestCase {
Class<?> classUnderTest = Course3.class;
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel();
PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO );
@ -153,7 +154,7 @@ public class AccessMappingTest extends TestCase {
Class<?> classUnderTest = Course5.class;
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Student.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel();
PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO );
@ -174,7 +175,7 @@ public class AccessMappingTest extends TestCase {
cfg.addAnnotatedClass( classUnderTest );
cfg.addAnnotatedClass( Person.class );
cfg.addAnnotatedClass( Being.class );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
SessionFactoryImplementor factory = ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
EntityMetamodel metaModel = factory.getEntityPersister( classUnderTest.getName() )
.getEntityMetamodel();
PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO );
@ -189,7 +190,7 @@ public class AccessMappingTest extends TestCase {
cfg.addAnnotatedClass( Horse.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() )
.getEntityMetamodel();
PojoEntityTuplizer tuplizer = ( PojoEntityTuplizer ) metaModel.getTuplizer( EntityMode.POJO );
@ -214,6 +215,6 @@ public class AccessMappingTest extends TestCase {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass( Course8.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;
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 org.hibernate.EntityMode;
@ -38,10 +32,17 @@ import org.hibernate.cfg.Environment;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.property.BasicPropertyAccessor;
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.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.
@ -50,15 +51,15 @@ import org.hibernate.tuple.entity.PojoEntityTuplizer;
*/
public class XmlAccessTest extends TestCase {
private ServiceRegistryHolder serviceRegistryHolder;
private ServiceRegistry serviceRegistry;
protected void setUp() {
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() );
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
}
protected void tearDown() {
if ( serviceRegistryHolder != null ) {
serviceRegistryHolder.destroy();
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
}
@ -184,7 +185,7 @@ public class XmlAccessTest extends TestCase {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( configFile );
cfg.addInputStream( is );
}
return ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
return ( SessionFactoryImplementor ) cfg.buildSessionFactory( serviceRegistry );
}
// uses the first getter of the tupelizer for the assertions

View File

@ -1,19 +1,19 @@
//$Id$
package org.hibernate.test.annotations.backquotes;
import java.io.PrintWriter;
import java.io.StringWriter;
import junit.framework.TestCase;
import org.hibernate.MappingException;
import org.hibernate.cfg.AnnotationConfiguration;
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.LoggerFactory;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* 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 ServiceRegistryHolder serviceRegistryHolder;
private ServiceRegistry serviceRegistry;
protected void setUp() {
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() );
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
}
protected void tearDown() {
if ( serviceRegistryHolder != null ) {
serviceRegistryHolder.destroy();
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
}
@ -41,7 +41,7 @@ public class BackquoteTest extends TestCase {
AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass(Bug.class);
config.addAnnotatedClass(Category.class);
config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
config.buildSessionFactory( serviceRegistry );
}
catch( Exception e ) {
StringWriter writer = new StringWriter();
@ -63,7 +63,7 @@ public class BackquoteTest extends TestCase {
AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass(Printer.class);
config.addAnnotatedClass(PrinterCable.class);
config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
config.buildSessionFactory( serviceRegistry );
fail("expected MappingException to be thrown");
}
//we WANT MappingException to be thrown

View File

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

View File

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

View File

@ -1,20 +1,20 @@
// $Id$
package org.hibernate.test.annotations.fkcircularity;
import java.io.PrintWriter;
import java.io.StringWriter;
import junit.framework.TestCase;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.HSQLDialect;
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.LoggerFactory;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* 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 ServiceRegistryHolder serviceRegistryHolder;
private ServiceRegistry serviceRegistry;
protected void setUp() {
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() );
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
}
protected void tearDown() {
if ( serviceRegistryHolder != null ) {
serviceRegistryHolder.destroy();
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
}
@ -43,7 +43,7 @@ public class FkCircularityTest extends TestCase {
config.addAnnotatedClass(B.class);
config.addAnnotatedClass(C.class);
config.addAnnotatedClass(D.class);
config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
config.buildSessionFactory( serviceRegistry );
String[] schema = config
.generateSchemaCreationScript(new SQLServerDialect());
for (String s : schema) {
@ -65,7 +65,7 @@ public class FkCircularityTest extends TestCase {
config.addAnnotatedClass(ClassB.class);
config.addAnnotatedClass(ClassC.class);
config.addAnnotatedClass(ClassD.class);
config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
config.buildSessionFactory( serviceRegistry );
String[] schema = config
.generateSchemaCreationScript(new HSQLDialect());
for (String s : schema) {

View File

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

View File

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

View File

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

View File

@ -21,17 +21,18 @@
*/
package org.hibernate.test.cfg;
import javax.persistence.Entity;
import javax.persistence.Id;
import junit.framework.Test;
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.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
@ -105,18 +106,18 @@ public class ConfigurationSerializationTest extends UnitTestCase {
cfg = ( Configuration ) SerializationHelper.deserialize( bytes );
SessionFactory factory = null;
ServiceRegistryHolder serviceRegistryHolder = null;
ServiceRegistry serviceRegistry = null;
try {
serviceRegistryHolder = new ServiceRegistryHolder( cfg.getProperties() );
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
// try to build SF
factory = cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry());
factory = cfg.buildSessionFactory( serviceRegistry );
}
finally {
if ( factory != null ) {
factory.close();
}
if ( serviceRegistryHolder != null ) {
serviceRegistryHolder.destroy();
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
}
}

View File

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

View File

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

View File

@ -1,7 +1,7 @@
/*
* 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
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,58 +21,29 @@
* 51 Franklin Street, Fifth Floor
* 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.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 {
private final ServiceRegistryImpl serviceRegistry;
private final Properties properties;
public ServiceRegistryHolder(Map props) {
properties = new Properties();
properties.putAll( props );
public class ServiceRegistryBuilder {
public static ServiceRegistryImpl buildServiceRegistry(Map serviceRegistryConfig) {
Properties properties = new Properties();
properties.putAll( serviceRegistryConfig );
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
serviceRegistry = new ServiceRegistryImpl( properties );
properties.putAll( serviceRegistry.getService( JdbcServices.class ).getDialect().getDefaultProperties() );
return new ServiceRegistryImpl( properties );
}
public Properties getProperties() {
return properties;
}
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();
}
public static void destroy(ServiceRegistry serviceRegistry) {
( (ServiceRegistryImpl) serviceRegistry ).destroy();
}
}

View File

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

View File

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

View File

@ -26,16 +26,7 @@
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
@ -43,7 +34,7 @@ import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.jdbc.Work;
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.FailureExpected;
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.tool.hbm2ddl.SchemaExport;
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.
@ -65,7 +65,7 @@ public abstract class HibernateTestCase extends TestCase {
protected static Configuration cfg;
private static Class<?> lastTestClass;
private ServiceRegistryHolder serviceRegistryHolder;
private ServiceRegistry serviceRegistry;
public HibernateTestCase() {
super();
@ -153,10 +153,10 @@ public abstract class HibernateTestCase extends TestCase {
}
protected ServiceRegistry getServiceRegistry() {
if ( serviceRegistryHolder == null ) {
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() );
if ( serviceRegistry == null ) {
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
}
return serviceRegistryHolder.getServiceRegistry();
return serviceRegistry;
}
protected JdbcServices getJdbcServices() {
@ -282,9 +282,9 @@ public abstract class HibernateTestCase extends TestCase {
protected abstract void handleUnclosedResources();
protected void closeResources() {
if ( serviceRegistryHolder != null ) {
serviceRegistryHolder.destroy();
serviceRegistryHolder = null;
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
serviceRegistry = null;
}
}

View File

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

View File

@ -1,8 +1,10 @@
package org.hibernate.envers.test;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.hibernate.MappingException;
import org.hibernate.Session;
@ -11,9 +13,12 @@ import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.envers.AuditReader;
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.
@ -24,7 +29,7 @@ import org.testng.annotations.*;
public abstract class AbstractSessionTest {
protected Configuration config;
private ServiceRegistryHolder serviceRegistryHolder;
private ServiceRegistry serviceRegistry;
private SessionFactory sessionFactory;
private Session session ;
private AuditReader auditReader;
@ -43,8 +48,8 @@ public abstract class AbstractSessionTest {
this.initMappings();
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() );
sessionFactory = config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
sessionFactory = config.buildSessionFactory( serviceRegistry );
}
protected abstract void initMappings() throws MappingException, URISyntaxException ;
@ -71,9 +76,9 @@ public abstract class AbstractSessionTest {
sessionFactory.close();
}
finally {
if ( serviceRegistryHolder != null ) {
serviceRegistryHolder.destroy();
serviceRegistryHolder = null;
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
serviceRegistry = null;
}
}
}

View File

@ -23,23 +23,13 @@
*/
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.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.infinispan.transaction.tm.BatchModeTransactionManager;
import org.hibernate.cache.CacheDataDescription;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.CollectionRegion;
import org.hibernate.cache.access.AccessType;
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.impl.BaseRegion;
import org.hibernate.cache.infinispan.util.CacheAdapter;
import org.hibernate.cache.infinispan.util.CacheAdapterImpl;
import org.hibernate.cache.infinispan.util.FlagAdapter;
import org.hibernate.cfg.Configuration;
import org.hibernate.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.functional.cluster.DualNodeJtaTransactionManagerImpl;
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.infinispan.Cache;
import org.infinispan.transaction.tm.BatchModeTransactionManager;
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.
@ -524,7 +519,7 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs
private final String configResource;
private final String configName;
private String preferIPv4Stack;
private ServiceRegistryHolder serviceRegistryHolder;
private ServiceRegistry serviceRegistry;
public AccessStrategyTestSetup(Test test, String configName) {
this(test, configName, null);
@ -544,17 +539,17 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs
preferIPv4Stack = System.getProperty(PREFER_IPV4STACK);
System.setProperty(PREFER_IPV4STACK, "true");
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() );
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
localCfg = createConfiguration(configName, configResource);
localRegionFactory = CacheTestUtil.startRegionFactory(
serviceRegistryHolder.getJdbcServicesImpl(),
serviceRegistry.getService( JdbcServices.class ),
localCfg
);
remoteCfg = createConfiguration(configName, configResource);
remoteRegionFactory = CacheTestUtil.startRegionFactory(
serviceRegistryHolder.getJdbcServicesImpl(),
serviceRegistry.getService( JdbcServices.class ),
remoteCfg
);
}
@ -578,8 +573,8 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs
remoteRegionFactory.stop();
}
finally {
if ( serviceRegistryHolder != null ) {
serviceRegistryHolder.destroy();
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
}
}

View File

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

View File

@ -25,16 +25,6 @@ package org.hibernate.test.cache.infinispan.tm;
import junit.framework.TestCase;
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.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
@ -43,6 +33,17 @@ import org.jnp.interfaces.NamingContext;
import org.jnp.server.Main;
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.InitialContext;
import javax.naming.Name;
@ -72,12 +73,12 @@ public class JBossStandaloneJtaExampleTest extends TestCase {
private static final JBossStandaloneJTAManagerLookup lookup = new JBossStandaloneJTAManagerLookup();
Context ctx;
Main jndiServer;
private ServiceRegistryHolder serviceRegistryHolder;
private ServiceRegistry serviceRegistry;
@Override
protected void setUp() throws Exception {
super.setUp();
serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() );
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
jndiServer = startJndiServer();
ctx = createJndiContext();
bindTransactionManager();
@ -93,8 +94,8 @@ public class JBossStandaloneJtaExampleTest extends TestCase {
jndiServer.stop();
}
finally {
if ( serviceRegistryHolder != null ) {
serviceRegistryHolder.destroy();
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
}
}
@ -301,6 +302,6 @@ public class JBossStandaloneJtaExampleTest extends TestCase {
Collection coll = (Collection) iter.next();
cfg.setCollectionCacheConcurrencyStrategy(coll.getRole(), "transactional");
}
return cfg.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() );
return cfg.buildSessionFactory( serviceRegistry );
}
}