HHH-7919 : Miscellaneous bugfixes
This commit is contained in:
parent
9583f24448
commit
a8e2296406
|
@ -43,6 +43,7 @@ import org.hibernate.sql.ordering.antlr.ColumnMapper;
|
|||
import org.hibernate.sql.ordering.antlr.ColumnReference;
|
||||
import org.hibernate.sql.ordering.antlr.SqlValueReference;
|
||||
import org.hibernate.testing.ServiceRegistryBuilder;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
|
@ -51,7 +52,7 @@ import static org.junit.Assert.assertEquals;
|
|||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class TemplateTest extends BaseUnitTestCase {
|
||||
public class TemplateTest extends BaseCoreFunctionalTestCase {
|
||||
private static final PropertyMapping PROPERTY_MAPPING = new PropertyMapping() {
|
||||
public String[] toColumns(String propertyName) throws QueryException, UnsupportedOperationException {
|
||||
if ( "sql".equals( propertyName ) ) {
|
||||
|
@ -107,29 +108,29 @@ public class TemplateTest extends BaseUnitTestCase {
|
|||
|
||||
private static final SQLFunctionRegistry FUNCTION_REGISTRY = new SQLFunctionRegistry( DIALECT, Collections.EMPTY_MAP );
|
||||
|
||||
private static SessionFactoryImplementor SESSION_FACTORY = null; // Required for ORDER BY rendering.
|
||||
|
||||
@BeforeClass
|
||||
public static void buildSessionFactory() {
|
||||
Configuration cfg = new Configuration();
|
||||
cfg.setProperty( AvailableSettings.DIALECT, DIALECT.getClass().getName() );
|
||||
ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
|
||||
if ( isMetadataUsed ) {
|
||||
SESSION_FACTORY = (SessionFactoryImplementor) new MetadataSources( serviceRegistry ).buildMetadata()
|
||||
.buildSessionFactory();
|
||||
}
|
||||
else {
|
||||
SESSION_FACTORY = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void closeSessionFactory() {
|
||||
if ( SESSION_FACTORY != null ) {
|
||||
SESSION_FACTORY.close();
|
||||
SESSION_FACTORY = null;
|
||||
}
|
||||
}
|
||||
// private static SessionFactoryImplementor SESSION_FACTORY = null; // Required for ORDER BY rendering.
|
||||
//
|
||||
// @BeforeClass
|
||||
// public static void buildSessionFactory() {
|
||||
// Configuration cfg = new Configuration();
|
||||
// cfg.setProperty( AvailableSettings.DIALECT, DIALECT.getClass().getName() );
|
||||
// ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
|
||||
// if ( isMetadataUsed() ) {
|
||||
// SESSION_FACTORY = (SessionFactoryImplementor) new MetadataSources( serviceRegistry ).buildMetadata()
|
||||
// .buildSessionFactory();
|
||||
// }
|
||||
// else {
|
||||
// SESSION_FACTORY = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @AfterClass
|
||||
// public static void closeSessionFactory() {
|
||||
// if ( SESSION_FACTORY != null ) {
|
||||
// SESSION_FACTORY.close();
|
||||
// SESSION_FACTORY = null;
|
||||
// }
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testSqlExtractFunction() {
|
||||
|
@ -275,6 +276,6 @@ public class TemplateTest extends BaseUnitTestCase {
|
|||
}
|
||||
|
||||
public String doStandardRendering(String fragment) {
|
||||
return Template.renderOrderByStringTemplate( fragment, MAPPER, SESSION_FACTORY, DIALECT, FUNCTION_REGISTRY );
|
||||
return Template.renderOrderByStringTemplate( fragment, MAPPER, sessionFactory(), DIALECT, FUNCTION_REGISTRY );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ public class EntityTest extends BaseCoreFunctionalTestCase {
|
|||
@Test
|
||||
public void testLoad() throws Exception {
|
||||
//put an object in DB
|
||||
if ( isMetadataUsed ) {
|
||||
if ( isMetadataUsed() ) {
|
||||
assertEquals( "Flight", getEntityBinding( Flight.class ).getPrimaryTableName() );
|
||||
}
|
||||
|
||||
|
@ -313,7 +313,7 @@ public class EntityTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testEntityName() throws Exception {
|
||||
if ( isMetadataUsed ) {
|
||||
if ( isMetadataUsed() ) {
|
||||
assertEquals( "Corporation", getEntityBinding( Company.class ).getPrimaryTableName() );
|
||||
}
|
||||
Session s = openSession();
|
||||
|
|
|
@ -23,20 +23,17 @@
|
|||
*/
|
||||
package org.hibernate.test.annotations.access.jpa;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.AnnotationConfiguration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.property.BasicPropertyAccessor;
|
||||
import org.hibernate.property.DirectPropertyAccessor;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.testing.ServiceRegistryBuilder;
|
||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestMethod;
|
||||
import org.hibernate.tuple.entity.EntityTuplizer;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -49,64 +46,36 @@ import static org.junit.Assert.fail;
|
|||
* @author Hardy Ferentschik
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation" })
|
||||
public class AccessMappingTest {
|
||||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if ( serviceRegistry != null ) {
|
||||
ServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
}
|
||||
}
|
||||
public class AccessMappingTest extends BaseCoreFunctionalTestMethod{
|
||||
|
||||
@Test
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public void testInconsistentAnnotationPlacement() throws Exception {
|
||||
AnnotationConfiguration cfg = new AnnotationConfiguration();
|
||||
cfg.addAnnotatedClass( Course1.class );
|
||||
cfg.addAnnotatedClass( Student.class );
|
||||
SessionFactory sf = null;
|
||||
try {
|
||||
sf= cfg.buildSessionFactory( serviceRegistry );
|
||||
getSF( Course1.class, Student.class );
|
||||
fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." );
|
||||
}
|
||||
catch ( MappingException e ) {
|
||||
// success
|
||||
} finally {
|
||||
if(sf!=null){
|
||||
sf.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldAnnotationPlacement() throws Exception {
|
||||
AnnotationConfiguration cfg = new AnnotationConfiguration();
|
||||
Class<?> classUnderTest = Course6.class;
|
||||
cfg.addAnnotatedClass( classUnderTest );
|
||||
cfg.addAnnotatedClass( Student.class );
|
||||
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
|
||||
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
|
||||
SessionFactoryImplementor factory =getSF( Course6.class, Student.class );
|
||||
EntityTuplizer tuplizer = factory.getEntityPersister( Course6.class.getName() )
|
||||
.getEntityMetamodel()
|
||||
.getTuplizer();
|
||||
assertTrue(
|
||||
"Field access should be used.",
|
||||
tuplizer.getIdentifierGetter() instanceof DirectPropertyAccessor.DirectGetter
|
||||
);
|
||||
factory.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyAnnotationPlacement() throws Exception {
|
||||
AnnotationConfiguration cfg = new AnnotationConfiguration();
|
||||
Class<?> classUnderTest = Course7.class;
|
||||
cfg.addAnnotatedClass( classUnderTest );
|
||||
cfg.addAnnotatedClass( Student.class );
|
||||
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
|
||||
SessionFactoryImplementor factory = getSF( classUnderTest, Student.class );
|
||||
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
|
||||
.getEntityMetamodel()
|
||||
.getTuplizer();
|
||||
|
@ -114,16 +83,12 @@ public class AccessMappingTest {
|
|||
"Property access should be used.",
|
||||
tuplizer.getIdentifierGetter() instanceof BasicPropertyAccessor.BasicGetter
|
||||
);
|
||||
factory.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicitPropertyAccessAnnotationsOnProperty() throws Exception {
|
||||
AnnotationConfiguration cfg = new AnnotationConfiguration();
|
||||
Class<?> classUnderTest = Course2.class;
|
||||
cfg.addAnnotatedClass( classUnderTest );
|
||||
cfg.addAnnotatedClass( Student.class );
|
||||
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
|
||||
SessionFactoryImplementor factory = getSF( classUnderTest, Student.class );
|
||||
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
|
||||
.getEntityMetamodel()
|
||||
.getTuplizer();
|
||||
|
@ -131,35 +96,24 @@ public class AccessMappingTest {
|
|||
"Property access should be used.",
|
||||
tuplizer.getIdentifierGetter() instanceof BasicPropertyAccessor.BasicGetter
|
||||
);
|
||||
factory.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public void testExplicitPropertyAccessAnnotationsOnField() throws Exception {
|
||||
AnnotationConfiguration cfg = new AnnotationConfiguration();
|
||||
cfg.addAnnotatedClass( Course4.class );
|
||||
cfg.addAnnotatedClass( Student.class );
|
||||
SessionFactory sf= null;
|
||||
try {
|
||||
sf = cfg.buildSessionFactory( serviceRegistry );
|
||||
getSF( Course4.class, Student.class );
|
||||
fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." );
|
||||
}
|
||||
catch ( MappingException e ) {
|
||||
// success
|
||||
} finally {
|
||||
if(sf!=null){
|
||||
sf.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicitPropertyAccessAnnotationsWithHibernateStyleOverride() throws Exception {
|
||||
AnnotationConfiguration cfg = new AnnotationConfiguration();
|
||||
Class<?> classUnderTest = Course3.class;
|
||||
cfg.addAnnotatedClass( classUnderTest );
|
||||
cfg.addAnnotatedClass( Student.class );
|
||||
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
|
||||
SessionFactoryImplementor factory = getSF( classUnderTest, Student.class );
|
||||
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
|
||||
.getEntityMetamodel()
|
||||
.getTuplizer();
|
||||
|
@ -169,19 +123,15 @@ public class AccessMappingTest {
|
|||
);
|
||||
|
||||
assertTrue(
|
||||
"Property access should be used.",
|
||||
tuplizer.getGetter( 0 ) instanceof BasicPropertyAccessor.BasicGetter
|
||||
"Property access should be used.", tuplizer.getGetter( 0 ) instanceof BasicPropertyAccessor.BasicGetter
|
||||
);
|
||||
factory.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public void testExplicitPropertyAccessAnnotationsWithJpaStyleOverride() throws Exception {
|
||||
AnnotationConfiguration cfg = new AnnotationConfiguration();
|
||||
Class<?> classUnderTest = Course5.class;
|
||||
cfg.addAnnotatedClass( classUnderTest );
|
||||
cfg.addAnnotatedClass( Student.class );
|
||||
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
|
||||
SessionFactoryImplementor factory = getSF( classUnderTest, Student.class );
|
||||
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
|
||||
.getEntityMetamodel()
|
||||
.getTuplizer();
|
||||
|
@ -191,20 +141,14 @@ public class AccessMappingTest {
|
|||
);
|
||||
|
||||
assertTrue(
|
||||
"Property access should be used.",
|
||||
tuplizer.getGetter( 0 ) instanceof BasicPropertyAccessor.BasicGetter
|
||||
"Property access should be used.", tuplizer.getGetter( 0 ) instanceof BasicPropertyAccessor.BasicGetter
|
||||
);
|
||||
factory.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultFieldAccessIsInherited() throws Exception {
|
||||
AnnotationConfiguration cfg = new AnnotationConfiguration();
|
||||
Class<?> classUnderTest = User.class;
|
||||
cfg.addAnnotatedClass( classUnderTest );
|
||||
cfg.addAnnotatedClass( Person.class );
|
||||
cfg.addAnnotatedClass( Being.class );
|
||||
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
|
||||
Class classUnderTest = User.class;
|
||||
SessionFactoryImplementor factory =getSF( classUnderTest, Person.class, Being.class );
|
||||
EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() )
|
||||
.getEntityMetamodel()
|
||||
.getTuplizer();
|
||||
|
@ -212,16 +156,13 @@ public class AccessMappingTest {
|
|||
"Field access should be used since the default access mode gets inherited",
|
||||
tuplizer.getIdentifierGetter() instanceof DirectPropertyAccessor.DirectGetter
|
||||
);
|
||||
factory.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public void testDefaultPropertyAccessIsInherited() throws Exception {
|
||||
AnnotationConfiguration cfg = new AnnotationConfiguration();
|
||||
cfg.addAnnotatedClass( Horse.class );
|
||||
cfg.addAnnotatedClass( Animal.class );
|
||||
SessionFactoryImplementor factory = getSF( Horse.class, Animal.class );
|
||||
|
||||
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
|
||||
EntityTuplizer tuplizer = factory.getEntityPersister( Animal.class.getName() )
|
||||
.getEntityMetamodel()
|
||||
.getTuplizer();
|
||||
|
@ -237,15 +178,17 @@ public class AccessMappingTest {
|
|||
"Field access should be used since the default access mode gets inherited",
|
||||
tuplizer.getGetter( 0 ) instanceof DirectPropertyAccessor.DirectGetter
|
||||
);
|
||||
factory.close();
|
||||
}
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-5004")
|
||||
@Test
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public void testAccessOnClassAndId() throws Exception {
|
||||
AnnotationConfiguration cfg = new AnnotationConfiguration();
|
||||
cfg.addAnnotatedClass( Course8.class );
|
||||
cfg.addAnnotatedClass( Student.class );
|
||||
cfg.buildSessionFactory( serviceRegistry ).close();
|
||||
getSF( Course8.class, Student.class );
|
||||
}
|
||||
|
||||
private SessionFactoryImplementor getSF(Class ... classes){
|
||||
getTestConfiguration().getAnnotatedClasses().addAll( Arrays.asList( classes ) );
|
||||
return getSessionFactoryHelper().getSessionFactory();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,6 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
|
@ -81,9 +79,8 @@ public class ArrayTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testNoIndexAnnotationFailure() {
|
||||
Properties properties = constructProperties();
|
||||
BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry();
|
||||
StandardServiceRegistry serviceRegistry = buildServiceRegistry( bootRegistry, properties );
|
||||
BootstrapServiceRegistry bootRegistry = getTestServiceRegistryHelper().buildBootstrapServiceRegistry();
|
||||
StandardServiceRegistry serviceRegistry = getTestServiceRegistryHelper().getServiceRegistry();
|
||||
MetadataSources sources = new MetadataSources( bootRegistry );
|
||||
sources.addAnnotatedClass( NoIndexArrayEntity.class );
|
||||
MetadataBuilder metadataBuilder = sources.getMetadataBuilder(serviceRegistry);
|
||||
|
|
|
@ -70,7 +70,7 @@ public class BeanValidationDisabledTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.setProperty( "javax.persistence.validation.mode", "none" );
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ public class BeanValidationGroupsTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.setProperty(
|
||||
"javax.persistence.validation.group.pre-persist",
|
||||
|
|
|
@ -73,7 +73,7 @@ public class BeanValidationProvidedFactoryTest extends BaseCoreFunctionalTestCas
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
final MessageInterpolator messageInterpolator = new MessageInterpolator() {
|
||||
|
||||
|
|
|
@ -99,13 +99,13 @@ public class DDLWithoutCallbackTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.setProperty( "javax.persistence.validation.mode", "ddl" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
public void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( "javax.persistence.validation.mode", "ddl" );
|
||||
}
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ public class HibernateTraversableResolverTest extends BaseCoreFunctionalTestCase
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.setProperty( "hibernate.validator.autoregister_listeners", "false" );
|
||||
}
|
||||
|
|
|
@ -4,18 +4,18 @@ package org.hibernate.test.annotations.configuration;
|
|||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.cfg.AnnotationConfiguration;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestMethod;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class ConfigurationTest {
|
||||
public class ConfigurationTest extends BaseCoreFunctionalTestMethod{
|
||||
@Test
|
||||
public void testMixPackageAndResourceOrdering() throws Exception {
|
||||
try {
|
||||
AnnotationConfiguration config = new AnnotationConfiguration();
|
||||
config.addResource( "org/hibernate/test/annotations/configuration/orm.xml" );
|
||||
config.addPackage( "org.hibernate.test.annotations.configuration" );
|
||||
getTestConfiguration().getOrmXmlFiles().add( "org/hibernate/test/annotations/configuration/orm.xml" );
|
||||
getTestConfiguration().getAnnotatedPackages().add( "org.hibernate.test.annotations.configuration" );
|
||||
getSessionFactoryHelper().getSessionFactory();
|
||||
}
|
||||
catch( Exception e ) {
|
||||
Assert.fail( "Processing package first when ORM.xml is used should not fail" );
|
||||
|
|
|
@ -1,44 +1,35 @@
|
|||
//$Id$
|
||||
package org.hibernate.test.annotations.duplicatedgenerator;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.AnnotationException;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.AnnotationConfiguration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.testing.ServiceRegistryBuilder;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestMethod;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class DuplicateTest {
|
||||
public class DuplicateTest extends BaseCoreFunctionalTestMethod {
|
||||
@Test
|
||||
public void testDuplicateEntityName() throws Exception {
|
||||
AnnotationConfiguration cfg = new AnnotationConfiguration();
|
||||
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
ServiceRegistry serviceRegistry = null;
|
||||
SessionFactory sf = 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" );
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
|
||||
sf = cfg.buildSessionFactory( serviceRegistry );
|
||||
|
||||
getTestConfiguration().addAnnotatedClass( Flight.class )
|
||||
.addAnnotatedClass( org.hibernate.test.annotations.Flight.class )
|
||||
.addOrmXmlFile( "org/hibernate/test/annotations/orm.xml" )
|
||||
.addOrmXmlFile( "org/hibernate/test/annotations/duplicatedgenerator/orm.xml" );
|
||||
getSessionFactoryHelper().getSessionFactory();
|
||||
Assert.fail( "Should not be able to map the same entity name twice" );
|
||||
}
|
||||
catch (AnnotationException ae) {
|
||||
catch ( AnnotationException ae ) {
|
||||
//success
|
||||
//todo we have mismatch behavior here, the old metamodel thorws this exception, but the new metamodel throws MappingException.
|
||||
}
|
||||
catch ( MappingException me ) {
|
||||
//success
|
||||
}
|
||||
finally {
|
||||
if (sf != null){
|
||||
sf.close();
|
||||
}
|
||||
if ( serviceRegistry != null ) {
|
||||
ServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -660,7 +660,7 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
|||
try {
|
||||
Configuration config = new Configuration();
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() );
|
||||
if ( isMetadataUsed ) {
|
||||
if ( isMetadataUsed() ) {
|
||||
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
|
||||
metadataSources.addAnnotatedClass( LocalContactDetails.class ).buildMetadata();
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public class HibernateAnnotationMappingTest extends BaseUnitTestCase {
|
|||
ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( configuration.getProperties() );
|
||||
SessionFactory sf = null;
|
||||
try {
|
||||
if ( isMetadataUsed ) {
|
||||
if ( isMetadataUsed() ) {
|
||||
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
|
||||
sf = metadataSources.addAnnotatedClass( Month.class ).buildMetadata().buildSessionFactory();
|
||||
|
||||
|
|
|
@ -68,13 +68,13 @@ public class GenericsTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
cfg.setProperty( Environment.AUTO_CLOSE_SESSION, "true" );
|
||||
super.configure( cfg );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
public void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( Environment.AUTO_CLOSE_SESSION, "true" );
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ public class NewGeneratorMappingsTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.setProperty( Environment.HBM2DDL_AUTO, "" );
|
||||
}
|
||||
|
|
|
@ -33,17 +33,9 @@ public class HibernateSequenceTest extends BaseCoreFunctionalTestCase {
|
|||
HibernateSequenceEntity.class
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.addResource( "org/hibernate/test/annotations/id/sequences/orm.xml" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addMappings(MetadataSources sources) {
|
||||
super.addMappings( sources );
|
||||
sources.addResource( "org/hibernate/test/annotations/id/sequences/orm.xml" );
|
||||
protected String[] getXmlFiles() {
|
||||
return new String[]{"org/hibernate/test/annotations/id/sequences/orm.xml"};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,7 +18,7 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|||
@RequiresDialect( Oracle8iDialect.class )
|
||||
public class LobWithSequenceIdentityGeneratorTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
public void configure(Configuration configuration) {
|
||||
configuration.setProperty( Environment.DIALECT, OracleSeqIdGenDialect.class.getName() );
|
||||
configuration.setProperty( Environment.USE_NEW_ID_GENERATOR_MAPPINGS, "false" );
|
||||
configuration.setProperty( Environment.USE_GET_GENERATED_KEYS, "true" );
|
||||
|
|
|
@ -36,7 +36,7 @@ import org.hibernate.cfg.Environment;
|
|||
@SuppressWarnings("unchecked")
|
||||
public class ManyToManyMaxFetchDepth0Test extends ManyToManyComplexTest {
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
cfg.setProperty( Environment.MAX_FETCH_DEPTH, "0" );
|
||||
super.configure( cfg );
|
||||
}
|
||||
|
|
|
@ -6,18 +6,20 @@ import java.io.StringWriter;
|
|||
import java.util.Iterator;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.AnnotationConfiguration;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.EJB3NamingStrategy;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.cfg.Mappings;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.testing.ServiceRegistryBuilder;
|
||||
import org.hibernate.metamodel.MetadataBuilder;
|
||||
import org.hibernate.metamodel.spi.MetadataImplementor;
|
||||
import org.hibernate.metamodel.spi.relational.Database;
|
||||
import org.hibernate.metamodel.spi.relational.Schema;
|
||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestMethod;
|
||||
import org.hibernate.testing.junit4.TestSessionFactoryHelper;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -28,83 +30,123 @@ import static org.junit.Assert.fail;
|
|||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class NamingStrategyTest {
|
||||
public class NamingStrategyTest extends BaseCoreFunctionalTestMethod {
|
||||
private static final Logger log = Logger.getLogger( NamingStrategyTest.class );
|
||||
|
||||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (serviceRegistry != null) ServiceRegistryBuilder.destroy(serviceRegistry);
|
||||
}
|
||||
@Test
|
||||
public void testWithCustomNamingStrategy() throws Exception {
|
||||
try {
|
||||
AnnotationConfiguration config = new AnnotationConfiguration();
|
||||
config.setNamingStrategy(new DummyNamingStrategy());
|
||||
config.addAnnotatedClass(Address.class);
|
||||
config.addAnnotatedClass(Person.class);
|
||||
config.buildMappings();
|
||||
getTestConfiguration().addAnnotatedClass( Address.class ).addAnnotatedClass( Person.class );
|
||||
getSessionFactoryHelper().setCallback(
|
||||
new TestSessionFactoryHelper.CallbackImpl() {
|
||||
@Override
|
||||
public void configure(final Configuration configuration) {
|
||||
configuration.setNamingStrategy( new DummyNamingStrategy() );
|
||||
}
|
||||
catch( Exception e ) {
|
||||
|
||||
@Override
|
||||
public void configure(final MetadataBuilder metadataBuilder) {
|
||||
metadataBuilder.with( new DummyNamingStrategy() );
|
||||
}
|
||||
}
|
||||
).getSessionFactory();
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
StringWriter writer = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(writer));
|
||||
log.debug(writer.toString());
|
||||
fail(e.getMessage());
|
||||
e.printStackTrace( new PrintWriter( writer ) );
|
||||
log.debug( writer.toString() );
|
||||
fail( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public void testWithEJB3NamingStrategy() throws Exception {
|
||||
SessionFactory sf = null;
|
||||
try {
|
||||
AnnotationConfiguration config = new AnnotationConfiguration();
|
||||
config.setNamingStrategy(EJB3NamingStrategy.INSTANCE);
|
||||
config.addAnnotatedClass(A.class);
|
||||
config.addAnnotatedClass(AddressEntry.class);
|
||||
sf = config.buildSessionFactory( serviceRegistry );
|
||||
Mappings mappings = config.createMappings();
|
||||
|
||||
getTestConfiguration().addAnnotatedClass( A.class ).addAnnotatedClass( AddressEntry.class );
|
||||
getSessionFactoryHelper().setCallback(
|
||||
new TestSessionFactoryHelper.CallbackImpl() {
|
||||
@Override
|
||||
public void configure(final Configuration configuration) {
|
||||
configuration.setNamingStrategy( EJB3NamingStrategy.INSTANCE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(final MetadataBuilder metadataBuilder) {
|
||||
metadataBuilder.with( EJB3NamingStrategy.INSTANCE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterConfigurationBuilt(
|
||||
final Mappings mappings, final Dialect dialect) {
|
||||
boolean foundIt = false;
|
||||
|
||||
for ( Iterator iter = mappings.iterateTables(); iter.hasNext(); ) {
|
||||
Table table = (Table) iter.next();
|
||||
log.info("testWithEJB3NamingStrategy table = " + table.getName());
|
||||
if ( table.getName().equalsIgnoreCase("A_ADDRESS")) {
|
||||
log.info( "testWithEJB3NamingStrategy table = " + table.getName() );
|
||||
if ( table.getName().equalsIgnoreCase( "A_ADDRESS" ) ) {
|
||||
foundIt = true;
|
||||
}
|
||||
// make sure we use A_ADDRESS instead of AEC_address
|
||||
assertFalse("got table name mapped to: AEC_address (should be A_ADDRESS) which violates JPA-2 spec section 11.1.8 ([OWNING_ENTITY_NAME]_[COLLECTION_ATTRIBUTE_NAME])",table.getName().equalsIgnoreCase("AEC_address"));
|
||||
assertFalse(
|
||||
"got table name mapped to: AEC_address (should be A_ADDRESS) which violates JPA-2 spec section 11.1.8 ([OWNING_ENTITY_NAME]_[COLLECTION_ATTRIBUTE_NAME])",
|
||||
table.getName().equalsIgnoreCase( "AEC_address" )
|
||||
);
|
||||
}
|
||||
assertTrue("table not mapped to A_ADDRESS which violates JPA-2 spec section 11.1.8",foundIt);
|
||||
assertTrue(
|
||||
"table not mapped to A_ADDRESS which violates JPA-2 spec section 11.1.8", foundIt
|
||||
);
|
||||
}
|
||||
catch( Exception e ) {
|
||||
|
||||
@Override
|
||||
public void afterMetadataBuilt(final MetadataImplementor metadataImplementor) {
|
||||
Database database = metadataImplementor.getDatabase();
|
||||
Schema schema = database.getDefaultSchema();
|
||||
boolean foundIt = false;
|
||||
for ( org.hibernate.metamodel.spi.relational.Table table : schema.getTables() ) {
|
||||
String name = table.getTableName().getName().getText();
|
||||
log.info( "testWithEJB3NamingStrategy table = " + name );
|
||||
if ( name.equalsIgnoreCase( "A_ADDRESS" ) ) {
|
||||
foundIt = true;
|
||||
}
|
||||
// make sure we use A_ADDRESS instead of AEC_address
|
||||
assertFalse(
|
||||
"got table name mapped to: AEC_address (should be A_ADDRESS) which violates JPA-2 spec section 11.1.8 ([OWNING_ENTITY_NAME]_[COLLECTION_ATTRIBUTE_NAME])",
|
||||
name.equalsIgnoreCase( "AEC_address" )
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
assertTrue(
|
||||
"table not mapped to A_ADDRESS which violates JPA-2 spec section 11.1.8", foundIt
|
||||
);
|
||||
}
|
||||
}
|
||||
).getSessionFactory();
|
||||
|
||||
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
StringWriter writer = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(writer));
|
||||
log.debug(writer.toString());
|
||||
fail(e.getMessage());
|
||||
} finally {
|
||||
if( sf != null ){
|
||||
sf.close();
|
||||
}
|
||||
e.printStackTrace( new PrintWriter( writer ) );
|
||||
log.debug( writer.toString() );
|
||||
fail( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithoutCustomNamingStrategy() throws Exception {
|
||||
try {
|
||||
AnnotationConfiguration config = new AnnotationConfiguration();
|
||||
config.addAnnotatedClass(Address.class);
|
||||
config.addAnnotatedClass(Person.class);
|
||||
config.buildMappings();
|
||||
getTestConfiguration().addAnnotatedClass( Address.class ).addAnnotatedClass( Person.class );
|
||||
getSessionFactoryHelper().getSessionFactory();
|
||||
|
||||
}
|
||||
catch( Exception e ) {
|
||||
catch ( Exception e ) {
|
||||
StringWriter writer = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(writer));
|
||||
log.debug(writer.toString());
|
||||
fail(e.getMessage());
|
||||
e.printStackTrace( new PrintWriter( writer ) );
|
||||
log.debug( writer.toString() );
|
||||
fail( e.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -327,13 +327,13 @@ public class ImmutableNaturalKeyLookupTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
|
||||
cfg.setProperty( Environment.USE_QUERY_CACHE, "true" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
public void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( Environment.GENERATE_STATISTICS, "true" );
|
||||
serviceRegistryBuilder.applySetting( Environment.USE_QUERY_CACHE, "true" );
|
||||
}
|
||||
|
|
|
@ -146,12 +146,12 @@ public class NaturalIdOnSingleManyToOneTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
cfg.setProperty( "hibernate.cache.use_query_cache", "true" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
public void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( "hibernate.cache.use_query_cache", "true" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -340,7 +340,7 @@ public class NaturalIdTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
cfg.setProperty( "hibernate.cache.use_query_cache", "true" );
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.junit.Test;
|
|||
comment = "By default H2 places NULL values first, so testing 'NULLS LAST' expression.")
|
||||
public class DefaultNullOrderingTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
public void configure(Configuration configuration) {
|
||||
configuration.setProperty( AvailableSettings.DEFAULT_NULL_ORDERING, "last" );
|
||||
}
|
||||
|
||||
|
|
|
@ -5,40 +5,23 @@ import org.junit.Assert;
|
|||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.AnnotationException;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.AnnotationConfiguration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.testing.ServiceRegistryBuilder;
|
||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestMethod;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class OneToOneErrorTest {
|
||||
public class OneToOneErrorTest extends BaseCoreFunctionalTestMethod {
|
||||
@Test
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public void testWrongOneToOne() throws Exception {
|
||||
AnnotationConfiguration cfg = new AnnotationConfiguration();
|
||||
cfg.addAnnotatedClass( Show.class )
|
||||
.addAnnotatedClass( ShowDescription.class );
|
||||
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
ServiceRegistry serviceRegistry = null;
|
||||
SessionFactory sessionFactory = null;
|
||||
getTestConfiguration().addAnnotatedClass( Show.class ).addAnnotatedClass( ShowDescription.class );
|
||||
try {
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
|
||||
sessionFactory = cfg.buildSessionFactory( serviceRegistry );
|
||||
getSessionFactoryHelper().getSessionFactory();
|
||||
Assert.fail( "Wrong mappedBy does not fail property" );
|
||||
}
|
||||
catch (AnnotationException e) {
|
||||
//success
|
||||
}
|
||||
finally {
|
||||
if(sessionFactory!=null){
|
||||
sessionFactory.close();
|
||||
}
|
||||
if ( serviceRegistry != null ) {
|
||||
ServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ public class HHH4851Test extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.setProperty( Environment.CHECK_NULLABILITY, "true" );
|
||||
}
|
||||
|
|
|
@ -496,12 +496,12 @@ public class QueryAndSQLTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
cfg.setProperty( "hibernate.cache.use_query_cache", "true" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
public void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( "hibernate.cache.use_query_cache", "true" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public class QuoteGlobalTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.setProperty( Environment.GLOBALLY_QUOTED_IDENTIFIERS, "true" );
|
||||
}
|
||||
|
|
|
@ -42,12 +42,12 @@ public class ExplicitSqlResultSetMappingTest extends BaseCoreFunctionalTestCase
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
cfg.setProperty( Environment.GLOBALLY_QUOTED_IDENTIFIERS, "true" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
public void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( Environment.GLOBALLY_QUOTED_IDENTIFIERS, "true" );
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public class StrategyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
cfg.setNamingStrategy( DefaultComponentSafeNamingStrategy.INSTANCE );
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ public class UniqueConstraintValidationTest extends BaseUnitTestCase {
|
|||
}
|
||||
|
||||
private void buildSessionFactory(Class<?> entity) {
|
||||
if ( isMetadataUsed ) {
|
||||
if ( isMetadataUsed() ) {
|
||||
StandardServiceRegistry registry = new StandardServiceRegistryBuilder().build();
|
||||
MetadataSources metadataSources = new MetadataSources( registry );
|
||||
metadataSources.addAnnotatedClass( entity );
|
||||
|
|
|
@ -40,7 +40,7 @@ public class NonExistentOrmVersionTest extends BaseCoreFunctionalTestCase {
|
|||
@Test
|
||||
public void testNonExistentOrmVersion() {
|
||||
try {
|
||||
MetadataSources sources = new MetadataSources( buildBootstrapServiceRegistry() );
|
||||
MetadataSources sources = new MetadataSources( getTestServiceRegistryHelper().buildBootstrapServiceRegistry() );
|
||||
String xmlFileName = "org/hibernate/test/annotations/xml/ejb3/orm5.xml";
|
||||
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFileName );
|
||||
sources.addInputStream( is );
|
||||
|
|
|
@ -56,14 +56,14 @@ public class BatchFetchTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
public void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
configuration.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
|
||||
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
public void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( AvailableSettings.GENERATE_STATISTICS, "true" );
|
||||
serviceRegistryBuilder.applySetting( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" );
|
||||
}
|
||||
|
|
|
@ -23,8 +23,6 @@
|
|||
*/
|
||||
package org.hibernate.test.bidir.onetomany.nonindexed;
|
||||
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -33,15 +31,10 @@ import org.junit.Test;
|
|||
*/
|
||||
public class AbstractBidirectionalOneToManyTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.setProperty( USE_NEW_METADATA_MAPPINGS, "true");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( USE_NEW_METADATA_MAPPINGS, "true" );
|
||||
public boolean isMetadataUsed() {
|
||||
return true; //TODO why force to use new metamodel?
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -52,7 +52,7 @@ public class InsertedDataTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.setProperty( Environment.CACHE_REGION_PREFIX, "" );
|
||||
cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
|
||||
|
|
|
@ -48,7 +48,7 @@ import static org.junit.Assert.assertTrue;
|
|||
*/
|
||||
public class ReferenceCacheTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
public void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
configuration.setProperty( AvailableSettings.USE_DIRECT_REFERENCE_CACHE_ENTRIES, "true" );
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public class CustomDirtinessStrategyTest extends BaseCoreFunctionalTestCase {
|
|||
private static final String SUBSEQUENT_NAME = "thing 2";
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
public void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
configuration.getProperties().put( AvailableSettings.CUSTOM_ENTITY_DIRTINESS_STRATEGY, Strategy.INSTANCE );
|
||||
}
|
||||
|
|
|
@ -50,16 +50,10 @@ import static org.junit.Assert.assertTrue;
|
|||
* @author Gavin King
|
||||
*/
|
||||
public class SimpleInheritanceTest extends BaseCoreFunctionalTestCase {
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.setProperty( USE_NEW_METADATA_MAPPINGS, "true");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( USE_NEW_METADATA_MAPPINGS, "true" );
|
||||
public boolean isMetadataUsed() {
|
||||
return true; //TODO why force to use new metamodel?
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "discriminator/SimpleInheritance.hbm.xml" };
|
||||
|
|
|
@ -66,7 +66,7 @@ public class InterceptorDynamicEntityTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder) {
|
||||
public void configSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder) {
|
||||
sessionFactoryBuilder.with( new ProxyInterceptor() );
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ public class TuplizerDynamicEntityTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder) {
|
||||
public void configSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder) {
|
||||
sessionFactoryBuilder.with( new EntityNameInterceptor() );
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ public class ImprovedTuplizerDynamicEntityTest extends BaseCoreFunctionalTestCas
|
|||
cfg.getEntityTuplizerFactory().registerDefaultTuplizerClass( EntityMode.POJO, MyEntityTuplizer.class );
|
||||
}
|
||||
@Override
|
||||
protected void configSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder) {
|
||||
public void configSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder) {
|
||||
sessionFactoryBuilder.with( EntityMode.POJO, MyEntityTuplizer.class );
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ public class UnspecifiedEnumTypeTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
public void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
configuration.setProperty( Environment.HBM2DDL_AUTO, "" );
|
||||
}
|
||||
|
|
|
@ -60,12 +60,12 @@ public class CallbackTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder) {
|
||||
public void configSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder) {
|
||||
sessionFactoryBuilder.add( observer );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareBootstrapServiceRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
|
||||
public void prepareBootstrapServiceRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
|
||||
super.prepareBootstrapServiceRegistryBuilder( builder );
|
||||
builder.with(
|
||||
new Integrator() {
|
||||
|
|
|
@ -73,13 +73,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
public void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( Environment.GENERATE_STATISTICS, "true" );
|
||||
serviceRegistryBuilder.applySetting( Environment.STATEMENT_BATCH_SIZE, "0" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configMetadataBuilder(MetadataBuilder metadataBuilder) {
|
||||
public void configure(MetadataBuilder metadataBuilder) {
|
||||
metadataBuilder.with( TextAsMaterializedClobType.INSTANCE );
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.hibernate.cfg.Environment;
|
|||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.testing.ServiceRegistryBuilder;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.testing.junit4.TestConfigurationHelper;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -37,7 +37,7 @@ public abstract class AbstractExecutable implements Executable {
|
|||
serviceRegistry = standardServiceRegistryBuilder.applySettings( cfg.getProperties() ).build();
|
||||
|
||||
String[] resources = getResources();
|
||||
if( BaseUnitTestCase.isMetadataUsed()){
|
||||
if( TestConfigurationHelper.DEFAULT_USE_NEW_METAMODEL ){
|
||||
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
|
||||
for(String resource : resources){
|
||||
metadataSources.addResource( resource );
|
||||
|
|
|
@ -153,7 +153,7 @@ public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends
|
|||
throw new HibernateException( "could not load executable", t );
|
||||
}
|
||||
try {
|
||||
if ( BaseUnitTestCase.isMetadataUsed() ) {
|
||||
if ( isMetadataUsed() ) {
|
||||
execClass.getMethod( PREPARE, SIG_METAMODEL )
|
||||
.invoke( executable, new ClassLoader[] { Thread.currentThread().getContextClassLoader() } );
|
||||
}
|
||||
|
|
|
@ -72,18 +72,18 @@ public abstract class AbstractJPATest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
public void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( Environment.JPAQL_STRICT_COMPLIANCE, "true" );
|
||||
serviceRegistryBuilder.applySetting( Environment.USE_SECOND_LEVEL_CACHE, "false" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder) {
|
||||
public void configSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder) {
|
||||
sessionFactoryBuilder.with( new JPAEntityNotFoundDelegate() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareBootstrapServiceRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
|
||||
public void prepareBootstrapServiceRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
|
||||
builder.with(
|
||||
new Integrator() {
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ public class ImmutableNaturalIdTest extends AbstractJPATest {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
public void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( Environment.USE_SECOND_LEVEL_CACHE, "true" );
|
||||
serviceRegistryBuilder.applySetting( Environment.USE_QUERY_CACHE, "true" );
|
||||
serviceRegistryBuilder.applySetting( Environment.GENERATE_STATISTICS, "true" );
|
||||
|
|
|
@ -51,7 +51,7 @@ public class TransactionJoiningTest extends AbstractJPATest {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
public void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
TestingJtaBootstrap.prepare( serviceRegistryBuilder.getSettings() );
|
||||
serviceRegistryBuilder.applySetting( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ public class CustomSQLTest extends LegacyTestCase {
|
|||
public static class NonIdentityGeneratorChecker implements DialectCheck {
|
||||
@Override
|
||||
public boolean isMatch(Dialect dialect) {
|
||||
return !PostInsertIdentifierGenerator.class.isAssignableFrom( getDialect().getNativeIdentifierGeneratorClass() );
|
||||
return !PostInsertIdentifierGenerator.class.isAssignableFrom( dialect.getNativeIdentifierGeneratorClass() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4527,7 +4527,7 @@ public class FooBarTest extends LegacyTestCase {
|
|||
err=true;
|
||||
}
|
||||
assertTrue(err);
|
||||
id = FumTest.fumKey( "abc" ); //yuck!!
|
||||
id = new FumTest().fumKey( "abc" ); //yuck!!
|
||||
Fo fo = Fo.newFo( (FumCompositeID) id );
|
||||
s.save(fo);
|
||||
s.flush();
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.hibernate.Session;
|
|||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.MatchMode;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.HSQLDialect;
|
||||
import org.hibernate.dialect.MckoiDialect;
|
||||
import org.hibernate.dialect.MySQLDialect;
|
||||
|
@ -306,11 +307,11 @@ public class FumTest extends LegacyTestCase {
|
|||
}
|
||||
|
||||
|
||||
public static FumCompositeID fumKey(String str) {
|
||||
public FumCompositeID fumKey(String str) {
|
||||
return fumKey(str,false);
|
||||
}
|
||||
|
||||
private static FumCompositeID fumKey(String str, boolean aCompositeQueryTest) {
|
||||
private FumCompositeID fumKey(String str, boolean aCompositeQueryTest) {
|
||||
FumCompositeID id = new FumCompositeID();
|
||||
if ( getDialect() instanceof MckoiDialect ) {
|
||||
GregorianCalendar now = new GregorianCalendar();
|
||||
|
|
|
@ -54,13 +54,13 @@ public class JpaLargeBlobTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
public void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
configuration.setProperty(Environment.USE_STREAMS_FOR_BINARY, "true");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
public void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( Environment.USE_STREAMS_FOR_BINARY, "true" );
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ import org.hibernate.testing.junit4.BaseUnitTestCase;
|
|||
public class ValueVisitorTest extends BaseUnitTestCase {
|
||||
@Test
|
||||
public void testProperCallbacks() {
|
||||
if ( isMetadataUsed ) {
|
||||
if ( isMetadataUsed() ) {
|
||||
//doesn't mean anything for new metamodel
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public class UserTypeMappingTest extends BaseUnitTestCase {
|
|||
ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
|
||||
SessionFactory sessions = null;
|
||||
try {
|
||||
if ( isMetadataUsed ) {
|
||||
if ( isMetadataUsed() ) {
|
||||
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
|
||||
for ( String mapping : mappings ) {
|
||||
metadataSources.addResource( mapping );
|
||||
|
|
|
@ -54,12 +54,12 @@ public class NamingStrategyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configMetadataBuilder(MetadataBuilder metadataBuilder) {
|
||||
public void configure(MetadataBuilder metadataBuilder) {
|
||||
metadataBuilder.with( new TestNamingStrategy() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Item.class
|
||||
};
|
||||
|
|
|
@ -212,12 +212,12 @@ public class ImmutableEntityNaturalIdTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
cfg.setProperty( "hibernate.cache.use_query_cache", "true" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
public void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( Environment.USE_QUERY_CACHE, "true" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -171,14 +171,14 @@ public class LazyLoadingTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration cfg) {
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.setProperty( Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true" );
|
||||
cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
public void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( Environment.GENERATE_STATISTICS, "true" );
|
||||
serviceRegistryBuilder.applySetting( Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true" );
|
||||
}
|
||||
|
|
|
@ -44,14 +44,14 @@ public class DoesNotWorkTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
public void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" );
|
||||
configuration.setProperty( AvailableSettings.HBM2DDL_IMPORT_FILES, "/org/hibernate/test/propertyref/import.sql" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
public void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" );
|
||||
serviceRegistryBuilder.applySetting( AvailableSettings.HBM2DDL_IMPORT_FILES, "/org/hibernate/test/propertyref/import.sql" );
|
||||
}
|
||||
|
|
|
@ -53,14 +53,14 @@ public class DoesNotWorkWithHbmTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
public void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" );
|
||||
configuration.setProperty( AvailableSettings.HBM2DDL_IMPORT_FILES, "/org/hibernate/test/propertyref/import.sql" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
public void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" );
|
||||
serviceRegistryBuilder.applySetting( AvailableSettings.HBM2DDL_IMPORT_FILES, "/org/hibernate/test/propertyref/import.sql" );
|
||||
}
|
||||
|
|
|
@ -282,7 +282,7 @@ public class PropertyRefTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testForeignKeyCreation() {
|
||||
if ( !isMetadataUsed ) {
|
||||
if ( !isMetadataUsed() ) {
|
||||
return;
|
||||
}
|
||||
TableSpecification table = SchemaUtil.getTable( Account.class, metadata() );
|
||||
|
|
|
@ -43,18 +43,20 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|||
*/
|
||||
@RequiresDialect( value = Oracle9iDialect.class )
|
||||
public class RowIdTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "rowid/Point.hbm.xml" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCacheConcurrencyStrategy() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createSchema() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterSessionFactoryBuilt() {
|
||||
super.afterSessionFactoryBuilt();
|
||||
final Session session = sessionFactory().openSession();
|
||||
|
|
|
@ -57,7 +57,7 @@ import static org.junit.Assert.fail;
|
|||
public class StoredProcedureTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected void afterConstructAndConfigureMetadata(MetadataImplementor metadataImplementor) {
|
||||
public void afterMetadataBuilt(MetadataImplementor metadataImplementor) {
|
||||
Database database = metadataImplementor.getDatabase();
|
||||
database.addAuxiliaryDatabaseObject( new org.hibernate.metamodel.spi.relational.AuxiliaryDatabaseObject() {
|
||||
@Override
|
||||
|
|
|
@ -39,21 +39,13 @@ public class HibernateCacheTest extends BaseCoreFunctionalTestCase {
|
|||
private static final String REGION_PREFIX = "hibernate.test.";
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration config) {
|
||||
config.setProperty( AvailableSettings.USE_QUERY_CACHE, "true");
|
||||
config.setProperty( AvailableSettings.USE_STRUCTURED_CACHE, "true" );
|
||||
config.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
|
||||
config.setProperty( AvailableSettings.CACHE_REGION_FACTORY, EhCacheRegionFactory.class.getName());
|
||||
config.setProperty( "net.sf.ehcache.configurationResourceName", "/hibernate-config/ehcache.xml" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
serviceRegistryBuilder.applySetting( AvailableSettings.USE_QUERY_CACHE, "true");
|
||||
serviceRegistryBuilder.applySetting( AvailableSettings.USE_STRUCTURED_CACHE, "true" );
|
||||
serviceRegistryBuilder.applySetting( AvailableSettings.GENERATE_STATISTICS, "true" );
|
||||
serviceRegistryBuilder.applySetting( AvailableSettings.CACHE_REGION_FACTORY, EhCacheRegionFactory.class.getName());
|
||||
serviceRegistryBuilder.applySetting( "net.sf.ehcache.configurationResourceName", "/hibernate-config/ehcache.xml" );
|
||||
protected void initialize() {
|
||||
super.initialize();
|
||||
getTestConfiguration().getProperties().setProperty( AvailableSettings.USE_QUERY_CACHE, "true");
|
||||
getTestConfiguration().getProperties().setProperty( AvailableSettings.USE_STRUCTURED_CACHE, "true" );
|
||||
getTestConfiguration().getProperties().setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
|
||||
getTestConfiguration().getProperties().setProperty( AvailableSettings.CACHE_REGION_FACTORY, EhCacheRegionFactory.class.getName());
|
||||
getTestConfiguration().getProperties().setProperty( "net.sf.ehcache.configurationResourceName", "/hibernate-config/ehcache.xml" );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,7 +32,6 @@ import java.net.URL;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
@ -40,7 +39,6 @@ import java.util.Properties;
|
|||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.jpa.AvailableSettings;
|
||||
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
|
||||
|
@ -97,7 +95,7 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseFunctional
|
|||
serviceRegistry = (StandardServiceRegistryImpl) entityManagerFactory.getSessionFactory()
|
||||
.getServiceRegistry()
|
||||
.getParentServiceRegistry();
|
||||
configuration = entityManagerFactoryBuilder.getHibernateConfiguration();
|
||||
getTestConfiguration().setConfiguration( entityManagerFactoryBuilder.getHibernateConfiguration() );
|
||||
afterEntityManagerFactoryBuilt();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,10 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|||
*/
|
||||
@RunWith(EnversRunner.class)
|
||||
public abstract class BaseEnversFunctionalTestCase extends BaseCoreFunctionalTestCase {
|
||||
protected BaseEnversFunctionalTestCase() {
|
||||
getTestConfiguration().getProperties().setProperty( EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, "false" );
|
||||
}
|
||||
|
||||
private String auditStrategy;
|
||||
|
||||
@Parameterized.Parameters
|
||||
|
@ -48,13 +52,6 @@ public abstract class BaseEnversFunctionalTestCase extends BaseCoreFunctionalTes
|
|||
return AuditReaderFactory.get( getSession() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Configuration constructConfiguration() {
|
||||
Configuration configuration = super.constructConfiguration();
|
||||
configuration.setProperty( EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, "false" );
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBaseForMappings() {
|
||||
return "";
|
||||
|
|
|
@ -24,7 +24,7 @@ public class OutsideTransactionTest extends BaseEnversFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
public void configure(Configuration configuration) {
|
||||
configuration.setProperty( EnversSettings.STORE_DATA_AT_DELETE, "true" );
|
||||
configuration.setProperty( EnversSettings.REVISION_ON_COLLECTION_CHANGE, "true" );
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public abstract class AbstractCollectionChangeTest extends BaseEnversFunctionalT
|
|||
protected Integer personId;
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
public void configure(Configuration configuration) {
|
||||
configuration.setProperty( EnversSettings.REVISION_ON_COLLECTION_CHANGE, getCollectionChangeValue() );
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ public class UnspecifiedEnumTypeTest extends BaseEnversFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
public void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
configuration.setProperty( Environment.HBM2DDL_AUTO, "" );
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public class EntityNamesTest extends BaseEnversFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
public void configure(Configuration configuration) {
|
||||
configuration.setProperty( EnversSettings.TRACK_ENTITIES_CHANGED_IN_REVISION, "true" );
|
||||
}
|
||||
|
||||
|
|
|
@ -101,33 +101,33 @@ public class ConcurrentWriteTest extends SingleNodeTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean getUseQueryCache() {
|
||||
public boolean getUseQueryCache() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TransactionManager getTransactionManager() {
|
||||
public TransactionManager getTransactionManager() {
|
||||
return DualNodeJtaTransactionManagerImpl.getInstance( DualNodeTestCase.LOCAL );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends ConnectionProvider> getConnectionProviderClass() {
|
||||
public Class<? extends ConnectionProvider> getConnectionProviderClass() {
|
||||
return DualNodeConnectionProviderImpl.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends JtaPlatform> getJtaPlatform() {
|
||||
public Class<? extends JtaPlatform> getJtaPlatform() {
|
||||
return DualNodeJtaPlatformImpl.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareTest() throws Exception {
|
||||
public void prepareTest() throws Exception {
|
||||
super.prepareTest();
|
||||
TERMINATE_ALL_USERS = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cleanupTest() throws Exception {
|
||||
public void cleanupTest() throws Exception {
|
||||
try {
|
||||
super.cleanupTest();
|
||||
}
|
||||
|
|
|
@ -81,12 +81,12 @@ public class JndiRegionFactoryTestCase extends SingleNodeTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends RegionFactory> getCacheRegionFactory() {
|
||||
public Class<? extends RegionFactory> getCacheRegionFactory() {
|
||||
return JndiInfinispanRegionFactory.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterConstructAndConfigureMetadata(MetadataImplementor metadataImplementor) {
|
||||
public void afterMetadataBuilt(MetadataImplementor metadataImplementor) {
|
||||
bindToJndi();
|
||||
}
|
||||
|
||||
|
|
|
@ -87,23 +87,23 @@ public abstract class SingleNodeTestCase extends BaseCoreFunctionalTestCase {
|
|||
return "transactional";
|
||||
}
|
||||
|
||||
protected Class<? extends RegionFactory> getCacheRegionFactory() {
|
||||
public Class<? extends RegionFactory> getCacheRegionFactory() {
|
||||
return TestInfinispanRegionFactory.class;
|
||||
}
|
||||
|
||||
protected Class<? extends TransactionFactory> getTransactionFactoryClass() {
|
||||
public Class<? extends TransactionFactory> getTransactionFactoryClass() {
|
||||
return CMTTransactionFactory.class;
|
||||
}
|
||||
|
||||
protected Class<? extends ConnectionProvider> getConnectionProviderClass() {
|
||||
public Class<? extends ConnectionProvider> getConnectionProviderClass() {
|
||||
return org.hibernate.test.cache.infinispan.tm.XaConnectionProvider.class;
|
||||
}
|
||||
|
||||
protected Class<? extends JtaPlatform> getJtaPlatform() {
|
||||
public Class<? extends JtaPlatform> getJtaPlatform() {
|
||||
return JtaPlatformImpl.class;
|
||||
}
|
||||
|
||||
protected boolean getUseQueryCache() {
|
||||
public boolean getUseQueryCache() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,11 +23,8 @@
|
|||
*/
|
||||
package org.hibernate.test.cache.infinispan.functional.cluster;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
||||
import org.hibernate.cache.spi.RegionFactory;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
@ -36,6 +33,10 @@ import org.hibernate.metamodel.MetadataBuilder;
|
|||
import org.hibernate.metamodel.SessionFactoryBuilder;
|
||||
import org.hibernate.metamodel.spi.MetadataImplementor;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.junit4.TestConfigurationHelper;
|
||||
import org.hibernate.testing.junit4.TestServiceRegistryHelper;
|
||||
import org.hibernate.testing.junit4.TestSessionFactoryHelper;
|
||||
|
||||
import org.infinispan.util.logging.Log;
|
||||
import org.infinispan.util.logging.LogFactory;
|
||||
import org.junit.After;
|
||||
|
@ -143,62 +144,55 @@ public abstract class DualNodeTestCase extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
public class SecondNodeEnvironment {
|
||||
private StandardServiceRegistryBuilder serviceRegistryBuilder;
|
||||
private StandardServiceRegistryImpl serviceRegistry;
|
||||
private SessionFactoryImplementor sessionFactory;
|
||||
private TestServiceRegistryHelper serviceRegistryHelper = new TestServiceRegistryHelper( getTestConfiguration() );
|
||||
private TestSessionFactoryHelper sessionFactoryHelper = new TestSessionFactoryHelper( serviceRegistryHelper, getTestConfiguration() );
|
||||
|
||||
|
||||
public SecondNodeEnvironment() {
|
||||
Properties properties = constructProperties();
|
||||
serviceRegistryHelper.setCallback( new TestServiceRegistryHelper.DefaultCallback(){
|
||||
|
||||
// TODO: Look into separating out some of these steps in
|
||||
// BaseCoreFuntionalTestCase
|
||||
BootstrapServiceRegistry bootstrapServiceRegistry = buildBootstrapServiceRegistry();
|
||||
serviceRegistryBuilder = new StandardServiceRegistryBuilder( bootstrapServiceRegistry )
|
||||
.applySettings( properties );
|
||||
@Override
|
||||
public void prepareStandardServiceRegistryBuilder(
|
||||
final StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
corePrepareStandardServiceRegistryBuilder( serviceRegistryBuilder );
|
||||
serviceRegistryBuilder.applySetting( NODE_ID_PROP, REMOTE );
|
||||
serviceRegistryBuilder.applySetting( NODE_ID_FIELD, REMOTE );
|
||||
configureSecondNode( serviceRegistryBuilder );
|
||||
serviceRegistry = (StandardServiceRegistryImpl) serviceRegistryBuilder.build();
|
||||
}
|
||||
});
|
||||
|
||||
MetadataBuilder metadataBuilder = getMetadataBuilder( bootstrapServiceRegistry, serviceRegistry );
|
||||
configMetadataBuilder(metadataBuilder);
|
||||
MetadataImplementor metadata = (MetadataImplementor)metadataBuilder.build();
|
||||
afterConstructAndConfigureMetadata( metadata );
|
||||
applyCacheSettings( metadata );
|
||||
SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
|
||||
configSessionFactoryBuilder(sessionFactoryBuilder);
|
||||
sessionFactory = ( SessionFactoryImplementor )sessionFactoryBuilder.build();
|
||||
// TODO: Look into separating out some of these steps in
|
||||
sessionFactoryHelper.setCallback( new TestSessionFactoryHelper.CallbackImpl(){
|
||||
@Override
|
||||
public void configure(final MetadataBuilder metadataBuilder) {
|
||||
DualNodeTestCase.this.configure( metadataBuilder );
|
||||
}
|
||||
|
||||
public StandardServiceRegistryBuilder getServiceRegistryBuilder() {
|
||||
return serviceRegistryBuilder;
|
||||
@Override
|
||||
public void afterMetadataBuilt(final MetadataImplementor metadataImplementor) {
|
||||
DualNodeTestCase.this.afterMetadataBuilt( metadataImplementor );
|
||||
|
||||
}
|
||||
|
||||
public StandardServiceRegistryImpl getServiceRegistry() {
|
||||
return serviceRegistry;
|
||||
@Override
|
||||
public void configSessionFactoryBuilder(final SessionFactoryBuilder sessionFactoryBuilder) {
|
||||
DualNodeTestCase.this.configSessionFactoryBuilder( sessionFactoryBuilder );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public SessionFactoryImplementor getSessionFactory() {
|
||||
return sessionFactory;
|
||||
return sessionFactoryHelper.getSessionFactory();
|
||||
}
|
||||
|
||||
public void shutDown() {
|
||||
if ( sessionFactory != null ) {
|
||||
try {
|
||||
sessionFactory.close();
|
||||
sessionFactory = null;
|
||||
}
|
||||
catch ( Exception ignore ) {
|
||||
}
|
||||
}
|
||||
if ( serviceRegistry != null ) {
|
||||
try {
|
||||
serviceRegistry.destroy();
|
||||
serviceRegistry = null;
|
||||
}
|
||||
catch ( Exception ignore ) {
|
||||
if(sessionFactoryHelper!=null){
|
||||
sessionFactoryHelper.destory();
|
||||
sessionFactoryHelper = null;
|
||||
}
|
||||
if(serviceRegistryHelper!=null){
|
||||
serviceRegistryHelper.destroy();
|
||||
serviceRegistryHelper = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,9 +57,7 @@ public class EntityCollectionInvalidationTestCase extends DualNodeTestCase {
|
|||
private static final Log log = LogFactory.getLog( EntityCollectionInvalidationTestCase.class );
|
||||
|
||||
private static final long SLEEP_TIME = 50l;
|
||||
private static final Integer CUSTOMER_ID = new Integer( 1 );
|
||||
|
||||
static int test = 0;
|
||||
private static final int CUSTOMER_ID = 1;
|
||||
|
||||
@Test
|
||||
public void testAll() throws Exception {
|
||||
|
@ -77,7 +75,8 @@ public class EntityCollectionInvalidationTestCase extends DualNodeTestCase {
|
|||
localContactCache.addListener( localListener );
|
||||
localCollectionCache.addListener( localListener );
|
||||
TransactionManager localTM = DualNodeJtaTransactionManagerImpl.getInstance( DualNodeTestCase.LOCAL );
|
||||
|
||||
SessionFactory localFactory = sessionFactory();
|
||||
SessionFactory remoteFactory = secondNodeEnvironment().getSessionFactory();
|
||||
// Bind a listener to the "remote" cache
|
||||
CacheContainer remoteManager = ClusterAwareRegionFactory.getCacheManager( DualNodeTestCase.REMOTE );
|
||||
Cache remoteCustomerCache = remoteManager.getCache( Customer.class.getName() );
|
||||
|
@ -89,8 +88,7 @@ public class EntityCollectionInvalidationTestCase extends DualNodeTestCase {
|
|||
remoteCollectionCache.addListener( remoteListener );
|
||||
TransactionManager remoteTM = DualNodeJtaTransactionManagerImpl.getInstance( DualNodeTestCase.REMOTE );
|
||||
|
||||
SessionFactory localFactory = sessionFactory();
|
||||
SessionFactory remoteFactory = secondNodeEnvironment().getSessionFactory();
|
||||
|
||||
|
||||
try {
|
||||
assertTrue( remoteListener.isEmpty() );
|
||||
|
@ -236,8 +234,8 @@ public class EntityCollectionInvalidationTestCase extends DualNodeTestCase {
|
|||
private Customer doGetCustomer(Integer id, Session session, TransactionManager tm) throws Exception {
|
||||
Customer customer = (Customer) session.get( Customer.class, id );
|
||||
// Access all the contacts
|
||||
for ( Iterator it = customer.getContacts().iterator(); it.hasNext(); ) {
|
||||
( (Contact) it.next() ).getName();
|
||||
for ( final Contact contact : customer.getContacts() ) {
|
||||
( contact ).getName();
|
||||
}
|
||||
return customer;
|
||||
}
|
||||
|
@ -288,8 +286,8 @@ public class EntityCollectionInvalidationTestCase extends DualNodeTestCase {
|
|||
Customer c = (Customer) session.get( Customer.class, CUSTOMER_ID );
|
||||
if ( c != null ) {
|
||||
Set contacts = c.getContacts();
|
||||
for ( Iterator it = contacts.iterator(); it.hasNext(); ) {
|
||||
session.delete( it.next() );
|
||||
for ( final Object contact : contacts ) {
|
||||
session.delete( contact );
|
||||
}
|
||||
c.setContacts( null );
|
||||
session.delete( c );
|
||||
|
|
|
@ -25,53 +25,31 @@ package org.hibernate.testing.junit4;
|
|||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.sql.Blob;
|
||||
import java.sql.Clob;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.EmptyInterceptor;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Interceptor;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.cfg.Mappings;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.jdbc.AbstractReturningWork;
|
||||
import org.hibernate.jdbc.Work;
|
||||
import org.hibernate.mapping.Collection;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.mapping.SimpleValue;
|
||||
import org.hibernate.metamodel.MetadataBuilder;
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.metamodel.SessionFactoryBuilder;
|
||||
import org.hibernate.metamodel.spi.MetadataImplementor;
|
||||
import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.Caching;
|
||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||
import org.hibernate.testing.AfterClassOnce;
|
||||
import org.hibernate.testing.BeforeClassOnce;
|
||||
import org.hibernate.testing.OnExpectedFailure;
|
||||
import org.hibernate.testing.OnFailure;
|
||||
import org.hibernate.testing.SkipLog;
|
||||
import org.hibernate.testing.cache.CachingRegionFactory;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
|
@ -80,14 +58,22 @@ import org.junit.Before;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class BaseCoreFunctionalTestCase extends BaseFunctionalTestCase {
|
||||
public abstract class BaseCoreFunctionalTestCase extends BaseFunctionalTestCase implements TestSessionFactoryHelper.Callback{
|
||||
|
||||
private SessionFactoryImplementor sessionFactory;
|
||||
private TestSessionFactoryHelper sessionFactoryBuilder;
|
||||
|
||||
public BaseCoreFunctionalTestCase(){
|
||||
initialize();
|
||||
getTestConfiguration().setCacheConcurrencyStrategy( getCacheConcurrencyStrategy() );
|
||||
getTestConfiguration().setOverrideCacheStrategy( overrideCacheStrategy() );
|
||||
sessionFactoryBuilder = new TestSessionFactoryHelper( getTestServiceRegistryHelper(),getTestConfiguration());
|
||||
sessionFactoryBuilder.setCallback( this );
|
||||
}
|
||||
|
||||
protected Session session;
|
||||
|
||||
protected SessionFactoryImplementor sessionFactory() {
|
||||
return sessionFactory;
|
||||
protected final SessionFactoryImplementor sessionFactory() {
|
||||
return getSessionFactoryBuilder().getSessionFactory();
|
||||
}
|
||||
|
||||
protected Session openSession() throws HibernateException {
|
||||
|
@ -100,190 +86,39 @@ public abstract class BaseCoreFunctionalTestCase extends BaseFunctionalTestCase
|
|||
return session;
|
||||
}
|
||||
|
||||
public TestSessionFactoryHelper getSessionFactoryBuilder() {
|
||||
return sessionFactoryBuilder;
|
||||
}
|
||||
|
||||
public void setSessionFactoryBuilder(final TestSessionFactoryHelper sessionFactoryBuilder) {
|
||||
this.sessionFactoryBuilder = sessionFactoryBuilder;
|
||||
}
|
||||
|
||||
// before/after test class ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@BeforeClassOnce
|
||||
@SuppressWarnings( {"UnusedDeclaration"})
|
||||
protected void buildSessionFactory() {
|
||||
Properties properties = constructProperties();
|
||||
|
||||
BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry();
|
||||
serviceRegistry = buildServiceRegistry( bootRegistry, properties );
|
||||
|
||||
ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );
|
||||
isMetadataUsed = configService.getSetting(
|
||||
USE_NEW_METADATA_MAPPINGS,
|
||||
new ConfigurationService.Converter<Boolean>() {
|
||||
@Override
|
||||
public Boolean convert(Object value) {
|
||||
return Boolean.parseBoolean( ( String ) value );
|
||||
}
|
||||
},
|
||||
true
|
||||
);
|
||||
if ( isMetadataUsed ) {
|
||||
MetadataBuilder metadataBuilder = getMetadataBuilder( bootRegistry, serviceRegistry );
|
||||
configMetadataBuilder(metadataBuilder);
|
||||
metadata = (MetadataImplementor)metadataBuilder.build();
|
||||
afterConstructAndConfigureMetadata( metadata );
|
||||
applyCacheSettings( metadata );
|
||||
SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
|
||||
configSessionFactoryBuilder(sessionFactoryBuilder);
|
||||
sessionFactory = ( SessionFactoryImplementor )sessionFactoryBuilder.build();
|
||||
}
|
||||
else {
|
||||
configuration = constructAndConfigureConfiguration(properties);
|
||||
// this is done here because Configuration does not currently support 4.0 xsd
|
||||
afterConstructAndConfigureConfiguration( configuration );
|
||||
sessionFactory = ( SessionFactoryImplementor ) configuration.buildSessionFactory( serviceRegistry );
|
||||
}
|
||||
afterSessionFactoryBuilt();
|
||||
getSessionFactoryBuilder().buildSessionFactory();
|
||||
}
|
||||
|
||||
protected void rebuildSessionFactory() {
|
||||
public void rebuildSessionFactory() {
|
||||
releaseSessionFactory();
|
||||
buildSessionFactory();
|
||||
}
|
||||
|
||||
|
||||
protected void afterConstructAndConfigureMetadata(MetadataImplementor metadataImplementor) {
|
||||
@Override
|
||||
public void afterMetadataBuilt(MetadataImplementor metadataImplementor) {
|
||||
}
|
||||
@Override
|
||||
public void configure(MetadataBuilder metadataBuilder) {
|
||||
}
|
||||
@Override
|
||||
public void configSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder) {
|
||||
}
|
||||
|
||||
protected void configMetadataBuilder(MetadataBuilder metadataBuilder) {
|
||||
}
|
||||
|
||||
protected void configSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder) {
|
||||
}
|
||||
|
||||
protected void configSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder, Configuration configuration) {
|
||||
if ( configuration.getEntityNotFoundDelegate() != null ) {
|
||||
sessionFactoryBuilder.with( configuration.getEntityNotFoundDelegate() );
|
||||
}
|
||||
if ( configuration.getSessionFactoryObserver() != null ){
|
||||
sessionFactoryBuilder.add( configuration.getSessionFactoryObserver() );
|
||||
}
|
||||
if ( configuration.getInterceptor() != EmptyInterceptor.INSTANCE ) {
|
||||
sessionFactoryBuilder.with( configuration.getInterceptor() );
|
||||
}
|
||||
}
|
||||
|
||||
protected MetadataBuilder getMetadataBuilder(
|
||||
BootstrapServiceRegistry bootRegistry,
|
||||
StandardServiceRegistryImpl serviceRegistry) {
|
||||
MetadataSources sources = new MetadataSources( bootRegistry );
|
||||
addMappings( sources );
|
||||
return sources.getMetadataBuilder(serviceRegistry);
|
||||
}
|
||||
|
||||
protected Configuration constructConfiguration() {
|
||||
return new Configuration().setProperties( constructProperties() );
|
||||
}
|
||||
|
||||
private Configuration constructAndConfigureConfiguration(Properties properties) {
|
||||
Configuration cfg = new Configuration().setProperties( properties );
|
||||
configure( cfg );
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private void afterConstructAndConfigureConfiguration(Configuration cfg) {
|
||||
addMappings( cfg );
|
||||
cfg.buildMappings();
|
||||
applyCacheSettings( cfg );
|
||||
afterConfigurationBuilt( cfg );
|
||||
}
|
||||
|
||||
protected Properties constructProperties() {
|
||||
Properties properties = new Properties();
|
||||
properties.put( Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName() );
|
||||
properties.put( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
properties.put( Environment.DIALECT, getDialect().getClass().getName() );
|
||||
if(createSchema()){
|
||||
properties.put( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
protected void configure(Configuration configuration) {
|
||||
}
|
||||
|
||||
public static void applyCacheSettings(MetadataImplementor metadataImplementor, String strategy, boolean overrideCacheStrategy){
|
||||
if( StringHelper.isEmpty(strategy)){
|
||||
return;
|
||||
}
|
||||
for( EntityBinding entityBinding : metadataImplementor.getEntityBindings()){
|
||||
boolean hasLob = false;
|
||||
for( AttributeBinding attributeBinding : entityBinding.getAttributeBindingClosure()){
|
||||
if ( attributeBinding.getAttribute().isSingular() ) {
|
||||
Type type = attributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping();
|
||||
String typeName = type.getName();
|
||||
if ( "blob".equals( typeName ) || "clob".equals( typeName ) ) {
|
||||
hasLob = true;
|
||||
}
|
||||
if ( Blob.class.getName().equals( typeName ) || Clob.class.getName().equals( typeName ) ) {
|
||||
hasLob = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !hasLob && entityBinding.getSuperEntityBinding() == null && overrideCacheStrategy ) {
|
||||
Caching caching = entityBinding.getHierarchyDetails().getCaching();
|
||||
if ( caching == null ) {
|
||||
caching = new Caching();
|
||||
}
|
||||
caching.setRegion( entityBinding.getEntity().getName() );
|
||||
caching.setCacheLazyProperties( true );
|
||||
caching.setAccessType( AccessType.fromExternalName( strategy ) );
|
||||
entityBinding.getHierarchyDetails().setCaching( caching );
|
||||
}
|
||||
for( AttributeBinding attributeBinding : entityBinding.getAttributeBindingClosure()){
|
||||
if ( !attributeBinding.getAttribute().isSingular() ) {
|
||||
AbstractPluralAttributeBinding binding = AbstractPluralAttributeBinding.class.cast( attributeBinding );
|
||||
Caching caching = binding.getCaching();
|
||||
if(caching == null){
|
||||
caching = new Caching( );
|
||||
}
|
||||
caching.setRegion( StringHelper.qualify( entityBinding.getEntity().getName() , attributeBinding.getAttribute().getName() ) );
|
||||
caching.setCacheLazyProperties( true );
|
||||
caching.setAccessType( AccessType.fromExternalName( strategy ) );
|
||||
binding.setCaching( caching );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void applyCacheSettings(MetadataImplementor metadataImplementor){
|
||||
applyCacheSettings( metadataImplementor, getCacheConcurrencyStrategy(), overrideCacheStrategy() );
|
||||
}
|
||||
|
||||
protected void applyCacheSettings(Configuration configuration) {
|
||||
if ( getCacheConcurrencyStrategy() != null ) {
|
||||
Iterator itr = configuration.getClassMappings();
|
||||
while ( itr.hasNext() ) {
|
||||
PersistentClass clazz = (PersistentClass) itr.next();
|
||||
Iterator props = clazz.getPropertyClosureIterator();
|
||||
boolean hasLob = false;
|
||||
while ( props.hasNext() ) {
|
||||
Property prop = (Property) props.next();
|
||||
if ( prop.getValue().isSimpleValue() ) {
|
||||
String type = ( (SimpleValue) prop.getValue() ).getTypeName();
|
||||
if ( "blob".equals(type) || "clob".equals(type) ) {
|
||||
hasLob = true;
|
||||
}
|
||||
if ( Blob.class.getName().equals(type) || Clob.class.getName().equals(type) ) {
|
||||
hasLob = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !hasLob && !clazz.isInherited() && overrideCacheStrategy() ) {
|
||||
configuration.setCacheConcurrencyStrategy( clazz.getEntityName(), getCacheConcurrencyStrategy() );
|
||||
}
|
||||
}
|
||||
itr = configuration.getCollectionMappings();
|
||||
while ( itr.hasNext() ) {
|
||||
Collection coll = (Collection) itr.next();
|
||||
configuration.setCollectionCacheConcurrencyStrategy( coll.getRole(), getCacheConcurrencyStrategy() );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void configure(Configuration configuration) {
|
||||
}
|
||||
|
||||
protected boolean overrideCacheStrategy() {
|
||||
|
@ -294,16 +129,13 @@ public abstract class BaseCoreFunctionalTestCase extends BaseFunctionalTestCase
|
|||
return null;
|
||||
}
|
||||
|
||||
protected void afterConfigurationBuilt(Configuration configuration) {
|
||||
afterConfigurationBuilt( configuration.createMappings(), getDialect() );
|
||||
}
|
||||
|
||||
protected void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
|
||||
@Override
|
||||
public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void afterSessionFactoryBuilt() {
|
||||
@Override
|
||||
public void afterSessionFactoryBuilt() {
|
||||
}
|
||||
|
||||
protected boolean rebuildSessionFactoryOnError() {
|
||||
|
@ -313,18 +145,13 @@ public abstract class BaseCoreFunctionalTestCase extends BaseFunctionalTestCase
|
|||
@AfterClassOnce
|
||||
@SuppressWarnings( {"UnusedDeclaration"})
|
||||
private void releaseSessionFactory() {
|
||||
if ( sessionFactory == null ) {
|
||||
return;
|
||||
if ( getSessionFactoryBuilder() != null ) {
|
||||
getSessionFactoryBuilder().destory();
|
||||
// setSessionFactoryBuilder( null );
|
||||
}
|
||||
sessionFactory.close();
|
||||
sessionFactory = null;
|
||||
configuration = null;
|
||||
metadata = null;
|
||||
if ( serviceRegistry == null ) {
|
||||
return;
|
||||
}
|
||||
serviceRegistry.destroy();
|
||||
serviceRegistry = null;
|
||||
getTestConfiguration().setConfiguration( null );
|
||||
getTestConfiguration().setMetadata( null );
|
||||
getTestServiceRegistryHelper().destroy();
|
||||
}
|
||||
|
||||
@OnFailure
|
||||
|
@ -360,12 +187,12 @@ public abstract class BaseCoreFunctionalTestCase extends BaseFunctionalTestCase
|
|||
}
|
||||
|
||||
protected void cleanupCache() {
|
||||
if ( sessionFactory != null ) {
|
||||
sessionFactory.getCache().evictCollectionRegions();
|
||||
sessionFactory.getCache().evictDefaultQueryRegion();
|
||||
sessionFactory.getCache().evictEntityRegions();
|
||||
sessionFactory.getCache().evictQueryRegions();
|
||||
sessionFactory.getCache().evictNaturalIdRegions();
|
||||
if ( sessionFactory() != null ) {
|
||||
sessionFactory().getCache().evictCollectionRegions();
|
||||
sessionFactory().getCache().evictDefaultQueryRegion();
|
||||
sessionFactory().getCache().evictEntityRegions();
|
||||
sessionFactory().getCache().evictQueryRegions();
|
||||
sessionFactory().getCache().evictNaturalIdRegions();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -408,7 +235,7 @@ public abstract class BaseCoreFunctionalTestCase extends BaseFunctionalTestCase
|
|||
return;
|
||||
}
|
||||
|
||||
Session tmpSession = sessionFactory.openSession();
|
||||
Session tmpSession = sessionFactory().openSession();
|
||||
try {
|
||||
List list = tmpSession.createQuery( "select o from java.lang.Object o" ).list();
|
||||
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package org.hibernate.testing.junit4;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
/**
|
||||
* @author Strong Liu <stliu@hibernate.org>
|
||||
*/
|
||||
public class BaseCoreFunctionalTestMethod extends BaseFunctionalTestCase {
|
||||
private TestSessionFactoryHelper sessionFactoryHelper;
|
||||
|
||||
@Before
|
||||
public final void beforeTest() throws Exception {
|
||||
setTestConfiguration( new TestConfigurationHelper() );
|
||||
setTestServiceRegistryHelper( new TestServiceRegistryHelper( getTestConfiguration() ) );
|
||||
sessionFactoryHelper = new TestSessionFactoryHelper(
|
||||
getTestServiceRegistryHelper(), getTestConfiguration()
|
||||
);
|
||||
initialize();
|
||||
prepareTest();
|
||||
}
|
||||
|
||||
protected void prepareTest() throws Exception {
|
||||
}
|
||||
|
||||
@After
|
||||
public final void afterTest() throws Exception {
|
||||
prepareCleanup();
|
||||
if ( getSessionFactoryHelper() != null ) {
|
||||
getSessionFactoryHelper().destory();
|
||||
}
|
||||
setSessionFactoryHelper( null );
|
||||
if( getTestServiceRegistryHelper()!=null){
|
||||
getTestServiceRegistryHelper().destroy();
|
||||
}
|
||||
setTestServiceRegistryHelper( null );
|
||||
setTestConfiguration( null );
|
||||
}
|
||||
|
||||
protected void prepareCleanup() {
|
||||
|
||||
}
|
||||
|
||||
public TestSessionFactoryHelper getSessionFactoryHelper() {
|
||||
return sessionFactoryHelper;
|
||||
}
|
||||
|
||||
public void setSessionFactoryHelper(final TestSessionFactoryHelper sessionFactoryHelper) {
|
||||
this.sessionFactoryHelper = sessionFactoryHelper;
|
||||
}
|
||||
}
|
|
@ -1,20 +1,13 @@
|
|||
package org.hibernate.testing.junit4;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.metamodel.spi.MetadataImplementor;
|
||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
|
||||
|
@ -25,16 +18,54 @@ import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
|
|||
public class BaseFunctionalTestCase extends BaseUnitTestCase {
|
||||
public static final String VALIDATE_DATA_CLEANUP = "hibernate.test.validateDataCleanup";
|
||||
|
||||
public static final Dialect DIALECT = Dialect.getDialect();
|
||||
protected static final String[] NO_MAPPINGS = new String[0];
|
||||
protected static final Class<?>[] NO_CLASSES = new Class[0];
|
||||
protected Configuration configuration;
|
||||
protected MetadataImplementor metadata;
|
||||
protected StandardServiceRegistryImpl serviceRegistry;
|
||||
private TestServiceRegistryHelper testServiceRegistryHelper = new TestServiceRegistryHelper( getTestConfiguration() );
|
||||
|
||||
protected void initialize(){
|
||||
//to keep compatibility, collect the static info here
|
||||
getTestConfiguration().setCreateSchema( createSchema() );
|
||||
getTestConfiguration().setSecondSchemaName( createSecondSchema() );
|
||||
|
||||
protected static Dialect getDialect() {
|
||||
return DIALECT;
|
||||
String[] mappings = getMappings();
|
||||
if ( mappings != null ) {
|
||||
for ( String mapping : mappings ) {
|
||||
getTestConfiguration().getMappings().add(
|
||||
getBaseForMappings() + mapping
|
||||
);
|
||||
}
|
||||
}
|
||||
Class<?>[] annotatedClasses = getAnnotatedClasses();
|
||||
if ( annotatedClasses != null ) {
|
||||
getTestConfiguration().getAnnotatedClasses().addAll( Arrays.asList( annotatedClasses ) );
|
||||
}
|
||||
String[] annotatedPackages = getAnnotatedPackages();
|
||||
if ( annotatedPackages != null ) {
|
||||
getTestConfiguration().getAnnotatedPackages().addAll( Arrays.asList( annotatedPackages ) );
|
||||
}
|
||||
String[] xmlFiles = getXmlFiles();
|
||||
if ( xmlFiles != null ) {
|
||||
getTestConfiguration().getOrmXmlFiles().addAll( Arrays.asList( xmlFiles ) );
|
||||
}
|
||||
getTestServiceRegistryHelper().setCallback(
|
||||
new TestServiceRegistryHelper.Callback() {
|
||||
@Override
|
||||
public void prepareStandardServiceRegistryBuilder(
|
||||
final StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
BaseFunctionalTestCase.this.prepareStandardServiceRegistryBuilder( serviceRegistryBuilder );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareBootstrapServiceRegistryBuilder(
|
||||
final BootstrapServiceRegistryBuilder builder) {
|
||||
BaseFunctionalTestCase.this.prepareBootstrapServiceRegistryBuilder( builder );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected final Dialect getDialect() {
|
||||
return getTestConfiguration().getDialect();
|
||||
}
|
||||
//----------------------- configuration properties
|
||||
|
||||
|
@ -42,51 +73,20 @@ public class BaseFunctionalTestCase extends BaseUnitTestCase {
|
|||
return true;
|
||||
}
|
||||
|
||||
protected Configuration configuration() {
|
||||
return configuration;
|
||||
protected final Configuration configuration() {
|
||||
return getTestConfiguration().getConfiguration();
|
||||
}
|
||||
|
||||
protected MetadataImplementor metadata() {
|
||||
return metadata;
|
||||
protected final MetadataImplementor metadata() {
|
||||
return getTestConfiguration().getMetadata();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------------- services and service registry
|
||||
protected BootstrapServiceRegistry buildBootstrapServiceRegistry() {
|
||||
final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
|
||||
prepareBootstrapServiceRegistryBuilder( builder );
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
protected StandardServiceRegistryImpl serviceRegistry() {
|
||||
return serviceRegistry;
|
||||
}
|
||||
|
||||
|
||||
protected StandardServiceRegistryImpl buildServiceRegistry(BootstrapServiceRegistry bootRegistry, Properties properties) {
|
||||
Environment.verifyProperties( properties );
|
||||
ConfigurationHelper.resolvePlaceHolders( properties );
|
||||
|
||||
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder( bootRegistry ).applySettings( properties );
|
||||
prepareStandardServiceRegistryBuilder( registryBuilder );
|
||||
|
||||
// TODO: StandardServiceRegistryBuilder#applySettings sets up the
|
||||
// Environment.URL property. Rather than rely on that, createH2Schema
|
||||
// could be refactored and this whole block put back in
|
||||
// BaseCoreFunctionalTestCase#constructProperties
|
||||
if ( createSchema() ) {
|
||||
registryBuilder.applySetting( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
final String secondSchemaName = createSecondSchema();
|
||||
if ( StringHelper.isNotEmpty( secondSchemaName ) ) {
|
||||
if ( !( getDialect() instanceof H2Dialect ) ) {
|
||||
throw new UnsupportedOperationException( "Only H2 dialect supports creation of second schema." );
|
||||
}
|
||||
Helper.createH2Schema( secondSchemaName, registryBuilder.getSettings() );
|
||||
}
|
||||
}
|
||||
|
||||
return (StandardServiceRegistryImpl) registryBuilder.build();
|
||||
return getTestServiceRegistryHelper().getServiceRegistry();
|
||||
}
|
||||
|
||||
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
|
@ -96,67 +96,6 @@ public class BaseFunctionalTestCase extends BaseUnitTestCase {
|
|||
}
|
||||
|
||||
|
||||
//----------------------- source mappings
|
||||
protected void addMappings(Configuration configuration) {
|
||||
String[] mappings = getMappings();
|
||||
if ( mappings != null ) {
|
||||
for ( String mapping : mappings ) {
|
||||
configuration.addResource(
|
||||
getBaseForMappings() + mapping,
|
||||
getClass().getClassLoader()
|
||||
);
|
||||
}
|
||||
}
|
||||
Class<?>[] annotatedClasses = getAnnotatedClasses();
|
||||
if ( annotatedClasses != null ) {
|
||||
for ( Class<?> annotatedClass : annotatedClasses ) {
|
||||
configuration.addAnnotatedClass( annotatedClass );
|
||||
}
|
||||
}
|
||||
String[] annotatedPackages = getAnnotatedPackages();
|
||||
if ( annotatedPackages != null ) {
|
||||
for ( String annotatedPackage : annotatedPackages ) {
|
||||
configuration.addPackage( annotatedPackage );
|
||||
}
|
||||
}
|
||||
String[] xmlFiles = getXmlFiles();
|
||||
if ( xmlFiles != null ) {
|
||||
for ( String xmlFile : xmlFiles ) {
|
||||
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile );
|
||||
configuration.addInputStream( is );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void addMappings(MetadataSources sources) {
|
||||
String[] mappings = getMappings();
|
||||
if ( mappings != null ) {
|
||||
for ( String mapping : mappings ) {
|
||||
sources.addResource(
|
||||
getBaseForMappings() + mapping
|
||||
);
|
||||
}
|
||||
}
|
||||
Class<?>[] annotatedClasses = getAnnotatedClasses();
|
||||
if ( annotatedClasses != null ) {
|
||||
for ( Class<?> annotatedClass : annotatedClasses ) {
|
||||
sources.addAnnotatedClass( annotatedClass );
|
||||
}
|
||||
}
|
||||
String[] annotatedPackages = getAnnotatedPackages();
|
||||
if ( annotatedPackages != null ) {
|
||||
for ( String annotatedPackage : annotatedPackages ) {
|
||||
sources.addPackage( annotatedPackage );
|
||||
}
|
||||
}
|
||||
String[] xmlFiles = getXmlFiles();
|
||||
if ( xmlFiles != null ) {
|
||||
for ( String xmlFile : xmlFiles ) {
|
||||
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile );
|
||||
sources.addInputStream( is );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Feature supported only by H2 dialect.
|
||||
|
@ -189,15 +128,22 @@ public class BaseFunctionalTestCase extends BaseUnitTestCase {
|
|||
//-------------------------------------------
|
||||
|
||||
protected EntityBinding getEntityBinding(Class<?> clazz) {
|
||||
return metadata.getEntityBinding( clazz.getName() );
|
||||
return getTestConfiguration().getMetadata().getEntityBinding( clazz.getName() );
|
||||
}
|
||||
|
||||
protected EntityBinding getRootEntityBinding(Class<?> clazz) {
|
||||
return metadata.getRootEntityBinding( clazz.getName() );
|
||||
return getTestConfiguration().getMetadata().getRootEntityBinding( clazz.getName() );
|
||||
}
|
||||
|
||||
protected Iterator<PluralAttributeBinding> getCollectionBindings() {
|
||||
return metadata.getCollectionBindings().iterator();
|
||||
return getTestConfiguration().getMetadata().getCollectionBindings().iterator();
|
||||
}
|
||||
|
||||
public TestServiceRegistryHelper getTestServiceRegistryHelper() {
|
||||
return testServiceRegistryHelper;
|
||||
}
|
||||
|
||||
public void setTestServiceRegistryHelper(final TestServiceRegistryHelper testServiceRegistryHelper) {
|
||||
this.testServiceRegistryHelper = testServiceRegistryHelper;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.junit.runner.RunWith;
|
|||
|
||||
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
|
||||
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
|
||||
|
||||
/**
|
||||
|
@ -45,16 +44,25 @@ import org.hibernate.testing.jta.TestingJtaPlatformImpl;
|
|||
@RunWith( CustomRunner.class )
|
||||
public abstract class BaseUnitTestCase {
|
||||
private static final Logger log = Logger.getLogger( BaseUnitTestCase.class );
|
||||
public static final String USE_NEW_METADATA_MAPPINGS = MetadataSources.USE_NEW_METADATA_MAPPINGS;
|
||||
/**
|
||||
* String that should be prepended to all standard output placed in tests. Output without this prefix may cause test
|
||||
* subclasses of {@link BaseSqlOutputTest} to fail.
|
||||
*/
|
||||
protected static final String OUTPUT_PREFIX = SqlStatementLogger.OUTPUT_PREFIX;
|
||||
protected static boolean isMetadataUsed = Boolean.valueOf( System.getProperty( USE_NEW_METADATA_MAPPINGS, "true" ) );
|
||||
public static boolean isMetadataUsed() {
|
||||
return isMetadataUsed;
|
||||
public boolean isMetadataUsed() {
|
||||
return getTestConfiguration().isMetadataUsed();
|
||||
}
|
||||
|
||||
private TestConfigurationHelper testConfiguration = new TestConfigurationHelper();
|
||||
|
||||
public TestConfigurationHelper getTestConfiguration() {
|
||||
return testConfiguration;
|
||||
}
|
||||
|
||||
public void setTestConfiguration(final TestConfigurationHelper testConfiguration) {
|
||||
this.testConfiguration = testConfiguration;
|
||||
}
|
||||
|
||||
@Rule
|
||||
public TestRule globalTimeout = new Timeout( 30 * 60 * 1000 ); // no test should run longer than 30 minutes
|
||||
|
||||
|
|
|
@ -219,6 +219,9 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
|
|||
// Now process that full list of test methods and build our custom result
|
||||
final List<FrameworkMethod> result = new ArrayList<FrameworkMethod>();
|
||||
final boolean doValidation = Boolean.getBoolean( Helper.VALIDATE_FAILURE_EXPECTED );
|
||||
boolean useNewMetadata = TestConfigurationHelper.DEFAULT_USE_NEW_METAMODEL;
|
||||
|
||||
|
||||
int testCount = 0;
|
||||
|
||||
Ignore virtualIgnore;
|
||||
|
@ -267,7 +270,16 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
|
|||
}
|
||||
|
||||
boolean useNewMetamodel() {
|
||||
return BaseUnitTestCase.isMetadataUsed();
|
||||
try {
|
||||
Object object = getTestInstance();
|
||||
if ( object != null && object instanceof BaseUnitTestCase ) {
|
||||
return ( (BaseUnitTestCase) object ).getTestConfiguration().isMetadataUsed();
|
||||
}
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
|
||||
}
|
||||
return TestConfigurationHelper.DEFAULT_USE_NEW_METAMODEL;
|
||||
}
|
||||
|
||||
protected Ignore convertSkipToIgnore(FrameworkMethod frameworkMethod) {
|
||||
|
|
|
@ -0,0 +1,173 @@
|
|||
package org.hibernate.testing.junit4;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.metamodel.spi.MetadataImplementor;
|
||||
import org.hibernate.testing.cache.CachingRegionFactory;
|
||||
|
||||
/**
|
||||
* @author Strong Liu <stliu@hibernate.org>
|
||||
*/
|
||||
public class TestConfigurationHelper {
|
||||
private static final Dialect DEFAULT_DIALECT = Dialect.getDialect();
|
||||
public static final boolean DEFAULT_USE_NEW_METAMODEL = Boolean.valueOf(
|
||||
System.getProperty(
|
||||
MetadataSources.USE_NEW_METADATA_MAPPINGS, "true"
|
||||
)
|
||||
);
|
||||
|
||||
protected Configuration configuration;
|
||||
protected MetadataImplementor metadata;
|
||||
protected StandardServiceRegistryImpl serviceRegistry;
|
||||
private Properties properties;
|
||||
|
||||
|
||||
private Dialect dialect = DEFAULT_DIALECT;
|
||||
private boolean isMetadataUsed = DEFAULT_USE_NEW_METAMODEL;
|
||||
private boolean createSchema = true;
|
||||
private String secondSchemaName = null;
|
||||
|
||||
private String cacheConcurrencyStrategy;
|
||||
|
||||
private boolean overrideCacheStrategy = true;
|
||||
|
||||
public boolean isOverrideCacheStrategy() {
|
||||
return overrideCacheStrategy;
|
||||
}
|
||||
|
||||
public void setOverrideCacheStrategy(final boolean overrideCacheStrategy) {
|
||||
this.overrideCacheStrategy = overrideCacheStrategy;
|
||||
}
|
||||
|
||||
public String getCacheConcurrencyStrategy() {
|
||||
return cacheConcurrencyStrategy;
|
||||
}
|
||||
|
||||
public void setCacheConcurrencyStrategy(final String cacheConcurrencyStrategy) {
|
||||
this.cacheConcurrencyStrategy = cacheConcurrencyStrategy;
|
||||
}
|
||||
|
||||
public String getSecondSchemaName() {
|
||||
return secondSchemaName;
|
||||
}
|
||||
|
||||
public void setSecondSchemaName(final String secondSchemaName) {
|
||||
this.secondSchemaName = secondSchemaName;
|
||||
}
|
||||
|
||||
public boolean isCreateSchema() {
|
||||
return createSchema;
|
||||
}
|
||||
|
||||
public void setCreateSchema(final boolean createSchema) {
|
||||
this.createSchema = createSchema;
|
||||
}
|
||||
|
||||
public Configuration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public void setConfiguration(final Configuration configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public MetadataImplementor getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public void setMetadata(final MetadataImplementor metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public StandardServiceRegistryImpl getServiceRegistry() {
|
||||
return serviceRegistry;
|
||||
}
|
||||
|
||||
public void setServiceRegistry(final StandardServiceRegistryImpl serviceRegistry) {
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
}
|
||||
|
||||
public Dialect getDialect() {
|
||||
return dialect;
|
||||
}
|
||||
|
||||
public void setDialect(final Dialect dialect) {
|
||||
this.dialect = dialect;
|
||||
}
|
||||
|
||||
public boolean isMetadataUsed() {
|
||||
return isMetadataUsed;
|
||||
}
|
||||
|
||||
public void setMetadataUsed(final boolean metadataUsed) {
|
||||
isMetadataUsed = metadataUsed;
|
||||
}
|
||||
//-------------------------------------- mappings
|
||||
private List<String> mappings = new ArrayList<String>();
|
||||
public List<String> getMappings() {
|
||||
return mappings;
|
||||
}
|
||||
|
||||
private List<Class> annotatedClasses = new ArrayList<Class>( );
|
||||
public List<Class> getAnnotatedClasses() {
|
||||
return annotatedClasses;
|
||||
}
|
||||
private List<String> annotatedPackages = new ArrayList<String>( );
|
||||
public List<String> getAnnotatedPackages() {
|
||||
return annotatedPackages;
|
||||
}
|
||||
private List<String> xmlFiles = new ArrayList<String>( );
|
||||
public List<String> getOrmXmlFiles() {
|
||||
return xmlFiles;
|
||||
}
|
||||
|
||||
public TestConfigurationHelper addAnnotatedClass(Class clazz){
|
||||
getAnnotatedClasses().add( clazz );
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestConfigurationHelper addAnnotatedPackage(String name){
|
||||
getAnnotatedPackages().add( name );
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestConfigurationHelper addMapping(String name){
|
||||
getMappings().add( name );
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestConfigurationHelper addOrmXmlFile(String name){
|
||||
getOrmXmlFiles().add( name );
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------- properties
|
||||
|
||||
public Properties getProperties() {
|
||||
if(properties == null){
|
||||
properties = constructProperties();
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
private Properties constructProperties() {
|
||||
Properties properties = new Properties();
|
||||
properties.put( Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName() );
|
||||
properties.put( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
properties.put( Environment.DIALECT, getDialect().getClass().getName() );
|
||||
if ( isCreateSchema() ) {
|
||||
properties.put( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
package org.hibernate.testing.junit4;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
|
||||
/**
|
||||
* @author Strong Liu <stliu@hibernate.org>
|
||||
*/
|
||||
public class TestServiceRegistryHelper {
|
||||
private static final DefaultCallback DEFAULT_REGISTERY_BUILDER_CALLBACK = new DefaultCallback();
|
||||
private final TestConfigurationHelper configuration;
|
||||
private StandardServiceRegistryImpl serviceRegistry;
|
||||
private BootstrapServiceRegistry bootstrapServiceRegistry;
|
||||
private Callback callback = DEFAULT_REGISTERY_BUILDER_CALLBACK;
|
||||
|
||||
public TestServiceRegistryHelper(final TestConfigurationHelper configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public TestConfigurationHelper getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public Callback getCallback() {
|
||||
return callback;
|
||||
}
|
||||
|
||||
public void setCallback(final Callback callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public BootstrapServiceRegistry buildBootstrapServiceRegistry() {
|
||||
final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
|
||||
getCallback().prepareBootstrapServiceRegistryBuilder( builder );
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public StandardServiceRegistryImpl getServiceRegistry() {
|
||||
if ( serviceRegistry == null ) {
|
||||
serviceRegistry = buildServiceRegistry( getBootstrapServiceRegistry() );
|
||||
}
|
||||
return serviceRegistry;
|
||||
}
|
||||
|
||||
public void setServiceRegistry(final StandardServiceRegistryImpl serviceRegistry) {
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
}
|
||||
|
||||
public BootstrapServiceRegistry getBootstrapServiceRegistry() {
|
||||
if ( bootstrapServiceRegistry == null ) {
|
||||
bootstrapServiceRegistry = buildBootstrapServiceRegistry();
|
||||
}
|
||||
return bootstrapServiceRegistry;
|
||||
}
|
||||
|
||||
|
||||
private StandardServiceRegistryImpl buildServiceRegistry(
|
||||
BootstrapServiceRegistry bootRegistry) {
|
||||
final Properties properties = getConfiguration().getProperties();
|
||||
Environment.verifyProperties( properties );
|
||||
ConfigurationHelper.resolvePlaceHolders( properties );
|
||||
|
||||
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder( bootRegistry ).applySettings(
|
||||
properties
|
||||
);
|
||||
getCallback().prepareStandardServiceRegistryBuilder( registryBuilder );
|
||||
|
||||
// TODO: StandardServiceRegistryBuilder#applySettings sets up the
|
||||
// Environment.URL property. Rather than rely on that, createH2Schema
|
||||
// could be refactored and this whole block put back in
|
||||
// BaseCoreFunctionalTestCase#constructProperties
|
||||
if ( getConfiguration().isCreateSchema() ) {
|
||||
registryBuilder.applySetting( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
final String secondSchemaName = getConfiguration().getSecondSchemaName();
|
||||
if ( StringHelper.isNotEmpty( secondSchemaName ) ) {
|
||||
if ( !( getConfiguration().getDialect() instanceof H2Dialect ) ) {
|
||||
throw new UnsupportedOperationException( "Only H2 dialect supports creation of second schema." );
|
||||
}
|
||||
Helper.createH2Schema( secondSchemaName, registryBuilder.getSettings() );
|
||||
}
|
||||
}
|
||||
|
||||
return (StandardServiceRegistryImpl) registryBuilder.build();
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if ( getServiceRegistry() != null ) {
|
||||
StandardServiceRegistryBuilder.destroy( getServiceRegistry() );
|
||||
setServiceRegistry( null );
|
||||
}
|
||||
if ( getBootstrapServiceRegistry() != null ) {
|
||||
bootstrapServiceRegistry = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static interface Callback {
|
||||
void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder);
|
||||
|
||||
void prepareBootstrapServiceRegistryBuilder(BootstrapServiceRegistryBuilder builder);
|
||||
}
|
||||
|
||||
public static class DefaultCallback implements Callback {
|
||||
@Override
|
||||
public void prepareBootstrapServiceRegistryBuilder(
|
||||
final BootstrapServiceRegistryBuilder builder) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareStandardServiceRegistryBuilder(
|
||||
final StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,344 @@
|
|||
package org.hibernate.testing.junit4;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.sql.Blob;
|
||||
import java.sql.Clob;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.EmptyInterceptor;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Mappings;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.mapping.Collection;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.mapping.SimpleValue;
|
||||
import org.hibernate.metamodel.MetadataBuilder;
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.metamodel.SessionFactoryBuilder;
|
||||
import org.hibernate.metamodel.spi.MetadataImplementor;
|
||||
import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.Caching;
|
||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* @author Strong Liu <stliu@hibernate.org>
|
||||
*/
|
||||
public class TestSessionFactoryHelper {
|
||||
|
||||
private SessionFactoryImplementor sessionFactory;
|
||||
private TestConfigurationHelper testConfiguration;
|
||||
private TestServiceRegistryHelper serviceRegistryHelper;
|
||||
private Callback callback = new CallbackImpl();
|
||||
|
||||
public TestSessionFactoryHelper(
|
||||
final TestServiceRegistryHelper serviceRegistryHelper, final TestConfigurationHelper testConfiguration) {
|
||||
this.serviceRegistryHelper = serviceRegistryHelper;
|
||||
this.testConfiguration = testConfiguration;
|
||||
}
|
||||
|
||||
public SessionFactoryImplementor getSessionFactory() {
|
||||
if ( sessionFactory == null || sessionFactory.isClosed() ) {
|
||||
destory();
|
||||
buildSessionFactory();
|
||||
}
|
||||
return sessionFactory;
|
||||
}
|
||||
|
||||
public TestServiceRegistryHelper getServiceRegistryHelper() {
|
||||
return serviceRegistryHelper;
|
||||
}
|
||||
|
||||
public void setServiceRegistryHelper(final TestServiceRegistryHelper serviceRegistryHelper) {
|
||||
this.serviceRegistryHelper = serviceRegistryHelper;
|
||||
}
|
||||
|
||||
public TestConfigurationHelper getTestConfiguration() {
|
||||
return testConfiguration;
|
||||
}
|
||||
|
||||
public void setTestConfiguration(final TestConfigurationHelper testConfiguration) {
|
||||
this.testConfiguration = testConfiguration;
|
||||
}
|
||||
|
||||
protected void configSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder, Configuration configuration) {
|
||||
if ( configuration.getEntityNotFoundDelegate() != null ) {
|
||||
sessionFactoryBuilder.with( configuration.getEntityNotFoundDelegate() );
|
||||
}
|
||||
if ( configuration.getSessionFactoryObserver() != null ){
|
||||
sessionFactoryBuilder.add( configuration.getSessionFactoryObserver() );
|
||||
}
|
||||
if ( configuration.getInterceptor() != EmptyInterceptor.INSTANCE ) {
|
||||
sessionFactoryBuilder.with( configuration.getInterceptor() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void buildSessionFactory() {
|
||||
Properties properties = getTestConfiguration().getProperties();
|
||||
|
||||
BootstrapServiceRegistry bootRegistry = getServiceRegistryHelper().getBootstrapServiceRegistry();
|
||||
|
||||
if ( getTestConfiguration().isMetadataUsed() ) {
|
||||
MetadataBuilder metadataBuilder = getMetadataBuilder(
|
||||
bootRegistry, getServiceRegistryHelper().getServiceRegistry()
|
||||
);
|
||||
getCallback().configure( metadataBuilder );
|
||||
MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();
|
||||
getCallback().afterMetadataBuilt( metadata );
|
||||
applyCacheSettings( metadata );
|
||||
getTestConfiguration().setMetadata( metadata );
|
||||
SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
|
||||
getCallback().configSessionFactoryBuilder( sessionFactoryBuilder );
|
||||
sessionFactory = (SessionFactoryImplementor) sessionFactoryBuilder.build();
|
||||
}
|
||||
else {
|
||||
Configuration configuration = constructAndConfigureConfiguration( properties );
|
||||
// this is done here because Configuration does not currently support 4.0 xsd
|
||||
afterConstructAndConfigureConfiguration( configuration );
|
||||
getTestConfiguration().setConfiguration( configuration );
|
||||
sessionFactory = (SessionFactoryImplementor) configuration.buildSessionFactory( getServiceRegistryHelper().getServiceRegistry() );
|
||||
}
|
||||
getCallback().afterSessionFactoryBuilt();
|
||||
}
|
||||
|
||||
// protected Configuration constructConfiguration() {
|
||||
// return new Configuration().setProperties( getTestConfiguration().getProperties() );
|
||||
// }
|
||||
|
||||
public static void applyCacheSettings(
|
||||
MetadataImplementor metadataImplementor, String strategy, boolean overrideCacheStrategy) {
|
||||
if ( StringHelper.isEmpty( strategy ) ) {
|
||||
return;
|
||||
}
|
||||
for ( EntityBinding entityBinding : metadataImplementor.getEntityBindings() ) {
|
||||
boolean hasLob = false;
|
||||
for ( AttributeBinding attributeBinding : entityBinding.getAttributeBindingClosure() ) {
|
||||
if ( attributeBinding.getAttribute().isSingular() ) {
|
||||
Type type = attributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping();
|
||||
String typeName = type.getName();
|
||||
if ( "blob".equals( typeName ) || "clob".equals( typeName ) ) {
|
||||
hasLob = true;
|
||||
}
|
||||
if ( Blob.class.getName().equals( typeName ) || Clob.class.getName().equals( typeName ) ) {
|
||||
hasLob = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !hasLob && entityBinding.getSuperEntityBinding() == null && overrideCacheStrategy ) {
|
||||
Caching caching = entityBinding.getHierarchyDetails().getCaching();
|
||||
if ( caching == null ) {
|
||||
caching = new Caching();
|
||||
}
|
||||
caching.setRegion( entityBinding.getEntity().getName() );
|
||||
caching.setCacheLazyProperties( true );
|
||||
caching.setAccessType( AccessType.fromExternalName( strategy ) );
|
||||
entityBinding.getHierarchyDetails().setCaching( caching );
|
||||
}
|
||||
for ( AttributeBinding attributeBinding : entityBinding.getAttributeBindingClosure() ) {
|
||||
if ( !attributeBinding.getAttribute().isSingular() ) {
|
||||
AbstractPluralAttributeBinding binding = AbstractPluralAttributeBinding.class.cast( attributeBinding );
|
||||
Caching caching = binding.getCaching();
|
||||
if ( caching == null ) {
|
||||
caching = new Caching();
|
||||
}
|
||||
caching.setRegion(
|
||||
StringHelper.qualify(
|
||||
entityBinding.getEntity().getName(),
|
||||
attributeBinding.getAttribute().getName()
|
||||
)
|
||||
);
|
||||
caching.setCacheLazyProperties( true );
|
||||
caching.setAccessType( AccessType.fromExternalName( strategy ) );
|
||||
binding.setCaching( caching );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void applyCacheSettings(MetadataImplementor metadataImplementor) {
|
||||
applyCacheSettings( metadataImplementor, getTestConfiguration().getCacheConcurrencyStrategy(), getTestConfiguration().isOverrideCacheStrategy() );
|
||||
}
|
||||
|
||||
protected void applyCacheSettings(Configuration configuration) {
|
||||
if ( getTestConfiguration().getCacheConcurrencyStrategy() != null ) {
|
||||
Iterator itr = configuration.getClassMappings();
|
||||
while ( itr.hasNext() ) {
|
||||
PersistentClass clazz = (PersistentClass) itr.next();
|
||||
Iterator props = clazz.getPropertyClosureIterator();
|
||||
boolean hasLob = false;
|
||||
while ( props.hasNext() ) {
|
||||
Property prop = (Property) props.next();
|
||||
if ( prop.getValue().isSimpleValue() ) {
|
||||
String type = ( (SimpleValue) prop.getValue() ).getTypeName();
|
||||
if ( "blob".equals( type ) || "clob".equals( type ) ) {
|
||||
hasLob = true;
|
||||
}
|
||||
if ( Blob.class.getName().equals( type ) || Clob.class.getName().equals( type ) ) {
|
||||
hasLob = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !hasLob && !clazz.isInherited() && getTestConfiguration().isOverrideCacheStrategy() ) {
|
||||
configuration.setCacheConcurrencyStrategy( clazz.getEntityName(), getTestConfiguration().getCacheConcurrencyStrategy() );
|
||||
}
|
||||
}
|
||||
itr = configuration.getCollectionMappings();
|
||||
while ( itr.hasNext() ) {
|
||||
Collection coll = (Collection) itr.next();
|
||||
configuration.setCollectionCacheConcurrencyStrategy( coll.getRole(), getTestConfiguration().getCacheConcurrencyStrategy() );
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void afterConfigurationBuilt(Configuration configuration) {
|
||||
getCallback().afterConfigurationBuilt( configuration.createMappings(), getTestConfiguration().getDialect() );
|
||||
}
|
||||
|
||||
private Configuration constructAndConfigureConfiguration(Properties properties) {
|
||||
Configuration cfg = new Configuration().setProperties( properties );
|
||||
getCallback().configure( cfg );
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private void afterConstructAndConfigureConfiguration(Configuration cfg) {
|
||||
addMappings( cfg );
|
||||
cfg.buildMappings();
|
||||
applyCacheSettings( cfg );
|
||||
afterConfigurationBuilt( cfg );
|
||||
}
|
||||
|
||||
|
||||
protected MetadataBuilder getMetadataBuilder(
|
||||
BootstrapServiceRegistry bootRegistry, StandardServiceRegistryImpl serviceRegistry) {
|
||||
MetadataSources sources = new MetadataSources( bootRegistry );
|
||||
addMappings( sources );
|
||||
return sources.getMetadataBuilder( serviceRegistry );
|
||||
}
|
||||
|
||||
//----------------------- source mappings
|
||||
public void addMappings(Configuration configuration) {
|
||||
List<String> mappings = getTestConfiguration().getMappings();
|
||||
if ( mappings != null ) {
|
||||
for ( String mapping : mappings ) {
|
||||
configuration.addResource(
|
||||
mapping, getClass().getClassLoader()
|
||||
);
|
||||
}
|
||||
}
|
||||
List<Class> annotatedClasses = getTestConfiguration().getAnnotatedClasses();
|
||||
if ( annotatedClasses != null ) {
|
||||
for ( Class<?> annotatedClass : annotatedClasses ) {
|
||||
configuration.addAnnotatedClass( annotatedClass );
|
||||
}
|
||||
}
|
||||
List<String> annotatedPackages = getTestConfiguration().getAnnotatedPackages();
|
||||
if ( annotatedPackages != null ) {
|
||||
for ( String annotatedPackage : annotatedPackages ) {
|
||||
configuration.addPackage( annotatedPackage );
|
||||
}
|
||||
}
|
||||
List<String> xmlFiles = getTestConfiguration().getOrmXmlFiles();
|
||||
if ( xmlFiles != null ) {
|
||||
for ( String xmlFile : xmlFiles ) {
|
||||
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile );
|
||||
configuration.addInputStream( is );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addMappings(MetadataSources sources) {
|
||||
List<String> mappings = getTestConfiguration().getMappings();
|
||||
if ( mappings != null ) {
|
||||
for ( String mapping : mappings ) {
|
||||
sources.addResource( mapping );
|
||||
}
|
||||
}
|
||||
List<Class> annotatedClasses = getTestConfiguration().getAnnotatedClasses();
|
||||
if ( annotatedClasses != null ) {
|
||||
for ( Class<?> annotatedClass : annotatedClasses ) {
|
||||
sources.addAnnotatedClass( annotatedClass );
|
||||
}
|
||||
}
|
||||
List<String> annotatedPackages = getTestConfiguration().getAnnotatedPackages();
|
||||
if ( annotatedPackages != null ) {
|
||||
for ( String annotatedPackage : annotatedPackages ) {
|
||||
sources.addPackage( annotatedPackage );
|
||||
}
|
||||
}
|
||||
List<String> xmlFiles = getTestConfiguration().getOrmXmlFiles();
|
||||
if ( xmlFiles != null ) {
|
||||
for ( String xmlFile : xmlFiles ) {
|
||||
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile );
|
||||
sources.addInputStream( is );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void destory() {
|
||||
if ( sessionFactory == null ) {
|
||||
return;
|
||||
}
|
||||
sessionFactory.close();
|
||||
sessionFactory = null;
|
||||
}
|
||||
|
||||
public Callback getCallback() {
|
||||
return callback;
|
||||
}
|
||||
|
||||
public TestSessionFactoryHelper setCallback(final Callback callback) {
|
||||
this.callback = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static interface Callback {
|
||||
void afterMetadataBuilt(MetadataImplementor metadataImplementor);
|
||||
|
||||
void configure(MetadataBuilder metadataBuilder);
|
||||
|
||||
void configSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder);
|
||||
|
||||
void afterSessionFactoryBuilt();
|
||||
|
||||
void configure(Configuration configuration);
|
||||
void afterConfigurationBuilt(Mappings mappings, Dialect dialect);
|
||||
}
|
||||
|
||||
public static class CallbackImpl implements Callback {
|
||||
@Override
|
||||
public void afterMetadataBuilt(final MetadataImplementor metadataImplementor) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void configSessionFactoryBuilder(final SessionFactoryBuilder sessionFactoryBuilder) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterSessionFactoryBuilt() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(final Configuration configuration) {
|
||||
}
|
||||
@Override
|
||||
public void configure(final MetadataBuilder metadataBuilder) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterConfigurationBuilt(final Mappings mappings, final Dialect dialect) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue