HHH-5942 - Migrate to JUnit 4

This commit is contained in:
Steve Ebersole 2011-03-12 14:47:55 -06:00
parent ed882f68ae
commit 20a120ef6c
119 changed files with 1528 additions and 1290 deletions

View File

@ -907,7 +907,7 @@ public final class SessionFactoryImpl
* <li>remove the JNDI binding * <li>remove the JNDI binding
* </ol> * </ol>
* *
* Note: Be aware that the sessionfactory instance still can * Note: Be aware that the sessionFactory instance still can
* be a "heavy" object memory wise after close() has been called. Thus * be a "heavy" object memory wise after close() has been called. Thus
* it is important to not keep referencing the instance to let the garbage * it is important to not keep referencing the instance to let the garbage
* collector release the memory. * collector release the memory.

View File

@ -23,13 +23,6 @@
*/ */
package org.hibernate.test.annotations.reflection; package org.hibernate.test.annotations.reflection;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.AssociationOverrides; import javax.persistence.AssociationOverrides;
import javax.persistence.AttributeOverrides; import javax.persistence.AttributeOverrides;
import javax.persistence.Basic; import javax.persistence.Basic;
@ -77,48 +70,41 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.Transient; import javax.persistence.Transient;
import javax.persistence.Version; import javax.persistence.Version;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader; import org.dom4j.io.SAXReader;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotSupportedException;
import org.hibernate.annotations.Columns; import org.hibernate.annotations.Columns;
import org.hibernate.cfg.EJB3DTDEntityResolver; import org.hibernate.cfg.EJB3DTDEntityResolver;
import org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader; import org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader;
import org.hibernate.cfg.annotations.reflection.XMLContext; import org.hibernate.cfg.annotations.reflection.XMLContext;
import org.hibernate.internal.util.xml.XMLHelper; import org.hibernate.internal.util.xml.XMLHelper;
import org.hibernate.testing.junit.functional.annotations.HibernateTestCase;
import org.xml.sax.InputSource; import org.junit.Test;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotSupportedException; import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class JPAOverridenAnnotationReaderTest extends HibernateTestCase { public class JPAOverridenAnnotationReaderTest extends BaseUnitTestCase {
@Test
@Override
protected void buildConfiguration() throws Exception {
//Do nothing
}
@Override
protected void runSchemaGeneration() {
//Do nothing
}
@Override
protected void runSchemaDrop() {
//Do nothing
}
@Override
protected void handleUnclosedResources() {
//Do nothing
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[0];
}
public void testMappedSuperclassAnnotations() throws Exception { public void testMappedSuperclassAnnotations() throws Exception {
XMLContext context = buildContext( XMLContext context = buildContext(
"org/hibernate/test/annotations/reflection/metadata-complete.xml" "org/hibernate/test/annotations/reflection/metadata-complete.xml"
@ -127,6 +113,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
assertTrue( reader.isAnnotationPresent( MappedSuperclass.class ) ); assertTrue( reader.isAnnotationPresent( MappedSuperclass.class ) );
} }
@Test
public void testEntityRelatedAnnotations() throws Exception { public void testEntityRelatedAnnotations() throws Exception {
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" ); XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
JPAOverridenAnnotationReader reader = new JPAOverridenAnnotationReader( Administration.class, context ); JPAOverridenAnnotationReader reader = new JPAOverridenAnnotationReader( Administration.class, context );
@ -257,6 +244,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
); );
} }
@Test
public void testEntityRelatedAnnotationsMetadataComplete() throws Exception { public void testEntityRelatedAnnotationsMetadataComplete() throws Exception {
XMLContext context = buildContext( XMLContext context = buildContext(
"org/hibernate/test/annotations/reflection/metadata-complete.xml" "org/hibernate/test/annotations/reflection/metadata-complete.xml"
@ -296,6 +284,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
assertNull( reader.getAnnotation( TableGenerator.class ) ); assertNull( reader.getAnnotation( TableGenerator.class ) );
} }
@Test
public void testIdRelatedAnnotations() throws Exception { public void testIdRelatedAnnotations() throws Exception {
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" ); XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
Method method = Administration.class.getDeclaredMethod( "getId" ); Method method = Administration.class.getDeclaredMethod( "getId" );
@ -342,6 +331,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
assertEquals( 1, reader.getAnnotation( AttributeOverrides.class ).value().length ); assertEquals( 1, reader.getAnnotation( AttributeOverrides.class ).value().length );
} }
@Test
public void testBasicRelatedAnnotations() throws Exception { public void testBasicRelatedAnnotations() throws Exception {
XMLContext context = buildContext( XMLContext context = buildContext(
"org/hibernate/test/annotations/reflection/metadata-complete.xml" "org/hibernate/test/annotations/reflection/metadata-complete.xml"
@ -366,6 +356,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
assertNotNull( reader.isAnnotationPresent( Basic.class ) ); assertNotNull( reader.isAnnotationPresent( Basic.class ) );
} }
@Test
public void testVersionRelatedAnnotations() throws Exception { public void testVersionRelatedAnnotations() throws Exception {
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" ); XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
Method method = Administration.class.getDeclaredMethod( "getVersion" ); Method method = Administration.class.getDeclaredMethod( "getVersion" );
@ -377,6 +368,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
assertNotNull( reader.getAnnotation( Version.class ) ); assertNotNull( reader.getAnnotation( Version.class ) );
} }
@Test
public void testTransientAndEmbeddedRelatedAnnotations() throws Exception { public void testTransientAndEmbeddedRelatedAnnotations() throws Exception {
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" ); XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
@ -390,6 +382,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
assertNotNull( reader.getAnnotation( Embedded.class ) ); assertNotNull( reader.getAnnotation( Embedded.class ) );
} }
@Test
public void testAssociationRelatedAnnotations() throws Exception { public void testAssociationRelatedAnnotations() throws Exception {
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" ); XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
@ -427,6 +420,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
assertEquals( "maxSpeed", reader.getAnnotation( OrderBy.class ).value() ); assertEquals( "maxSpeed", reader.getAnnotation( OrderBy.class ).value() );
} }
@Test
public void testEntityListeners() throws Exception { public void testEntityListeners() throws Exception {
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" ); XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );

View File

@ -23,6 +23,7 @@
*/ */
package org.hibernate.test.annotations.xml.ejb3; package org.hibernate.test.annotations.xml.ejb3;
import javax.persistence.Access; import javax.persistence.Access;
import javax.persistence.AccessType; import javax.persistence.AccessType;
import javax.persistence.AssociationOverride; import javax.persistence.AssociationOverride;
@ -51,8 +52,14 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase { import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
@Test
public void testNoChildren() throws Exception { public void testNoChildren() throws Exception {
reader = getReader( Entity2.class, "field1", "element-collection.orm1.xml" ); reader = getReader( Entity2.class, "field1", "element-collection.orm1.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -80,6 +87,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
assertEquals( void.class, relAnno.targetClass() ); assertEquals( void.class, relAnno.targetClass() );
} }
@Test
public void testOrderBy() throws Exception { public void testOrderBy() throws Exception {
reader = getReader( Entity2.class, "field1", "element-collection.orm2.xml" ); reader = getReader( Entity2.class, "field1", "element-collection.orm2.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -91,6 +99,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
); );
} }
@Test
public void testOrderColumnNoAttributes() throws Exception { public void testOrderColumnNoAttributes() throws Exception {
reader = getReader( Entity2.class, "field1", "element-collection.orm3.xml" ); reader = getReader( Entity2.class, "field1", "element-collection.orm3.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -104,6 +113,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
assertTrue( orderColumnAnno.updatable() ); assertTrue( orderColumnAnno.updatable() );
} }
@Test
public void testOrderColumnAllAttributes() throws Exception { public void testOrderColumnAllAttributes() throws Exception {
reader = getReader( Entity2.class, "field1", "element-collection.orm4.xml" ); reader = getReader( Entity2.class, "field1", "element-collection.orm4.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -117,6 +127,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
assertFalse( orderColumnAnno.updatable() ); assertFalse( orderColumnAnno.updatable() );
} }
@Test
public void testMapKeyNoAttributes() throws Exception { public void testMapKeyNoAttributes() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm5.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm5.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -130,6 +141,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
assertEquals( "", reader.getAnnotation( MapKey.class ).name() ); assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
} }
@Test
public void testMapKeyAllAttributes() throws Exception { public void testMapKeyAllAttributes() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm6.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm6.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -143,6 +155,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() ); assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
} }
@Test
public void testMapKeyClass() throws Exception { public void testMapKeyClass() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm7.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm7.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -159,6 +172,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
); );
} }
@Test
public void testMapKeyTemporal() throws Exception { public void testMapKeyTemporal() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm8.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm8.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -176,6 +190,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
); );
} }
@Test
public void testMapKeyEnumerated() throws Exception { public void testMapKeyEnumerated() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm9.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm9.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -197,6 +212,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
* When there's a single map key attribute override, we still wrap it with * When there's a single map key attribute override, we still wrap it with
* an AttributeOverrides annotation. * an AttributeOverrides annotation.
*/ */
@Test
public void testSingleMapKeyAttributeOverride() throws Exception { public void testSingleMapKeyAttributeOverride() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm10.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm10.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -217,6 +233,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
assertEquals( "col1", overrides[0].column().name() ); assertEquals( "col1", overrides[0].column().name() );
} }
@Test
public void testMultipleMapKeyAttributeOverrides() throws Exception { public void testMultipleMapKeyAttributeOverrides() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm11.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm11.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -257,6 +274,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
assertEquals( 1, overrides[1].column().scale() ); assertEquals( 1, overrides[1].column().scale() );
} }
@Test
public void testMapKeyColumnNoAttributes() throws Exception { public void testMapKeyColumnNoAttributes() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm12.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm12.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -280,6 +298,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
assertEquals( 0, keyColAnno.scale() ); assertEquals( 0, keyColAnno.scale() );
} }
@Test
public void testMapKeyColumnAllAttributes() throws Exception { public void testMapKeyColumnAllAttributes() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm13.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm13.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -307,6 +326,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
* When there's a single map key join column, we still wrap it with a * When there's a single map key join column, we still wrap it with a
* MapKeyJoinColumns annotation. * MapKeyJoinColumns annotation.
*/ */
@Test
public void testSingleMapKeyJoinColumn() throws Exception { public void testSingleMapKeyJoinColumn() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm14.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm14.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -324,6 +344,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
assertEquals( "col1", joinColumns[0].name() ); assertEquals( "col1", joinColumns[0].name() );
} }
@Test
public void testMultipleMapKeyJoinColumns() throws Exception { public void testMultipleMapKeyJoinColumns() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm15.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm15.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -356,6 +377,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
assertEquals( "table1", joinColumns[1].table() ); assertEquals( "table1", joinColumns[1].table() );
} }
@Test
public void testColumnNoAttributes() throws Exception { public void testColumnNoAttributes() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm16.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm16.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -373,6 +395,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
assertEquals( 0, column.scale() ); assertEquals( 0, column.scale() );
} }
@Test
public void testColumnAllAttributes() throws Exception { public void testColumnAllAttributes() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm17.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm17.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -390,6 +413,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
assertEquals( 1, column.scale() ); assertEquals( 1, column.scale() );
} }
@Test
public void testTemporal() throws Exception { public void testTemporal() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm18.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm18.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -403,6 +427,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
); );
} }
@Test
public void testEnumerated() throws Exception { public void testEnumerated() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm19.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm19.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -416,6 +441,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
); );
} }
@Test
public void testLob() throws Exception { public void testLob() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm20.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm20.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -428,6 +454,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
* When there's a single attribute override, we still wrap it with an * When there's a single attribute override, we still wrap it with an
* AttributeOverrides annotation. * AttributeOverrides annotation.
*/ */
@Test
public void testSingleAttributeOverride() throws Exception { public void testSingleAttributeOverride() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm21.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm21.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -441,6 +468,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
assertEquals( "col1", overrides[0].column().name() ); assertEquals( "col1", overrides[0].column().name() );
} }
@Test
public void testMultipleAttributeOverrides() throws Exception { public void testMultipleAttributeOverrides() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm22.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm22.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -478,6 +506,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
* Tests that map-key-attribute-override and attribute-override elements * Tests that map-key-attribute-override and attribute-override elements
* both end up in the AttributeOverrides annotation. * both end up in the AttributeOverrides annotation.
*/ */
@Test
public void testMixedAttributeOverrides() throws Exception { public void testMixedAttributeOverrides() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm23.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm23.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -497,6 +526,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
* When there's a single association override, we still wrap it with an * When there's a single association override, we still wrap it with an
* AssociationOverrides annotation. * AssociationOverrides annotation.
*/ */
@Test
public void testSingleAssociationOverride() throws Exception { public void testSingleAssociationOverride() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm24.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm24.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -510,6 +540,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
assertEquals( "", overrides[0].joinTable().name() ); assertEquals( "", overrides[0].joinTable().name() );
} }
@Test
public void testMultipleAssociationOverridesJoinColumns() throws Exception { public void testMultipleAssociationOverridesJoinColumns() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm25.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm25.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -603,6 +634,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
assertTrue( joinColumns[1].unique() ); assertTrue( joinColumns[1].unique() );
} }
@Test
public void testCollectionTableNoChildren() throws Exception { public void testCollectionTableNoChildren() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm26.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm26.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -615,6 +647,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
assertEquals( 0, tableAnno.uniqueConstraints().length ); assertEquals( 0, tableAnno.uniqueConstraints().length );
} }
@Test
public void testCollectionTableAllChildren() throws Exception { public void testCollectionTableAllChildren() throws Exception {
reader = getReader( Entity3.class, "field1", "element-collection.orm27.xml" ); reader = getReader( Entity3.class, "field1", "element-collection.orm27.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );
@ -656,6 +689,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
assertEquals( "col5", uniqueConstraints[1].columnNames()[1] ); assertEquals( "col5", uniqueConstraints[1].columnNames()[1] );
} }
@Test
public void testAllAttributes() throws Exception { public void testAllAttributes() throws Exception {
reader = getReader( Entity2.class, "field1", "element-collection.orm28.xml" ); reader = getReader( Entity2.class, "field1", "element-collection.orm28.xml" );
assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( ElementCollection.class );

View File

@ -21,8 +21,8 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.annotations.xml.ejb3; package org.hibernate.test.annotations.xml.ejb3;
import javax.persistence.Access; import javax.persistence.Access;
import javax.persistence.AccessType; import javax.persistence.AccessType;
import javax.persistence.AttributeOverride; import javax.persistence.AttributeOverride;
@ -46,8 +46,14 @@ import javax.persistence.OrderColumn;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase { import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
@Test
public void testNoChildren() throws Exception { public void testNoChildren() throws Exception {
reader = getReader( Entity2.class, "field1", "many-to-many.orm1.xml" ); reader = getReader( Entity2.class, "field1", "many-to-many.orm1.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -69,6 +75,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
assertEquals( void.class, relAnno.targetEntity() ); assertEquals( void.class, relAnno.targetEntity() );
} }
@Test
public void testOrderBy() throws Exception { public void testOrderBy() throws Exception {
reader = getReader( Entity2.class, "field1", "many-to-many.orm2.xml" ); reader = getReader( Entity2.class, "field1", "many-to-many.orm2.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -80,6 +87,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
); );
} }
@Test
public void testOrderColumnNoAttributes() throws Exception { public void testOrderColumnNoAttributes() throws Exception {
reader = getReader( Entity2.class, "field1", "many-to-many.orm3.xml" ); reader = getReader( Entity2.class, "field1", "many-to-many.orm3.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -93,6 +101,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
assertTrue( orderColumnAnno.updatable() ); assertTrue( orderColumnAnno.updatable() );
} }
@Test
public void testOrderColumnAllAttributes() throws Exception { public void testOrderColumnAllAttributes() throws Exception {
reader = getReader( Entity2.class, "field1", "many-to-many.orm4.xml" ); reader = getReader( Entity2.class, "field1", "many-to-many.orm4.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -106,6 +115,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
assertFalse( orderColumnAnno.updatable() ); assertFalse( orderColumnAnno.updatable() );
} }
@Test
public void testMapKeyNoAttributes() throws Exception { public void testMapKeyNoAttributes() throws Exception {
reader = getReader( Entity3.class, "field1", "many-to-many.orm5.xml" ); reader = getReader( Entity3.class, "field1", "many-to-many.orm5.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -119,6 +129,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
assertEquals( "", reader.getAnnotation( MapKey.class ).name() ); assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
} }
@Test
public void testMapKeyAllAttributes() throws Exception { public void testMapKeyAllAttributes() throws Exception {
reader = getReader( Entity3.class, "field1", "many-to-many.orm6.xml" ); reader = getReader( Entity3.class, "field1", "many-to-many.orm6.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -132,6 +143,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() ); assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
} }
@Test
public void testMapKeyClass() throws Exception { public void testMapKeyClass() throws Exception {
reader = getReader( Entity3.class, "field1", "many-to-many.orm7.xml" ); reader = getReader( Entity3.class, "field1", "many-to-many.orm7.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -148,6 +160,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
); );
} }
@Test
public void testMapKeyTemporal() throws Exception { public void testMapKeyTemporal() throws Exception {
reader = getReader( Entity3.class, "field1", "many-to-many.orm8.xml" ); reader = getReader( Entity3.class, "field1", "many-to-many.orm8.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -165,6 +178,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
); );
} }
@Test
public void testMapKeyEnumerated() throws Exception { public void testMapKeyEnumerated() throws Exception {
reader = getReader( Entity3.class, "field1", "many-to-many.orm9.xml" ); reader = getReader( Entity3.class, "field1", "many-to-many.orm9.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -186,6 +200,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
* When there's a single map key attribute override, we still wrap it with * When there's a single map key attribute override, we still wrap it with
* an AttributeOverrides annotation. * an AttributeOverrides annotation.
*/ */
@Test
public void testSingleMapKeyAttributeOverride() throws Exception { public void testSingleMapKeyAttributeOverride() throws Exception {
reader = getReader( Entity3.class, "field1", "many-to-many.orm10.xml" ); reader = getReader( Entity3.class, "field1", "many-to-many.orm10.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -206,6 +221,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
assertEquals( "col1", overrides[0].column().name() ); assertEquals( "col1", overrides[0].column().name() );
} }
@Test
public void testMultipleMapKeyAttributeOverrides() throws Exception { public void testMultipleMapKeyAttributeOverrides() throws Exception {
reader = getReader( Entity3.class, "field1", "many-to-many.orm11.xml" ); reader = getReader( Entity3.class, "field1", "many-to-many.orm11.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -246,6 +262,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
assertEquals( 1, overrides[1].column().scale() ); assertEquals( 1, overrides[1].column().scale() );
} }
@Test
public void testMapKeyColumnNoAttributes() throws Exception { public void testMapKeyColumnNoAttributes() throws Exception {
reader = getReader( Entity3.class, "field1", "many-to-many.orm12.xml" ); reader = getReader( Entity3.class, "field1", "many-to-many.orm12.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -269,6 +286,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
assertEquals( 0, keyColAnno.scale() ); assertEquals( 0, keyColAnno.scale() );
} }
@Test
public void testMapKeyColumnAllAttributes() throws Exception { public void testMapKeyColumnAllAttributes() throws Exception {
reader = getReader( Entity3.class, "field1", "many-to-many.orm13.xml" ); reader = getReader( Entity3.class, "field1", "many-to-many.orm13.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -296,6 +314,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
* When there's a single map key join column, we still wrap it with a * When there's a single map key join column, we still wrap it with a
* MapKeyJoinColumns annotation. * MapKeyJoinColumns annotation.
*/ */
@Test
public void testSingleMapKeyJoinColumn() throws Exception { public void testSingleMapKeyJoinColumn() throws Exception {
reader = getReader( Entity3.class, "field1", "many-to-many.orm14.xml" ); reader = getReader( Entity3.class, "field1", "many-to-many.orm14.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -313,6 +332,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
assertEquals( "col1", joinColumns[0].name() ); assertEquals( "col1", joinColumns[0].name() );
} }
@Test
public void testMultipleMapKeyJoinColumns() throws Exception { public void testMultipleMapKeyJoinColumns() throws Exception {
reader = getReader( Entity3.class, "field1", "many-to-many.orm15.xml" ); reader = getReader( Entity3.class, "field1", "many-to-many.orm15.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -345,6 +365,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
assertEquals( "table1", joinColumns[1].table() ); assertEquals( "table1", joinColumns[1].table() );
} }
@Test
public void testJoinTableNoChildren() throws Exception { public void testJoinTableNoChildren() throws Exception {
reader = getReader( Entity2.class, "field1", "many-to-many.orm16.xml" ); reader = getReader( Entity2.class, "field1", "many-to-many.orm16.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -360,6 +381,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
assertEquals( 0, joinTableAnno.uniqueConstraints().length ); assertEquals( 0, joinTableAnno.uniqueConstraints().length );
} }
@Test
public void testJoinTableAllChildren() throws Exception { public void testJoinTableAllChildren() throws Exception {
reader = getReader( Entity2.class, "field1", "many-to-many.orm17.xml" ); reader = getReader( Entity2.class, "field1", "many-to-many.orm17.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -424,6 +446,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] ); assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
} }
@Test
public void testCascadeAll() throws Exception { public void testCascadeAll() throws Exception {
reader = getReader( Entity2.class, "field1", "many-to-many.orm18.xml" ); reader = getReader( Entity2.class, "field1", "many-to-many.orm18.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -432,6 +455,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
assertEquals( CascadeType.ALL, relAnno.cascade()[0] ); assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
} }
@Test
public void testCascadeSomeWithDefaultPersist() throws Exception { public void testCascadeSomeWithDefaultPersist() throws Exception {
reader = getReader( Entity2.class, "field1", "many-to-many.orm19.xml" ); reader = getReader( Entity2.class, "field1", "many-to-many.orm19.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -448,6 +472,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
* is specified in addition to a default cascade-persist or individual * is specified in addition to a default cascade-persist or individual
* cascade settings. * cascade settings.
*/ */
@Test
public void testCascadeAllPlusMore() throws Exception { public void testCascadeAllPlusMore() throws Exception {
reader = getReader( Entity2.class, "field1", "many-to-many.orm20.xml" ); reader = getReader( Entity2.class, "field1", "many-to-many.orm20.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );
@ -461,6 +486,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] ); assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
} }
@Test
public void testAllAttributes() throws Exception { public void testAllAttributes() throws Exception {
reader = getReader( Entity2.class, "field1", "many-to-many.orm21.xml" ); reader = getReader( Entity2.class, "field1", "many-to-many.orm21.xml" );
assertAnnotationPresent( ManyToMany.class ); assertAnnotationPresent( ManyToMany.class );

View File

@ -21,8 +21,8 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.annotations.xml.ejb3; package org.hibernate.test.annotations.xml.ejb3;
import javax.persistence.Access; import javax.persistence.Access;
import javax.persistence.AccessType; import javax.persistence.AccessType;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
@ -35,8 +35,14 @@ import javax.persistence.ManyToOne;
import javax.persistence.MapsId; import javax.persistence.MapsId;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase { import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
@Test
public void testNoJoins() throws Exception { public void testNoJoins() throws Exception {
reader = getReader( Entity1.class, "field1", "many-to-one.orm1.xml" ); reader = getReader( Entity1.class, "field1", "many-to-one.orm1.xml" );
assertAnnotationPresent( ManyToOne.class ); assertAnnotationPresent( ManyToOne.class );
@ -57,6 +63,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
* When there's a single join column, we still wrap it with a JoinColumns * When there's a single join column, we still wrap it with a JoinColumns
* annotation. * annotation.
*/ */
@Test
public void testSingleJoinColumn() throws Exception { public void testSingleJoinColumn() throws Exception {
reader = getReader( Entity1.class, "field1", "many-to-one.orm2.xml" ); reader = getReader( Entity1.class, "field1", "many-to-one.orm2.xml" );
assertAnnotationPresent( ManyToOne.class ); assertAnnotationPresent( ManyToOne.class );
@ -71,6 +78,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
assertEquals( "table1", joinColumns[0].table() ); assertEquals( "table1", joinColumns[0].table() );
} }
@Test
public void testMultipleJoinColumns() throws Exception { public void testMultipleJoinColumns() throws Exception {
reader = getReader( Entity1.class, "field1", "many-to-one.orm3.xml" ); reader = getReader( Entity1.class, "field1", "many-to-one.orm3.xml" );
assertAnnotationPresent( ManyToOne.class ); assertAnnotationPresent( ManyToOne.class );
@ -98,6 +106,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
assertTrue( joinColumns[1].unique() ); assertTrue( joinColumns[1].unique() );
} }
@Test
public void testJoinTableNoChildren() throws Exception { public void testJoinTableNoChildren() throws Exception {
reader = getReader( Entity1.class, "field1", "many-to-one.orm4.xml" ); reader = getReader( Entity1.class, "field1", "many-to-one.orm4.xml" );
assertAnnotationPresent( ManyToOne.class ); assertAnnotationPresent( ManyToOne.class );
@ -113,6 +122,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
assertEquals( 0, joinTableAnno.uniqueConstraints().length ); assertEquals( 0, joinTableAnno.uniqueConstraints().length );
} }
@Test
public void testJoinTableAllChildren() throws Exception { public void testJoinTableAllChildren() throws Exception {
reader = getReader( Entity1.class, "field1", "many-to-one.orm5.xml" ); reader = getReader( Entity1.class, "field1", "many-to-one.orm5.xml" );
assertAnnotationPresent( ManyToOne.class ); assertAnnotationPresent( ManyToOne.class );
@ -177,6 +187,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] ); assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
} }
@Test
public void testAllAttributes() throws Exception { public void testAllAttributes() throws Exception {
reader = getReader( Entity1.class, "field1", "many-to-one.orm6.xml" ); reader = getReader( Entity1.class, "field1", "many-to-one.orm6.xml" );
assertAnnotationPresent( ManyToOne.class ); assertAnnotationPresent( ManyToOne.class );
@ -198,6 +209,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
); );
} }
@Test
public void testCascadeAll() throws Exception { public void testCascadeAll() throws Exception {
reader = getReader( Entity1.class, "field1", "many-to-one.orm7.xml" ); reader = getReader( Entity1.class, "field1", "many-to-one.orm7.xml" );
assertAnnotationPresent( ManyToOne.class ); assertAnnotationPresent( ManyToOne.class );
@ -206,6 +218,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
assertEquals( CascadeType.ALL, relAnno.cascade()[0] ); assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
} }
@Test
public void testCascadeSomeWithDefaultPersist() throws Exception { public void testCascadeSomeWithDefaultPersist() throws Exception {
reader = getReader( Entity1.class, "field1", "many-to-one.orm8.xml" ); reader = getReader( Entity1.class, "field1", "many-to-one.orm8.xml" );
assertAnnotationPresent( ManyToOne.class ); assertAnnotationPresent( ManyToOne.class );
@ -222,6 +235,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
* is specified in addition to a default cascade-persist or individual * is specified in addition to a default cascade-persist or individual
* cascade settings. * cascade settings.
*/ */
@Test
public void testCascadeAllPlusMore() throws Exception { public void testCascadeAllPlusMore() throws Exception {
reader = getReader( Entity1.class, "field1", "many-to-one.orm9.xml" ); reader = getReader( Entity1.class, "field1", "many-to-one.orm9.xml" );
assertAnnotationPresent( ManyToOne.class ); assertAnnotationPresent( ManyToOne.class );

View File

@ -21,8 +21,8 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.annotations.xml.ejb3; package org.hibernate.test.annotations.xml.ejb3;
import javax.persistence.Access; import javax.persistence.Access;
import javax.persistence.AccessType; import javax.persistence.AccessType;
import javax.persistence.AttributeOverride; import javax.persistence.AttributeOverride;
@ -46,8 +46,14 @@ import javax.persistence.OrderColumn;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase { import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
@Test
public void testNoChildren() throws Exception { public void testNoChildren() throws Exception {
reader = getReader( Entity2.class, "field1", "one-to-many.orm1.xml" ); reader = getReader( Entity2.class, "field1", "one-to-many.orm1.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -72,6 +78,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
assertEquals( void.class, relAnno.targetEntity() ); assertEquals( void.class, relAnno.targetEntity() );
} }
@Test
public void testOrderBy() throws Exception { public void testOrderBy() throws Exception {
reader = getReader( Entity2.class, "field1", "one-to-many.orm2.xml" ); reader = getReader( Entity2.class, "field1", "one-to-many.orm2.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -83,6 +90,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
); );
} }
@Test
public void testOrderColumnNoAttributes() throws Exception { public void testOrderColumnNoAttributes() throws Exception {
reader = getReader( Entity2.class, "field1", "one-to-many.orm3.xml" ); reader = getReader( Entity2.class, "field1", "one-to-many.orm3.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -96,6 +104,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
assertTrue( orderColumnAnno.updatable() ); assertTrue( orderColumnAnno.updatable() );
} }
@Test
public void testOrderColumnAllAttributes() throws Exception { public void testOrderColumnAllAttributes() throws Exception {
reader = getReader( Entity2.class, "field1", "one-to-many.orm4.xml" ); reader = getReader( Entity2.class, "field1", "one-to-many.orm4.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -109,6 +118,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
assertFalse( orderColumnAnno.updatable() ); assertFalse( orderColumnAnno.updatable() );
} }
@Test
public void testMapKeyNoAttributes() throws Exception { public void testMapKeyNoAttributes() throws Exception {
reader = getReader( Entity3.class, "field1", "one-to-many.orm5.xml" ); reader = getReader( Entity3.class, "field1", "one-to-many.orm5.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -122,6 +132,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
assertEquals( "", reader.getAnnotation( MapKey.class ).name() ); assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
} }
@Test
public void testMapKeyAllAttributes() throws Exception { public void testMapKeyAllAttributes() throws Exception {
reader = getReader( Entity3.class, "field1", "one-to-many.orm6.xml" ); reader = getReader( Entity3.class, "field1", "one-to-many.orm6.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -135,6 +146,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() ); assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
} }
@Test
public void testMapKeyClass() throws Exception { public void testMapKeyClass() throws Exception {
reader = getReader( Entity3.class, "field1", "one-to-many.orm7.xml" ); reader = getReader( Entity3.class, "field1", "one-to-many.orm7.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -151,6 +163,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
); );
} }
@Test
public void testMapKeyTemporal() throws Exception { public void testMapKeyTemporal() throws Exception {
reader = getReader( Entity3.class, "field1", "one-to-many.orm8.xml" ); reader = getReader( Entity3.class, "field1", "one-to-many.orm8.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -168,6 +181,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
); );
} }
@Test
public void testMapKeyEnumerated() throws Exception { public void testMapKeyEnumerated() throws Exception {
reader = getReader( Entity3.class, "field1", "one-to-many.orm9.xml" ); reader = getReader( Entity3.class, "field1", "one-to-many.orm9.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -189,6 +203,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
* When there's a single map key attribute override, we still wrap it with * When there's a single map key attribute override, we still wrap it with
* an AttributeOverrides annotation. * an AttributeOverrides annotation.
*/ */
@Test
public void testSingleMapKeyAttributeOverride() throws Exception { public void testSingleMapKeyAttributeOverride() throws Exception {
reader = getReader( Entity3.class, "field1", "one-to-many.orm10.xml" ); reader = getReader( Entity3.class, "field1", "one-to-many.orm10.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -209,6 +224,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
assertEquals( "col1", overrides[0].column().name() ); assertEquals( "col1", overrides[0].column().name() );
} }
@Test
public void testMultipleMapKeyAttributeOverrides() throws Exception { public void testMultipleMapKeyAttributeOverrides() throws Exception {
reader = getReader( Entity3.class, "field1", "one-to-many.orm11.xml" ); reader = getReader( Entity3.class, "field1", "one-to-many.orm11.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -249,6 +265,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
assertEquals( 1, overrides[1].column().scale() ); assertEquals( 1, overrides[1].column().scale() );
} }
@Test
public void testMapKeyColumnNoAttributes() throws Exception { public void testMapKeyColumnNoAttributes() throws Exception {
reader = getReader( Entity3.class, "field1", "one-to-many.orm12.xml" ); reader = getReader( Entity3.class, "field1", "one-to-many.orm12.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -272,6 +289,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
assertEquals( 0, keyColAnno.scale() ); assertEquals( 0, keyColAnno.scale() );
} }
@Test
public void testMapKeyColumnAllAttributes() throws Exception { public void testMapKeyColumnAllAttributes() throws Exception {
reader = getReader( Entity3.class, "field1", "one-to-many.orm13.xml" ); reader = getReader( Entity3.class, "field1", "one-to-many.orm13.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -299,6 +317,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
* When there's a single map key join column, we still wrap it with a * When there's a single map key join column, we still wrap it with a
* MapKeyJoinColumns annotation. * MapKeyJoinColumns annotation.
*/ */
@Test
public void testSingleMapKeyJoinColumn() throws Exception { public void testSingleMapKeyJoinColumn() throws Exception {
reader = getReader( Entity3.class, "field1", "one-to-many.orm14.xml" ); reader = getReader( Entity3.class, "field1", "one-to-many.orm14.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -316,6 +335,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
assertEquals( "col1", joinColumns[0].name() ); assertEquals( "col1", joinColumns[0].name() );
} }
@Test
public void testMultipleMapKeyJoinColumns() throws Exception { public void testMultipleMapKeyJoinColumns() throws Exception {
reader = getReader( Entity3.class, "field1", "one-to-many.orm15.xml" ); reader = getReader( Entity3.class, "field1", "one-to-many.orm15.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -348,6 +368,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
assertEquals( "table1", joinColumns[1].table() ); assertEquals( "table1", joinColumns[1].table() );
} }
@Test
public void testJoinTableNoChildren() throws Exception { public void testJoinTableNoChildren() throws Exception {
reader = getReader( Entity2.class, "field1", "one-to-many.orm16.xml" ); reader = getReader( Entity2.class, "field1", "one-to-many.orm16.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -363,6 +384,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
assertEquals( 0, joinTableAnno.uniqueConstraints().length ); assertEquals( 0, joinTableAnno.uniqueConstraints().length );
} }
@Test
public void testJoinTableAllChildren() throws Exception { public void testJoinTableAllChildren() throws Exception {
reader = getReader( Entity2.class, "field1", "one-to-many.orm17.xml" ); reader = getReader( Entity2.class, "field1", "one-to-many.orm17.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -431,6 +453,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
* When there's a single join column, we still wrap it with a JoinColumns * When there's a single join column, we still wrap it with a JoinColumns
* annotation. * annotation.
*/ */
@Test
public void testSingleJoinColumn() throws Exception { public void testSingleJoinColumn() throws Exception {
reader = getReader( Entity2.class, "field1", "one-to-many.orm18.xml" ); reader = getReader( Entity2.class, "field1", "one-to-many.orm18.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -445,6 +468,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
assertEquals( "table1", joinColumns[0].table() ); assertEquals( "table1", joinColumns[0].table() );
} }
@Test
public void testMultipleJoinColumns() throws Exception { public void testMultipleJoinColumns() throws Exception {
reader = getReader( Entity2.class, "field1", "one-to-many.orm19.xml" ); reader = getReader( Entity2.class, "field1", "one-to-many.orm19.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -472,6 +496,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
assertTrue( joinColumns[1].unique() ); assertTrue( joinColumns[1].unique() );
} }
@Test
public void testCascadeAll() throws Exception { public void testCascadeAll() throws Exception {
reader = getReader( Entity2.class, "field1", "one-to-many.orm20.xml" ); reader = getReader( Entity2.class, "field1", "one-to-many.orm20.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -480,6 +505,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
assertEquals( CascadeType.ALL, relAnno.cascade()[0] ); assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
} }
@Test
public void testCascadeSomeWithDefaultPersist() throws Exception { public void testCascadeSomeWithDefaultPersist() throws Exception {
reader = getReader( Entity2.class, "field1", "one-to-many.orm21.xml" ); reader = getReader( Entity2.class, "field1", "one-to-many.orm21.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -496,6 +522,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
* is specified in addition to a default cascade-persist or individual * is specified in addition to a default cascade-persist or individual
* cascade settings. * cascade settings.
*/ */
@Test
public void testCascadeAllPlusMore() throws Exception { public void testCascadeAllPlusMore() throws Exception {
reader = getReader( Entity2.class, "field1", "one-to-many.orm22.xml" ); reader = getReader( Entity2.class, "field1", "one-to-many.orm22.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );
@ -509,6 +536,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] ); assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
} }
@Test
public void testAllAttributes() throws Exception { public void testAllAttributes() throws Exception {
reader = getReader( Entity2.class, "field1", "one-to-many.orm23.xml" ); reader = getReader( Entity2.class, "field1", "one-to-many.orm23.xml" );
assertAnnotationPresent( OneToMany.class ); assertAnnotationPresent( OneToMany.class );

View File

@ -23,6 +23,7 @@
*/ */
package org.hibernate.test.annotations.xml.ejb3; package org.hibernate.test.annotations.xml.ejb3;
import javax.persistence.Access; import javax.persistence.Access;
import javax.persistence.AccessType; import javax.persistence.AccessType;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
@ -37,8 +38,14 @@ import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.PrimaryKeyJoinColumns; import javax.persistence.PrimaryKeyJoinColumns;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase { import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
@Test
public void testNoChildren() throws Exception { public void testNoChildren() throws Exception {
reader = getReader( Entity1.class, "field1", "one-to-one.orm1.xml" ); reader = getReader( Entity1.class, "field1", "one-to-one.orm1.xml" );
assertAnnotationPresent( OneToOne.class ); assertAnnotationPresent( OneToOne.class );
@ -63,6 +70,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
* When there's a single primary key join column, we still wrap it with * When there's a single primary key join column, we still wrap it with
* a PrimaryKeyJoinColumns annotation. * a PrimaryKeyJoinColumns annotation.
*/ */
@Test
public void testSinglePrimaryKeyJoinColumn() throws Exception { public void testSinglePrimaryKeyJoinColumn() throws Exception {
reader = getReader( Entity1.class, "field1", "one-to-one.orm2.xml" ); reader = getReader( Entity1.class, "field1", "one-to-one.orm2.xml" );
assertAnnotationPresent( OneToOne.class ); assertAnnotationPresent( OneToOne.class );
@ -80,6 +88,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
assertEquals( "int", joinColumns[0].columnDefinition() ); assertEquals( "int", joinColumns[0].columnDefinition() );
} }
@Test
public void testMultiplePrimaryKeyJoinColumn() throws Exception { public void testMultiplePrimaryKeyJoinColumn() throws Exception {
reader = getReader( Entity1.class, "field1", "one-to-one.orm3.xml" ); reader = getReader( Entity1.class, "field1", "one-to-one.orm3.xml" );
assertAnnotationPresent( OneToOne.class ); assertAnnotationPresent( OneToOne.class );
@ -104,6 +113,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
* When there's a single join column, we still wrap it with a JoinColumns * When there's a single join column, we still wrap it with a JoinColumns
* annotation. * annotation.
*/ */
@Test
public void testSingleJoinColumn() throws Exception { public void testSingleJoinColumn() throws Exception {
reader = getReader( Entity1.class, "field1", "one-to-one.orm4.xml" ); reader = getReader( Entity1.class, "field1", "one-to-one.orm4.xml" );
assertAnnotationPresent( OneToOne.class ); assertAnnotationPresent( OneToOne.class );
@ -120,6 +130,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
assertEquals( "table1", joinColumns[0].table() ); assertEquals( "table1", joinColumns[0].table() );
} }
@Test
public void testMultipleJoinColumns() throws Exception { public void testMultipleJoinColumns() throws Exception {
reader = getReader( Entity1.class, "field1", "one-to-one.orm5.xml" ); reader = getReader( Entity1.class, "field1", "one-to-one.orm5.xml" );
assertAnnotationPresent( OneToOne.class ); assertAnnotationPresent( OneToOne.class );
@ -149,6 +160,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
assertTrue( joinColumns[1].unique() ); assertTrue( joinColumns[1].unique() );
} }
@Test
public void testJoinTableNoChildren() throws Exception { public void testJoinTableNoChildren() throws Exception {
reader = getReader( Entity1.class, "field1", "one-to-one.orm6.xml" ); reader = getReader( Entity1.class, "field1", "one-to-one.orm6.xml" );
assertAnnotationPresent( OneToOne.class ); assertAnnotationPresent( OneToOne.class );
@ -166,6 +178,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
assertEquals( 0, joinTableAnno.uniqueConstraints().length ); assertEquals( 0, joinTableAnno.uniqueConstraints().length );
} }
@Test
public void testJoinTableAllChildren() throws Exception { public void testJoinTableAllChildren() throws Exception {
reader = getReader( Entity1.class, "field1", "one-to-one.orm7.xml" ); reader = getReader( Entity1.class, "field1", "one-to-one.orm7.xml" );
assertAnnotationPresent( OneToOne.class ); assertAnnotationPresent( OneToOne.class );
@ -232,6 +245,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] ); assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
} }
@Test
public void testCascadeAll() throws Exception { public void testCascadeAll() throws Exception {
reader = getReader( Entity1.class, "field1", "one-to-one.orm8.xml" ); reader = getReader( Entity1.class, "field1", "one-to-one.orm8.xml" );
assertAnnotationPresent( OneToOne.class ); assertAnnotationPresent( OneToOne.class );
@ -240,6 +254,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
assertEquals( CascadeType.ALL, relAnno.cascade()[0] ); assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
} }
@Test
public void testCascadeSomeWithDefaultPersist() throws Exception { public void testCascadeSomeWithDefaultPersist() throws Exception {
reader = getReader( Entity1.class, "field1", "one-to-one.orm9.xml" ); reader = getReader( Entity1.class, "field1", "one-to-one.orm9.xml" );
assertAnnotationPresent( OneToOne.class ); assertAnnotationPresent( OneToOne.class );
@ -256,6 +271,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
* is specified in addition to a default cascade-persist or individual * is specified in addition to a default cascade-persist or individual
* cascade settings. * cascade settings.
*/ */
@Test
public void testCascadeAllPlusMore() throws Exception { public void testCascadeAllPlusMore() throws Exception {
reader = getReader( Entity1.class, "field1", "one-to-one.orm10.xml" ); reader = getReader( Entity1.class, "field1", "one-to-one.orm10.xml" );
assertAnnotationPresent( OneToOne.class ); assertAnnotationPresent( OneToOne.class );
@ -269,6 +285,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] ); assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
} }
@Test
public void testAllAttributes() throws Exception { public void testAllAttributes() throws Exception {
reader = getReader( Entity1.class, "field1", "one-to-one.orm11.xml" ); reader = getReader( Entity1.class, "field1", "one-to-one.orm11.xml" );
assertAnnotationPresent( OneToOne.class ); assertAnnotationPresent( OneToOne.class );

View File

@ -23,48 +23,31 @@
*/ */
package org.hibernate.test.annotations.xml.ejb3; package org.hibernate.test.annotations.xml.ejb3;
import java.io.InputStream; import java.io.InputStream;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement; import java.lang.reflect.AnnotatedElement;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.io.SAXReader; import org.dom4j.io.SAXReader;
import org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader; import org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader;
import org.hibernate.cfg.annotations.reflection.XMLContext; import org.hibernate.cfg.annotations.reflection.XMLContext;
import org.hibernate.testing.junit.functional.annotations.HibernateTestCase;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/** /**
* Test superclass to provide utility methods for testing the mapping of JPA * Test superclass to provide utility methods for testing the mapping of JPA
* XML to JPA annotations. The configuration is built within each test, and no * XML to JPA annotations. The configuration is built within each test, and no
* database is used. Thus, no schema generation or cleanup will be performed. * database is used. Thus, no schema generation or cleanup will be performed.
*/ */
abstract class Ejb3XmlTestCase extends HibernateTestCase { abstract class Ejb3XmlTestCase extends BaseUnitTestCase {
protected JPAOverridenAnnotationReader reader; protected JPAOverridenAnnotationReader reader;
@Override
protected void buildConfiguration() throws Exception {
//Do nothing
}
@Override
protected void runSchemaGeneration() {
//Do nothing
}
@Override
protected void runSchemaDrop() {
//Do nothing
}
@Override
protected void handleUnclosedResources() {
//Do nothing
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[0];
}
protected void assertAnnotationPresent(Class<? extends Annotation> annotationType) { protected void assertAnnotationPresent(Class<? extends Annotation> annotationType) {
assertTrue( assertTrue(
"Expected annotation " + annotationType.getSimpleName() + " was not present", "Expected annotation " + annotationType.getSimpleName() + " was not present",

View File

@ -45,7 +45,6 @@ import org.junit.Test;
import org.hibernate.testing.FailureExpected; import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
@ -160,14 +159,14 @@ public class ComponentTest extends BaseCoreFunctionalTestCase {
User u = new User( "steve", "hibernater", new Person( "Steve Ebersole", new Date(), "Main St") ); User u = new User( "steve", "hibernater", new Person( "Steve Ebersole", new Date(), "Main St") );
s.persist( u ); s.persist( u );
s.flush(); s.flush();
long intialUpdateCount = sfi().getStatistics().getEntityUpdateCount(); long intialUpdateCount = sessionFactory().getStatistics().getEntityUpdateCount();
u.getPerson().setAddress( "Austin" ); u.getPerson().setAddress( "Austin" );
s.flush(); s.flush();
assertEquals( intialUpdateCount + 1, sfi().getStatistics().getEntityUpdateCount() ); assertEquals( intialUpdateCount + 1, sessionFactory().getStatistics().getEntityUpdateCount() );
intialUpdateCount = sfi().getStatistics().getEntityUpdateCount(); intialUpdateCount = sessionFactory().getStatistics().getEntityUpdateCount();
u.getPerson().setAddress( "Cedar Park" ); u.getPerson().setAddress( "Cedar Park" );
s.flush(); s.flush();
assertEquals( intialUpdateCount + 1, sfi().getStatistics().getEntityUpdateCount() ); assertEquals( intialUpdateCount + 1, sessionFactory().getStatistics().getEntityUpdateCount() );
s.delete( u ); s.delete( u );
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();

View File

@ -57,7 +57,7 @@ public class HibernateCreateBlobFailedCase extends BaseCoreFunctionalTestCase {
@Test @Test
public void testLobCreation() throws SQLException { public void testLobCreation() throws SQLException {
Session session = sfi().getCurrentSession(); Session session = sessionFactory().getCurrentSession();
session.beginTransaction(); session.beginTransaction();
Blob blob = Hibernate.getLobCreator( session ).createBlob( new byte[] {} ); Blob blob = Hibernate.getLobCreator( session ).createBlob( new byte[] {} );
blob.free(); blob.free();

View File

@ -103,7 +103,7 @@ public class SuppliedConnectionTest extends ConnectionManagementTestCase {
super.prepareTest(); super.prepareTest();
Connection conn = cp.getConnection(); Connection conn = cp.getConnection();
try { try {
new SchemaExport( getCfg(), conn ).create( false, true ); new SchemaExport( configuration(), conn ).create( false, true );
} }
finally { finally {
if ( conn != null ) { if ( conn != null ) {
@ -120,7 +120,7 @@ public class SuppliedConnectionTest extends ConnectionManagementTestCase {
protected void cleanupTest() throws Exception { protected void cleanupTest() throws Exception {
Connection conn = cp.getConnection(); Connection conn = cp.getConnection();
try { try {
new SchemaExport( getCfg(), conn ).drop( false, true ); new SchemaExport( configuration(), conn ).drop( false, true );
} }
finally { finally {
if ( conn != null ) { if ( conn != null ) {

View File

@ -51,7 +51,7 @@ public class ThreadLocalCurrentSessionTest extends ConnectionManagementTestCase
@Override @Override
protected Session getSessionUnderTest() throws Throwable { protected Session getSessionUnderTest() throws Throwable {
Session session = getSessions().getCurrentSession(); Session session = sessionFactory().getCurrentSession();
session.beginTransaction(); session.beginTransaction();
return session; return session;
} }
@ -59,12 +59,12 @@ public class ThreadLocalCurrentSessionTest extends ConnectionManagementTestCase
@Override @Override
protected void release(Session session) { protected void release(Session session) {
if ( session.getTransaction().getLocalStatus() != LocalStatus.ACTIVE ) { if ( session.getTransaction().getLocalStatus() != LocalStatus.ACTIVE ) {
TestableThreadLocalContext.unbind( sfi() ); TestableThreadLocalContext.unbind( sessionFactory() );
return; return;
} }
long initialCount = getSessions().getStatistics().getSessionCloseCount(); long initialCount = sessionFactory().getStatistics().getSessionCloseCount();
session.getTransaction().commit(); session.getTransaction().commit();
long subsequentCount = getSessions().getStatistics().getSessionCloseCount(); long subsequentCount = sessionFactory().getStatistics().getSessionCloseCount();
assertEquals( "Session still open after commit", initialCount + 1, subsequentCount ); assertEquals( "Session still open after commit", initialCount + 1, subsequentCount );
// also make sure it was cleaned up from the internal ThreadLocal... // also make sure it was cleaned up from the internal ThreadLocal...
assertFalse( "session still bound to internal ThreadLocal", TestableThreadLocalContext.hasBind() ); assertFalse( "session still bound to internal ThreadLocal", TestableThreadLocalContext.hasBind() );

View File

@ -159,7 +159,7 @@ public class MultiRepresentationTest extends BaseCoreFunctionalTestCase {
private Long stockId; private Long stockId;
private void create() { private void create() {
Session session = getSessions().openSession(); Session session = sessionFactory().openSession();
session.beginTransaction(); session.beginTransaction();
Stock stock = new Stock(); Stock stock = new Stock();
stock.setTradeSymbol( "JBOSS" ); stock.setTradeSymbol( "JBOSS" );
@ -180,7 +180,7 @@ public class MultiRepresentationTest extends BaseCoreFunctionalTestCase {
} }
private void destroy() { private void destroy() {
Session session = getSessions().openSession(); Session session = sessionFactory().openSession();
session.beginTransaction(); session.beginTransaction();
Iterator stocks = session.createQuery( "from Stock" ).list().iterator(); Iterator stocks = session.createQuery( "from Stock" ).list().iterator();
while ( stocks.hasNext() ) { while ( stocks.hasNext() ) {

View File

@ -63,7 +63,7 @@ public class CallbackTest extends BaseCoreFunctionalTestCase {
assertEquals( "observer not notified of creation", 1, observer.creationCount ); assertEquals( "observer not notified of creation", 1, observer.creationCount );
assertEquals( "listener not notified of creation", 1, listener.initCount ); assertEquals( "listener not notified of creation", 1, listener.initCount );
sfi().close(); sessionFactory().close();
assertEquals( "observer not notified of close", 1, observer.closedCount ); assertEquals( "observer not notified of close", 1, observer.closedCount );
assertEquals( "listener not notified of close", 1, listener.destoryCount ); assertEquals( "listener not notified of close", 1, listener.destoryCount );

View File

@ -120,7 +120,7 @@ public class ExtendsTest extends BaseUnitTestCase {
cfg.buildSessionFactory( serviceRegistry ); cfg.buildSessionFactory( serviceRegistry );
fail( "Should not be able to build sessionfactory without a Person" ); fail( "Should not be able to build sessionFactory without a Person" );
} }
catch ( HibernateException e ) { catch ( HibernateException e ) {

View File

@ -89,7 +89,7 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
session.getTransaction().commit(); session.getTransaction().commit();
session.close(); session.close();
sfi().getStatistics().clear(); sessionFactory().getStatistics().clear();
testCode.perform( testCode.perform(
new TestData() { new TestData() {
@ -134,13 +134,13 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
Session session = openSession(); Session session = openSession();
session.beginTransaction(); session.beginTransaction();
CourseOffering section = ( CourseOffering ) session.get( CourseOffering.class, data.getSectionId() ); CourseOffering section = ( CourseOffering ) session.get( CourseOffering.class, data.getSectionId() );
assertEquals( 1, sfi().getStatistics().getEntityLoadCount() ); assertEquals( 1, sessionFactory().getStatistics().getEntityLoadCount() );
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() ); assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
assertFalse( Hibernate.isInitialized( section.getCourse() ) ); assertFalse( Hibernate.isInitialized( section.getCourse() ) );
assertFalse( Hibernate.isInitialized( section.getEnrollments() ) ); assertFalse( Hibernate.isInitialized( section.getEnrollments() ) );
assertFalse( Hibernate.isInitialized( section.getCourse().getCode().getDepartment() ) ); assertFalse( Hibernate.isInitialized( section.getCourse().getCode().getDepartment() ) );
assertTrue( Hibernate.isInitialized( section.getCourse() ) ); assertTrue( Hibernate.isInitialized( section.getCourse() ) );
assertEquals( 1, sfi().getStatistics().getEntityFetchCount() ); assertEquals( 1, sessionFactory().getStatistics().getEntityFetchCount() );
session.getTransaction().commit(); session.getTransaction().commit();
session.close(); session.close();
} }
@ -156,13 +156,13 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
Session session = openSession(); Session session = openSession();
session.beginTransaction(); session.beginTransaction();
CourseOffering section = ( CourseOffering ) session.createCriteria( CourseOffering.class ).uniqueResult(); CourseOffering section = ( CourseOffering ) session.createCriteria( CourseOffering.class ).uniqueResult();
assertEquals( 1, sfi().getStatistics().getEntityLoadCount() ); assertEquals( 1, sessionFactory().getStatistics().getEntityLoadCount() );
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() ); assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
assertFalse( Hibernate.isInitialized( section.getCourse() ) ); assertFalse( Hibernate.isInitialized( section.getCourse() ) );
assertFalse( Hibernate.isInitialized( section.getEnrollments() ) ); assertFalse( Hibernate.isInitialized( section.getEnrollments() ) );
assertFalse( Hibernate.isInitialized( section.getCourse().getCode().getDepartment() ) ); assertFalse( Hibernate.isInitialized( section.getCourse().getCode().getDepartment() ) );
assertTrue( Hibernate.isInitialized( section.getCourse() ) ); assertTrue( Hibernate.isInitialized( section.getCourse() ) );
assertEquals( 1, sfi().getStatistics().getEntityFetchCount() ); assertEquals( 1, sessionFactory().getStatistics().getEntityFetchCount() );
session.getTransaction().commit(); session.getTransaction().commit();
session.close(); session.close();
} }
@ -172,9 +172,9 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testBasicFetchProfileOperation() { public void testBasicFetchProfileOperation() {
assertTrue( "fetch profile not parsed properly", sfi().containsFetchProfileDefinition( "enrollment.details" ) ); assertTrue( "fetch profile not parsed properly", sessionFactory().containsFetchProfileDefinition( "enrollment.details" ) );
assertTrue( "fetch profile not parsed properly", sfi().containsFetchProfileDefinition( "offering.details" ) ); assertTrue( "fetch profile not parsed properly", sessionFactory().containsFetchProfileDefinition( "offering.details" ) );
assertTrue( "fetch profile not parsed properly", sfi().containsFetchProfileDefinition( "course.details" ) ); assertTrue( "fetch profile not parsed properly", sessionFactory().containsFetchProfileDefinition( "course.details" ) );
Session s = openSession(); Session s = openSession();
SessionImplementor si = ( SessionImplementor ) s; SessionImplementor si = ( SessionImplementor ) s;
s.enableFetchProfile( "enrollment.details" ); s.enableFetchProfile( "enrollment.details" );
@ -199,11 +199,11 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
session.beginTransaction(); session.beginTransaction();
session.enableFetchProfile( "enrollment.details" ); session.enableFetchProfile( "enrollment.details" );
Enrollment enrollment = ( Enrollment ) session.get( Enrollment.class, data.getEnrollmentId() ); Enrollment enrollment = ( Enrollment ) session.get( Enrollment.class, data.getEnrollmentId() );
assertEquals( 3, sfi().getStatistics().getEntityLoadCount() ); // enrollment + (section + student) assertEquals( 3, sessionFactory().getStatistics().getEntityLoadCount() ); // enrollment + (section + student)
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() ); assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
assertTrue( Hibernate.isInitialized( enrollment.getOffering() ) ); assertTrue( Hibernate.isInitialized( enrollment.getOffering() ) );
assertTrue( Hibernate.isInitialized( enrollment.getStudent() ) ); assertTrue( Hibernate.isInitialized( enrollment.getStudent() ) );
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() ); assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
session.getTransaction().commit(); session.getTransaction().commit();
session.close(); session.close();
} }
@ -220,11 +220,11 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
session.beginTransaction(); session.beginTransaction();
session.enableFetchProfile( "enrollment.details" ); session.enableFetchProfile( "enrollment.details" );
Enrollment enrollment = ( Enrollment ) session.createCriteria( Enrollment.class ).uniqueResult(); Enrollment enrollment = ( Enrollment ) session.createCriteria( Enrollment.class ).uniqueResult();
assertEquals( 3, sfi().getStatistics().getEntityLoadCount() ); // enrollment + (section + student) assertEquals( 3, sessionFactory().getStatistics().getEntityLoadCount() ); // enrollment + (section + student)
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() ); assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
assertTrue( Hibernate.isInitialized( enrollment.getOffering() ) ); assertTrue( Hibernate.isInitialized( enrollment.getOffering() ) );
assertTrue( Hibernate.isInitialized( enrollment.getStudent() ) ); assertTrue( Hibernate.isInitialized( enrollment.getStudent() ) );
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() ); assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
session.getTransaction().commit(); session.getTransaction().commit();
session.close(); session.close();
} }
@ -241,8 +241,8 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
session.beginTransaction(); session.beginTransaction();
session.enableFetchProfile( "offering.details" ); session.enableFetchProfile( "offering.details" );
CourseOffering section = ( CourseOffering ) session.get( CourseOffering.class, data.getSectionId() ); CourseOffering section = ( CourseOffering ) session.get( CourseOffering.class, data.getSectionId() );
assertEquals( 3, sfi().getStatistics().getEntityLoadCount() ); // section + (enrollments + course) assertEquals( 3, sessionFactory().getStatistics().getEntityLoadCount() ); // section + (enrollments + course)
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() ); assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
assertTrue( Hibernate.isInitialized( section.getEnrollments() ) ); assertTrue( Hibernate.isInitialized( section.getEnrollments() ) );
session.getTransaction().commit(); session.getTransaction().commit();
session.close(); session.close();
@ -264,8 +264,8 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
session.enableFetchProfile( "offering.details" ); session.enableFetchProfile( "offering.details" );
session.enableFetchProfile( "enrollment.details" ); session.enableFetchProfile( "enrollment.details" );
CourseOffering section = ( CourseOffering ) session.get( CourseOffering.class, data.getSectionId() ); CourseOffering section = ( CourseOffering ) session.get( CourseOffering.class, data.getSectionId() );
assertEquals( 4, sfi().getStatistics().getEntityLoadCount() ); // section + (course + enrollments + (student)) assertEquals( 4, sessionFactory().getStatistics().getEntityLoadCount() ); // section + (course + enrollments + (student))
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() ); assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
assertTrue( Hibernate.isInitialized( section.getEnrollments() ) ); assertTrue( Hibernate.isInitialized( section.getEnrollments() ) );
session.getTransaction().commit(); session.getTransaction().commit();
session.close(); session.close();
@ -283,8 +283,8 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
session.beginTransaction(); session.beginTransaction();
session.enableFetchProfile( "course.details" ); session.enableFetchProfile( "course.details" );
Course course = ( Course ) session.get( Course.class, data.getCourseId() ); Course course = ( Course ) session.get( Course.class, data.getCourseId() );
assertEquals( 2, sfi().getStatistics().getEntityLoadCount() ); // course + department assertEquals( 2, sessionFactory().getStatistics().getEntityLoadCount() ); // course + department
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() ); assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
assertTrue( Hibernate.isInitialized( course.getCode().getDepartment() ) ); assertTrue( Hibernate.isInitialized( course.getCode().getDepartment() ) );
session.getTransaction().commit(); session.getTransaction().commit();
session.close(); session.close();
@ -310,8 +310,8 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
List sections = session.createQuery( "from CourseOffering" ).list(); List sections = session.createQuery( "from CourseOffering" ).list();
int sectionCount = sections.size(); int sectionCount = sections.size();
assertEquals( "unexpected CourseOffering count", 1, sectionCount ); assertEquals( "unexpected CourseOffering count", 1, sectionCount );
assertEquals( 1, sfi().getStatistics().getEntityLoadCount() ); assertEquals( 1, sessionFactory().getStatistics().getEntityLoadCount() );
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() ); assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
session.getTransaction().commit(); session.getTransaction().commit();
session.close(); session.close();
} }

View File

@ -111,7 +111,7 @@ public class DynamicFilterTest extends BaseCoreFunctionalTestCase {
CollectionPersister persister = sessionFactory().getCollectionPersister( Salesperson.class.getName() + ".orders" ); CollectionPersister persister = sessionFactory().getCollectionPersister( Salesperson.class.getName() + ".orders" );
assertTrue( "No cache for collection", persister.hasCache() ); assertTrue( "No cache for collection", persister.hasCache() );
CollectionCacheEntry cachedData = ( CollectionCacheEntry ) persister.getCacheAccessStrategy() CollectionCacheEntry cachedData = ( CollectionCacheEntry ) persister.getCacheAccessStrategy()
.get( new CacheKey( testData.steveId, persister.getKeyType(), persister.getRole(), EntityMode.POJO, sfi() ), ts ); .get( new CacheKey( testData.steveId, persister.getKeyType(), persister.getRole(), EntityMode.POJO, sessionFactory() ), ts );
assertNotNull( "collection was not in cache", cachedData ); assertNotNull( "collection was not in cache", cachedData );
session.close(); session.close();
@ -125,7 +125,7 @@ public class DynamicFilterTest extends BaseCoreFunctionalTestCase {
assertEquals( "Filtered-collection not bypassing 2L-cache", 1, sp.getOrders().size() ); assertEquals( "Filtered-collection not bypassing 2L-cache", 1, sp.getOrders().size() );
CollectionCacheEntry cachedData2 = ( CollectionCacheEntry ) persister.getCacheAccessStrategy() CollectionCacheEntry cachedData2 = ( CollectionCacheEntry ) persister.getCacheAccessStrategy()
.get( new CacheKey( testData.steveId, persister.getKeyType(), persister.getRole(), EntityMode.POJO, sfi() ), ts ); .get( new CacheKey( testData.steveId, persister.getKeyType(), persister.getRole(), EntityMode.POJO, sessionFactory() ), ts );
assertNotNull( "collection no longer in cache!", cachedData2 ); assertNotNull( "collection no longer in cache!", cachedData2 );
assertSame( "Different cache values!", cachedData, cachedData2 ); assertSame( "Different cache values!", cachedData, cachedData2 );

View File

@ -52,15 +52,15 @@ public class IdentityGeneratedKeysTest extends BaseCoreFunctionalTestCase {
assertEquals( id, myEntity1.getId() ); assertEquals( id, myEntity1.getId() );
// next test persist() which should cause a delayed insert... // next test persist() which should cause a delayed insert...
long initialInsertCount = sfi().getStatistics().getEntityInsertCount(); long initialInsertCount = sessionFactory().getStatistics().getEntityInsertCount();
MyEntity myEntity2 = new MyEntity( "test-persist"); MyEntity myEntity2 = new MyEntity( "test-persist");
s.persist( myEntity2 ); s.persist( myEntity2 );
assertEquals( "persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount() ); assertEquals( "persist on identity column not delayed", initialInsertCount, sessionFactory().getStatistics().getEntityInsertCount() );
assertNull( myEntity2.getId() ); assertNull( myEntity2.getId() );
// an explicit flush should cause execution of the delayed insertion // an explicit flush should cause execution of the delayed insertion
s.flush(); s.flush();
assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 1, sfi().getStatistics().getEntityInsertCount() ); assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 1, sessionFactory().getStatistics().getEntityInsertCount() );
s.close(); s.close();
s = openSession(); s = openSession();
@ -74,15 +74,15 @@ public class IdentityGeneratedKeysTest extends BaseCoreFunctionalTestCase {
@Test @Test
@SuppressWarnings( {"unchecked"}) @SuppressWarnings( {"unchecked"})
public void testPersistOutsideTransactionCascadedToNonInverseCollection() { public void testPersistOutsideTransactionCascadedToNonInverseCollection() {
long initialInsertCount = sfi().getStatistics().getEntityInsertCount(); long initialInsertCount = sessionFactory().getStatistics().getEntityInsertCount();
Session s = openSession(); Session s = openSession();
MyEntity myEntity = new MyEntity( "test-persist"); MyEntity myEntity = new MyEntity( "test-persist");
myEntity.getNonInverseChildren().add( new MyChild( "test-child-persist-non-inverse" ) ); myEntity.getNonInverseChildren().add( new MyChild( "test-child-persist-non-inverse" ) );
s.persist( myEntity ); s.persist( myEntity );
assertEquals( "persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount() ); assertEquals( "persist on identity column not delayed", initialInsertCount, sessionFactory().getStatistics().getEntityInsertCount() );
assertNull( myEntity.getId() ); assertNull( myEntity.getId() );
s.flush(); s.flush();
assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount() ); assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sessionFactory().getStatistics().getEntityInsertCount() );
s.close(); s.close();
s = openSession(); s = openSession();
@ -96,17 +96,17 @@ public class IdentityGeneratedKeysTest extends BaseCoreFunctionalTestCase {
@Test @Test
@SuppressWarnings( {"unchecked"}) @SuppressWarnings( {"unchecked"})
public void testPersistOutsideTransactionCascadedToInverseCollection() { public void testPersistOutsideTransactionCascadedToInverseCollection() {
long initialInsertCount = sfi().getStatistics().getEntityInsertCount(); long initialInsertCount = sessionFactory().getStatistics().getEntityInsertCount();
Session s = openSession(); Session s = openSession();
MyEntity myEntity2 = new MyEntity( "test-persist-2"); MyEntity myEntity2 = new MyEntity( "test-persist-2");
MyChild child = new MyChild( "test-child-persist-inverse" ); MyChild child = new MyChild( "test-child-persist-inverse" );
myEntity2.getInverseChildren().add( child ); myEntity2.getInverseChildren().add( child );
child.setInverseParent( myEntity2 ); child.setInverseParent( myEntity2 );
s.persist( myEntity2 ); s.persist( myEntity2 );
assertEquals( "persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount() ); assertEquals( "persist on identity column not delayed", initialInsertCount, sessionFactory().getStatistics().getEntityInsertCount() );
assertNull( myEntity2.getId() ); assertNull( myEntity2.getId() );
s.flush(); s.flush();
assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount() ); assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sessionFactory().getStatistics().getEntityInsertCount() );
s.close(); s.close();
s = openSession(); s = openSession();
@ -119,15 +119,15 @@ public class IdentityGeneratedKeysTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testPersistOutsideTransactionCascadedToManyToOne() { public void testPersistOutsideTransactionCascadedToManyToOne() {
long initialInsertCount = sfi().getStatistics().getEntityInsertCount(); long initialInsertCount = sessionFactory().getStatistics().getEntityInsertCount();
Session s = openSession(); Session s = openSession();
MyEntity myEntity = new MyEntity( "test-persist"); MyEntity myEntity = new MyEntity( "test-persist");
myEntity.setSibling( new MySibling( "test-persist-sibling-out" ) ); myEntity.setSibling( new MySibling( "test-persist-sibling-out" ) );
s.persist( myEntity ); s.persist( myEntity );
assertEquals( "persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount() ); assertEquals( "persist on identity column not delayed", initialInsertCount, sessionFactory().getStatistics().getEntityInsertCount() );
assertNull( myEntity.getId() ); assertNull( myEntity.getId() );
s.flush(); s.flush();
assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount() ); assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sessionFactory().getStatistics().getEntityInsertCount() );
s.close(); s.close();
s = openSession(); s = openSession();
@ -140,16 +140,16 @@ public class IdentityGeneratedKeysTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testPersistOutsideTransactionCascadedFromManyToOne() { public void testPersistOutsideTransactionCascadedFromManyToOne() {
long initialInsertCount = sfi().getStatistics().getEntityInsertCount(); long initialInsertCount = sessionFactory().getStatistics().getEntityInsertCount();
Session s = openSession(); Session s = openSession();
MyEntity myEntity2 = new MyEntity( "test-persist-2"); MyEntity myEntity2 = new MyEntity( "test-persist-2");
MySibling sibling = new MySibling( "test-persist-sibling-in" ); MySibling sibling = new MySibling( "test-persist-sibling-in" );
sibling.setEntity( myEntity2 ); sibling.setEntity( myEntity2 );
s.persist( sibling ); s.persist( sibling );
assertEquals( "persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount() ); assertEquals( "persist on identity column not delayed", initialInsertCount, sessionFactory().getStatistics().getEntityInsertCount() );
assertNull( myEntity2.getId() ); assertNull( myEntity2.getId() );
s.flush(); s.flush();
assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount() ); assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sessionFactory().getStatistics().getEntityInsertCount() );
s.close(); s.close();
s = openSession(); s = openSession();

View File

@ -2394,7 +2394,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
sr.close(); sr.close();
// caching... // caching...
QueryStatistics stats = getSessions().getStatistics().getQueryStatistics( "select new Animal(an.description, an.bodyWeight) from Animal an" ); QueryStatistics stats = sessionFactory().getStatistics().getQueryStatistics( "select new Animal(an.description, an.bodyWeight) from Animal an" );
results = session.createQuery( "select new Animal(an.description, an.bodyWeight) from Animal an" ) results = session.createQuery( "select new Animal(an.description, an.bodyWeight) from Animal an" )
.setCacheable( true ) .setCacheable( true )
.list(); .list();
@ -2440,20 +2440,20 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
t.commit(); t.commit();
s.close(); s.close();
getSessions().getCache().evictQueryRegions(); sessionFactory().getCache().evictQueryRegions();
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
List list = s.createQuery( "from Animal a left join fetch a.mother" ).setCacheable( true ).list(); List list = s.createQuery( "from Animal a left join fetch a.mother" ).setCacheable( true ).list();
assertEquals( 0, getSessions().getStatistics().getQueryCacheHitCount() ); assertEquals( 0, sessionFactory().getStatistics().getQueryCacheHitCount() );
assertEquals( 1, getSessions().getStatistics().getQueryCachePutCount() ); assertEquals( 1, sessionFactory().getStatistics().getQueryCachePutCount() );
list = s.createQuery( "select a from Animal a left join fetch a.mother" ).setCacheable( true ).list(); list = s.createQuery( "select a from Animal a left join fetch a.mother" ).setCacheable( true ).list();
assertEquals( 1, getSessions().getStatistics().getQueryCacheHitCount() ); assertEquals( 1, sessionFactory().getStatistics().getQueryCacheHitCount() );
assertEquals( 1, getSessions().getStatistics().getQueryCachePutCount() ); assertEquals( 1, sessionFactory().getStatistics().getQueryCachePutCount() );
list = s.createQuery( "select a, m from Animal a left join a.mother m" ).setCacheable( true ).list(); list = s.createQuery( "select a, m from Animal a left join a.mother m" ).setCacheable( true ).list();
assertEquals( 1, getSessions().getStatistics().getQueryCacheHitCount() ); assertEquals( 1, sessionFactory().getStatistics().getQueryCacheHitCount() );
assertEquals( 2, getSessions().getStatistics().getQueryCachePutCount() ); assertEquals( 2, sessionFactory().getStatistics().getQueryCachePutCount() );
s.createQuery( "delete from Animal" ).executeUpdate(); s.createQuery( "delete from Animal" ).executeUpdate();
t.commit(); t.commit();
s.close(); s.close();
@ -2477,8 +2477,8 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
a.addOffspring( offspring2 ); a.addOffspring( offspring2 );
offspring2.setMother( a ); offspring2.setMother( a );
getSessions().getCache().evictQueryRegions(); sessionFactory().getCache().evictQueryRegions();
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
@ -2492,14 +2492,14 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
List list = s.createQuery( "from Animal a left join fetch a.offspring" ).setCacheable( true ).list(); List list = s.createQuery( "from Animal a left join fetch a.offspring" ).setCacheable( true ).list();
assertEquals( 0, getSessions().getStatistics().getQueryCacheHitCount() ); assertEquals( 0, sessionFactory().getStatistics().getQueryCacheHitCount() );
assertEquals( 1, getSessions().getStatistics().getQueryCachePutCount() ); assertEquals( 1, sessionFactory().getStatistics().getQueryCachePutCount() );
list = s.createQuery( "select a from Animal a left join fetch a.offspring" ).setCacheable( true ).list(); list = s.createQuery( "select a from Animal a left join fetch a.offspring" ).setCacheable( true ).list();
assertEquals( 1, getSessions().getStatistics().getQueryCacheHitCount() ); assertEquals( 1, sessionFactory().getStatistics().getQueryCacheHitCount() );
assertEquals( 1, getSessions().getStatistics().getQueryCachePutCount() ); assertEquals( 1, sessionFactory().getStatistics().getQueryCachePutCount() );
list = s.createQuery( "select a, o from Animal a left join a.offspring o" ).setCacheable( true ).list(); list = s.createQuery( "select a, o from Animal a left join a.offspring o" ).setCacheable( true ).list();
assertEquals( 1, getSessions().getStatistics().getQueryCacheHitCount() ); assertEquals( 1, sessionFactory().getStatistics().getQueryCacheHitCount() );
assertEquals( 2, getSessions().getStatistics().getQueryCachePutCount() ); assertEquals( 2, sessionFactory().getStatistics().getQueryCachePutCount() );
s.createQuery( "delete from Animal" ).executeUpdate(); s.createQuery( "delete from Animal" ).executeUpdate();
t.commit(); t.commit();
s.close(); s.close();

View File

@ -342,7 +342,7 @@ public class BulkManipulationTest extends BaseCoreFunctionalTestCase {
} }
protected boolean supportsBulkInsertIdGeneration(Class entityClass) { protected boolean supportsBulkInsertIdGeneration(Class entityClass) {
EntityPersister persister = sfi().getEntityPersister( entityClass.getName() ); EntityPersister persister = sessionFactory().getEntityPersister( entityClass.getName() );
IdentifierGenerator generator = persister.getIdentifierGenerator(); IdentifierGenerator generator = persister.getIdentifierGenerator();
return HqlSqlWalker.supportsIdGenWithBulkInsertion( generator ); return HqlSqlWalker.supportsIdGenWithBulkInsertion( generator );
} }

View File

@ -262,11 +262,11 @@ public class EJBQLTest extends BaseCoreFunctionalTestCase {
private void assertEjbqlEqualsHql(String ejbql, String hql) { private void assertEjbqlEqualsHql(String ejbql, String hql) {
QueryTranslatorFactory ast = new ASTQueryTranslatorFactory(); QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
QueryTranslator queryTranslator = ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, sfi() ); QueryTranslator queryTranslator = ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, sessionFactory() );
queryTranslator.compile( Collections.EMPTY_MAP, true ); queryTranslator.compile( Collections.EMPTY_MAP, true );
String hqlSql = queryTranslator.getSQLString(); String hqlSql = queryTranslator.getSQLString();
queryTranslator = ast.createQueryTranslator( ejbql, ejbql, Collections.EMPTY_MAP, sfi() ); queryTranslator = ast.createQueryTranslator( ejbql, ejbql, Collections.EMPTY_MAP, sessionFactory() );
queryTranslator.compile( Collections.EMPTY_MAP, true ); queryTranslator.compile( Collections.EMPTY_MAP, true );
String ejbqlSql = queryTranslator.getSQLString(); String ejbqlSql = queryTranslator.getSQLString();
@ -275,7 +275,7 @@ public class EJBQLTest extends BaseCoreFunctionalTestCase {
private QueryTranslatorImpl compile(String input) { private QueryTranslatorImpl compile(String input) {
QueryTranslatorFactory ast = new ASTQueryTranslatorFactory(); QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
QueryTranslator queryTranslator = ast.createQueryTranslator( input, input, Collections.EMPTY_MAP, sfi() ); QueryTranslator queryTranslator = ast.createQueryTranslator( input, input, Collections.EMPTY_MAP, sessionFactory() );
queryTranslator.compile( Collections.EMPTY_MAP, true ); queryTranslator.compile( Collections.EMPTY_MAP, true );
return ( QueryTranslatorImpl ) queryTranslator; return ( QueryTranslatorImpl ) queryTranslator;
@ -305,7 +305,7 @@ public class EJBQLTest extends BaseCoreFunctionalTestCase {
private String toSql(String hql) { private String toSql(String hql) {
QueryTranslatorFactory ast = new ASTQueryTranslatorFactory(); QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
QueryTranslator queryTranslator = ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, sfi() ); QueryTranslator queryTranslator = ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, sessionFactory() );
queryTranslator.compile( Collections.EMPTY_MAP, true ); queryTranslator.compile( Collections.EMPTY_MAP, true );
return queryTranslator.getSQLString(); return queryTranslator.getSQLString();
} }

View File

@ -34,7 +34,6 @@ import org.junit.Test;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -49,7 +48,7 @@ public class BasicForcedTableSequenceTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testNormalBoundary() { public void testNormalBoundary() {
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() ); EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
assertTrue( assertTrue(
"sequence style generator was not used", "sequence style generator was not used",
SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() ) SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )

View File

@ -34,7 +34,6 @@ import org.junit.Test;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -50,7 +49,7 @@ public class HiLoForcedTableSequenceTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testNormalBoundary() { public void testNormalBoundary() {
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() ); EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
assertTrue( assertTrue(
"sequence style generator was not used", "sequence style generator was not used",
SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() ) SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )

View File

@ -34,7 +34,6 @@ import org.junit.Test;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -48,7 +47,7 @@ public class PooledForcedTableSequenceTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testNormalBoundary() { public void testNormalBoundary() {
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() ); EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
assertTrue( assertTrue(
"sequence style generator was not used", "sequence style generator was not used",
SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() ) SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )

View File

@ -34,7 +34,6 @@ import org.junit.Test;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability; import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -48,7 +47,7 @@ public class HiLoSequenceTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testNormalBoundary() { public void testNormalBoundary() {
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() ); EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
assertClassAssignability( SequenceStyleGenerator.class, persister.getIdentifierGenerator().getClass() ); assertClassAssignability( SequenceStyleGenerator.class, persister.getIdentifierGenerator().getClass() );
SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator(); SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
assertClassAssignability( OptimizerFactory.HiLoOptimizer.class, generator.getOptimizer().getClass() ); assertClassAssignability( OptimizerFactory.HiLoOptimizer.class, generator.getOptimizer().getClass() );

View File

@ -22,7 +22,6 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.immutable.entitywithmutablecollection; package org.hibernate.test.immutable.entitywithmutablecollection;
import java.util.Iterator;
import org.hibernate.QueryException; import org.hibernate.QueryException;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.StaleObjectStateException; import org.hibernate.StaleObjectStateException;
@ -68,23 +67,23 @@ public abstract class AbstractEntityWithOneToManyTest extends BaseCoreFunctional
protected void prepareTest() throws Exception { protected void prepareTest() throws Exception {
super.prepareTest(); super.prepareTest();
isContractPartiesInverse = ( ( SessionFactoryImpl ) getSessions() ).getCollectionPersister( Contract.class.getName() + ".parties" ).isInverse(); isContractPartiesInverse = ( ( SessionFactoryImpl ) sessionFactory() ).getCollectionPersister( Contract.class.getName() + ".parties" ).isInverse();
try { try {
( ( SessionFactoryImpl ) getSessions() ).getEntityPersister( Party.class.getName() ).getPropertyType( "contract" ); ( ( SessionFactoryImpl ) sessionFactory() ).getEntityPersister( Party.class.getName() ).getPropertyType( "contract" );
isContractPartiesBidirectional = true; isContractPartiesBidirectional = true;
} }
catch ( QueryException ex) { catch ( QueryException ex) {
isContractPartiesBidirectional = false; isContractPartiesBidirectional = false;
} }
try { try {
( ( SessionFactoryImpl ) getSessions() ).getEntityPersister( ContractVariation.class.getName() ).getPropertyType( "contract" ); ( ( SessionFactoryImpl ) sessionFactory() ).getEntityPersister( ContractVariation.class.getName() ).getPropertyType( "contract" );
isContractVariationsBidirectional = true; isContractVariationsBidirectional = true;
} }
catch ( QueryException ex) { catch ( QueryException ex) {
isContractVariationsBidirectional = false; isContractVariationsBidirectional = false;
} }
isContractVersioned = ( ( SessionFactoryImpl ) getSessions() ).getEntityPersister( Contract.class.getName() ).isVersioned(); isContractVersioned = ( ( SessionFactoryImpl ) sessionFactory() ).getEntityPersister( Contract.class.getName() ).isVersioned();
} }
@Test @Test
@ -1201,21 +1200,21 @@ public abstract class AbstractEntityWithOneToManyTest extends BaseCoreFunctional
} }
protected void clearCounts() { protected void clearCounts() {
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
} }
protected void assertInsertCount(int expected) { protected void assertInsertCount(int expected) {
int inserts = ( int ) getSessions().getStatistics().getEntityInsertCount(); int inserts = ( int ) sessionFactory().getStatistics().getEntityInsertCount();
assertEquals( "unexpected insert count", expected, inserts ); assertEquals( "unexpected insert count", expected, inserts );
} }
protected void assertUpdateCount(int expected) { protected void assertUpdateCount(int expected) {
int updates = ( int ) getSessions().getStatistics().getEntityUpdateCount(); int updates = ( int ) sessionFactory().getStatistics().getEntityUpdateCount();
assertEquals( "unexpected update counts", expected, updates ); assertEquals( "unexpected update counts", expected, updates );
} }
protected void assertDeleteCount(int expected) { protected void assertDeleteCount(int expected) {
int deletes = ( int ) getSessions().getStatistics().getEntityDeleteCount(); int deletes = ( int ) sessionFactory().getStatistics().getEntityDeleteCount();
assertEquals( "unexpected delete counts", expected, deletes ); assertEquals( "unexpected delete counts", expected, deletes );
} }
} }

View File

@ -24,6 +24,7 @@
package org.hibernate.test.instrument.runtime; package org.hibernate.test.instrument.runtime;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
@ -32,16 +33,23 @@ import org.hibernate.bytecode.InstrumentedClassLoader;
import org.hibernate.bytecode.util.BasicClassFilter; import org.hibernate.bytecode.util.BasicClassFilter;
import org.hibernate.bytecode.util.FieldFilter; import org.hibernate.bytecode.util.FieldFilter;
import org.hibernate.testing.junit4.BaseClassLoaderIsolatedTestCase; import org.hibernate.testing.junit4.BaseClassLoaderIsolatedTestCase;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.testing.junit4.ClassLoadingIsolater;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends BaseClassLoaderIsolatedTestCase { public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends BaseUnitTestCase {
protected ClassLoader buildIsolatedClassLoader(ClassLoader parent) { @Rule
BytecodeProvider provider = buildBytecodeProvider(); public ClassLoadingIsolater isolater = new ClassLoadingIsolater(
new ClassLoadingIsolater.IsolatedClassLoaderProvider() {
final BytecodeProvider provider = buildBytecodeProvider();
@Override
public ClassLoader buildIsolatedClassLoader() {
return new InstrumentedClassLoader( return new InstrumentedClassLoader(
parent, Thread.currentThread().getContextClassLoader(),
provider.getTransformer( provider.getTransformer(
new BasicClassFilter( new String[] { "org.hibernate.test.instrument" }, null ), new BasicClassFilter( new String[] { "org.hibernate.test.instrument" }, null ),
new FieldFilter() { new FieldFilter() {
@ -55,11 +63,14 @@ public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends
} }
) )
); );
} }
protected void releaseIsolatedClassLoader(ClassLoader isolatedLoader) { @Override
public void releaseIsolatedClassLoader(ClassLoader isolatedClassLoader) {
// nothing to do
} }
}
);
protected abstract BytecodeProvider buildBytecodeProvider(); protected abstract BytecodeProvider buildBytecodeProvider();

View File

@ -57,7 +57,7 @@ public class IterateTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testIterate() throws Exception { public void testIterate() throws Exception {
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Item i1 = new Item("foo"); Item i1 = new Item("foo");
@ -86,12 +86,12 @@ public class IterateTest extends BaseCoreFunctionalTestCase {
s.delete(i2); s.delete(i2);
t.commit(); t.commit();
s.close(); s.close();
assertEquals( getSessions().getStatistics().getEntityFetchCount(), 2 ); assertEquals( sessionFactory().getStatistics().getEntityFetchCount(), 2 );
} }
@Test @Test
public void testScroll() throws Exception { public void testScroll() throws Exception {
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Item i1 = new Item("foo"); Item i1 = new Item("foo");
@ -117,7 +117,7 @@ public class IterateTest extends BaseCoreFunctionalTestCase {
s.delete(i2); s.delete(i2);
t.commit(); t.commit();
s.close(); s.close();
assertEquals( getSessions().getStatistics().getEntityFetchCount(), 0 ); assertEquals( sessionFactory().getStatistics().getEntityFetchCount(), 0 );
} }
} }

View File

@ -87,7 +87,7 @@ public class LazyKeyManyToOneTest extends BaseCoreFunctionalTestCase {
cust.getOrders().add( order ); cust.getOrders().add( order );
s.save( cust ); s.save( cust );
s.flush(); s.flush();
assertEquals( 2, sfi().getStatistics().getEntityInsertCount() ); assertEquals( 2, sessionFactory().getStatistics().getEntityInsertCount() );
s.delete( cust ); s.delete( cust );
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();

View File

@ -60,7 +60,7 @@ public class KeyManyToOneTest extends BaseCoreFunctionalTestCase {
cust.getOrders().add( order ); cust.getOrders().add( order );
s.save( cust ); s.save( cust );
s.flush(); s.flush();
assertEquals( 2, sfi().getStatistics().getEntityInsertCount() ); assertEquals( 2, sessionFactory().getStatistics().getEntityInsertCount() );
s.delete( cust ); s.delete( cust );
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();

View File

@ -68,21 +68,21 @@ public class InstrumentCacheTest extends BaseCoreFunctionalTestCase {
Session s; Session s;
Transaction tx; Transaction tx;
s = getSessions().openSession(); s = sessionFactory().openSession();
tx = s.beginTransaction(); tx = s.beginTransaction();
s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") ); s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") );
tx.commit(); tx.commit();
s.close(); s.close();
s = getSessions().openSession(); s = sessionFactory().openSession();
tx = s.beginTransaction(); tx = s.beginTransaction();
s.createQuery("from Document fetch all properties").uniqueResult(); s.createQuery("from Document fetch all properties").uniqueResult();
tx.commit(); tx.commit();
s.close(); s.close();
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
s = getSessions().openSession(); s = sessionFactory().openSession();
tx = s.beginTransaction(); tx = s.beginTransaction();
Document d = (Document) s.createCriteria(Document.class).uniqueResult(); Document d = (Document) s.createCriteria(Document.class).uniqueResult();
assertFalse( Hibernate.isPropertyInitialized(d, "text") ); assertFalse( Hibernate.isPropertyInitialized(d, "text") );
@ -93,9 +93,9 @@ public class InstrumentCacheTest extends BaseCoreFunctionalTestCase {
tx.commit(); tx.commit();
s.close(); s.close();
assertEquals( 2, getSessions().getStatistics().getPrepareStatementCount() ); assertEquals( 2, sessionFactory().getStatistics().getPrepareStatementCount() );
s = getSessions().openSession(); s = sessionFactory().openSession();
tx = s.beginTransaction(); tx = s.beginTransaction();
d = (Document) s.get(Document.class, d.getId()); d = (Document) s.get(Document.class, d.getId());
assertFalse( Hibernate.isPropertyInitialized(d, "text") ); assertFalse( Hibernate.isPropertyInitialized(d, "text") );
@ -109,21 +109,21 @@ public class InstrumentCacheTest extends BaseCoreFunctionalTestCase {
Session s; Session s;
Transaction tx; Transaction tx;
s = getSessions().openSession(); s = sessionFactory().openSession();
tx = s.beginTransaction(); tx = s.beginTransaction();
s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") ); s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") );
tx.commit(); tx.commit();
s.close(); s.close();
s = getSessions().openSession(); s = sessionFactory().openSession();
tx = s.beginTransaction(); tx = s.beginTransaction();
s.createQuery("from Document fetch all properties").uniqueResult(); s.createQuery("from Document fetch all properties").uniqueResult();
tx.commit(); tx.commit();
s.close(); s.close();
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
s = getSessions().openSession(); s = sessionFactory().openSession();
tx = s.beginTransaction(); tx = s.beginTransaction();
Document d = (Document) s.createCriteria(Document.class).uniqueResult(); Document d = (Document) s.createCriteria(Document.class).uniqueResult();
assertFalse( Hibernate.isPropertyInitialized(d, "text") ); assertFalse( Hibernate.isPropertyInitialized(d, "text") );
@ -134,9 +134,9 @@ public class InstrumentCacheTest extends BaseCoreFunctionalTestCase {
tx.commit(); tx.commit();
s.close(); s.close();
assertEquals( 1, getSessions().getStatistics().getPrepareStatementCount() ); assertEquals( 1, sessionFactory().getStatistics().getPrepareStatementCount() );
s = getSessions().openSession(); s = sessionFactory().openSession();
tx = s.beginTransaction(); tx = s.beginTransaction();
d = (Document) s.get(Document.class, d.getId()); d = (Document) s.get(Document.class, d.getId());
assertTrue( Hibernate.isPropertyInitialized(d, "text") ); assertTrue( Hibernate.isPropertyInitialized(d, "text") );

View File

@ -57,14 +57,14 @@ public class ABCTest extends LegacyTestCase {
d = (D) s.get(D.class, did); d = (D) s.get(D.class, did);
assertTrue(d.getReverse().getId().equals(did)); assertTrue(d.getReverse().getId().equals(did));
s.clear(); s.clear();
getSessions().evict(D.class); sessionFactory().evict(D.class);
getSessions().evict(A.class); sessionFactory().evict(A.class);
d = (D) s.get(D.class, did); d = (D) s.get(D.class, did);
assertTrue(d.inverse.getId().equals(did)); assertTrue(d.inverse.getId().equals(did));
assertTrue(d.inverse.getName().equals("a")); assertTrue(d.inverse.getName().equals("a"));
s.clear(); s.clear();
getSessions().evict(D.class); sessionFactory().evict(D.class);
getSessions().evict(A.class); sessionFactory().evict(A.class);
assertTrue( s.createQuery( "from D d join d.reverse r join d.inverse i where i = r" ).list().size()==1 ); assertTrue( s.createQuery( "from D d join d.reverse r join d.inverse i where i = r" ).list().size()==1 );
t.commit(); t.commit();
s.close(); s.close();
@ -72,7 +72,7 @@ public class ABCTest extends LegacyTestCase {
@Test @Test
public void testHigherLevelIndexDefinition() throws Throwable { public void testHigherLevelIndexDefinition() throws Throwable {
String[] commands = getCfg().generateSchemaCreationScript( getDialect() ); String[] commands = configuration().generateSchemaCreationScript( getDialect() );
int max = commands.length; int max = commands.length;
boolean found = false; boolean found = false;
for (int indx = 0; indx < max; indx++) { for (int indx = 0; indx < max; indx++) {
@ -105,7 +105,7 @@ public class ABCTest extends LegacyTestCase {
t.commit(); t.commit();
s.close(); s.close();
getSessions().evict(A.class); sessionFactory().evict(A.class);
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
@ -120,7 +120,7 @@ public class ABCTest extends LegacyTestCase {
t.commit(); t.commit();
s.close(); s.close();
getSessions().evict(A.class); sessionFactory().evict(A.class);
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();

View File

@ -49,7 +49,7 @@ public class CustomSQLTest extends LegacyTestCase {
s.connection().commit(); s.connection().commit();
s.close(); s.close();
getSessions().evict(Role.class); sessionFactory().evict(Role.class);
s = openSession(); s = openSession();
Role p2 = (Role) s.get(Role.class, new Long(p.getId())); Role p2 = (Role) s.get(Role.class, new Long(p.getId()));
@ -178,7 +178,7 @@ public class CustomSQLTest extends LegacyTestCase {
s.connection().commit(); s.connection().commit();
s.close(); s.close();
getSessions().evict(Person.class); sessionFactory().evict(Person.class);
s = openSession(); s = openSession();
Person p2 = (Person) s.get(Person.class, p.getId()); Person p2 = (Person) s.get(Person.class, p.getId());

View File

@ -291,7 +291,7 @@ public class FooBarTest extends LegacyTestCase {
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
getSessions().evictCollection("org.hibernate.test.legacy.Baz.fooSet"); sessionFactory().evictCollection("org.hibernate.test.legacy.Baz.fooSet");
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
@ -340,7 +340,7 @@ public class FooBarTest extends LegacyTestCase {
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
getSessions().evictCollection("org.hibernate.test.legacy.Baz.fooSet"); sessionFactory().evictCollection("org.hibernate.test.legacy.Baz.fooSet");
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
@ -1518,7 +1518,7 @@ public class FooBarTest extends LegacyTestCase {
} }
private boolean isOuterJoinFetchingDisabled() { private boolean isOuterJoinFetchingDisabled() {
return new Integer(0).equals( ( (SessionFactoryImplementor) getSessions() ).getSettings().getMaximumFetchDepth() ); return new Integer(0).equals( ( (SessionFactoryImplementor) sessionFactory() ).getSettings().getMaximumFetchDepth() );
} }
@Test @Test
@ -1542,7 +1542,7 @@ public class FooBarTest extends LegacyTestCase {
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
getSessions().evict(Foo.class); sessionFactory().evict(Foo.class);
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
@ -3202,7 +3202,7 @@ public class FooBarTest extends LegacyTestCase {
txn.commit(); txn.commit();
s.close(); s.close();
getSessions().evict(Glarch.class); sessionFactory().evict(Glarch.class);
s = openSession(); s = openSession();
txn = s.beginTransaction(); txn = s.beginTransaction();
@ -3221,7 +3221,7 @@ public class FooBarTest extends LegacyTestCase {
txn.commit(); txn.commit();
s.close(); s.close();
getSessions().evict(Glarch.class); sessionFactory().evict(Glarch.class);
s = openSession(); s = openSession();
txn = s.beginTransaction(); txn = s.beginTransaction();
@ -4337,7 +4337,7 @@ public class FooBarTest extends LegacyTestCase {
@Test @Test
public void testUserProvidedConnection() throws Exception { public void testUserProvidedConnection() throws Exception {
ConnectionProvider dcp = ConnectionProviderBuilder.buildConnectionProvider(); ConnectionProvider dcp = ConnectionProviderBuilder.buildConnectionProvider();
Session s = getSessions().openSession( dcp.getConnection() ); Session s = sessionFactory().openSession( dcp.getConnection() );
Transaction tx = s.beginTransaction(); Transaction tx = s.beginTransaction();
s.createQuery( "from Fo" ).list(); s.createQuery( "from Fo" ).list();
tx.commit(); tx.commit();

View File

@ -733,7 +733,7 @@ public class FumTest extends LegacyTestCase {
public void testUnflushedSessionSerialization() throws Exception { public void testUnflushedSessionSerialization() throws Exception {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Test insertions across serializations // Test insertions across serializations
Session s = getSessions().openSession(); Session s = sessionFactory().openSession();
s.setFlushMode(FlushMode.MANUAL); s.setFlushMode(FlushMode.MANUAL);
s.beginTransaction(); s.beginTransaction();
@ -766,7 +766,7 @@ public class FumTest extends LegacyTestCase {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Test updates across serializations // Test updates across serializations
s = getSessions().openSession(); s = sessionFactory().openSession();
s.setFlushMode(FlushMode.MANUAL); s.setFlushMode(FlushMode.MANUAL);
s.beginTransaction(); s.beginTransaction();
@ -789,7 +789,7 @@ public class FumTest extends LegacyTestCase {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Test deletions across serializations // Test deletions across serializations
s = getSessions().openSession(); s = sessionFactory().openSession();
s.setFlushMode(FlushMode.MANUAL); s.setFlushMode(FlushMode.MANUAL);
s.beginTransaction(); s.beginTransaction();
@ -812,7 +812,7 @@ public class FumTest extends LegacyTestCase {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Test collection actions across serializations // Test collection actions across serializations
s = getSessions().openSession(); s = sessionFactory().openSession();
s.setFlushMode(FlushMode.MANUAL); s.setFlushMode(FlushMode.MANUAL);
s.beginTransaction(); s.beginTransaction();
@ -842,7 +842,7 @@ public class FumTest extends LegacyTestCase {
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
s = getSessions().openSession(); s = sessionFactory().openSession();
s.setFlushMode(FlushMode.MANUAL); s.setFlushMode(FlushMode.MANUAL);
s.beginTransaction(); s.beginTransaction();
fum = (Fum) s.load( Fum.class, fum.getId() ); fum = (Fum) s.load( Fum.class, fum.getId() );
@ -861,7 +861,7 @@ public class FumTest extends LegacyTestCase {
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
s = getSessions().openSession(); s = sessionFactory().openSession();
s.setFlushMode(FlushMode.MANUAL); s.setFlushMode(FlushMode.MANUAL);
fum = (Fum) s.load( Fum.class, fum.getId() ); fum = (Fum) s.load( Fum.class, fum.getId() );
assertTrue("the Fum.friends is not empty", fum.getFriends() == null || fum.getFriends().size() == 0); assertTrue("the Fum.friends is not empty", fum.getFriends() == null || fum.getFriends().size() == 0);

View File

@ -99,7 +99,7 @@ public class MasterDetailTest extends LegacyTestCase {
@Test @Test
public void testMeta() throws Exception { public void testMeta() throws Exception {
PersistentClass clazz = getCfg().getClassMapping( Master.class.getName() ); PersistentClass clazz = configuration().getClassMapping( Master.class.getName() );
MetaAttribute meta = clazz.getMetaAttribute("foo"); MetaAttribute meta = clazz.getMetaAttribute("foo");
assertTrue( "foo".equals( meta.getValue() ) ); assertTrue( "foo".equals( meta.getValue() ) );
meta = clazz.getProperty("name").getMetaAttribute("bar"); meta = clazz.getProperty("name").getMetaAttribute("bar");
@ -873,13 +873,13 @@ public class MasterDetailTest extends LegacyTestCase {
protected boolean isSerializableIsolationEnforced() throws Exception { protected boolean isSerializableIsolationEnforced() throws Exception {
Connection conn = null; Connection conn = null;
try { try {
conn = sfi().getConnectionProvider().getConnection(); conn = sessionFactory().getConnectionProvider().getConnection();
return conn.getTransactionIsolation() >= Connection.TRANSACTION_SERIALIZABLE; return conn.getTransactionIsolation() >= Connection.TRANSACTION_SERIALIZABLE;
} }
finally { finally {
if ( conn != null ) { if ( conn != null ) {
try { try {
sfi().getConnectionProvider().closeConnection( conn ); sessionFactory().getConnectionProvider().closeConnection( conn );
} }
catch ( Throwable ignore ) { catch ( Throwable ignore ) {
// ignore... // ignore...
@ -1041,7 +1041,7 @@ public class MasterDetailTest extends LegacyTestCase {
s.connection().commit(); s.connection().commit();
s.close(); s.close();
getSessions().evictCollection("org.hibernate.test.legacy.Assignable.categories"); sessionFactory().evictCollection("org.hibernate.test.legacy.Assignable.categories");
s = openSession(); s = openSession();
a = (Assignable) s.get(Assignable.class, "foo"); a = (Assignable) s.get(Assignable.class, "foo");
@ -1054,7 +1054,7 @@ public class MasterDetailTest extends LegacyTestCase {
s.connection().commit(); s.connection().commit();
s.close(); s.close();
getSessions().evictCollection("org.hibernate.test.legacy.Assignable.categories"); sessionFactory().evictCollection("org.hibernate.test.legacy.Assignable.categories");
s = openSession(); s = openSession();
a = (Assignable) s.get(Assignable.class, "foo"); a = (Assignable) s.get(Assignable.class, "foo");
@ -1068,7 +1068,7 @@ public class MasterDetailTest extends LegacyTestCase {
s.connection().commit(); s.connection().commit();
s.close(); s.close();
getSessions().evictCollection("org.hibernate.test.legacy.Assignable.categories"); sessionFactory().evictCollection("org.hibernate.test.legacy.Assignable.categories");
s = openSession(); s = openSession();
a = (Assignable) s.get(Assignable.class, "foo"); a = (Assignable) s.get(Assignable.class, "foo");

View File

@ -117,7 +117,7 @@ public class MultiTableTest extends LegacyTestCase {
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
getSessions().evict(SubMulti.class); sessionFactory().evict(SubMulti.class);
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();

View File

@ -63,7 +63,7 @@ public class OneToOneCacheTest extends LegacyTestCase {
assertNotNull( mainObject.getObj2() ); assertNotNull( mainObject.getObj2() );
// after evicting, it works. // after evicting, it works.
getSessions().evict( MainObject.class ); sessionFactory().evict( MainObject.class );
mainObject = readMainObject(); mainObject = readMainObject();

View File

@ -1194,7 +1194,7 @@ public class ParentChildTest extends LegacyTestCase {
} }
// Next, lets create that entity "under the covers" // Next, lets create that entity "under the covers"
Session anotherSession = getSessions().openSession(); Session anotherSession = sessionFactory().openSession();
anotherSession.beginTransaction(); anotherSession.beginTransaction();
Simple myNewSimple = new Simple(); Simple myNewSimple = new Simple();
myNewSimple.setName("My under the radar Simple entity"); myNewSimple.setName("My under the radar Simple entity");

View File

@ -111,7 +111,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
@ -123,9 +123,9 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 ); assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 1 );
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 ); assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 0 );
assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 1 ); assertEquals( sessionFactory().getStatistics().getQueryCachePutCount(), 1 );
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
@ -134,7 +134,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
@ -143,15 +143,15 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
.setCacheable( true ) .setCacheable( true )
.uniqueResult(); .uniqueResult();
assertNotNull( u ); assertNotNull( u );
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 ); assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 0 );
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 1 ); assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 1 );
u = ( User ) s.createCriteria( User.class ) u = ( User ) s.createCriteria( User.class )
.add( Restrictions.naturalId().set( "userName", "steve" ) ) .add( Restrictions.naturalId().set( "userName", "steve" ) )
.setCacheable( true ) .setCacheable( true )
.uniqueResult(); .uniqueResult();
assertNotNull( u ); assertNotNull( u );
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 ); assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 0 );
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 2 ); assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 2 );
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
@ -171,7 +171,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
@ -183,11 +183,11 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 ); assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 1 );
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 ); assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 0 );
assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 1 ); assertEquals( sessionFactory().getStatistics().getQueryCachePutCount(), 1 );
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
@ -196,8 +196,8 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
.setCacheable( true ) .setCacheable( true )
.uniqueResult(); .uniqueResult();
assertNotNull( u ); assertNotNull( u );
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 ); assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 0 );
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 1 ); assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 1 );
s.delete( u ); s.delete( u );
@ -226,7 +226,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
@ -236,11 +236,11 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
.uniqueResult(); .uniqueResult();
assertNotNull( u ); assertNotNull( u );
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 ); assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 1 );
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 ); assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 0 );
assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 1 ); assertEquals( sessionFactory().getStatistics().getQueryCachePutCount(), 1 );
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
s.getTransaction().commit(); s.getTransaction().commit();
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
@ -249,8 +249,8 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
.setCacheable( true ) .setCacheable( true )
.uniqueResult(); .uniqueResult();
assertNotNull( u ); assertNotNull( u );
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 ); assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 0 );
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 1 ); assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 1 );
s.delete( u ); s.delete( u );

View File

@ -80,26 +80,26 @@ public abstract class AbstractOperationTestCase extends BaseCoreFunctionalTestCa
} }
protected void clearCounts() { protected void clearCounts() {
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
} }
protected void assertInsertCount(int expected) { protected void assertInsertCount(int expected) {
int inserts = ( int ) getSessions().getStatistics().getEntityInsertCount(); int inserts = ( int ) sessionFactory().getStatistics().getEntityInsertCount();
assertEquals( "unexpected insert count", expected, inserts ); assertEquals( "unexpected insert count", expected, inserts );
} }
protected void assertUpdateCount(int expected) { protected void assertUpdateCount(int expected) {
int updates = ( int ) getSessions().getStatistics().getEntityUpdateCount(); int updates = ( int ) sessionFactory().getStatistics().getEntityUpdateCount();
assertEquals( "unexpected update counts", expected, updates ); assertEquals( "unexpected update counts", expected, updates );
} }
protected void assertDeleteCount(int expected) { protected void assertDeleteCount(int expected) {
int deletes = ( int ) getSessions().getStatistics().getEntityDeleteCount(); int deletes = ( int ) sessionFactory().getStatistics().getEntityDeleteCount();
assertEquals( "unexpected delete counts", expected, deletes ); assertEquals( "unexpected delete counts", expected, deletes );
} }
protected void assertFetchCount(int count) { protected void assertFetchCount(int count) {
int fetches = ( int ) getSessions().getStatistics().getEntityFetchCount(); int fetches = ( int ) sessionFactory().getStatistics().getEntityFetchCount();
assertEquals( count, fetches ); assertEquals( count, fetches );
} }

View File

@ -1,7 +1,6 @@
//$Id: MergeTest.java 11037 2007-01-09 16:04:16Z steve.ebersole@jboss.com $ //$Id: MergeTest.java 11037 2007-01-09 16:04:16Z steve.ebersole@jboss.com $
package org.hibernate.test.nonflushedchanges; package org.hibernate.test.nonflushedchanges;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -493,7 +492,7 @@ public class MergeTest extends AbstractOperationTestCase {
assertUpdateCount( 1 ); assertUpdateCount( 1 );
clearCounts(); clearCounts();
getSessions().getCache().evictEntityRegion( NumberedNode.class ); sessionFactory().getCache().evictEntityRegion( NumberedNode.class );
NumberedNode child2 = new NumberedNode( "child2" ); NumberedNode child2 = new NumberedNode( "child2" );
NumberedNode grandchild3 = new NumberedNode( "grandchild3" ); NumberedNode grandchild3 = new NumberedNode( "grandchild3" );

View File

@ -60,7 +60,7 @@ public class OnDeleteTest extends BaseCoreFunctionalTestCase {
comment = "db/dialect does not support circular cascade delete constraints" comment = "db/dialect does not support circular cascade delete constraints"
) )
public void testJoinedSubclass() { public void testJoinedSubclass() {
Statistics statistics = getSessions().getStatistics(); Statistics statistics = sessionFactory().getStatistics();
statistics.clear(); statistics.clear();
Session s = openSession(); Session s = openSession();

View File

@ -71,8 +71,8 @@ public class JoinedSubclassOneToOneTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
EntityStatistics addressStats = getSessions().getStatistics().getEntityStatistics( Address.class.getName() ); EntityStatistics addressStats = sessionFactory().getStatistics().getEntityStatistics( Address.class.getName() );
EntityStatistics mailingAddressStats = getSessions().getStatistics().getEntityStatistics("MailingAddress"); EntityStatistics mailingAddressStats = sessionFactory().getStatistics().getEntityStatistics("MailingAddress");
p = (Person) s.createQuery("from Person p join fetch p.address left join fetch p.mailingAddress").uniqueResult(); p = (Person) s.createQuery("from Person p join fetch p.address left join fetch p.mailingAddress").uniqueResult();
assertNotNull(p.address); assertNull(p.mailingAddress); assertNotNull(p.address); assertNull(p.mailingAddress);

View File

@ -53,7 +53,7 @@ public class DynamicMapOneToOneTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
EntityStatistics addressStats = getSessions().getStatistics().getEntityStatistics( "Address" ); EntityStatistics addressStats = sessionFactory().getStatistics().getEntityStatistics( "Address" );
person = ( Map ) s.createQuery( "from Person p join fetch p.address" ).uniqueResult(); person = ( Map ) s.createQuery( "from Person p join fetch p.address" ).uniqueResult();
assertNotNull( "could not locate person", person ); assertNotNull( "could not locate person", person );

View File

@ -73,8 +73,8 @@ public class DiscrimSubclassOneToOneTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
EntityStatistics addressStats = getSessions().getStatistics().getEntityStatistics( Address.class.getName() ); EntityStatistics addressStats = sessionFactory().getStatistics().getEntityStatistics( Address.class.getName() );
EntityStatistics mailingAddressStats = getSessions().getStatistics().getEntityStatistics("MailingAddress"); EntityStatistics mailingAddressStats = sessionFactory().getStatistics().getEntityStatistics("MailingAddress");
p = (Person) s.createQuery("from Person p join fetch p.address left join fetch p.mailingAddress").uniqueResult(); p = (Person) s.createQuery("from Person p join fetch p.address left join fetch p.mailingAddress").uniqueResult();
assertNotNull(p.address); assertNull(p.mailingAddress); assertNotNull(p.address); assertNull(p.mailingAddress);

View File

@ -47,21 +47,21 @@ public abstract class AbstractOperationTestCase extends BaseCoreFunctionalTestCa
} }
protected void clearCounts() { protected void clearCounts() {
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
} }
protected void assertInsertCount(int expected) { protected void assertInsertCount(int expected) {
int inserts = ( int ) getSessions().getStatistics().getEntityInsertCount(); int inserts = ( int ) sessionFactory().getStatistics().getEntityInsertCount();
assertEquals( "unexpected insert count", expected, inserts ); assertEquals( "unexpected insert count", expected, inserts );
} }
protected void assertUpdateCount(int expected) { protected void assertUpdateCount(int expected) {
int updates = ( int ) getSessions().getStatistics().getEntityUpdateCount(); int updates = ( int ) sessionFactory().getStatistics().getEntityUpdateCount();
assertEquals( "unexpected update counts", expected, updates ); assertEquals( "unexpected update counts", expected, updates );
} }
protected void assertDeleteCount(int expected) { protected void assertDeleteCount(int expected) {
int deletes = ( int ) getSessions().getStatistics().getEntityDeleteCount(); int deletes = ( int ) sessionFactory().getStatistics().getEntityDeleteCount();
assertEquals( "unexpected delete counts", expected, deletes ); assertEquals( "unexpected delete counts", expected, deletes );
} }
} }

View File

@ -505,7 +505,7 @@ public class MergeTest extends AbstractOperationTestCase {
assertUpdateCount(1); assertUpdateCount(1);
clearCounts(); clearCounts();
getSessions().getCache().evictEntityRegion( NumberedNode.class ); sessionFactory().getCache().evictEntityRegion( NumberedNode.class );
NumberedNode child2 = new NumberedNode("child2"); NumberedNode child2 = new NumberedNode("child2");
NumberedNode grandchild3 = new NumberedNode("grandchild3"); NumberedNode grandchild3 = new NumberedNode("grandchild3");

View File

@ -271,8 +271,8 @@ public class OrphanTest extends BaseCoreFunctionalTestCase {
t.commit(); t.commit();
session.close(); session.close();
getSessions().getCache().evictEntityRegion( Product.class ); sessionFactory().getCache().evictEntityRegion( Product.class );
getSessions().getCache().evictEntityRegion( Part.class ); sessionFactory().getCache().evictEntityRegion( Part.class );
session = openSession(); session = openSession();

View File

@ -241,18 +241,18 @@ public class PropertyRefTest extends BaseCoreFunctionalTestCase {
s.flush(); s.flush();
s.clear(); s.clear();
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
p = (Person) s.get( Person.class, p.getId() ); //get address reference by outer join p = (Person) s.get( Person.class, p.getId() ); //get address reference by outer join
assertTrue( Hibernate.isInitialized( p.getAddress() ) ); assertTrue( Hibernate.isInitialized( p.getAddress() ) );
assertNotNull( p.getAddress() ); assertNotNull( p.getAddress() );
assertEquals( getSessions().getStatistics().getPrepareStatementCount(), 1 ); assertEquals( sessionFactory().getStatistics().getPrepareStatementCount(), 1 );
assertEquals( getSessions().getStatistics().getEntityFetchCount(), 0 ); assertEquals( sessionFactory().getStatistics().getEntityFetchCount(), 0 );
s.clear(); s.clear();
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
p = (Person) s.createCriteria(Person.class) p = (Person) s.createCriteria(Person.class)
.setFetchMode("address", FetchMode.SELECT) .setFetchMode("address", FetchMode.SELECT)
@ -260,8 +260,8 @@ public class PropertyRefTest extends BaseCoreFunctionalTestCase {
assertTrue( Hibernate.isInitialized( p.getAddress() ) ); assertTrue( Hibernate.isInitialized( p.getAddress() ) );
assertNotNull( p.getAddress() ); assertNotNull( p.getAddress() );
assertEquals( getSessions().getStatistics().getPrepareStatementCount(), 2 ); assertEquals( sessionFactory().getStatistics().getPrepareStatementCount(), 2 );
assertEquals( getSessions().getStatistics().getEntityFetchCount(), 0 ); assertEquals( sessionFactory().getStatistics().getEntityFetchCount(), 0 );
s.createQuery("delete from Address").executeUpdate(); s.createQuery("delete from Address").executeUpdate();
s.createQuery("delete from Person").executeUpdate(); s.createQuery("delete from Person").executeUpdate();
@ -272,7 +272,7 @@ public class PropertyRefTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testForeignKeyCreation() { public void testForeignKeyCreation() {
PersistentClass classMapping = getCfg().getClassMapping("org.hibernate.test.propertyref.basic.Account"); PersistentClass classMapping = configuration().getClassMapping("org.hibernate.test.propertyref.basic.Account");
Iterator foreignKeyIterator = classMapping.getTable().getForeignKeyIterator(); Iterator foreignKeyIterator = classMapping.getTable().getForeignKeyIterator();
boolean found = false; boolean found = false;

View File

@ -2219,7 +2219,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
} }
private Constructor getConstructor() { private Constructor getConstructor() {
Type studentNametype = Type studentNametype =
( ( SessionFactoryImpl ) getSessions() ) ( ( SessionFactoryImpl ) sessionFactory() )
.getEntityPersister( Student.class.getName() ) .getEntityPersister( Student.class.getName() )
.getPropertyType( "name" ); .getPropertyType( "name" );
return ReflectHelper.getConstructor( Student.class, new Type[] {Hibernate.LONG, studentNametype} ); return ReflectHelper.getConstructor( Student.class, new Type[] {Hibernate.LONG, studentNametype} );

View File

@ -47,7 +47,7 @@ public class NativeSQLQueryPlanEqualsTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testNativeSQLQuerySpecEquals() { public void testNativeSQLQuerySpecEquals() {
QueryPlanCache cache = new QueryPlanCache( sfi() ); QueryPlanCache cache = new QueryPlanCache( sessionFactory() );
NativeSQLQuerySpecification firstSpec = createSpec(); NativeSQLQuerySpecification firstSpec = createSpec();
NativeSQLQuerySpecification secondSpec = createSpec(); NativeSQLQuerySpecification secondSpec = createSpec();
@ -63,7 +63,7 @@ public class NativeSQLQueryPlanEqualsTest extends BaseCoreFunctionalTestCase {
String blah = "blah"; String blah = "blah";
String select = "select blah from blah"; String select = "select blah from blah";
NativeSQLQueryReturn[] queryReturns = new NativeSQLQueryScalarReturn[] { NativeSQLQueryReturn[] queryReturns = new NativeSQLQueryScalarReturn[] {
new NativeSQLQueryScalarReturn( blah, sfi().getTypeResolver().basic( "int" ) ) new NativeSQLQueryScalarReturn( blah, sessionFactory().getTypeResolver().basic( "int" ) )
}; };
return new NativeSQLQuerySpecification( select, queryReturns, null ); return new NativeSQLQuerySpecification( select, queryReturns, null );
} }

View File

@ -57,7 +57,7 @@ public class RowIdTest extends BaseCoreFunctionalTestCase {
public void afterSessionFactoryBuilt() { public void afterSessionFactoryBuilt() {
super.afterSessionFactoryBuilt(); super.afterSessionFactoryBuilt();
Session session = sfi().openSession(); Session session = sessionFactory().openSession();
session.doWork( session.doWork(
new Work() { new Work() {
@Override @Override

View File

@ -78,9 +78,9 @@ public abstract class CustomSQLTestSupport extends BaseCoreFunctionalTestCase {
t.commit(); t.commit();
s.close(); s.close();
getSessions().getCache().evictEntityRegion( Organization.class ); sessionFactory().getCache().evictEntityRegion( Organization.class );
getSessions().getCache().evictEntityRegion( Person.class ); sessionFactory().getCache().evictEntityRegion( Person.class );
getSessions().getCache().evictEntityRegion( Employment.class ); sessionFactory().getCache().evictEntityRegion( Employment.class );
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();

View File

@ -146,7 +146,7 @@ public class NativeSQLQueriesTest extends BaseCoreFunctionalTestCase {
Session s = openSession(); Session s = openSession();
s.beginTransaction(); s.beginTransaction();
sfi().getStatistics().clear(); sessionFactory().getStatistics().clear();
// create an Organization... // create an Organization...
Organization jboss = new Organization( "JBoss" ); Organization jboss = new Organization( "JBoss" );
@ -154,11 +154,11 @@ public class NativeSQLQueriesTest extends BaseCoreFunctionalTestCase {
// now query on Employment, this should not cause an auto-flush // now query on Employment, this should not cause an auto-flush
s.createSQLQuery( getEmploymentSQL() ).list(); s.createSQLQuery( getEmploymentSQL() ).list();
assertEquals( 0, sfi().getStatistics().getEntityInsertCount() ); assertEquals( 0, sessionFactory().getStatistics().getEntityInsertCount() );
// now try to query on Employment but this time add Organization as a synchronized query space... // now try to query on Employment but this time add Organization as a synchronized query space...
s.createSQLQuery( getEmploymentSQL() ).addSynchronizedEntityClass( Organization.class ).list(); s.createSQLQuery( getEmploymentSQL() ).addSynchronizedEntityClass( Organization.class ).list();
assertEquals( 1, sfi().getStatistics().getEntityInsertCount() ); assertEquals( 1, sessionFactory().getStatistics().getEntityInsertCount() );
// clean up // clean up
s.delete( jboss ); s.delete( jboss );

View File

@ -52,8 +52,8 @@ public class NativeSqlAndQuotedIdentifiersTest extends BaseCoreFunctionalTestCas
@Override @Override
protected void prepareTest() throws Exception { protected void prepareTest() throws Exception {
if(sfi()==null)return; if( sessionFactory()==null)return;
Session session = sfi().openSession(); Session session = sessionFactory().openSession();
session.beginTransaction(); session.beginTransaction();
session.save( new Person( "me" ) ); session.save( new Person( "me" ) );
session.getTransaction().commit(); session.getTransaction().commit();
@ -62,8 +62,8 @@ public class NativeSqlAndQuotedIdentifiersTest extends BaseCoreFunctionalTestCas
@Override @Override
protected void cleanupTest() throws Exception { protected void cleanupTest() throws Exception {
if(sfi()==null)return; if( sessionFactory()==null)return;
Session session = sfi().openSession(); Session session = sessionFactory().openSession();
session.beginTransaction(); session.beginTransaction();
session.createQuery( "delete Person" ).executeUpdate(); session.createQuery( "delete Person" ).executeUpdate();
session.getTransaction().commit(); session.getTransaction().commit();

View File

@ -56,7 +56,7 @@ public class StatelessSessionQueryTest extends BaseCoreFunctionalTestCase {
public void testCriteria() { public void testCriteria() {
TestData testData=new TestData(); TestData testData=new TestData();
testData.createData(); testData.createData();
StatelessSession s = getSessions().openStatelessSession(); StatelessSession s = sessionFactory().openStatelessSession();
assertEquals( 1, s.createCriteria( Contact.class ).list().size() ); assertEquals( 1, s.createCriteria( Contact.class ).list().size() );
s.close(); s.close();
testData.cleanData(); testData.cleanData();
@ -66,7 +66,7 @@ public class StatelessSessionQueryTest extends BaseCoreFunctionalTestCase {
public void testCriteriaWithSelectFetchMode() { public void testCriteriaWithSelectFetchMode() {
TestData testData=new TestData(); TestData testData=new TestData();
testData.createData(); testData.createData();
StatelessSession s = getSessions().openStatelessSession(); StatelessSession s = sessionFactory().openStatelessSession();
assertEquals( 1, s.createCriteria( Contact.class ).setFetchMode( "org", FetchMode.SELECT ) assertEquals( 1, s.createCriteria( Contact.class ).setFetchMode( "org", FetchMode.SELECT )
.list().size() ); .list().size() );
s.close(); s.close();
@ -77,7 +77,7 @@ public class StatelessSessionQueryTest extends BaseCoreFunctionalTestCase {
public void testHQL() { public void testHQL() {
TestData testData=new TestData(); TestData testData=new TestData();
testData.createData(); testData.createData();
StatelessSession s = getSessions().openStatelessSession(); StatelessSession s = sessionFactory().openStatelessSession();
assertEquals( 1, s.createQuery( "from Contact c join fetch c.org join fetch c.org.country" ) assertEquals( 1, s.createQuery( "from Contact c join fetch c.org join fetch c.org.country" )
.list().size() ); .list().size() );
s.close(); s.close();

View File

@ -47,7 +47,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testCreateUpdateReadDelete() { public void testCreateUpdateReadDelete() {
StatelessSession ss = getSessions().openStatelessSession(); StatelessSession ss = sessionFactory().openStatelessSession();
Transaction tx = ss.beginTransaction(); Transaction tx = ss.beginTransaction();
Document doc = new Document("blah blah blah", "Blahs"); Document doc = new Document("blah blah blah", "Blahs");
ss.insert(doc); ss.insert(doc);
@ -109,7 +109,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testHqlBulk() { public void testHqlBulk() {
StatelessSession ss = getSessions().openStatelessSession(); StatelessSession ss = sessionFactory().openStatelessSession();
Transaction tx = ss.beginTransaction(); Transaction tx = ss.beginTransaction();
Document doc = new Document("blah blah blah", "Blahs"); Document doc = new Document("blah blah blah", "Blahs");
ss.insert(doc); ss.insert(doc);
@ -141,7 +141,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testInitId() { public void testInitId() {
StatelessSession ss = getSessions().openStatelessSession(); StatelessSession ss = sessionFactory().openStatelessSession();
Transaction tx = ss.beginTransaction(); Transaction tx = ss.beginTransaction();
Paper paper = new Paper(); Paper paper = new Paper();
paper.setColor( "White" ); paper.setColor( "White" );
@ -157,7 +157,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testRefresh() { public void testRefresh() {
StatelessSession ss = getSessions().openStatelessSession(); StatelessSession ss = sessionFactory().openStatelessSession();
Transaction tx = ss.beginTransaction(); Transaction tx = ss.beginTransaction();
Paper paper = new Paper(); Paper paper = new Paper();
paper.setColor( "whtie" ); paper.setColor( "whtie" );
@ -165,7 +165,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
tx.commit(); tx.commit();
ss.close(); ss.close();
ss = getSessions().openStatelessSession(); ss = sessionFactory().openStatelessSession();
tx = ss.beginTransaction(); tx = ss.beginTransaction();
Paper p2 = ( Paper ) ss.get( Paper.class, paper.getId() ); Paper p2 = ( Paper ) ss.get( Paper.class, paper.getId() );
p2.setColor( "White" ); p2.setColor( "White" );
@ -173,7 +173,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
tx.commit(); tx.commit();
ss.close(); ss.close();
ss = getSessions().openStatelessSession(); ss = sessionFactory().openStatelessSession();
tx = ss.beginTransaction(); tx = ss.beginTransaction();
assertEquals( "whtie", paper.getColor() ); assertEquals( "whtie", paper.getColor() );
ss.refresh( paper ); ss.refresh( paper );

View File

@ -114,7 +114,7 @@ public class StatelessSessionFetchingTest extends BaseCoreFunctionalTestCase {
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
StatelessSession ss = sfi().openStatelessSession(); StatelessSession ss = sessionFactory().openStatelessSession();
ss.beginTransaction(); ss.beginTransaction();
Task taskRef = ( Task ) ss.createQuery( "from Task t join fetch t.resource join fetch t.user" ).uniqueResult(); Task taskRef = ( Task ) ss.createQuery( "from Task t join fetch t.resource join fetch t.user" ).uniqueResult();
assertTrue( taskRef != null ); assertTrue( taskRef != null );

View File

@ -63,7 +63,7 @@ public class StatsTest extends BaseCoreFunctionalTestCase {
@Test @Test
@SuppressWarnings( {"UnusedAssignment"}) @SuppressWarnings( {"UnusedAssignment"})
public void testCollectionFetchVsLoad() throws Exception { public void testCollectionFetchVsLoad() throws Exception {
Statistics stats = getSessions().getStatistics(); Statistics stats = sessionFactory().getStatistics();
stats.clear(); stats.clear();
Session s = openSession(); Session s = openSession();
@ -151,7 +151,7 @@ public class StatsTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testQueryStatGathering() { public void testQueryStatGathering() {
Statistics stats = getSessions().getStatistics(); Statistics stats = sessionFactory().getStatistics();
stats.clear(); stats.clear();
Session s = openSession(); Session s = openSession();

View File

@ -68,7 +68,7 @@ public class SubselectTest extends BaseCoreFunctionalTestCase {
assertNotNull( being.getSpecies() ); assertNotNull( being.getSpecies() );
} }
s.clear(); s.clear();
getSessions().getCache().evictEntityRegion( Being.class ); sessionFactory().getCache().evictEntityRegion( Being.class );
Being gav = (Being) s.get(Being.class, gavin.getId()); Being gav = (Being) s.get(Being.class, gavin.getId());
assertEquals( gav.getLocation(), gavin.getAddress() ); assertEquals( gav.getLocation(), gavin.getAddress() );
assertEquals( gav.getSpecies(), "human" ); assertEquals( gav.getSpecies(), "human" );

View File

@ -50,7 +50,7 @@ public class TimestampTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testUpdateFalse() { public void testUpdateFalse() {
getSessions().getStatistics().clear(); sessionFactory().getStatistics().clear();
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
@ -61,8 +61,8 @@ public class TimestampTest extends BaseCoreFunctionalTestCase {
t.commit(); t.commit();
s.close(); s.close();
assertEquals( 1, getSessions().getStatistics().getEntityInsertCount() ); assertEquals( 1, sessionFactory().getStatistics().getEntityInsertCount() );
assertEquals( 0, getSessions().getStatistics().getEntityUpdateCount() ); assertEquals( 0, sessionFactory().getStatistics().getEntityUpdateCount() );
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
@ -72,7 +72,7 @@ public class TimestampTest extends BaseCoreFunctionalTestCase {
t.commit(); t.commit();
s.close(); s.close();
assertEquals( 1, getSessions().getStatistics().getEntityDeleteCount() ); assertEquals( 1, sessionFactory().getStatistics().getEntityDeleteCount() );
} }
@Test @Test

View File

@ -133,7 +133,7 @@ public class TypeOverrideTest extends BaseCoreFunctionalTestCase {
} }
private SqlTypeDescriptor getResolvedSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) { private SqlTypeDescriptor getResolvedSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
return ( ( SessionFactoryImplementor ) getSessions() ) return ( ( SessionFactoryImplementor ) sessionFactory() )
.getTypeResolver() .getTypeResolver()
.resolveSqlTypeDescriptor( sqlTypeDescriptor ); .resolveSqlTypeDescriptor( sqlTypeDescriptor );
} }
@ -197,7 +197,7 @@ public class TypeOverrideTest extends BaseCoreFunctionalTestCase {
else { else {
assertSame( assertSame(
VarcharTypeDescriptor.INSTANCE, VarcharTypeDescriptor.INSTANCE,
( ( SessionFactoryImplementor ) getSessions() ) ( ( SessionFactoryImplementor ) sessionFactory() )
.getTypeResolver() .getTypeResolver()
.resolveSqlTypeDescriptor( VarcharTypeDescriptor.INSTANCE ) .resolveSqlTypeDescriptor( VarcharTypeDescriptor.INSTANCE )
); );

View File

@ -65,9 +65,9 @@ public class SybaseTimestampVersioningTest extends BaseCoreFunctionalTestCase {
Transaction t1 = null; Transaction t1 = null;
Transaction t2 = null; Transaction t2 = null;
try { try {
s1 = getSessions().openSession(); s1 = sessionFactory().openSession();
t1 = s1.beginTransaction(); t1 = s1.beginTransaction();
s2 = getSessions().openSession(); s2 = sessionFactory().openSession();
t2 = s2.beginTransaction(); t2 = s2.beginTransaction();
User user1 = ( User ) s1.get( User.class, steve.getId() ); User user1 = ( User ) s1.get( User.class, steve.getId() );

View File

@ -180,7 +180,7 @@ public class EhCacheTest extends BaseCoreFunctionalTestCase {
} }
// check the version value in the cache... // check the version value in the cache...
SecondLevelCacheStatistics slcs = sfi().getStatistics() SecondLevelCacheStatistics slcs = sessionFactory().getStatistics()
.getSecondLevelCacheStatistics( VersionedItem.class.getName() ); .getSecondLevelCacheStatistics( VersionedItem.class.getName() );
Object entry = slcs.getEntries().get( item.getId() ); Object entry = slcs.getEntries().get( item.getId() );

View File

@ -94,6 +94,7 @@ import org.hibernate.mapping.AuxiliaryDatabaseObject;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.secure.JACCConfiguration; import org.hibernate.secure.JACCConfiguration;
import org.hibernate.service.internal.ServiceRegistryImpl;
import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator; import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator;
import org.hibernate.service.spi.ServiceRegistry; import org.hibernate.service.spi.ServiceRegistry;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -871,6 +872,10 @@ public class Ejb3Configuration implements Serializable, Referenceable {
return buildEntityManagerFactory(); return buildEntityManagerFactory();
} }
public EntityManagerFactory createEntityManagerFactory(Map config, ServiceRegistryImpl serviceRegistry) {
return null; // todo : implement method body
}
/** /**
* Process configuration and build an EntityManagerFactory <b>when</b> the configuration is ready * Process configuration and build an EntityManagerFactory <b>when</b> the configuration is ready
* @deprecated * @deprecated
@ -882,6 +887,10 @@ public class Ejb3Configuration implements Serializable, Referenceable {
} }
public EntityManagerFactory buildEntityManagerFactory() { public EntityManagerFactory buildEntityManagerFactory() {
return buildEntityManagerFactory( new ServiceRegistryImpl( cfg.getProperties() ) );
}
public EntityManagerFactory buildEntityManagerFactory(ServiceRegistry serviceRegistry) {
Thread thread = null; Thread thread = null;
ClassLoader contextClassLoader = null; ClassLoader contextClassLoader = null;
if (overridenClassLoader != null) { if (overridenClassLoader != null) {
@ -897,7 +906,8 @@ public class Ejb3Configuration implements Serializable, Referenceable {
discardOnClose, discardOnClose,
getSessionInterceptorClass( cfg.getProperties() ), getSessionInterceptorClass( cfg.getProperties() ),
cfg, cfg,
connectionProviderInjectionData connectionProviderInjectionData,
serviceRegistry
); );
} }
catch (HibernateException e) { catch (HibernateException e) {

View File

@ -38,6 +38,7 @@ import javax.persistence.spi.PersistenceUnitTransactionType;
import org.hibernate.EntityMode; import org.hibernate.EntityMode;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl; import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.metamodel.MetamodelImpl; import org.hibernate.ejb.metamodel.MetamodelImpl;
@ -46,6 +47,7 @@ import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.metadata.ClassMetadata; import org.hibernate.metadata.ClassMetadata;
import org.hibernate.service.internal.ServiceRegistryImpl; import org.hibernate.service.internal.ServiceRegistryImpl;
import org.hibernate.service.spi.ServiceRegistry;
/** /**
* Actual Hiberate implementation of {@link javax.persistence.EntityManagerFactory}. * Actual Hiberate implementation of {@link javax.persistence.EntityManagerFactory}.
@ -55,7 +57,7 @@ import org.hibernate.service.internal.ServiceRegistryImpl;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory { public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
private final transient ServiceRegistryImpl serviceRegistry; private final transient ServiceRegistry serviceRegistry;
private final SessionFactory sessionFactory; private final SessionFactory sessionFactory;
private final PersistenceUnitTransactionType transactionType; private final PersistenceUnitTransactionType transactionType;
private final boolean discardOnClose; private final boolean discardOnClose;
@ -72,16 +74,11 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
public EntityManagerFactoryImpl( public EntityManagerFactoryImpl(
PersistenceUnitTransactionType transactionType, PersistenceUnitTransactionType transactionType,
boolean discardOnClose, boolean discardOnClose,
Class<?> sessionInterceptorClass, Class sessionInterceptorClass,
Configuration cfg, AnnotationConfiguration cfg,
Map connectionProviderInjectionData) { Map connectionProviderInjectionData,
// FIXME: Get rid of this temporary way of creating the service registry for EM ServiceRegistry serviceRegistry) {
Map serviceRegistryProperties = new HashMap( this.serviceRegistry = serviceRegistry;
cfg.getProperties().size() + connectionProviderInjectionData.size()
);
serviceRegistryProperties.putAll( cfg.getProperties() );
serviceRegistryProperties.putAll( connectionProviderInjectionData );
this.serviceRegistry = new ServiceRegistryImpl( serviceRegistryProperties );
this.sessionFactory = cfg.buildSessionFactory( serviceRegistry ); this.sessionFactory = cfg.buildSessionFactory( serviceRegistry );
this.transactionType = transactionType; this.transactionType = transactionType;
this.discardOnClose = discardOnClose; this.discardOnClose = discardOnClose;
@ -134,7 +131,6 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
public void close() { public void close() {
sessionFactory.close(); sessionFactory.close();
serviceRegistry.destroy();
} }
public Map<String, Object> getProperties() { public Map<String, Object> getProperties() {

View File

@ -42,7 +42,7 @@ import org.hibernate.ejb.metamodel.Phone;
import org.hibernate.ejb.metamodel.Product; import org.hibernate.ejb.metamodel.Product;
import org.hibernate.ejb.metamodel.ShelfLife; import org.hibernate.ejb.metamodel.ShelfLife;
import org.hibernate.ejb.metamodel.Spouse; import org.hibernate.ejb.metamodel.Spouse;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.ejb.test.callbacks.RemoteControl; import org.hibernate.ejb.test.callbacks.RemoteControl;
import org.hibernate.ejb.test.callbacks.Television; import org.hibernate.ejb.test.callbacks.Television;
import org.hibernate.ejb.test.callbacks.VideoSystem; import org.hibernate.ejb.test.callbacks.VideoSystem;
@ -54,7 +54,7 @@ import org.hibernate.ejb.test.inheritance.Strawberry;
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class CriteriaCompilingTest extends TestCase { public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase {
public Class[] getAnnotatedClasses() { public Class[] getAnnotatedClasses() {
return new Class[] { return new Class[] {
Customer.class, Customer.class,

View File

@ -44,14 +44,14 @@ import org.hibernate.ejb.metamodel.Phone;
import org.hibernate.ejb.metamodel.Product; import org.hibernate.ejb.metamodel.Product;
import org.hibernate.ejb.metamodel.ShelfLife; import org.hibernate.ejb.metamodel.ShelfLife;
import org.hibernate.ejb.metamodel.Spouse; import org.hibernate.ejb.metamodel.Spouse;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* TODO : javadoc * TODO : javadoc
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class QueryBuilderTest extends TestCase { public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase {
@Override @Override
public Class[] getAnnotatedClasses() { public Class[] getAnnotatedClasses() {
return new Class[] { return new Class[] {

View File

@ -26,14 +26,15 @@ import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import javax.persistence.metamodel.SingularAttribute; import javax.persistence.metamodel.SingularAttribute;
import org.hibernate.ejb.test.TestCase;
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* TODO : javadoc * TODO : javadoc
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class BasicCriteriaUsageTest extends TestCase { public class BasicCriteriaUsageTest extends BaseEntityManagerFunctionalTestCase {
public Class[] getAnnotatedClasses() { public Class[] getAnnotatedClasses() {
return new Class[] { Wall.class }; return new Class[] { Wall.class };

View File

@ -27,13 +27,14 @@ import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import org.hibernate.ejb.test.TestCase;
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* *
* @author alan.oleary * @author alan.oleary
*/ */
public class ComponentCriteriaTest extends TestCase { public class ComponentCriteriaTest extends BaseEntityManagerFunctionalTestCase {
public Class[] getAnnotatedClasses() { public Class[] getAnnotatedClasses() {
return new Class[] { Client.class }; return new Class[] { Client.class };
} }

View File

@ -22,14 +22,14 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.ejb.metamodel; package org.hibernate.ejb.metamodel;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* TODO : javadoc * TODO : javadoc
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public abstract class AbstractMetamodelSpecificTest extends TestCase { public abstract class AbstractMetamodelSpecificTest extends BaseEntityManagerFunctionalTestCase {
@Override @Override
public Class[] getAnnotatedClasses() { public Class[] getAnnotatedClasses() {
return new Class[] { return new Class[] {

View File

@ -25,14 +25,14 @@ package org.hibernate.ejb.metamodel;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.metamodel.EntityType; import javax.persistence.metamodel.EntityType;
import javax.persistence.metamodel.SingularAttribute; import javax.persistence.metamodel.SingularAttribute;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* TODO : javadoc * TODO : javadoc
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class EmbeddedTypeTest extends TestCase { public class EmbeddedTypeTest extends BaseEntityManagerFunctionalTestCase {
@Override @Override
public Class[] getAnnotatedClasses() { public Class[] getAnnotatedClasses() {
return new Class[] { return new Class[] {

View File

@ -1,4 +1,3 @@
// $Id$
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
@ -23,7 +22,10 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.ejb.test; package org.hibernate.ejb.test;
import static org.hibernate.testing.TestLogger.LOG;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
@ -31,15 +33,20 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.ejb.AvailableSettings; import org.hibernate.ejb.AvailableSettings;
import org.hibernate.ejb.Ejb3Configuration; import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.testing.junit.functional.annotations.HibernateTestCase; import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.internal.ServiceRegistryImpl;
import org.hibernate.testing.AfterClassOnce;
import org.hibernate.testing.BeforeClassOnce;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.hibernate.testing.TestLogger.LOG;
/** /**
* A base class for all ejb tests. * A base class for all ejb tests.
@ -47,41 +54,174 @@ import org.hibernate.testing.junit.functional.annotations.HibernateTestCase;
* @author Emmanuel Bernard * @author Emmanuel Bernard
* @author Hardy Ferentschik * @author Hardy Ferentschik
*/ */
public abstract class TestCase extends HibernateTestCase { public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCase {
private static final Dialect dialect = Dialect.getDialect();
protected static EntityManagerFactory factory; private static ServiceRegistryImpl serviceRegistry;
private static EntityManagerFactory factory;
private EntityManager em; private EntityManager em;
private ArrayList isolatedEms = new ArrayList(); private ArrayList<EntityManager> isolatedEms = new ArrayList<EntityManager>();
public static Dialect getDialect() {
public TestCase() { return dialect;
super();
} }
public TestCase(String name) { @BeforeClassOnce
super( name ); private void buildSessionFactory() throws Exception {
LOG.trace( "Building session factory" );
Ejb3Configuration ejb3Configuration = buildConfiguration();
serviceRegistry = buildServiceRegistry( ejb3Configuration.getHibernateConfiguration() );
factory = ejb3Configuration.createEntityManagerFactory( getConfig(), serviceRegistry );
afterEntityManagerFactoryBuilt();
}
protected Ejb3Configuration buildConfiguration() {
Ejb3Configuration ejb3Cfg = constructConfiguration();
configure( ejb3Cfg.getHibernateConfiguration() );
addMappings( ejb3Cfg.getHibernateConfiguration() );
ejb3Cfg.getHibernateConfiguration().buildMappings();
afterConfigurationBuilt( ejb3Cfg.getHibernateConfiguration() );
return ejb3Cfg;
}
protected Ejb3Configuration constructConfiguration() {
Ejb3Configuration ejb3Configuration = new Ejb3Configuration();
if ( createSchema() ) {
ejb3Configuration.getHibernateConfiguration().setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
}
ejb3Configuration
.getHibernateConfiguration()
.setProperty( Configuration.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
ejb3Configuration
.getHibernateConfiguration()
.setProperty( Environment.DIALECT, getDialect().getClass().getName() );
return ejb3Configuration;
}
protected void configure(Configuration hibernateConfiguration) {
}
protected Map getConfig() {
Map<Object, Object> config = loadProperties();
ArrayList<Class> classes = new ArrayList<Class>();
classes.addAll( Arrays.asList( getAnnotatedClasses() ) );
config.put( AvailableSettings.LOADED_CLASSES, classes );
for ( Map.Entry<Class, String> entry : getCachedClasses().entrySet() ) {
config.put(
AvailableSettings.CLASS_CACHE_PREFIX + "." + entry.getKey().getName(),
entry.getValue()
);
}
for ( Map.Entry<String, String> entry : getCachedCollections().entrySet() ) {
config.put(
AvailableSettings.COLLECTION_CACHE_PREFIX + "." + entry.getKey(),
entry.getValue()
);
}
if ( getEjb3DD().length > 0 ) {
ArrayList<String> dds = new ArrayList<String>();
dds.addAll( Arrays.asList( getEjb3DD() ) );
config.put( AvailableSettings.XML_FILE_NAMES, dds );
}
addConfigOptions( config );
return config;
}
protected void addConfigOptions(Map options) {
}
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 = getOrmXmlFiles();
// if ( xmlFiles != null ) {
// for ( String xmlFile : xmlFiles ) {
// configuration.addResource( xmlFile );
// }
// }
}
protected static final String[] NO_MAPPINGS = new String[0];
protected String[] getMappings() {
return NO_MAPPINGS;
}
protected String getBaseForMappings() {
return "org/hibernate/test/";
}
protected static final Class<?>[] NO_CLASSES = new Class[0];
protected Class<?>[] getAnnotatedClasses() {
return NO_CLASSES;
}
protected String[] getAnnotatedPackages() {
return NO_MAPPINGS;
}
protected String[] getOrmXmlFiles() {
return NO_MAPPINGS;
}
protected void afterConfigurationBuilt(Configuration hibernateConfiguration) {
}
protected ServiceRegistryImpl buildServiceRegistry(Configuration configuration) {
Properties properties = new Properties();
properties.putAll( configuration.getProperties() );
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
ServiceRegistryImpl serviceRegistry = new ServiceRegistryImpl( properties );
applyServices( serviceRegistry );
return serviceRegistry;
}
protected void applyServices(ServiceRegistryImpl serviceRegistry) {
}
protected void afterEntityManagerFactoryBuilt() {
}
protected boolean createSchema() {
return true;
} }
@Override @AfterClassOnce
public void tearDown() throws Exception { public void releaseResources() {
super.tearDown(); cleanUnclosed( this.em );
for ( EntityManager isolatedEm : isolatedEms ) {
cleanUnclosed( isolatedEm );
} }
@Override if ( factory != null ) {
protected void buildConfiguration() throws Exception { factory.close();
Ejb3Configuration ejbconfig = new Ejb3Configuration();
HibernateTestCase.cfg = ejbconfig.getHibernateConfiguration();
if ( recreateSchema() ) {
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
} }
cfg.setProperty( Configuration.USE_NEW_ID_GENERATOR_MAPPINGS, "true" ); if ( serviceRegistry != null ) {
serviceRegistry.destroy();
for ( String mappingFile : getMappings() ) {
cfg.addResource( mappingFile );
} }
factory = ejbconfig.createEntityManagerFactory( getConfig() );
} }
private void cleanUnclosed(EntityManager em) { private void cleanUnclosed(EntityManager em) {
@ -100,24 +240,6 @@ public abstract class TestCase extends HibernateTestCase {
} }
} }
@Override
protected void handleUnclosedResources() {
cfg = null;
}
@Override
protected void closeResources() {
cleanUnclosed( this.em );
for ( Object isolatedEm : isolatedEms ) {
cleanUnclosed( (EntityManager) isolatedEm );
}
if ( factory != null ) {
factory.close();
}
super.closeResources();
}
protected EntityManager getOrCreateEntityManager() { protected EntityManager getOrCreateEntityManager() {
if ( em == null || !em.isOpen() ) { if ( em == null || !em.isOpen() ) {
em = factory.createEntityManager(); em = factory.createEntityManager();
@ -181,47 +303,4 @@ public abstract class TestCase extends HibernateTestCase {
props.setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); props.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
return props; return props;
} }
public Map getConfig() {
Map<Object, Object> config = loadProperties();
ArrayList<Class> classes = new ArrayList<Class>();
classes.addAll( Arrays.asList( getAnnotatedClasses() ) );
config.put( AvailableSettings.LOADED_CLASSES, classes );
for ( Map.Entry<Class, String> entry : getCachedClasses().entrySet() ) {
config.put(
AvailableSettings.CLASS_CACHE_PREFIX + "." + entry.getKey().getName(),
entry.getValue()
);
}
for ( Map.Entry<String, String> entry : getCachedCollections().entrySet() ) {
config.put(
AvailableSettings.COLLECTION_CACHE_PREFIX + "." + entry.getKey(),
entry.getValue()
);
}
if ( getEjb3DD().length > 0 ) {
ArrayList<String> dds = new ArrayList<String>();
dds.addAll( Arrays.asList( getEjb3DD() ) );
config.put( AvailableSettings.XML_FILE_NAMES, dds );
}
addConfigOptions( config );
return config;
}
protected void addConfigOptions(Map options) {
}
@Override
public void runBare() throws Throwable {
if ( !appliesTo( Dialect.getDialect() ) ) {
return;
}
super.runBare();
}
public boolean appliesTo(Dialect dialect) {
return true;
}
} }

View File

@ -45,7 +45,7 @@ import org.hibernate.stat.Statistics;
/** /**
* @author Gavin King * @author Gavin King
*/ */
public class EntityManagerTest extends TestCase { public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
public Class[] getAnnotatedClasses() { public Class[] getAnnotatedClasses() {
return new Class[] { return new Class[] {

View File

@ -1,12 +1,12 @@
//$Id$ //$Id$
package org.hibernate.ejb.test.association; package org.hibernate.ejb.test.association;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class AssociationTest extends TestCase { public class AssociationTest extends BaseEntityManagerFunctionalTestCase {
public void testBidirOneToOne() throws Exception { public void testBidirOneToOne() throws Exception {
EntityManager em = getOrCreateEntityManager(); EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin(); em.getTransaction().begin();

View File

@ -3,12 +3,13 @@ import java.math.BigDecimal;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.RollbackException; import javax.persistence.RollbackException;
import javax.validation.ConstraintViolationException; import javax.validation.ConstraintViolationException;
import org.hibernate.ejb.test.TestCase;
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class BeanValidationTest extends TestCase { public class BeanValidationTest extends BaseEntityManagerFunctionalTestCase {
public void testBeanValidationIntegrationOnFlush() { public void testBeanValidationIntegrationOnFlush() {
CupHolder ch = new CupHolder(); CupHolder ch = new CupHolder();

View File

@ -31,7 +31,7 @@ import org.hibernate.Session;
import org.hibernate.ejb.AvailableSettings; import org.hibernate.ejb.AvailableSettings;
import org.hibernate.ejb.HibernateEntityManager; import org.hibernate.ejb.HibernateEntityManager;
import org.hibernate.ejb.HibernateQuery; import org.hibernate.ejb.HibernateQuery;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.impl.AbstractQueryImpl; import org.hibernate.impl.AbstractQueryImpl;
/** /**
@ -39,7 +39,7 @@ import org.hibernate.impl.AbstractQueryImpl;
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class SharedCacheModesTest extends TestCase { public class SharedCacheModesTest extends BaseEntityManagerFunctionalTestCase {
@Override @Override
public Class[] getAnnotatedClasses() { public Class[] getAnnotatedClasses() {
return new Class[] { SimpleEntity.class }; return new Class[] { SimpleEntity.class };

View File

@ -3,12 +3,12 @@ package org.hibernate.ejb.test.callbacks;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class CallbackAndDirtyTest extends TestCase { public class CallbackAndDirtyTest extends BaseEntityManagerFunctionalTestCase {
public void testDirtyButNotDirty() throws Exception { public void testDirtyButNotDirty() throws Exception {
EntityManager manager = getOrCreateEntityManager(); EntityManager manager = getOrCreateEntityManager();

View File

@ -6,14 +6,14 @@ import java.util.List;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import org.hibernate.ejb.test.Cat; import org.hibernate.ejb.test.Cat;
import org.hibernate.ejb.test.Kitten; import org.hibernate.ejb.test.Kitten;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.FailureExpected; import org.hibernate.testing.FailureExpected;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class CallbacksTest extends TestCase { public class CallbacksTest extends BaseEntityManagerFunctionalTestCase {
public void testCallbackMethod() throws Exception { public void testCallbackMethod() throws Exception {
EntityManager em = getOrCreateEntityManager(); EntityManager em = getOrCreateEntityManager();

View File

@ -2,13 +2,13 @@
package org.hibernate.ejb.test.cascade; package org.hibernate.ejb.test.cascade;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction; import javax.persistence.EntityTransaction;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* @author Max Rydahl Andersen * @author Max Rydahl Andersen
*/ */
public class CascadeTest extends TestCase { public class CascadeTest extends BaseEntityManagerFunctionalTestCase {
public void testCascade() throws Exception { public void testCascade() throws Exception {

View File

@ -9,12 +9,12 @@ import java.io.ObjectOutputStream;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction; import javax.persistence.EntityTransaction;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class DeleteOrphanTest extends TestCase { public class DeleteOrphanTest extends BaseEntityManagerFunctionalTestCase {
public void testDeleteOrphan() throws Exception { public void testDeleteOrphan() throws Exception {
EntityTransaction tx; EntityTransaction tx;

View File

@ -9,12 +9,12 @@ import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class DetachAndContainsTest extends TestCase { public class DetachAndContainsTest extends BaseEntityManagerFunctionalTestCase {
public void testDetach() { public void testDetach() {
EntityManager em = getOrCreateEntityManager(); EntityManager em = getOrCreateEntityManager();

View File

@ -7,12 +7,12 @@ import javax.persistence.EntityTransaction;
import javax.persistence.Query; import javax.persistence.Query;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.ejb.HibernateEntityManager; import org.hibernate.ejb.HibernateEntityManager;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class FetchTest extends TestCase { public class FetchTest extends BaseEntityManagerFunctionalTestCase {
public void testCascadeAndFetchCollection() throws Exception { public void testCascadeAndFetchCollection() throws Exception {
EntityManager em = getOrCreateEntityManager(); EntityManager em = getOrCreateEntityManager();

View File

@ -1,8 +1,8 @@
package org.hibernate.ejb.test.cascade; package org.hibernate.ejb.test.cascade;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
public class FetchTest2 extends TestCase { public class FetchTest2 extends BaseEntityManagerFunctionalTestCase {
public void testProxyTransientStuff() throws Exception { public void testProxyTransientStuff() throws Exception {

View File

@ -9,6 +9,7 @@ import java.util.Date;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory;
import org.hibernate.ejb.HibernateEntityManager; import org.hibernate.ejb.HibernateEntityManager;
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.ejb.test.Cat; import org.hibernate.ejb.test.Cat;
import org.hibernate.ejb.test.Distributor; import org.hibernate.ejb.test.Distributor;
import org.hibernate.ejb.test.Item; import org.hibernate.ejb.test.Item;
@ -18,7 +19,7 @@ import org.hibernate.ejb.test.Wallet;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class EntityManagerSerializationTest extends org.hibernate.ejb.test.TestCase { public class EntityManagerSerializationTest extends BaseEntityManagerFunctionalTestCase {
public void testSerialization() throws Exception { public void testSerialization() throws Exception {
ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteArrayOutputStream stream = new ByteArrayOutputStream();

View File

@ -26,12 +26,12 @@ package org.hibernate.ejb.test.emops;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class FlushModeTest extends TestCase { public class FlushModeTest extends BaseEntityManagerFunctionalTestCase {
public void testCreateEMFlushMode() throws Exception { public void testCreateEMFlushMode() throws Exception {
Map<String, String> properties = new HashMap<String, String>(); Map<String, String> properties = new HashMap<String, String>();

View File

@ -7,12 +7,13 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.Query; import javax.persistence.Query;
import org.hibernate.ejb.test.TestCase;
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class FlushTest extends TestCase { public class FlushTest extends BaseEntityManagerFunctionalTestCase {
private static Set<String> names= new HashSet<String>(); private static Set<String> names= new HashSet<String>();
static { static {
names.add("Toonses"); names.add("Toonses");

View File

@ -1,13 +1,13 @@
//$Id$ //$Id$
package org.hibernate.ejb.test.emops; package org.hibernate.ejb.test.emops;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class GetReferenceTest extends TestCase { public class GetReferenceTest extends BaseEntityManagerFunctionalTestCase {
public void testWrongIdType() throws Exception { public void testWrongIdType() throws Exception {
EntityManager em = getOrCreateEntityManager(); EntityManager em = getOrCreateEntityManager();

View File

@ -3,12 +3,12 @@ package org.hibernate.ejb.test.emops;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class MergeTest extends TestCase { public class MergeTest extends BaseEntityManagerFunctionalTestCase {
public void testMergeWithIndexColumn() { public void testMergeWithIndexColumn() {
Race race = new Race(); Race race = new Race();
race.competitors.add( new Competitor( "Name" ) ); race.competitors.add( new Competitor( "Name" ) );

View File

@ -1,12 +1,12 @@
//$Id$ //$Id$
package org.hibernate.ejb.test.emops; package org.hibernate.ejb.test.emops;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class RefreshTest extends TestCase { public class RefreshTest extends BaseEntityManagerFunctionalTestCase {
public void testRefreshNonManaged() throws Exception { public void testRefreshNonManaged() throws Exception {
EntityManager em = getOrCreateEntityManager(); EntityManager em = getOrCreateEntityManager();

View File

@ -4,12 +4,13 @@ import static org.hibernate.testing.TestLogger.LOG;
import java.util.Map; import java.util.Map;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.OptimisticLockException; import javax.persistence.OptimisticLockException;
import org.hibernate.ejb.test.TestCase;
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class RemoveTest extends TestCase { public class RemoveTest extends BaseEntityManagerFunctionalTestCase {
public void testRemove() { public void testRemove() {
Race race = new Race(); Race race = new Race();

View File

@ -2,13 +2,13 @@
package org.hibernate.ejb.test.emops.cascade; package org.hibernate.ejb.test.emops.cascade;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.stat.Statistics; import org.hibernate.stat.Statistics;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class CascadePersistTest extends TestCase { public class CascadePersistTest extends BaseEntityManagerFunctionalTestCase {
public void testLazyCollectionsStayLazyOnPersist() throws Exception { public void testLazyCollectionsStayLazyOnPersist() throws Exception {
EntityManager em = getOrCreateEntityManager(); EntityManager em = getOrCreateEntityManager();

View File

@ -7,14 +7,14 @@ import javax.persistence.EntityNotFoundException;
import javax.persistence.OptimisticLockException; import javax.persistence.OptimisticLockException;
import javax.persistence.PersistenceException; import javax.persistence.PersistenceException;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.exception.ConstraintViolationException; import org.hibernate.exception.ConstraintViolationException;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class ExceptionTest extends TestCase { public class ExceptionTest extends BaseEntityManagerFunctionalTestCase {
public void testOptimisticLockingException() throws Exception { public void testOptimisticLockingException() throws Exception {
EntityManager em = getOrCreateEntityManager(); EntityManager em = getOrCreateEntityManager();

View File

@ -1,12 +1,12 @@
//$Id$ //$Id$
package org.hibernate.ejb.test.inheritance; package org.hibernate.ejb.test.inheritance;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class InheritanceTest extends TestCase { public class InheritanceTest extends BaseEntityManagerFunctionalTestCase {
public void testFind() throws Exception { public void testFind() throws Exception {
EntityManager firstSession = getOrCreateEntityManager( ); EntityManager firstSession = getOrCreateEntityManager( );

View File

@ -1,19 +1,49 @@
//$Id$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.ejb.test.lob; package org.hibernate.ejb.test.lob;
import javax.persistence.EntityManager;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.persistence.EntityManager;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.dialect.Dialect; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.ejb.test.TestCase;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import static org.junit.Assert.assertTrue;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class BlobTest extends TestCase { @RequiresDialectFeature( DialectChecks.SupportsExpectedLobUsagePattern.class )
public class BlobTest extends BaseEntityManagerFunctionalTestCase {
public void testBlobSerialization() throws Exception { public void testBlobSerialization() throws Exception {
EntityManager em = getOrCreateEntityManager(); EntityManager em = getOrCreateEntityManager();
@ -39,14 +69,7 @@ public class BlobTest extends TestCase {
em.close(); em.close();
} }
@Override
public boolean appliesTo(Dialect dialect) {
return dialect.supportsExpectedLobUsagePattern();
}
public Class[] getAnnotatedClasses() { public Class[] getAnnotatedClasses() {
return new Class[]{ return new Class[] { ImageReader.class };
ImageReader.class
};
} }
} }

View File

@ -17,12 +17,12 @@ import javax.persistence.QueryTimeoutException;
import org.hibernate.dialect.HSQLDialect; import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.Oracle10gDialect; import org.hibernate.dialect.Oracle10gDialect;
import org.hibernate.ejb.AvailableSettings; import org.hibernate.ejb.AvailableSettings;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class LockTest extends TestCase { public class LockTest extends BaseEntityManagerFunctionalTestCase {
public void testFindWithTimeoutHint() { public void testFindWithTimeoutHint() {
EntityManager em = getOrCreateEntityManager(); EntityManager em = getOrCreateEntityManager();

View File

@ -29,7 +29,7 @@ import org.hibernate.LockMode;
import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.ejb.AvailableSettings; import org.hibernate.ejb.AvailableSettings;
import org.hibernate.ejb.QueryImpl; import org.hibernate.ejb.QueryImpl;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.impl.SessionImpl; import org.hibernate.impl.SessionImpl;
/** /**
@ -37,7 +37,7 @@ import org.hibernate.impl.SessionImpl;
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class QueryLockingTest extends TestCase { public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
@Override @Override
protected Class<?>[] getAnnotatedClasses() { protected Class<?>[] getAnnotatedClasses() {

View File

@ -1,10 +1,10 @@
package org.hibernate.ejb.test.mapping; package org.hibernate.ejb.test.mapping;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class QuotingTest extends TestCase { public class QuotingTest extends BaseEntityManagerFunctionalTestCase {
public void testQuote() { public void testQuote() {
// the configuration was failing // the configuration was failing

View File

@ -38,13 +38,13 @@ import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.Type; import javax.persistence.metamodel.Type;
import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.ejb.metamodel.MetamodelImpl; import org.hibernate.ejb.metamodel.MetamodelImpl;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class MetadataTest extends TestCase { public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
public void testBaseOfService() throws Exception { public void testBaseOfService() throws Exception {
EntityManagerFactory emf = factory; EntityManagerFactory emf = factory;

Some files were not shown because too many files have changed in this diff Show More