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