HHH-5942 - Migrate to JUnit 4
This commit is contained in:
parent
ed882f68ae
commit
20a120ef6c
|
@ -907,7 +907,7 @@ public final class SessionFactoryImpl
|
|||
* <li>remove the JNDI binding
|
||||
* </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
|
||||
* it is important to not keep referencing the instance to let the garbage
|
||||
* collector release the memory.
|
||||
|
|
|
@ -23,13 +23,6 @@
|
|||
*/
|
||||
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.AttributeOverrides;
|
||||
import javax.persistence.Basic;
|
||||
|
@ -77,48 +70,41 @@ import javax.persistence.Temporal;
|
|||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.Transient;
|
||||
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.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.cfg.EJB3DTDEntityResolver;
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader;
|
||||
import org.hibernate.cfg.annotations.reflection.XMLContext;
|
||||
import org.hibernate.internal.util.xml.XMLHelper;
|
||||
import org.hibernate.testing.junit.functional.annotations.HibernateTestCase;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXNotSupportedException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
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
|
||||
*/
|
||||
public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
|
||||
|
||||
@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 class JPAOverridenAnnotationReaderTest extends BaseUnitTestCase {
|
||||
@Test
|
||||
public void testMappedSuperclassAnnotations() throws Exception {
|
||||
XMLContext context = buildContext(
|
||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||
|
@ -127,6 +113,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
|
|||
assertTrue( reader.isAnnotationPresent( MappedSuperclass.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEntityRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
JPAOverridenAnnotationReader reader = new JPAOverridenAnnotationReader( Administration.class, context );
|
||||
|
@ -257,6 +244,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEntityRelatedAnnotationsMetadataComplete() throws Exception {
|
||||
XMLContext context = buildContext(
|
||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||
|
@ -296,6 +284,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
|
|||
assertNull( reader.getAnnotation( TableGenerator.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
Method method = Administration.class.getDeclaredMethod( "getId" );
|
||||
|
@ -342,6 +331,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
|
|||
assertEquals( 1, reader.getAnnotation( AttributeOverrides.class ).value().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext(
|
||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||
|
@ -366,6 +356,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
|
|||
assertNotNull( reader.isAnnotationPresent( Basic.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVersionRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
Method method = Administration.class.getDeclaredMethod( "getVersion" );
|
||||
|
@ -377,6 +368,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
|
|||
assertNotNull( reader.getAnnotation( Version.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransientAndEmbeddedRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
|
||||
|
@ -390,6 +382,7 @@ public class JPAOverridenAnnotationReaderTest extends HibernateTestCase {
|
|||
assertNotNull( reader.getAnnotation( Embedded.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssociationRelatedAnnotations() throws Exception {
|
||||
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() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEntityListeners() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
|
||||
package org.hibernate.test.annotations.xml.ejb3;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.AssociationOverride;
|
||||
|
@ -51,8 +52,14 @@ import javax.persistence.Temporal;
|
|||
import javax.persistence.TemporalType;
|
||||
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 {
|
||||
reader = getReader( Entity2.class, "field1", "element-collection.orm1.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -80,6 +87,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
assertEquals( void.class, relAnno.targetClass() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderBy() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "element-collection.orm2.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -91,6 +99,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "element-collection.orm3.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -104,6 +113,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
assertTrue( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "element-collection.orm4.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -117,6 +127,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
assertFalse( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm5.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -130,6 +141,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm6.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -143,6 +155,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyClass() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm7.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -159,6 +172,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyTemporal() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm8.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -176,6 +190,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyEnumerated() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm9.xml" );
|
||||
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
|
||||
* an AttributeOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyAttributeOverride() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm10.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -217,6 +233,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "col1", overrides[0].column().name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyAttributeOverrides() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm11.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -257,6 +274,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
assertEquals( 1, overrides[1].column().scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm12.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -280,6 +298,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
assertEquals( 0, keyColAnno.scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm13.xml" );
|
||||
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
|
||||
* MapKeyJoinColumns annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyJoinColumn() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm14.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -324,6 +344,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "col1", joinColumns[0].name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyJoinColumns() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm15.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -356,6 +377,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "table1", joinColumns[1].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm16.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -373,6 +395,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
assertEquals( 0, column.scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm17.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -390,6 +413,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
assertEquals( 1, column.scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemporal() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm18.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -403,6 +427,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumerated() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm19.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -416,6 +441,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLob() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm20.xml" );
|
||||
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
|
||||
* AttributeOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleAttributeOverride() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm21.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -441,6 +468,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "col1", overrides[0].column().name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleAttributeOverrides() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm22.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -478,6 +506,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
* Tests that map-key-attribute-override and attribute-override elements
|
||||
* both end up in the AttributeOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testMixedAttributeOverrides() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm23.xml" );
|
||||
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
|
||||
* AssociationOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleAssociationOverride() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm24.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -510,6 +540,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "", overrides[0].joinTable().name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleAssociationOverridesJoinColumns() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm25.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -603,6 +634,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
assertTrue( joinColumns[1].unique() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollectionTableNoChildren() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm26.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -615,6 +647,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
assertEquals( 0, tableAnno.uniqueConstraints().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollectionTableAllChildren() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm27.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
@ -656,6 +689,7 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "col5", uniqueConstraints[1].columnNames()[1] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "element-collection.orm28.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package org.hibernate.test.annotations.xml.ejb3;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.AttributeOverride;
|
||||
|
@ -46,8 +46,14 @@ import javax.persistence.OrderColumn;
|
|||
import javax.persistence.TemporalType;
|
||||
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 {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm1.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -69,6 +75,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( void.class, relAnno.targetEntity() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderBy() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm2.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -80,6 +87,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm3.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -93,6 +101,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
assertTrue( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm4.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -106,6 +115,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
assertFalse( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm5.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -119,6 +129,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm6.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -132,6 +143,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyClass() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm7.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -148,6 +160,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyTemporal() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm8.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -165,6 +178,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyEnumerated() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm9.xml" );
|
||||
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
|
||||
* an AttributeOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyAttributeOverride() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm10.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -206,6 +221,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "col1", overrides[0].column().name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyAttributeOverrides() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm11.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -246,6 +262,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( 1, overrides[1].column().scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm12.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -269,6 +286,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( 0, keyColAnno.scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm13.xml" );
|
||||
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
|
||||
* MapKeyJoinColumns annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyJoinColumn() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm14.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -313,6 +332,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "col1", joinColumns[0].name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyJoinColumns() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm15.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -345,6 +365,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "table1", joinColumns[1].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableNoChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm16.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -360,6 +381,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableAllChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm17.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -424,6 +446,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeAll() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm18.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -432,6 +455,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm19.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -448,6 +472,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
* is specified in addition to a default cascade-persist or individual
|
||||
* cascade settings.
|
||||
*/
|
||||
@Test
|
||||
public void testCascadeAllPlusMore() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm20.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
@ -461,6 +486,7 @@ public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm21.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package org.hibernate.test.annotations.xml.ejb3;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.CascadeType;
|
||||
|
@ -35,8 +35,14 @@ import javax.persistence.ManyToOne;
|
|||
import javax.persistence.MapsId;
|
||||
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 {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm1.xml" );
|
||||
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
|
||||
* annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleJoinColumn() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm2.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
|
@ -71,6 +78,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "table1", joinColumns[0].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleJoinColumns() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm3.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
|
@ -98,6 +106,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
|||
assertTrue( joinColumns[1].unique() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableNoChildren() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm4.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
|
@ -113,6 +122,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
|||
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableAllChildren() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm5.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
|
@ -177,6 +187,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllAttributes() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm6.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
|
@ -198,6 +209,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeAll() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm7.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
|
@ -206,6 +218,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
|||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm8.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
|
@ -222,6 +235,7 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
|||
* is specified in addition to a default cascade-persist or individual
|
||||
* cascade settings.
|
||||
*/
|
||||
@Test
|
||||
public void testCascadeAllPlusMore() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm9.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package org.hibernate.test.annotations.xml.ejb3;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.AttributeOverride;
|
||||
|
@ -46,8 +46,14 @@ import javax.persistence.OrderColumn;
|
|||
import javax.persistence.TemporalType;
|
||||
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 {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm1.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -72,6 +78,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( void.class, relAnno.targetEntity() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderBy() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm2.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -83,6 +90,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm3.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -96,6 +104,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
assertTrue( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm4.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -109,6 +118,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
assertFalse( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm5.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -122,6 +132,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm6.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -135,6 +146,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyClass() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm7.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -151,6 +163,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyTemporal() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm8.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -168,6 +181,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyEnumerated() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm9.xml" );
|
||||
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
|
||||
* an AttributeOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyAttributeOverride() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm10.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -209,6 +224,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "col1", overrides[0].column().name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyAttributeOverrides() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm11.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -249,6 +265,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( 1, overrides[1].column().scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm12.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -272,6 +289,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( 0, keyColAnno.scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm13.xml" );
|
||||
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
|
||||
* MapKeyJoinColumns annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyJoinColumn() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm14.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -316,6 +335,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "col1", joinColumns[0].name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyJoinColumns() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm15.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -348,6 +368,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "table1", joinColumns[1].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableNoChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm16.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -363,6 +384,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableAllChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm17.xml" );
|
||||
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
|
||||
* annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleJoinColumn() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm18.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -445,6 +468,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "table1", joinColumns[0].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleJoinColumns() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm19.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -472,6 +496,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
assertTrue( joinColumns[1].unique() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeAll() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm20.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -480,6 +505,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm21.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -496,6 +522,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
* is specified in addition to a default cascade-persist or individual
|
||||
* cascade settings.
|
||||
*/
|
||||
@Test
|
||||
public void testCascadeAllPlusMore() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm22.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
@ -509,6 +536,7 @@ public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
|||
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm23.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
|
||||
package org.hibernate.test.annotations.xml.ejb3;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.CascadeType;
|
||||
|
@ -37,8 +38,14 @@ import javax.persistence.PrimaryKeyJoinColumn;
|
|||
import javax.persistence.PrimaryKeyJoinColumns;
|
||||
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 {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm1.xml" );
|
||||
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
|
||||
* a PrimaryKeyJoinColumns annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSinglePrimaryKeyJoinColumn() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm2.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
|
@ -80,6 +88,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "int", joinColumns[0].columnDefinition() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiplePrimaryKeyJoinColumn() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm3.xml" );
|
||||
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
|
||||
* annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleJoinColumn() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm4.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
|
@ -120,6 +130,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "table1", joinColumns[0].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleJoinColumns() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm5.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
|
@ -149,6 +160,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
|||
assertTrue( joinColumns[1].unique() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableNoChildren() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm6.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
|
@ -166,6 +178,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
|||
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableAllChildren() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm7.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
|
@ -232,6 +245,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
|||
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeAll() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm8.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
|
@ -240,6 +254,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
|||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm9.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
|
@ -256,6 +271,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
|||
* is specified in addition to a default cascade-persist or individual
|
||||
* cascade settings.
|
||||
*/
|
||||
@Test
|
||||
public void testCascadeAllPlusMore() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm10.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
|
@ -269,6 +285,7 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
|||
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllAttributes() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm11.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
|
|
|
@ -23,48 +23,31 @@
|
|||
*/
|
||||
|
||||
package org.hibernate.test.annotations.xml.ejb3;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.io.SAXReader;
|
||||
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader;
|
||||
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
|
||||
* 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.
|
||||
*/
|
||||
abstract class Ejb3XmlTestCase extends HibernateTestCase {
|
||||
abstract class Ejb3XmlTestCase extends BaseUnitTestCase {
|
||||
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) {
|
||||
assertTrue(
|
||||
"Expected annotation " + annotationType.getSimpleName() + " was not present",
|
||||
|
|
|
@ -45,7 +45,6 @@ import org.junit.Test;
|
|||
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
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") );
|
||||
s.persist( u );
|
||||
s.flush();
|
||||
long intialUpdateCount = sfi().getStatistics().getEntityUpdateCount();
|
||||
long intialUpdateCount = sessionFactory().getStatistics().getEntityUpdateCount();
|
||||
u.getPerson().setAddress( "Austin" );
|
||||
s.flush();
|
||||
assertEquals( intialUpdateCount + 1, sfi().getStatistics().getEntityUpdateCount() );
|
||||
intialUpdateCount = sfi().getStatistics().getEntityUpdateCount();
|
||||
assertEquals( intialUpdateCount + 1, sessionFactory().getStatistics().getEntityUpdateCount() );
|
||||
intialUpdateCount = sessionFactory().getStatistics().getEntityUpdateCount();
|
||||
u.getPerson().setAddress( "Cedar Park" );
|
||||
s.flush();
|
||||
assertEquals( intialUpdateCount + 1, sfi().getStatistics().getEntityUpdateCount() );
|
||||
assertEquals( intialUpdateCount + 1, sessionFactory().getStatistics().getEntityUpdateCount() );
|
||||
s.delete( u );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
|
|
@ -57,7 +57,7 @@ public class HibernateCreateBlobFailedCase extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testLobCreation() throws SQLException {
|
||||
Session session = sfi().getCurrentSession();
|
||||
Session session = sessionFactory().getCurrentSession();
|
||||
session.beginTransaction();
|
||||
Blob blob = Hibernate.getLobCreator( session ).createBlob( new byte[] {} );
|
||||
blob.free();
|
||||
|
|
|
@ -103,7 +103,7 @@ public class SuppliedConnectionTest extends ConnectionManagementTestCase {
|
|||
super.prepareTest();
|
||||
Connection conn = cp.getConnection();
|
||||
try {
|
||||
new SchemaExport( getCfg(), conn ).create( false, true );
|
||||
new SchemaExport( configuration(), conn ).create( false, true );
|
||||
}
|
||||
finally {
|
||||
if ( conn != null ) {
|
||||
|
@ -120,7 +120,7 @@ public class SuppliedConnectionTest extends ConnectionManagementTestCase {
|
|||
protected void cleanupTest() throws Exception {
|
||||
Connection conn = cp.getConnection();
|
||||
try {
|
||||
new SchemaExport( getCfg(), conn ).drop( false, true );
|
||||
new SchemaExport( configuration(), conn ).drop( false, true );
|
||||
}
|
||||
finally {
|
||||
if ( conn != null ) {
|
||||
|
|
|
@ -51,7 +51,7 @@ public class ThreadLocalCurrentSessionTest extends ConnectionManagementTestCase
|
|||
|
||||
@Override
|
||||
protected Session getSessionUnderTest() throws Throwable {
|
||||
Session session = getSessions().getCurrentSession();
|
||||
Session session = sessionFactory().getCurrentSession();
|
||||
session.beginTransaction();
|
||||
return session;
|
||||
}
|
||||
|
@ -59,12 +59,12 @@ public class ThreadLocalCurrentSessionTest extends ConnectionManagementTestCase
|
|||
@Override
|
||||
protected void release(Session session) {
|
||||
if ( session.getTransaction().getLocalStatus() != LocalStatus.ACTIVE ) {
|
||||
TestableThreadLocalContext.unbind( sfi() );
|
||||
TestableThreadLocalContext.unbind( sessionFactory() );
|
||||
return;
|
||||
}
|
||||
long initialCount = getSessions().getStatistics().getSessionCloseCount();
|
||||
long initialCount = sessionFactory().getStatistics().getSessionCloseCount();
|
||||
session.getTransaction().commit();
|
||||
long subsequentCount = getSessions().getStatistics().getSessionCloseCount();
|
||||
long subsequentCount = sessionFactory().getStatistics().getSessionCloseCount();
|
||||
assertEquals( "Session still open after commit", initialCount + 1, subsequentCount );
|
||||
// also make sure it was cleaned up from the internal ThreadLocal...
|
||||
assertFalse( "session still bound to internal ThreadLocal", TestableThreadLocalContext.hasBind() );
|
||||
|
|
|
@ -159,7 +159,7 @@ public class MultiRepresentationTest extends BaseCoreFunctionalTestCase {
|
|||
private Long stockId;
|
||||
|
||||
private void create() {
|
||||
Session session = getSessions().openSession();
|
||||
Session session = sessionFactory().openSession();
|
||||
session.beginTransaction();
|
||||
Stock stock = new Stock();
|
||||
stock.setTradeSymbol( "JBOSS" );
|
||||
|
@ -180,7 +180,7 @@ public class MultiRepresentationTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
private void destroy() {
|
||||
Session session = getSessions().openSession();
|
||||
Session session = sessionFactory().openSession();
|
||||
session.beginTransaction();
|
||||
Iterator stocks = session.createQuery( "from Stock" ).list().iterator();
|
||||
while ( stocks.hasNext() ) {
|
||||
|
|
|
@ -63,7 +63,7 @@ public class CallbackTest extends BaseCoreFunctionalTestCase {
|
|||
assertEquals( "observer not notified of creation", 1, observer.creationCount );
|
||||
assertEquals( "listener not notified of creation", 1, listener.initCount );
|
||||
|
||||
sfi().close();
|
||||
sessionFactory().close();
|
||||
|
||||
assertEquals( "observer not notified of close", 1, observer.closedCount );
|
||||
assertEquals( "listener not notified of close", 1, listener.destoryCount );
|
||||
|
|
|
@ -120,7 +120,7 @@ public class ExtendsTest extends BaseUnitTestCase {
|
|||
|
||||
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 ) {
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
|||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
sfi().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
|
||||
testCode.perform(
|
||||
new TestData() {
|
||||
|
@ -134,13 +134,13 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
|||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
CourseOffering section = ( CourseOffering ) session.get( CourseOffering.class, data.getSectionId() );
|
||||
assertEquals( 1, sfi().getStatistics().getEntityLoadCount() );
|
||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
||||
assertEquals( 1, sessionFactory().getStatistics().getEntityLoadCount() );
|
||||
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||
assertFalse( Hibernate.isInitialized( section.getCourse() ) );
|
||||
assertFalse( Hibernate.isInitialized( section.getEnrollments() ) );
|
||||
assertFalse( Hibernate.isInitialized( section.getCourse().getCode().getDepartment() ) );
|
||||
assertTrue( Hibernate.isInitialized( section.getCourse() ) );
|
||||
assertEquals( 1, sfi().getStatistics().getEntityFetchCount() );
|
||||
assertEquals( 1, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
@ -156,13 +156,13 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
|||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
CourseOffering section = ( CourseOffering ) session.createCriteria( CourseOffering.class ).uniqueResult();
|
||||
assertEquals( 1, sfi().getStatistics().getEntityLoadCount() );
|
||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
||||
assertEquals( 1, sessionFactory().getStatistics().getEntityLoadCount() );
|
||||
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||
assertFalse( Hibernate.isInitialized( section.getCourse() ) );
|
||||
assertFalse( Hibernate.isInitialized( section.getEnrollments() ) );
|
||||
assertFalse( Hibernate.isInitialized( section.getCourse().getCode().getDepartment() ) );
|
||||
assertTrue( Hibernate.isInitialized( section.getCourse() ) );
|
||||
assertEquals( 1, sfi().getStatistics().getEntityFetchCount() );
|
||||
assertEquals( 1, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
@ -172,9 +172,9 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testBasicFetchProfileOperation() {
|
||||
assertTrue( "fetch profile not parsed properly", sfi().containsFetchProfileDefinition( "enrollment.details" ) );
|
||||
assertTrue( "fetch profile not parsed properly", sfi().containsFetchProfileDefinition( "offering.details" ) );
|
||||
assertTrue( "fetch profile not parsed properly", sfi().containsFetchProfileDefinition( "course.details" ) );
|
||||
assertTrue( "fetch profile not parsed properly", sessionFactory().containsFetchProfileDefinition( "enrollment.details" ) );
|
||||
assertTrue( "fetch profile not parsed properly", sessionFactory().containsFetchProfileDefinition( "offering.details" ) );
|
||||
assertTrue( "fetch profile not parsed properly", sessionFactory().containsFetchProfileDefinition( "course.details" ) );
|
||||
Session s = openSession();
|
||||
SessionImplementor si = ( SessionImplementor ) s;
|
||||
s.enableFetchProfile( "enrollment.details" );
|
||||
|
@ -199,11 +199,11 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
|||
session.beginTransaction();
|
||||
session.enableFetchProfile( "enrollment.details" );
|
||||
Enrollment enrollment = ( Enrollment ) session.get( Enrollment.class, data.getEnrollmentId() );
|
||||
assertEquals( 3, sfi().getStatistics().getEntityLoadCount() ); // enrollment + (section + student)
|
||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
||||
assertEquals( 3, sessionFactory().getStatistics().getEntityLoadCount() ); // enrollment + (section + student)
|
||||
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||
assertTrue( Hibernate.isInitialized( enrollment.getOffering() ) );
|
||||
assertTrue( Hibernate.isInitialized( enrollment.getStudent() ) );
|
||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
||||
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
@ -220,11 +220,11 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
|||
session.beginTransaction();
|
||||
session.enableFetchProfile( "enrollment.details" );
|
||||
Enrollment enrollment = ( Enrollment ) session.createCriteria( Enrollment.class ).uniqueResult();
|
||||
assertEquals( 3, sfi().getStatistics().getEntityLoadCount() ); // enrollment + (section + student)
|
||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
||||
assertEquals( 3, sessionFactory().getStatistics().getEntityLoadCount() ); // enrollment + (section + student)
|
||||
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||
assertTrue( Hibernate.isInitialized( enrollment.getOffering() ) );
|
||||
assertTrue( Hibernate.isInitialized( enrollment.getStudent() ) );
|
||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
||||
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
@ -241,8 +241,8 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
|||
session.beginTransaction();
|
||||
session.enableFetchProfile( "offering.details" );
|
||||
CourseOffering section = ( CourseOffering ) session.get( CourseOffering.class, data.getSectionId() );
|
||||
assertEquals( 3, sfi().getStatistics().getEntityLoadCount() ); // section + (enrollments + course)
|
||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
||||
assertEquals( 3, sessionFactory().getStatistics().getEntityLoadCount() ); // section + (enrollments + course)
|
||||
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||
assertTrue( Hibernate.isInitialized( section.getEnrollments() ) );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
@ -264,8 +264,8 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
|||
session.enableFetchProfile( "offering.details" );
|
||||
session.enableFetchProfile( "enrollment.details" );
|
||||
CourseOffering section = ( CourseOffering ) session.get( CourseOffering.class, data.getSectionId() );
|
||||
assertEquals( 4, sfi().getStatistics().getEntityLoadCount() ); // section + (course + enrollments + (student))
|
||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
||||
assertEquals( 4, sessionFactory().getStatistics().getEntityLoadCount() ); // section + (course + enrollments + (student))
|
||||
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||
assertTrue( Hibernate.isInitialized( section.getEnrollments() ) );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
@ -283,8 +283,8 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
|||
session.beginTransaction();
|
||||
session.enableFetchProfile( "course.details" );
|
||||
Course course = ( Course ) session.get( Course.class, data.getCourseId() );
|
||||
assertEquals( 2, sfi().getStatistics().getEntityLoadCount() ); // course + department
|
||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
||||
assertEquals( 2, sessionFactory().getStatistics().getEntityLoadCount() ); // course + department
|
||||
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||
assertTrue( Hibernate.isInitialized( course.getCode().getDepartment() ) );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
@ -310,8 +310,8 @@ public class JoinFetchProfileTest extends BaseCoreFunctionalTestCase {
|
|||
List sections = session.createQuery( "from CourseOffering" ).list();
|
||||
int sectionCount = sections.size();
|
||||
assertEquals( "unexpected CourseOffering count", 1, sectionCount );
|
||||
assertEquals( 1, sfi().getStatistics().getEntityLoadCount() );
|
||||
assertEquals( 0, sfi().getStatistics().getEntityFetchCount() );
|
||||
assertEquals( 1, sessionFactory().getStatistics().getEntityLoadCount() );
|
||||
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ public class DynamicFilterTest extends BaseCoreFunctionalTestCase {
|
|||
CollectionPersister persister = sessionFactory().getCollectionPersister( Salesperson.class.getName() + ".orders" );
|
||||
assertTrue( "No cache for collection", persister.hasCache() );
|
||||
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 );
|
||||
|
||||
session.close();
|
||||
|
@ -125,7 +125,7 @@ public class DynamicFilterTest extends BaseCoreFunctionalTestCase {
|
|||
assertEquals( "Filtered-collection not bypassing 2L-cache", 1, sp.getOrders().size() );
|
||||
|
||||
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 );
|
||||
assertSame( "Different cache values!", cachedData, cachedData2 );
|
||||
|
||||
|
|
|
@ -52,15 +52,15 @@ public class IdentityGeneratedKeysTest extends BaseCoreFunctionalTestCase {
|
|||
assertEquals( id, myEntity1.getId() );
|
||||
|
||||
// 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");
|
||||
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() );
|
||||
|
||||
// an explicit flush should cause execution of the delayed insertion
|
||||
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 = openSession();
|
||||
|
@ -74,15 +74,15 @@ public class IdentityGeneratedKeysTest extends BaseCoreFunctionalTestCase {
|
|||
@Test
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public void testPersistOutsideTransactionCascadedToNonInverseCollection() {
|
||||
long initialInsertCount = sfi().getStatistics().getEntityInsertCount();
|
||||
long initialInsertCount = sessionFactory().getStatistics().getEntityInsertCount();
|
||||
Session s = openSession();
|
||||
MyEntity myEntity = new MyEntity( "test-persist");
|
||||
myEntity.getNonInverseChildren().add( new MyChild( "test-child-persist-non-inverse" ) );
|
||||
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() );
|
||||
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 = openSession();
|
||||
|
@ -96,17 +96,17 @@ public class IdentityGeneratedKeysTest extends BaseCoreFunctionalTestCase {
|
|||
@Test
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public void testPersistOutsideTransactionCascadedToInverseCollection() {
|
||||
long initialInsertCount = sfi().getStatistics().getEntityInsertCount();
|
||||
long initialInsertCount = sessionFactory().getStatistics().getEntityInsertCount();
|
||||
Session s = openSession();
|
||||
MyEntity myEntity2 = new MyEntity( "test-persist-2");
|
||||
MyChild child = new MyChild( "test-child-persist-inverse" );
|
||||
myEntity2.getInverseChildren().add( child );
|
||||
child.setInverseParent( 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() );
|
||||
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 = openSession();
|
||||
|
@ -119,15 +119,15 @@ public class IdentityGeneratedKeysTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testPersistOutsideTransactionCascadedToManyToOne() {
|
||||
long initialInsertCount = sfi().getStatistics().getEntityInsertCount();
|
||||
long initialInsertCount = sessionFactory().getStatistics().getEntityInsertCount();
|
||||
Session s = openSession();
|
||||
MyEntity myEntity = new MyEntity( "test-persist");
|
||||
myEntity.setSibling( new MySibling( "test-persist-sibling-out" ) );
|
||||
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() );
|
||||
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 = openSession();
|
||||
|
@ -140,16 +140,16 @@ public class IdentityGeneratedKeysTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testPersistOutsideTransactionCascadedFromManyToOne() {
|
||||
long initialInsertCount = sfi().getStatistics().getEntityInsertCount();
|
||||
long initialInsertCount = sessionFactory().getStatistics().getEntityInsertCount();
|
||||
Session s = openSession();
|
||||
MyEntity myEntity2 = new MyEntity( "test-persist-2");
|
||||
MySibling sibling = new MySibling( "test-persist-sibling-in" );
|
||||
sibling.setEntity( myEntity2 );
|
||||
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() );
|
||||
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 = openSession();
|
||||
|
|
|
@ -2394,7 +2394,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
|
|||
sr.close();
|
||||
|
||||
// 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" )
|
||||
.setCacheable( true )
|
||||
.list();
|
||||
|
@ -2440,20 +2440,20 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
|
|||
t.commit();
|
||||
s.close();
|
||||
|
||||
getSessions().getCache().evictQueryRegions();
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getCache().evictQueryRegions();
|
||||
sessionFactory().getStatistics().clear();
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
List list = s.createQuery( "from Animal a left join fetch a.mother" ).setCacheable( true ).list();
|
||||
assertEquals( 0, getSessions().getStatistics().getQueryCacheHitCount() );
|
||||
assertEquals( 1, getSessions().getStatistics().getQueryCachePutCount() );
|
||||
assertEquals( 0, sessionFactory().getStatistics().getQueryCacheHitCount() );
|
||||
assertEquals( 1, sessionFactory().getStatistics().getQueryCachePutCount() );
|
||||
list = s.createQuery( "select a from Animal a left join fetch a.mother" ).setCacheable( true ).list();
|
||||
assertEquals( 1, getSessions().getStatistics().getQueryCacheHitCount() );
|
||||
assertEquals( 1, getSessions().getStatistics().getQueryCachePutCount() );
|
||||
assertEquals( 1, sessionFactory().getStatistics().getQueryCacheHitCount() );
|
||||
assertEquals( 1, sessionFactory().getStatistics().getQueryCachePutCount() );
|
||||
list = s.createQuery( "select a, m from Animal a left join a.mother m" ).setCacheable( true ).list();
|
||||
assertEquals( 1, getSessions().getStatistics().getQueryCacheHitCount() );
|
||||
assertEquals( 2, getSessions().getStatistics().getQueryCachePutCount() );
|
||||
assertEquals( 1, sessionFactory().getStatistics().getQueryCacheHitCount() );
|
||||
assertEquals( 2, sessionFactory().getStatistics().getQueryCachePutCount() );
|
||||
s.createQuery( "delete from Animal" ).executeUpdate();
|
||||
t.commit();
|
||||
s.close();
|
||||
|
@ -2477,8 +2477,8 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
|
|||
a.addOffspring( offspring2 );
|
||||
offspring2.setMother( a );
|
||||
|
||||
getSessions().getCache().evictQueryRegions();
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getCache().evictQueryRegions();
|
||||
sessionFactory().getStatistics().clear();
|
||||
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
|
@ -2492,14 +2492,14 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
|
|||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
List list = s.createQuery( "from Animal a left join fetch a.offspring" ).setCacheable( true ).list();
|
||||
assertEquals( 0, getSessions().getStatistics().getQueryCacheHitCount() );
|
||||
assertEquals( 1, getSessions().getStatistics().getQueryCachePutCount() );
|
||||
assertEquals( 0, sessionFactory().getStatistics().getQueryCacheHitCount() );
|
||||
assertEquals( 1, sessionFactory().getStatistics().getQueryCachePutCount() );
|
||||
list = s.createQuery( "select a from Animal a left join fetch a.offspring" ).setCacheable( true ).list();
|
||||
assertEquals( 1, getSessions().getStatistics().getQueryCacheHitCount() );
|
||||
assertEquals( 1, getSessions().getStatistics().getQueryCachePutCount() );
|
||||
assertEquals( 1, sessionFactory().getStatistics().getQueryCacheHitCount() );
|
||||
assertEquals( 1, sessionFactory().getStatistics().getQueryCachePutCount() );
|
||||
list = s.createQuery( "select a, o from Animal a left join a.offspring o" ).setCacheable( true ).list();
|
||||
assertEquals( 1, getSessions().getStatistics().getQueryCacheHitCount() );
|
||||
assertEquals( 2, getSessions().getStatistics().getQueryCachePutCount() );
|
||||
assertEquals( 1, sessionFactory().getStatistics().getQueryCacheHitCount() );
|
||||
assertEquals( 2, sessionFactory().getStatistics().getQueryCachePutCount() );
|
||||
s.createQuery( "delete from Animal" ).executeUpdate();
|
||||
t.commit();
|
||||
s.close();
|
||||
|
|
|
@ -342,7 +342,7 @@ public class BulkManipulationTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
protected boolean supportsBulkInsertIdGeneration(Class entityClass) {
|
||||
EntityPersister persister = sfi().getEntityPersister( entityClass.getName() );
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( entityClass.getName() );
|
||||
IdentifierGenerator generator = persister.getIdentifierGenerator();
|
||||
return HqlSqlWalker.supportsIdGenWithBulkInsertion( generator );
|
||||
}
|
||||
|
|
|
@ -262,11 +262,11 @@ public class EJBQLTest extends BaseCoreFunctionalTestCase {
|
|||
private void assertEjbqlEqualsHql(String ejbql, String hql) {
|
||||
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 );
|
||||
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 );
|
||||
String ejbqlSql = queryTranslator.getSQLString();
|
||||
|
||||
|
@ -275,7 +275,7 @@ public class EJBQLTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
private QueryTranslatorImpl compile(String input) {
|
||||
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 );
|
||||
|
||||
return ( QueryTranslatorImpl ) queryTranslator;
|
||||
|
@ -305,7 +305,7 @@ public class EJBQLTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
private String toSql(String hql) {
|
||||
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 );
|
||||
return queryTranslator.getSQLString();
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.junit.Test;
|
|||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
@ -49,7 +48,7 @@ public class BasicForcedTableSequenceTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testNormalBoundary() {
|
||||
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertTrue(
|
||||
"sequence style generator was not used",
|
||||
SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.junit.Test;
|
|||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
@ -50,7 +49,7 @@ public class HiLoForcedTableSequenceTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testNormalBoundary() {
|
||||
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertTrue(
|
||||
"sequence style generator was not used",
|
||||
SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.junit.Test;
|
|||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
@ -48,7 +47,7 @@ public class PooledForcedTableSequenceTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testNormalBoundary() {
|
||||
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertTrue(
|
||||
"sequence style generator was not used",
|
||||
SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.junit.Test;
|
|||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
@ -48,7 +47,7 @@ public class HiLoSequenceTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testNormalBoundary() {
|
||||
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertClassAssignability( SequenceStyleGenerator.class, persister.getIdentifierGenerator().getClass() );
|
||||
SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
|
||||
assertClassAssignability( OptimizerFactory.HiLoOptimizer.class, generator.getOptimizer().getClass() );
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.immutable.entitywithmutablecollection;
|
||||
import java.util.Iterator;
|
||||
import org.hibernate.QueryException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.StaleObjectStateException;
|
||||
|
@ -68,23 +67,23 @@ public abstract class AbstractEntityWithOneToManyTest extends BaseCoreFunctional
|
|||
|
||||
protected void prepareTest() throws Exception {
|
||||
super.prepareTest();
|
||||
isContractPartiesInverse = ( ( SessionFactoryImpl ) getSessions() ).getCollectionPersister( Contract.class.getName() + ".parties" ).isInverse();
|
||||
isContractPartiesInverse = ( ( SessionFactoryImpl ) sessionFactory() ).getCollectionPersister( Contract.class.getName() + ".parties" ).isInverse();
|
||||
try {
|
||||
( ( SessionFactoryImpl ) getSessions() ).getEntityPersister( Party.class.getName() ).getPropertyType( "contract" );
|
||||
( ( SessionFactoryImpl ) sessionFactory() ).getEntityPersister( Party.class.getName() ).getPropertyType( "contract" );
|
||||
isContractPartiesBidirectional = true;
|
||||
}
|
||||
catch ( QueryException ex) {
|
||||
isContractPartiesBidirectional = false;
|
||||
}
|
||||
try {
|
||||
( ( SessionFactoryImpl ) getSessions() ).getEntityPersister( ContractVariation.class.getName() ).getPropertyType( "contract" );
|
||||
( ( SessionFactoryImpl ) sessionFactory() ).getEntityPersister( ContractVariation.class.getName() ).getPropertyType( "contract" );
|
||||
isContractVariationsBidirectional = true;
|
||||
}
|
||||
catch ( QueryException ex) {
|
||||
isContractVariationsBidirectional = false;
|
||||
}
|
||||
|
||||
isContractVersioned = ( ( SessionFactoryImpl ) getSessions() ).getEntityPersister( Contract.class.getName() ).isVersioned();
|
||||
isContractVersioned = ( ( SessionFactoryImpl ) sessionFactory() ).getEntityPersister( Contract.class.getName() ).isVersioned();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1201,21 +1200,21 @@ public abstract class AbstractEntityWithOneToManyTest extends BaseCoreFunctional
|
|||
}
|
||||
|
||||
protected void clearCounts() {
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
}
|
||||
|
||||
protected void assertInsertCount(int expected) {
|
||||
int inserts = ( int ) getSessions().getStatistics().getEntityInsertCount();
|
||||
int inserts = ( int ) sessionFactory().getStatistics().getEntityInsertCount();
|
||||
assertEquals( "unexpected insert count", expected, inserts );
|
||||
}
|
||||
|
||||
protected void assertUpdateCount(int expected) {
|
||||
int updates = ( int ) getSessions().getStatistics().getEntityUpdateCount();
|
||||
int updates = ( int ) sessionFactory().getStatistics().getEntityUpdateCount();
|
||||
assertEquals( "unexpected update counts", expected, updates );
|
||||
}
|
||||
|
||||
protected void assertDeleteCount(int expected) {
|
||||
int deletes = ( int ) getSessions().getStatistics().getEntityDeleteCount();
|
||||
int deletes = ( int ) sessionFactory().getStatistics().getEntityDeleteCount();
|
||||
assertEquals( "unexpected delete counts", expected, deletes );
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@
|
|||
package org.hibernate.test.instrument.runtime;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
|
@ -32,34 +33,44 @@ import org.hibernate.bytecode.InstrumentedClassLoader;
|
|||
import org.hibernate.bytecode.util.BasicClassFilter;
|
||||
import org.hibernate.bytecode.util.FieldFilter;
|
||||
import org.hibernate.testing.junit4.BaseClassLoaderIsolatedTestCase;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.testing.junit4.ClassLoadingIsolater;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends BaseClassLoaderIsolatedTestCase {
|
||||
public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends BaseUnitTestCase {
|
||||
|
||||
protected ClassLoader buildIsolatedClassLoader(ClassLoader parent) {
|
||||
BytecodeProvider provider = buildBytecodeProvider();
|
||||
return new InstrumentedClassLoader(
|
||||
parent,
|
||||
provider.getTransformer(
|
||||
new BasicClassFilter( new String[] { "org.hibernate.test.instrument" }, null ),
|
||||
new FieldFilter() {
|
||||
public boolean shouldInstrumentField(String className, String fieldName) {
|
||||
return className.startsWith( "org.hibernate.test.instrument.domain" );
|
||||
}
|
||||
public boolean shouldTransformFieldAccess(String transformingClassName, String fieldOwnerClassName, String fieldName) {
|
||||
return fieldOwnerClassName.startsWith( "org.hibernate.test.instrument.domain" )
|
||||
&& transformingClassName.equals( fieldOwnerClassName );
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
@Rule
|
||||
public ClassLoadingIsolater isolater = new ClassLoadingIsolater(
|
||||
new ClassLoadingIsolater.IsolatedClassLoaderProvider() {
|
||||
final BytecodeProvider provider = buildBytecodeProvider();
|
||||
|
||||
}
|
||||
@Override
|
||||
public ClassLoader buildIsolatedClassLoader() {
|
||||
return new InstrumentedClassLoader(
|
||||
Thread.currentThread().getContextClassLoader(),
|
||||
provider.getTransformer(
|
||||
new BasicClassFilter( new String[] { "org.hibernate.test.instrument" }, null ),
|
||||
new FieldFilter() {
|
||||
public boolean shouldInstrumentField(String className, String fieldName) {
|
||||
return className.startsWith( "org.hibernate.test.instrument.domain" );
|
||||
}
|
||||
public boolean shouldTransformFieldAccess(String transformingClassName, String fieldOwnerClassName, String fieldName) {
|
||||
return fieldOwnerClassName.startsWith( "org.hibernate.test.instrument.domain" )
|
||||
&& transformingClassName.equals( fieldOwnerClassName );
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected void releaseIsolatedClassLoader(ClassLoader isolatedLoader) {
|
||||
}
|
||||
@Override
|
||||
public void releaseIsolatedClassLoader(ClassLoader isolatedClassLoader) {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
protected abstract BytecodeProvider buildBytecodeProvider();
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public class IterateTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testIterate() throws Exception {
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
Item i1 = new Item("foo");
|
||||
|
@ -86,12 +86,12 @@ public class IterateTest extends BaseCoreFunctionalTestCase {
|
|||
s.delete(i2);
|
||||
t.commit();
|
||||
s.close();
|
||||
assertEquals( getSessions().getStatistics().getEntityFetchCount(), 2 );
|
||||
assertEquals( sessionFactory().getStatistics().getEntityFetchCount(), 2 );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScroll() throws Exception {
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
Item i1 = new Item("foo");
|
||||
|
@ -117,7 +117,7 @@ public class IterateTest extends BaseCoreFunctionalTestCase {
|
|||
s.delete(i2);
|
||||
t.commit();
|
||||
s.close();
|
||||
assertEquals( getSessions().getStatistics().getEntityFetchCount(), 0 );
|
||||
assertEquals( sessionFactory().getStatistics().getEntityFetchCount(), 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ public class LazyKeyManyToOneTest extends BaseCoreFunctionalTestCase {
|
|||
cust.getOrders().add( order );
|
||||
s.save( cust );
|
||||
s.flush();
|
||||
assertEquals( 2, sfi().getStatistics().getEntityInsertCount() );
|
||||
assertEquals( 2, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||
s.delete( cust );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
|
|
@ -60,7 +60,7 @@ public class KeyManyToOneTest extends BaseCoreFunctionalTestCase {
|
|||
cust.getOrders().add( order );
|
||||
s.save( cust );
|
||||
s.flush();
|
||||
assertEquals( 2, sfi().getStatistics().getEntityInsertCount() );
|
||||
assertEquals( 2, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||
s.delete( cust );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
|
|
@ -68,21 +68,21 @@ public class InstrumentCacheTest extends BaseCoreFunctionalTestCase {
|
|||
Session s;
|
||||
Transaction tx;
|
||||
|
||||
s = getSessions().openSession();
|
||||
s = sessionFactory().openSession();
|
||||
tx = s.beginTransaction();
|
||||
s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") );
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
s = getSessions().openSession();
|
||||
s = sessionFactory().openSession();
|
||||
tx = s.beginTransaction();
|
||||
s.createQuery("from Document fetch all properties").uniqueResult();
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
|
||||
s = getSessions().openSession();
|
||||
s = sessionFactory().openSession();
|
||||
tx = s.beginTransaction();
|
||||
Document d = (Document) s.createCriteria(Document.class).uniqueResult();
|
||||
assertFalse( Hibernate.isPropertyInitialized(d, "text") );
|
||||
|
@ -93,9 +93,9 @@ public class InstrumentCacheTest extends BaseCoreFunctionalTestCase {
|
|||
tx.commit();
|
||||
s.close();
|
||||
|
||||
assertEquals( 2, getSessions().getStatistics().getPrepareStatementCount() );
|
||||
assertEquals( 2, sessionFactory().getStatistics().getPrepareStatementCount() );
|
||||
|
||||
s = getSessions().openSession();
|
||||
s = sessionFactory().openSession();
|
||||
tx = s.beginTransaction();
|
||||
d = (Document) s.get(Document.class, d.getId());
|
||||
assertFalse( Hibernate.isPropertyInitialized(d, "text") );
|
||||
|
@ -109,21 +109,21 @@ public class InstrumentCacheTest extends BaseCoreFunctionalTestCase {
|
|||
Session s;
|
||||
Transaction tx;
|
||||
|
||||
s = getSessions().openSession();
|
||||
s = sessionFactory().openSession();
|
||||
tx = s.beginTransaction();
|
||||
s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") );
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
s = getSessions().openSession();
|
||||
s = sessionFactory().openSession();
|
||||
tx = s.beginTransaction();
|
||||
s.createQuery("from Document fetch all properties").uniqueResult();
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
|
||||
s = getSessions().openSession();
|
||||
s = sessionFactory().openSession();
|
||||
tx = s.beginTransaction();
|
||||
Document d = (Document) s.createCriteria(Document.class).uniqueResult();
|
||||
assertFalse( Hibernate.isPropertyInitialized(d, "text") );
|
||||
|
@ -134,9 +134,9 @@ public class InstrumentCacheTest extends BaseCoreFunctionalTestCase {
|
|||
tx.commit();
|
||||
s.close();
|
||||
|
||||
assertEquals( 1, getSessions().getStatistics().getPrepareStatementCount() );
|
||||
assertEquals( 1, sessionFactory().getStatistics().getPrepareStatementCount() );
|
||||
|
||||
s = getSessions().openSession();
|
||||
s = sessionFactory().openSession();
|
||||
tx = s.beginTransaction();
|
||||
d = (Document) s.get(Document.class, d.getId());
|
||||
assertTrue( Hibernate.isPropertyInitialized(d, "text") );
|
||||
|
|
|
@ -57,14 +57,14 @@ public class ABCTest extends LegacyTestCase {
|
|||
d = (D) s.get(D.class, did);
|
||||
assertTrue(d.getReverse().getId().equals(did));
|
||||
s.clear();
|
||||
getSessions().evict(D.class);
|
||||
getSessions().evict(A.class);
|
||||
sessionFactory().evict(D.class);
|
||||
sessionFactory().evict(A.class);
|
||||
d = (D) s.get(D.class, did);
|
||||
assertTrue(d.inverse.getId().equals(did));
|
||||
assertTrue(d.inverse.getName().equals("a"));
|
||||
s.clear();
|
||||
getSessions().evict(D.class);
|
||||
getSessions().evict(A.class);
|
||||
sessionFactory().evict(D.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 );
|
||||
t.commit();
|
||||
s.close();
|
||||
|
@ -72,7 +72,7 @@ public class ABCTest extends LegacyTestCase {
|
|||
|
||||
@Test
|
||||
public void testHigherLevelIndexDefinition() throws Throwable {
|
||||
String[] commands = getCfg().generateSchemaCreationScript( getDialect() );
|
||||
String[] commands = configuration().generateSchemaCreationScript( getDialect() );
|
||||
int max = commands.length;
|
||||
boolean found = false;
|
||||
for (int indx = 0; indx < max; indx++) {
|
||||
|
@ -105,7 +105,7 @@ public class ABCTest extends LegacyTestCase {
|
|||
t.commit();
|
||||
s.close();
|
||||
|
||||
getSessions().evict(A.class);
|
||||
sessionFactory().evict(A.class);
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
|
@ -120,7 +120,7 @@ public class ABCTest extends LegacyTestCase {
|
|||
t.commit();
|
||||
s.close();
|
||||
|
||||
getSessions().evict(A.class);
|
||||
sessionFactory().evict(A.class);
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
|
|
|
@ -49,7 +49,7 @@ public class CustomSQLTest extends LegacyTestCase {
|
|||
s.connection().commit();
|
||||
s.close();
|
||||
|
||||
getSessions().evict(Role.class);
|
||||
sessionFactory().evict(Role.class);
|
||||
s = openSession();
|
||||
|
||||
Role p2 = (Role) s.get(Role.class, new Long(p.getId()));
|
||||
|
@ -178,7 +178,7 @@ public class CustomSQLTest extends LegacyTestCase {
|
|||
s.connection().commit();
|
||||
s.close();
|
||||
|
||||
getSessions().evict(Person.class);
|
||||
sessionFactory().evict(Person.class);
|
||||
s = openSession();
|
||||
|
||||
Person p2 = (Person) s.get(Person.class, p.getId());
|
||||
|
|
|
@ -291,7 +291,7 @@ public class FooBarTest extends LegacyTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
getSessions().evictCollection("org.hibernate.test.legacy.Baz.fooSet");
|
||||
sessionFactory().evictCollection("org.hibernate.test.legacy.Baz.fooSet");
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
|
@ -340,7 +340,7 @@ public class FooBarTest extends LegacyTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
getSessions().evictCollection("org.hibernate.test.legacy.Baz.fooSet");
|
||||
sessionFactory().evictCollection("org.hibernate.test.legacy.Baz.fooSet");
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
|
@ -1518,7 +1518,7 @@ public class FooBarTest extends LegacyTestCase {
|
|||
}
|
||||
|
||||
private boolean isOuterJoinFetchingDisabled() {
|
||||
return new Integer(0).equals( ( (SessionFactoryImplementor) getSessions() ).getSettings().getMaximumFetchDepth() );
|
||||
return new Integer(0).equals( ( (SessionFactoryImplementor) sessionFactory() ).getSettings().getMaximumFetchDepth() );
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1542,7 +1542,7 @@ public class FooBarTest extends LegacyTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
getSessions().evict(Foo.class);
|
||||
sessionFactory().evict(Foo.class);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
|
@ -3202,7 +3202,7 @@ public class FooBarTest extends LegacyTestCase {
|
|||
txn.commit();
|
||||
s.close();
|
||||
|
||||
getSessions().evict(Glarch.class);
|
||||
sessionFactory().evict(Glarch.class);
|
||||
|
||||
s = openSession();
|
||||
txn = s.beginTransaction();
|
||||
|
@ -3221,7 +3221,7 @@ public class FooBarTest extends LegacyTestCase {
|
|||
txn.commit();
|
||||
s.close();
|
||||
|
||||
getSessions().evict(Glarch.class);
|
||||
sessionFactory().evict(Glarch.class);
|
||||
|
||||
s = openSession();
|
||||
txn = s.beginTransaction();
|
||||
|
@ -4337,7 +4337,7 @@ public class FooBarTest extends LegacyTestCase {
|
|||
@Test
|
||||
public void testUserProvidedConnection() throws Exception {
|
||||
ConnectionProvider dcp = ConnectionProviderBuilder.buildConnectionProvider();
|
||||
Session s = getSessions().openSession( dcp.getConnection() );
|
||||
Session s = sessionFactory().openSession( dcp.getConnection() );
|
||||
Transaction tx = s.beginTransaction();
|
||||
s.createQuery( "from Fo" ).list();
|
||||
tx.commit();
|
||||
|
|
|
@ -733,7 +733,7 @@ public class FumTest extends LegacyTestCase {
|
|||
public void testUnflushedSessionSerialization() throws Exception {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Test insertions across serializations
|
||||
Session s = getSessions().openSession();
|
||||
Session s = sessionFactory().openSession();
|
||||
s.setFlushMode(FlushMode.MANUAL);
|
||||
s.beginTransaction();
|
||||
|
||||
|
@ -766,7 +766,7 @@ public class FumTest extends LegacyTestCase {
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Test updates across serializations
|
||||
s = getSessions().openSession();
|
||||
s = sessionFactory().openSession();
|
||||
s.setFlushMode(FlushMode.MANUAL);
|
||||
s.beginTransaction();
|
||||
|
||||
|
@ -789,7 +789,7 @@ public class FumTest extends LegacyTestCase {
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Test deletions across serializations
|
||||
s = getSessions().openSession();
|
||||
s = sessionFactory().openSession();
|
||||
s.setFlushMode(FlushMode.MANUAL);
|
||||
s.beginTransaction();
|
||||
|
||||
|
@ -812,7 +812,7 @@ public class FumTest extends LegacyTestCase {
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Test collection actions across serializations
|
||||
s = getSessions().openSession();
|
||||
s = sessionFactory().openSession();
|
||||
s.setFlushMode(FlushMode.MANUAL);
|
||||
s.beginTransaction();
|
||||
|
||||
|
@ -842,7 +842,7 @@ public class FumTest extends LegacyTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = getSessions().openSession();
|
||||
s = sessionFactory().openSession();
|
||||
s.setFlushMode(FlushMode.MANUAL);
|
||||
s.beginTransaction();
|
||||
fum = (Fum) s.load( Fum.class, fum.getId() );
|
||||
|
@ -861,7 +861,7 @@ public class FumTest extends LegacyTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = getSessions().openSession();
|
||||
s = sessionFactory().openSession();
|
||||
s.setFlushMode(FlushMode.MANUAL);
|
||||
fum = (Fum) s.load( Fum.class, fum.getId() );
|
||||
assertTrue("the Fum.friends is not empty", fum.getFriends() == null || fum.getFriends().size() == 0);
|
||||
|
|
|
@ -99,7 +99,7 @@ public class MasterDetailTest extends LegacyTestCase {
|
|||
|
||||
@Test
|
||||
public void testMeta() throws Exception {
|
||||
PersistentClass clazz = getCfg().getClassMapping( Master.class.getName() );
|
||||
PersistentClass clazz = configuration().getClassMapping( Master.class.getName() );
|
||||
MetaAttribute meta = clazz.getMetaAttribute("foo");
|
||||
assertTrue( "foo".equals( meta.getValue() ) );
|
||||
meta = clazz.getProperty("name").getMetaAttribute("bar");
|
||||
|
@ -873,13 +873,13 @@ public class MasterDetailTest extends LegacyTestCase {
|
|||
protected boolean isSerializableIsolationEnforced() throws Exception {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = sfi().getConnectionProvider().getConnection();
|
||||
conn = sessionFactory().getConnectionProvider().getConnection();
|
||||
return conn.getTransactionIsolation() >= Connection.TRANSACTION_SERIALIZABLE;
|
||||
}
|
||||
finally {
|
||||
if ( conn != null ) {
|
||||
try {
|
||||
sfi().getConnectionProvider().closeConnection( conn );
|
||||
sessionFactory().getConnectionProvider().closeConnection( conn );
|
||||
}
|
||||
catch ( Throwable ignore ) {
|
||||
// ignore...
|
||||
|
@ -1041,7 +1041,7 @@ public class MasterDetailTest extends LegacyTestCase {
|
|||
s.connection().commit();
|
||||
s.close();
|
||||
|
||||
getSessions().evictCollection("org.hibernate.test.legacy.Assignable.categories");
|
||||
sessionFactory().evictCollection("org.hibernate.test.legacy.Assignable.categories");
|
||||
|
||||
s = openSession();
|
||||
a = (Assignable) s.get(Assignable.class, "foo");
|
||||
|
@ -1054,7 +1054,7 @@ public class MasterDetailTest extends LegacyTestCase {
|
|||
s.connection().commit();
|
||||
s.close();
|
||||
|
||||
getSessions().evictCollection("org.hibernate.test.legacy.Assignable.categories");
|
||||
sessionFactory().evictCollection("org.hibernate.test.legacy.Assignable.categories");
|
||||
|
||||
s = openSession();
|
||||
a = (Assignable) s.get(Assignable.class, "foo");
|
||||
|
@ -1068,7 +1068,7 @@ public class MasterDetailTest extends LegacyTestCase {
|
|||
s.connection().commit();
|
||||
s.close();
|
||||
|
||||
getSessions().evictCollection("org.hibernate.test.legacy.Assignable.categories");
|
||||
sessionFactory().evictCollection("org.hibernate.test.legacy.Assignable.categories");
|
||||
|
||||
s = openSession();
|
||||
a = (Assignable) s.get(Assignable.class, "foo");
|
||||
|
|
|
@ -117,7 +117,7 @@ public class MultiTableTest extends LegacyTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
getSessions().evict(SubMulti.class);
|
||||
sessionFactory().evict(SubMulti.class);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
|
|
|
@ -63,7 +63,7 @@ public class OneToOneCacheTest extends LegacyTestCase {
|
|||
assertNotNull( mainObject.getObj2() );
|
||||
|
||||
// after evicting, it works.
|
||||
getSessions().evict( MainObject.class );
|
||||
sessionFactory().evict( MainObject.class );
|
||||
|
||||
mainObject = readMainObject();
|
||||
|
||||
|
|
|
@ -1194,7 +1194,7 @@ public class ParentChildTest extends LegacyTestCase {
|
|||
}
|
||||
|
||||
// Next, lets create that entity "under the covers"
|
||||
Session anotherSession = getSessions().openSession();
|
||||
Session anotherSession = sessionFactory().openSession();
|
||||
anotherSession.beginTransaction();
|
||||
Simple myNewSimple = new Simple();
|
||||
myNewSimple.setName("My under the radar Simple entity");
|
||||
|
|
|
@ -111,7 +111,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
|
@ -123,9 +123,9 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
|
||||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
|
||||
assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 1 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 1 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 0 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryCachePutCount(), 1 );
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
|
@ -134,7 +134,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
|
@ -143,15 +143,15 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
|||
.setCacheable( true )
|
||||
.uniqueResult();
|
||||
assertNotNull( u );
|
||||
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 );
|
||||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 1 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 0 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 1 );
|
||||
u = ( User ) s.createCriteria( User.class )
|
||||
.add( Restrictions.naturalId().set( "userName", "steve" ) )
|
||||
.setCacheable( true )
|
||||
.uniqueResult();
|
||||
assertNotNull( u );
|
||||
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 );
|
||||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 2 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 0 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 2 );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
|
@ -171,7 +171,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
|
@ -183,11 +183,11 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
|
||||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
|
||||
assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 1 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 1 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 0 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryCachePutCount(), 1 );
|
||||
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
|
@ -196,8 +196,8 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
|||
.setCacheable( true )
|
||||
.uniqueResult();
|
||||
assertNotNull( u );
|
||||
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 );
|
||||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 1 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 0 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 1 );
|
||||
|
||||
s.delete( u );
|
||||
|
||||
|
@ -226,7 +226,7 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
|
@ -236,11 +236,11 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
|||
.uniqueResult();
|
||||
assertNotNull( u );
|
||||
|
||||
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
|
||||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
|
||||
assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 1 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 1 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 0 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryCachePutCount(), 1 );
|
||||
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
s.getTransaction().commit();
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
|
@ -249,8 +249,8 @@ public class ImmutableNaturalIdTest extends BaseCoreFunctionalTestCase {
|
|||
.setCacheable( true )
|
||||
.uniqueResult();
|
||||
assertNotNull( u );
|
||||
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 );
|
||||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 1 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 0 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 1 );
|
||||
|
||||
s.delete( u );
|
||||
|
||||
|
|
|
@ -80,26 +80,26 @@ public abstract class AbstractOperationTestCase extends BaseCoreFunctionalTestCa
|
|||
}
|
||||
|
||||
protected void clearCounts() {
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
}
|
||||
|
||||
protected void assertInsertCount(int expected) {
|
||||
int inserts = ( int ) getSessions().getStatistics().getEntityInsertCount();
|
||||
int inserts = ( int ) sessionFactory().getStatistics().getEntityInsertCount();
|
||||
assertEquals( "unexpected insert count", expected, inserts );
|
||||
}
|
||||
|
||||
protected void assertUpdateCount(int expected) {
|
||||
int updates = ( int ) getSessions().getStatistics().getEntityUpdateCount();
|
||||
int updates = ( int ) sessionFactory().getStatistics().getEntityUpdateCount();
|
||||
assertEquals( "unexpected update counts", expected, updates );
|
||||
}
|
||||
|
||||
protected void assertDeleteCount(int expected) {
|
||||
int deletes = ( int ) getSessions().getStatistics().getEntityDeleteCount();
|
||||
int deletes = ( int ) sessionFactory().getStatistics().getEntityDeleteCount();
|
||||
assertEquals( "unexpected delete counts", expected, deletes );
|
||||
}
|
||||
|
||||
protected void assertFetchCount(int count) {
|
||||
int fetches = ( int ) getSessions().getStatistics().getEntityFetchCount();
|
||||
int fetches = ( int ) sessionFactory().getStatistics().getEntityFetchCount();
|
||||
assertEquals( count, fetches );
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//$Id: MergeTest.java 11037 2007-01-09 16:04:16Z steve.ebersole@jboss.com $
|
||||
package org.hibernate.test.nonflushedchanges;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -493,7 +492,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
assertUpdateCount( 1 );
|
||||
clearCounts();
|
||||
|
||||
getSessions().getCache().evictEntityRegion( NumberedNode.class );
|
||||
sessionFactory().getCache().evictEntityRegion( NumberedNode.class );
|
||||
|
||||
NumberedNode child2 = new NumberedNode( "child2" );
|
||||
NumberedNode grandchild3 = new NumberedNode( "grandchild3" );
|
||||
|
|
|
@ -60,7 +60,7 @@ public class OnDeleteTest extends BaseCoreFunctionalTestCase {
|
|||
comment = "db/dialect does not support circular cascade delete constraints"
|
||||
)
|
||||
public void testJoinedSubclass() {
|
||||
Statistics statistics = getSessions().getStatistics();
|
||||
Statistics statistics = sessionFactory().getStatistics();
|
||||
statistics.clear();
|
||||
|
||||
Session s = openSession();
|
||||
|
|
|
@ -71,8 +71,8 @@ public class JoinedSubclassOneToOneTest extends BaseCoreFunctionalTestCase {
|
|||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
|
||||
EntityStatistics addressStats = getSessions().getStatistics().getEntityStatistics( Address.class.getName() );
|
||||
EntityStatistics mailingAddressStats = getSessions().getStatistics().getEntityStatistics("MailingAddress");
|
||||
EntityStatistics addressStats = sessionFactory().getStatistics().getEntityStatistics( Address.class.getName() );
|
||||
EntityStatistics mailingAddressStats = sessionFactory().getStatistics().getEntityStatistics("MailingAddress");
|
||||
|
||||
p = (Person) s.createQuery("from Person p join fetch p.address left join fetch p.mailingAddress").uniqueResult();
|
||||
assertNotNull(p.address); assertNull(p.mailingAddress);
|
||||
|
|
|
@ -53,7 +53,7 @@ public class DynamicMapOneToOneTest extends BaseCoreFunctionalTestCase {
|
|||
s = openSession();
|
||||
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();
|
||||
assertNotNull( "could not locate person", person );
|
||||
|
|
|
@ -73,8 +73,8 @@ public class DiscrimSubclassOneToOneTest extends BaseCoreFunctionalTestCase {
|
|||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
|
||||
EntityStatistics addressStats = getSessions().getStatistics().getEntityStatistics( Address.class.getName() );
|
||||
EntityStatistics mailingAddressStats = getSessions().getStatistics().getEntityStatistics("MailingAddress");
|
||||
EntityStatistics addressStats = sessionFactory().getStatistics().getEntityStatistics( Address.class.getName() );
|
||||
EntityStatistics mailingAddressStats = sessionFactory().getStatistics().getEntityStatistics("MailingAddress");
|
||||
|
||||
p = (Person) s.createQuery("from Person p join fetch p.address left join fetch p.mailingAddress").uniqueResult();
|
||||
assertNotNull(p.address); assertNull(p.mailingAddress);
|
||||
|
|
|
@ -47,21 +47,21 @@ public abstract class AbstractOperationTestCase extends BaseCoreFunctionalTestCa
|
|||
}
|
||||
|
||||
protected void clearCounts() {
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
}
|
||||
|
||||
protected void assertInsertCount(int expected) {
|
||||
int inserts = ( int ) getSessions().getStatistics().getEntityInsertCount();
|
||||
int inserts = ( int ) sessionFactory().getStatistics().getEntityInsertCount();
|
||||
assertEquals( "unexpected insert count", expected, inserts );
|
||||
}
|
||||
|
||||
protected void assertUpdateCount(int expected) {
|
||||
int updates = ( int ) getSessions().getStatistics().getEntityUpdateCount();
|
||||
int updates = ( int ) sessionFactory().getStatistics().getEntityUpdateCount();
|
||||
assertEquals( "unexpected update counts", expected, updates );
|
||||
}
|
||||
|
||||
protected void assertDeleteCount(int expected) {
|
||||
int deletes = ( int ) getSessions().getStatistics().getEntityDeleteCount();
|
||||
int deletes = ( int ) sessionFactory().getStatistics().getEntityDeleteCount();
|
||||
assertEquals( "unexpected delete counts", expected, deletes );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -505,7 +505,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
assertUpdateCount(1);
|
||||
clearCounts();
|
||||
|
||||
getSessions().getCache().evictEntityRegion( NumberedNode.class );
|
||||
sessionFactory().getCache().evictEntityRegion( NumberedNode.class );
|
||||
|
||||
NumberedNode child2 = new NumberedNode("child2");
|
||||
NumberedNode grandchild3 = new NumberedNode("grandchild3");
|
||||
|
|
|
@ -271,8 +271,8 @@ public class OrphanTest extends BaseCoreFunctionalTestCase {
|
|||
t.commit();
|
||||
session.close();
|
||||
|
||||
getSessions().getCache().evictEntityRegion( Product.class );
|
||||
getSessions().getCache().evictEntityRegion( Part.class );
|
||||
sessionFactory().getCache().evictEntityRegion( Product.class );
|
||||
sessionFactory().getCache().evictEntityRegion( Part.class );
|
||||
|
||||
|
||||
session = openSession();
|
||||
|
|
|
@ -241,18 +241,18 @@ public class PropertyRefTest extends BaseCoreFunctionalTestCase {
|
|||
s.flush();
|
||||
s.clear();
|
||||
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
|
||||
p = (Person) s.get( Person.class, p.getId() ); //get address reference by outer join
|
||||
|
||||
assertTrue( Hibernate.isInitialized( p.getAddress() ) );
|
||||
assertNotNull( p.getAddress() );
|
||||
assertEquals( getSessions().getStatistics().getPrepareStatementCount(), 1 );
|
||||
assertEquals( getSessions().getStatistics().getEntityFetchCount(), 0 );
|
||||
assertEquals( sessionFactory().getStatistics().getPrepareStatementCount(), 1 );
|
||||
assertEquals( sessionFactory().getStatistics().getEntityFetchCount(), 0 );
|
||||
|
||||
s.clear();
|
||||
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
|
||||
p = (Person) s.createCriteria(Person.class)
|
||||
.setFetchMode("address", FetchMode.SELECT)
|
||||
|
@ -260,8 +260,8 @@ public class PropertyRefTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
assertTrue( Hibernate.isInitialized( p.getAddress() ) );
|
||||
assertNotNull( p.getAddress() );
|
||||
assertEquals( getSessions().getStatistics().getPrepareStatementCount(), 2 );
|
||||
assertEquals( getSessions().getStatistics().getEntityFetchCount(), 0 );
|
||||
assertEquals( sessionFactory().getStatistics().getPrepareStatementCount(), 2 );
|
||||
assertEquals( sessionFactory().getStatistics().getEntityFetchCount(), 0 );
|
||||
|
||||
s.createQuery("delete from Address").executeUpdate();
|
||||
s.createQuery("delete from Person").executeUpdate();
|
||||
|
@ -272,7 +272,7 @@ public class PropertyRefTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
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();
|
||||
boolean found = false;
|
||||
|
|
|
@ -2219,7 +2219,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
|
|||
}
|
||||
private Constructor getConstructor() {
|
||||
Type studentNametype =
|
||||
( ( SessionFactoryImpl ) getSessions() )
|
||||
( ( SessionFactoryImpl ) sessionFactory() )
|
||||
.getEntityPersister( Student.class.getName() )
|
||||
.getPropertyType( "name" );
|
||||
return ReflectHelper.getConstructor( Student.class, new Type[] {Hibernate.LONG, studentNametype} );
|
||||
|
|
|
@ -47,7 +47,7 @@ public class NativeSQLQueryPlanEqualsTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testNativeSQLQuerySpecEquals() {
|
||||
QueryPlanCache cache = new QueryPlanCache( sfi() );
|
||||
QueryPlanCache cache = new QueryPlanCache( sessionFactory() );
|
||||
NativeSQLQuerySpecification firstSpec = createSpec();
|
||||
|
||||
NativeSQLQuerySpecification secondSpec = createSpec();
|
||||
|
@ -63,7 +63,7 @@ public class NativeSQLQueryPlanEqualsTest extends BaseCoreFunctionalTestCase {
|
|||
String blah = "blah";
|
||||
String select = "select blah from blah";
|
||||
NativeSQLQueryReturn[] queryReturns = new NativeSQLQueryScalarReturn[] {
|
||||
new NativeSQLQueryScalarReturn( blah, sfi().getTypeResolver().basic( "int" ) )
|
||||
new NativeSQLQueryScalarReturn( blah, sessionFactory().getTypeResolver().basic( "int" ) )
|
||||
};
|
||||
return new NativeSQLQuerySpecification( select, queryReturns, null );
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public class RowIdTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
public void afterSessionFactoryBuilt() {
|
||||
super.afterSessionFactoryBuilt();
|
||||
Session session = sfi().openSession();
|
||||
Session session = sessionFactory().openSession();
|
||||
session.doWork(
|
||||
new Work() {
|
||||
@Override
|
||||
|
|
|
@ -78,9 +78,9 @@ public abstract class CustomSQLTestSupport extends BaseCoreFunctionalTestCase {
|
|||
t.commit();
|
||||
s.close();
|
||||
|
||||
getSessions().getCache().evictEntityRegion( Organization.class );
|
||||
getSessions().getCache().evictEntityRegion( Person.class );
|
||||
getSessions().getCache().evictEntityRegion( Employment.class );
|
||||
sessionFactory().getCache().evictEntityRegion( Organization.class );
|
||||
sessionFactory().getCache().evictEntityRegion( Person.class );
|
||||
sessionFactory().getCache().evictEntityRegion( Employment.class );
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
|
|
|
@ -146,7 +146,7 @@ public class NativeSQLQueriesTest extends BaseCoreFunctionalTestCase {
|
|||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
|
||||
sfi().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
|
||||
// create an Organization...
|
||||
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
|
||||
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...
|
||||
s.createSQLQuery( getEmploymentSQL() ).addSynchronizedEntityClass( Organization.class ).list();
|
||||
assertEquals( 1, sfi().getStatistics().getEntityInsertCount() );
|
||||
assertEquals( 1, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||
|
||||
// clean up
|
||||
s.delete( jboss );
|
||||
|
|
|
@ -52,8 +52,8 @@ public class NativeSqlAndQuotedIdentifiersTest extends BaseCoreFunctionalTestCas
|
|||
|
||||
@Override
|
||||
protected void prepareTest() throws Exception {
|
||||
if(sfi()==null)return;
|
||||
Session session = sfi().openSession();
|
||||
if( sessionFactory()==null)return;
|
||||
Session session = sessionFactory().openSession();
|
||||
session.beginTransaction();
|
||||
session.save( new Person( "me" ) );
|
||||
session.getTransaction().commit();
|
||||
|
@ -62,8 +62,8 @@ public class NativeSqlAndQuotedIdentifiersTest extends BaseCoreFunctionalTestCas
|
|||
|
||||
@Override
|
||||
protected void cleanupTest() throws Exception {
|
||||
if(sfi()==null)return;
|
||||
Session session = sfi().openSession();
|
||||
if( sessionFactory()==null)return;
|
||||
Session session = sessionFactory().openSession();
|
||||
session.beginTransaction();
|
||||
session.createQuery( "delete Person" ).executeUpdate();
|
||||
session.getTransaction().commit();
|
||||
|
|
|
@ -56,7 +56,7 @@ public class StatelessSessionQueryTest extends BaseCoreFunctionalTestCase {
|
|||
public void testCriteria() {
|
||||
TestData testData=new TestData();
|
||||
testData.createData();
|
||||
StatelessSession s = getSessions().openStatelessSession();
|
||||
StatelessSession s = sessionFactory().openStatelessSession();
|
||||
assertEquals( 1, s.createCriteria( Contact.class ).list().size() );
|
||||
s.close();
|
||||
testData.cleanData();
|
||||
|
@ -66,7 +66,7 @@ public class StatelessSessionQueryTest extends BaseCoreFunctionalTestCase {
|
|||
public void testCriteriaWithSelectFetchMode() {
|
||||
TestData testData=new TestData();
|
||||
testData.createData();
|
||||
StatelessSession s = getSessions().openStatelessSession();
|
||||
StatelessSession s = sessionFactory().openStatelessSession();
|
||||
assertEquals( 1, s.createCriteria( Contact.class ).setFetchMode( "org", FetchMode.SELECT )
|
||||
.list().size() );
|
||||
s.close();
|
||||
|
@ -77,7 +77,7 @@ public class StatelessSessionQueryTest extends BaseCoreFunctionalTestCase {
|
|||
public void testHQL() {
|
||||
TestData testData=new TestData();
|
||||
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" )
|
||||
.list().size() );
|
||||
s.close();
|
||||
|
|
|
@ -47,7 +47,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testCreateUpdateReadDelete() {
|
||||
StatelessSession ss = getSessions().openStatelessSession();
|
||||
StatelessSession ss = sessionFactory().openStatelessSession();
|
||||
Transaction tx = ss.beginTransaction();
|
||||
Document doc = new Document("blah blah blah", "Blahs");
|
||||
ss.insert(doc);
|
||||
|
@ -109,7 +109,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testHqlBulk() {
|
||||
StatelessSession ss = getSessions().openStatelessSession();
|
||||
StatelessSession ss = sessionFactory().openStatelessSession();
|
||||
Transaction tx = ss.beginTransaction();
|
||||
Document doc = new Document("blah blah blah", "Blahs");
|
||||
ss.insert(doc);
|
||||
|
@ -141,7 +141,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testInitId() {
|
||||
StatelessSession ss = getSessions().openStatelessSession();
|
||||
StatelessSession ss = sessionFactory().openStatelessSession();
|
||||
Transaction tx = ss.beginTransaction();
|
||||
Paper paper = new Paper();
|
||||
paper.setColor( "White" );
|
||||
|
@ -157,7 +157,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testRefresh() {
|
||||
StatelessSession ss = getSessions().openStatelessSession();
|
||||
StatelessSession ss = sessionFactory().openStatelessSession();
|
||||
Transaction tx = ss.beginTransaction();
|
||||
Paper paper = new Paper();
|
||||
paper.setColor( "whtie" );
|
||||
|
@ -165,7 +165,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
|
|||
tx.commit();
|
||||
ss.close();
|
||||
|
||||
ss = getSessions().openStatelessSession();
|
||||
ss = sessionFactory().openStatelessSession();
|
||||
tx = ss.beginTransaction();
|
||||
Paper p2 = ( Paper ) ss.get( Paper.class, paper.getId() );
|
||||
p2.setColor( "White" );
|
||||
|
@ -173,7 +173,7 @@ public class StatelessSessionTest extends BaseCoreFunctionalTestCase {
|
|||
tx.commit();
|
||||
ss.close();
|
||||
|
||||
ss = getSessions().openStatelessSession();
|
||||
ss = sessionFactory().openStatelessSession();
|
||||
tx = ss.beginTransaction();
|
||||
assertEquals( "whtie", paper.getColor() );
|
||||
ss.refresh( paper );
|
||||
|
|
|
@ -114,7 +114,7 @@ public class StatelessSessionFetchingTest extends BaseCoreFunctionalTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
StatelessSession ss = sfi().openStatelessSession();
|
||||
StatelessSession ss = sessionFactory().openStatelessSession();
|
||||
ss.beginTransaction();
|
||||
Task taskRef = ( Task ) ss.createQuery( "from Task t join fetch t.resource join fetch t.user" ).uniqueResult();
|
||||
assertTrue( taskRef != null );
|
||||
|
|
|
@ -63,7 +63,7 @@ public class StatsTest extends BaseCoreFunctionalTestCase {
|
|||
@Test
|
||||
@SuppressWarnings( {"UnusedAssignment"})
|
||||
public void testCollectionFetchVsLoad() throws Exception {
|
||||
Statistics stats = getSessions().getStatistics();
|
||||
Statistics stats = sessionFactory().getStatistics();
|
||||
stats.clear();
|
||||
|
||||
Session s = openSession();
|
||||
|
@ -151,7 +151,7 @@ public class StatsTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testQueryStatGathering() {
|
||||
Statistics stats = getSessions().getStatistics();
|
||||
Statistics stats = sessionFactory().getStatistics();
|
||||
stats.clear();
|
||||
|
||||
Session s = openSession();
|
||||
|
|
|
@ -68,7 +68,7 @@ public class SubselectTest extends BaseCoreFunctionalTestCase {
|
|||
assertNotNull( being.getSpecies() );
|
||||
}
|
||||
s.clear();
|
||||
getSessions().getCache().evictEntityRegion( Being.class );
|
||||
sessionFactory().getCache().evictEntityRegion( Being.class );
|
||||
Being gav = (Being) s.get(Being.class, gavin.getId());
|
||||
assertEquals( gav.getLocation(), gavin.getAddress() );
|
||||
assertEquals( gav.getSpecies(), "human" );
|
||||
|
|
|
@ -50,7 +50,7 @@ public class TimestampTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testUpdateFalse() {
|
||||
getSessions().getStatistics().clear();
|
||||
sessionFactory().getStatistics().clear();
|
||||
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
|
@ -61,8 +61,8 @@ public class TimestampTest extends BaseCoreFunctionalTestCase {
|
|||
t.commit();
|
||||
s.close();
|
||||
|
||||
assertEquals( 1, getSessions().getStatistics().getEntityInsertCount() );
|
||||
assertEquals( 0, getSessions().getStatistics().getEntityUpdateCount() );
|
||||
assertEquals( 1, sessionFactory().getStatistics().getEntityInsertCount() );
|
||||
assertEquals( 0, sessionFactory().getStatistics().getEntityUpdateCount() );
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
|
@ -72,7 +72,7 @@ public class TimestampTest extends BaseCoreFunctionalTestCase {
|
|||
t.commit();
|
||||
s.close();
|
||||
|
||||
assertEquals( 1, getSessions().getStatistics().getEntityDeleteCount() );
|
||||
assertEquals( 1, sessionFactory().getStatistics().getEntityDeleteCount() );
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -133,7 +133,7 @@ public class TypeOverrideTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
private SqlTypeDescriptor getResolvedSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
|
||||
return ( ( SessionFactoryImplementor ) getSessions() )
|
||||
return ( ( SessionFactoryImplementor ) sessionFactory() )
|
||||
.getTypeResolver()
|
||||
.resolveSqlTypeDescriptor( sqlTypeDescriptor );
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ public class TypeOverrideTest extends BaseCoreFunctionalTestCase {
|
|||
else {
|
||||
assertSame(
|
||||
VarcharTypeDescriptor.INSTANCE,
|
||||
( ( SessionFactoryImplementor ) getSessions() )
|
||||
( ( SessionFactoryImplementor ) sessionFactory() )
|
||||
.getTypeResolver()
|
||||
.resolveSqlTypeDescriptor( VarcharTypeDescriptor.INSTANCE )
|
||||
);
|
||||
|
|
|
@ -65,9 +65,9 @@ public class SybaseTimestampVersioningTest extends BaseCoreFunctionalTestCase {
|
|||
Transaction t1 = null;
|
||||
Transaction t2 = null;
|
||||
try {
|
||||
s1 = getSessions().openSession();
|
||||
s1 = sessionFactory().openSession();
|
||||
t1 = s1.beginTransaction();
|
||||
s2 = getSessions().openSession();
|
||||
s2 = sessionFactory().openSession();
|
||||
t2 = s2.beginTransaction();
|
||||
|
||||
User user1 = ( User ) s1.get( User.class, steve.getId() );
|
||||
|
|
|
@ -180,7 +180,7 @@ public class EhCacheTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
// check the version value in the cache...
|
||||
SecondLevelCacheStatistics slcs = sfi().getStatistics()
|
||||
SecondLevelCacheStatistics slcs = sessionFactory().getStatistics()
|
||||
.getSecondLevelCacheStatistics( VersionedItem.class.getName() );
|
||||
|
||||
Object entry = slcs.getEntries().get( item.getId() );
|
||||
|
|
|
@ -94,6 +94,7 @@ import org.hibernate.mapping.AuxiliaryDatabaseObject;
|
|||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||
import org.hibernate.secure.JACCConfiguration;
|
||||
import org.hibernate.service.internal.ServiceRegistryImpl;
|
||||
import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator;
|
||||
import org.hibernate.service.spi.ServiceRegistry;
|
||||
import org.jboss.logging.Logger;
|
||||
|
@ -871,6 +872,10 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
|||
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
|
||||
* @deprecated
|
||||
|
@ -882,6 +887,10 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
|||
}
|
||||
|
||||
public EntityManagerFactory buildEntityManagerFactory() {
|
||||
return buildEntityManagerFactory( new ServiceRegistryImpl( cfg.getProperties() ) );
|
||||
}
|
||||
|
||||
public EntityManagerFactory buildEntityManagerFactory(ServiceRegistry serviceRegistry) {
|
||||
Thread thread = null;
|
||||
ClassLoader contextClassLoader = null;
|
||||
if (overridenClassLoader != null) {
|
||||
|
@ -897,7 +906,8 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
|||
discardOnClose,
|
||||
getSessionInterceptorClass( cfg.getProperties() ),
|
||||
cfg,
|
||||
connectionProviderInjectionData
|
||||
connectionProviderInjectionData,
|
||||
serviceRegistry
|
||||
);
|
||||
}
|
||||
catch (HibernateException e) {
|
||||
|
|
|
@ -38,6 +38,7 @@ import javax.persistence.spi.PersistenceUnitTransactionType;
|
|||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.AnnotationConfiguration;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
|
||||
import org.hibernate.ejb.metamodel.MetamodelImpl;
|
||||
|
@ -46,6 +47,7 @@ import org.hibernate.engine.SessionFactoryImplementor;
|
|||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.metadata.ClassMetadata;
|
||||
import org.hibernate.service.internal.ServiceRegistryImpl;
|
||||
import org.hibernate.service.spi.ServiceRegistry;
|
||||
|
||||
/**
|
||||
* Actual Hiberate implementation of {@link javax.persistence.EntityManagerFactory}.
|
||||
|
@ -55,7 +57,7 @@ import org.hibernate.service.internal.ServiceRegistryImpl;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
|
||||
private final transient ServiceRegistryImpl serviceRegistry;
|
||||
private final transient ServiceRegistry serviceRegistry;
|
||||
private final SessionFactory sessionFactory;
|
||||
private final PersistenceUnitTransactionType transactionType;
|
||||
private final boolean discardOnClose;
|
||||
|
@ -72,16 +74,11 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
|
|||
public EntityManagerFactoryImpl(
|
||||
PersistenceUnitTransactionType transactionType,
|
||||
boolean discardOnClose,
|
||||
Class<?> sessionInterceptorClass,
|
||||
Configuration cfg,
|
||||
Map connectionProviderInjectionData) {
|
||||
// FIXME: Get rid of this temporary way of creating the service registry for EM
|
||||
Map serviceRegistryProperties = new HashMap(
|
||||
cfg.getProperties().size() + connectionProviderInjectionData.size()
|
||||
);
|
||||
serviceRegistryProperties.putAll( cfg.getProperties() );
|
||||
serviceRegistryProperties.putAll( connectionProviderInjectionData );
|
||||
this.serviceRegistry = new ServiceRegistryImpl( serviceRegistryProperties );
|
||||
Class sessionInterceptorClass,
|
||||
AnnotationConfiguration cfg,
|
||||
Map connectionProviderInjectionData,
|
||||
ServiceRegistry serviceRegistry) {
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.sessionFactory = cfg.buildSessionFactory( serviceRegistry );
|
||||
this.transactionType = transactionType;
|
||||
this.discardOnClose = discardOnClose;
|
||||
|
@ -134,7 +131,6 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
|
|||
|
||||
public void close() {
|
||||
sessionFactory.close();
|
||||
serviceRegistry.destroy();
|
||||
}
|
||||
|
||||
public Map<String, Object> getProperties() {
|
||||
|
|
|
@ -42,7 +42,7 @@ import org.hibernate.ejb.metamodel.Phone;
|
|||
import org.hibernate.ejb.metamodel.Product;
|
||||
import org.hibernate.ejb.metamodel.ShelfLife;
|
||||
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.Television;
|
||||
import org.hibernate.ejb.test.callbacks.VideoSystem;
|
||||
|
@ -54,7 +54,7 @@ import org.hibernate.ejb.test.inheritance.Strawberry;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class CriteriaCompilingTest extends TestCase {
|
||||
public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase {
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Customer.class,
|
||||
|
|
|
@ -44,14 +44,14 @@ import org.hibernate.ejb.metamodel.Phone;
|
|||
import org.hibernate.ejb.metamodel.Product;
|
||||
import org.hibernate.ejb.metamodel.ShelfLife;
|
||||
import org.hibernate.ejb.metamodel.Spouse;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class QueryBuilderTest extends TestCase {
|
||||
public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase {
|
||||
@Override
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
|
|
|
@ -26,14 +26,15 @@ import javax.persistence.criteria.ParameterExpression;
|
|||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.persistence.metamodel.SingularAttribute;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class BasicCriteriaUsageTest extends TestCase {
|
||||
public class BasicCriteriaUsageTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] { Wall.class };
|
||||
|
|
|
@ -27,13 +27,14 @@ import javax.persistence.EntityManager;
|
|||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Root;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author alan.oleary
|
||||
*/
|
||||
public class ComponentCriteriaTest extends TestCase {
|
||||
public class ComponentCriteriaTest extends BaseEntityManagerFunctionalTestCase {
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] { Client.class };
|
||||
}
|
||||
|
|
|
@ -22,14 +22,14 @@
|
|||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.ejb.metamodel;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractMetamodelSpecificTest extends TestCase {
|
||||
public abstract class AbstractMetamodelSpecificTest extends BaseEntityManagerFunctionalTestCase {
|
||||
@Override
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
|
|
|
@ -25,14 +25,14 @@ package org.hibernate.ejb.metamodel;
|
|||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.metamodel.EntityType;
|
||||
import javax.persistence.metamodel.SingularAttribute;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class EmbeddedTypeTest extends TestCase {
|
||||
public class EmbeddedTypeTest extends BaseEntityManagerFunctionalTestCase {
|
||||
@Override
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
// $Id$
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
|
@ -23,7 +22,10 @@
|
|||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
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.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
@ -31,15 +33,20 @@ import java.util.Arrays;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
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.Environment;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.ejb.AvailableSettings;
|
||||
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.
|
||||
|
@ -47,41 +54,174 @@ import org.hibernate.testing.junit.functional.annotations.HibernateTestCase;
|
|||
* @author Emmanuel Bernard
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public abstract class TestCase extends HibernateTestCase {
|
||||
|
||||
protected static EntityManagerFactory factory;
|
||||
public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCase {
|
||||
private static final Dialect dialect = Dialect.getDialect();
|
||||
private static ServiceRegistryImpl serviceRegistry;
|
||||
private static EntityManagerFactory factory;
|
||||
private EntityManager em;
|
||||
private ArrayList isolatedEms = new ArrayList();
|
||||
private ArrayList<EntityManager> isolatedEms = new ArrayList<EntityManager>();
|
||||
|
||||
|
||||
public TestCase() {
|
||||
super();
|
||||
public static Dialect getDialect() {
|
||||
return dialect;
|
||||
}
|
||||
|
||||
public TestCase(String name) {
|
||||
super( name );
|
||||
@BeforeClassOnce
|
||||
private void buildSessionFactory() throws Exception {
|
||||
LOG.trace( "Building session factory" );
|
||||
Ejb3Configuration ejb3Configuration = buildConfiguration();
|
||||
serviceRegistry = buildServiceRegistry( ejb3Configuration.getHibernateConfiguration() );
|
||||
factory = ejb3Configuration.createEntityManagerFactory( getConfig(), serviceRegistry );
|
||||
afterEntityManagerFactoryBuilt();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
protected Ejb3Configuration buildConfiguration() {
|
||||
Ejb3Configuration ejb3Cfg = constructConfiguration();
|
||||
configure( ejb3Cfg.getHibernateConfiguration() );
|
||||
addMappings( ejb3Cfg.getHibernateConfiguration() );
|
||||
ejb3Cfg.getHibernateConfiguration().buildMappings();
|
||||
afterConfigurationBuilt( ejb3Cfg.getHibernateConfiguration() );
|
||||
return ejb3Cfg;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildConfiguration() throws Exception {
|
||||
Ejb3Configuration ejbconfig = new Ejb3Configuration();
|
||||
HibernateTestCase.cfg = ejbconfig.getHibernateConfiguration();
|
||||
if ( recreateSchema() ) {
|
||||
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
protected Ejb3Configuration constructConfiguration() {
|
||||
Ejb3Configuration ejb3Configuration = new Ejb3Configuration();
|
||||
if ( createSchema() ) {
|
||||
ejb3Configuration.getHibernateConfiguration().setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
}
|
||||
cfg.setProperty( Configuration.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
ejb3Configuration
|
||||
.getHibernateConfiguration()
|
||||
.setProperty( Configuration.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
ejb3Configuration
|
||||
.getHibernateConfiguration()
|
||||
.setProperty( Environment.DIALECT, getDialect().getClass().getName() );
|
||||
return ejb3Configuration;
|
||||
}
|
||||
|
||||
for ( String mappingFile : getMappings() ) {
|
||||
cfg.addResource( mappingFile );
|
||||
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 );
|
||||
}
|
||||
|
||||
factory = ejbconfig.createEntityManagerFactory( getConfig() );
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@AfterClassOnce
|
||||
public void releaseResources() {
|
||||
cleanUnclosed( this.em );
|
||||
for ( EntityManager isolatedEm : isolatedEms ) {
|
||||
cleanUnclosed( isolatedEm );
|
||||
}
|
||||
|
||||
if ( factory != null ) {
|
||||
factory.close();
|
||||
}
|
||||
if ( serviceRegistry != null ) {
|
||||
serviceRegistry.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
if ( em == null || !em.isOpen() ) {
|
||||
em = factory.createEntityManager();
|
||||
|
@ -181,47 +303,4 @@ public abstract class TestCase extends HibernateTestCase {
|
|||
props.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -45,7 +45,7 @@ import org.hibernate.stat.Statistics;
|
|||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class EntityManagerTest extends TestCase {
|
||||
public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
|
|
|
@ -1,57 +1,57 @@
|
|||
//$Id$
|
||||
//$Id$
|
||||
package org.hibernate.ejb.test.association;
|
||||
import javax.persistence.EntityManager;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class AssociationTest extends TestCase {
|
||||
public void testBidirOneToOne() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
String id = "10";
|
||||
Incident i = em.find( Incident.class, id );
|
||||
if ( i == null ) {
|
||||
i = new Incident( id );
|
||||
IncidentStatus ist = new IncidentStatus( id );
|
||||
i.setIncidentStatus( ist );
|
||||
ist.setIncident( i );
|
||||
em.persist( i );
|
||||
}
|
||||
em.getTransaction().commit();
|
||||
em.clear();
|
||||
em.getTransaction().begin();
|
||||
em.remove( em.find(Incident.class, id) );
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testMergeAndBidirOneToOne() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
Oven oven = new Oven();
|
||||
Kitchen kitchen = new Kitchen();
|
||||
em.persist( oven );
|
||||
em.persist( kitchen );
|
||||
kitchen.setOven( oven );
|
||||
oven.setKitchen( kitchen );
|
||||
em.flush();
|
||||
em.clear();
|
||||
//oven = em.find(Oven.class, oven.getId() );
|
||||
oven = em.merge( oven );
|
||||
em.flush();
|
||||
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
Incident.class,
|
||||
IncidentStatus.class,
|
||||
Kitchen.class,
|
||||
Oven.class
|
||||
};
|
||||
}
|
||||
}
|
||||
import javax.persistence.EntityManager;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class AssociationTest extends BaseEntityManagerFunctionalTestCase {
|
||||
public void testBidirOneToOne() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
String id = "10";
|
||||
Incident i = em.find( Incident.class, id );
|
||||
if ( i == null ) {
|
||||
i = new Incident( id );
|
||||
IncidentStatus ist = new IncidentStatus( id );
|
||||
i.setIncidentStatus( ist );
|
||||
ist.setIncident( i );
|
||||
em.persist( i );
|
||||
}
|
||||
em.getTransaction().commit();
|
||||
em.clear();
|
||||
em.getTransaction().begin();
|
||||
em.remove( em.find(Incident.class, id) );
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testMergeAndBidirOneToOne() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
Oven oven = new Oven();
|
||||
Kitchen kitchen = new Kitchen();
|
||||
em.persist( oven );
|
||||
em.persist( kitchen );
|
||||
kitchen.setOven( oven );
|
||||
oven.setKitchen( kitchen );
|
||||
em.flush();
|
||||
em.clear();
|
||||
//oven = em.find(Oven.class, oven.getId() );
|
||||
oven = em.merge( oven );
|
||||
em.flush();
|
||||
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
Incident.class,
|
||||
IncidentStatus.class,
|
||||
Kitchen.class,
|
||||
Oven.class
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,13 @@ import java.math.BigDecimal;
|
|||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.RollbackException;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class BeanValidationTest extends TestCase {
|
||||
public class BeanValidationTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testBeanValidationIntegrationOnFlush() {
|
||||
CupHolder ch = new CupHolder();
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.hibernate.Session;
|
|||
import org.hibernate.ejb.AvailableSettings;
|
||||
import org.hibernate.ejb.HibernateEntityManager;
|
||||
import org.hibernate.ejb.HibernateQuery;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.impl.AbstractQueryImpl;
|
||||
|
||||
/**
|
||||
|
@ -39,7 +39,7 @@ import org.hibernate.impl.AbstractQueryImpl;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SharedCacheModesTest extends TestCase {
|
||||
public class SharedCacheModesTest extends BaseEntityManagerFunctionalTestCase {
|
||||
@Override
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] { SimpleEntity.class };
|
||||
|
|
|
@ -3,12 +3,12 @@ package org.hibernate.ejb.test.callbacks;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import javax.persistence.EntityManager;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class CallbackAndDirtyTest extends TestCase {
|
||||
public class CallbackAndDirtyTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testDirtyButNotDirty() throws Exception {
|
||||
EntityManager manager = getOrCreateEntityManager();
|
||||
|
|
|
@ -6,14 +6,14 @@ import java.util.List;
|
|||
import javax.persistence.EntityManager;
|
||||
import org.hibernate.ejb.test.Cat;
|
||||
import org.hibernate.ejb.test.Kitten;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class CallbacksTest extends TestCase {
|
||||
public class CallbacksTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testCallbackMethod() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
|
|
|
@ -1,93 +1,93 @@
|
|||
//$Id$
|
||||
//$Id$
|
||||
package org.hibernate.ejb.test.cascade;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityTransaction;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
|
||||
|
||||
/**
|
||||
* @author Max Rydahl Andersen
|
||||
*/
|
||||
public class CascadeTest extends TestCase {
|
||||
|
||||
public void testCascade() throws Exception {
|
||||
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
Teacher teacher = null;
|
||||
|
||||
teacher = new Teacher();
|
||||
|
||||
Student student = new Student();
|
||||
|
||||
teacher.setFavoriteStudent(student);
|
||||
student.setFavoriteTeacher(teacher);
|
||||
|
||||
teacher.getStudents().add(student);
|
||||
student.setPrimaryTeacher(teacher);
|
||||
|
||||
em.persist( teacher );
|
||||
em.getTransaction().commit();
|
||||
|
||||
em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
Teacher foundTeacher = (Teacher) em.createQuery( "select t from Teacher as t" ).getSingleResult();
|
||||
|
||||
System.out.println(foundTeacher);
|
||||
System.out.println(foundTeacher.getFavoriteStudent());
|
||||
|
||||
for (Student fstudent : foundTeacher.getStudents()) {
|
||||
System.out.println(fstudent);
|
||||
System.out.println(fstudent.getFavoriteTeacher());
|
||||
System.out.println(fstudent.getPrimaryTeacher());
|
||||
}
|
||||
|
||||
em.getTransaction().commit(); // here *alot* of flushes occur on an object graph that has *Zero* changes.
|
||||
em.close();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void testNoCascadeAndMerge() throws Exception {
|
||||
Song e1 = new Song();
|
||||
Author e2 = new Author();
|
||||
|
||||
e1.setAuthor(e2);
|
||||
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
EntityTransaction tx = em.getTransaction();
|
||||
tx.begin();
|
||||
em.persist(e2);
|
||||
em.persist(e1);
|
||||
tx.commit();
|
||||
em.close();
|
||||
|
||||
em = getOrCreateEntityManager();
|
||||
|
||||
e1 = em.find(Song.class, e1.getId());
|
||||
e2 = null;
|
||||
|
||||
|
||||
tx = em.getTransaction();
|
||||
tx.begin();
|
||||
em.merge(e1);
|
||||
//em.refresh(e1);
|
||||
tx.commit();
|
||||
em.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
Teacher.class,
|
||||
Student.class,
|
||||
Song.class,
|
||||
Author.class
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityTransaction;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
|
||||
/**
|
||||
* @author Max Rydahl Andersen
|
||||
*/
|
||||
public class CascadeTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testCascade() throws Exception {
|
||||
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
Teacher teacher = null;
|
||||
|
||||
teacher = new Teacher();
|
||||
|
||||
Student student = new Student();
|
||||
|
||||
teacher.setFavoriteStudent(student);
|
||||
student.setFavoriteTeacher(teacher);
|
||||
|
||||
teacher.getStudents().add(student);
|
||||
student.setPrimaryTeacher(teacher);
|
||||
|
||||
em.persist( teacher );
|
||||
em.getTransaction().commit();
|
||||
|
||||
em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
Teacher foundTeacher = (Teacher) em.createQuery( "select t from Teacher as t" ).getSingleResult();
|
||||
|
||||
System.out.println(foundTeacher);
|
||||
System.out.println(foundTeacher.getFavoriteStudent());
|
||||
|
||||
for (Student fstudent : foundTeacher.getStudents()) {
|
||||
System.out.println(fstudent);
|
||||
System.out.println(fstudent.getFavoriteTeacher());
|
||||
System.out.println(fstudent.getPrimaryTeacher());
|
||||
}
|
||||
|
||||
em.getTransaction().commit(); // here *alot* of flushes occur on an object graph that has *Zero* changes.
|
||||
em.close();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void testNoCascadeAndMerge() throws Exception {
|
||||
Song e1 = new Song();
|
||||
Author e2 = new Author();
|
||||
|
||||
e1.setAuthor(e2);
|
||||
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
EntityTransaction tx = em.getTransaction();
|
||||
tx.begin();
|
||||
em.persist(e2);
|
||||
em.persist(e1);
|
||||
tx.commit();
|
||||
em.close();
|
||||
|
||||
em = getOrCreateEntityManager();
|
||||
|
||||
e1 = em.find(Song.class, e1.getId());
|
||||
e2 = null;
|
||||
|
||||
|
||||
tx = em.getTransaction();
|
||||
tx.begin();
|
||||
em.merge(e1);
|
||||
//em.refresh(e1);
|
||||
tx.commit();
|
||||
em.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
Teacher.class,
|
||||
Student.class,
|
||||
Song.class,
|
||||
Author.class
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ import java.io.ObjectOutputStream;
|
|||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityTransaction;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class DeleteOrphanTest extends TestCase {
|
||||
public class DeleteOrphanTest extends BaseEntityManagerFunctionalTestCase {
|
||||
public void testDeleteOrphan() throws Exception {
|
||||
EntityTransaction tx;
|
||||
|
||||
|
|
|
@ -9,12 +9,12 @@ import javax.persistence.GeneratedValue;
|
|||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class DetachAndContainsTest extends TestCase {
|
||||
public class DetachAndContainsTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testDetach() {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
|
|
|
@ -7,12 +7,12 @@ import javax.persistence.EntityTransaction;
|
|||
import javax.persistence.Query;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.ejb.HibernateEntityManager;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class FetchTest extends TestCase {
|
||||
public class FetchTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testCascadeAndFetchCollection() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package org.hibernate.ejb.test.cascade;
|
||||
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 {
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Date;
|
|||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import org.hibernate.ejb.HibernateEntityManager;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.ejb.test.Cat;
|
||||
import org.hibernate.ejb.test.Distributor;
|
||||
import org.hibernate.ejb.test.Item;
|
||||
|
@ -18,7 +19,7 @@ import org.hibernate.ejb.test.Wallet;
|
|||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class EntityManagerSerializationTest extends org.hibernate.ejb.test.TestCase {
|
||||
public class EntityManagerSerializationTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testSerialization() throws Exception {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
|
|
|
@ -1,60 +1,60 @@
|
|||
//$Id$
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, 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
|
||||
*/
|
||||
//$Id$
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, 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.emops;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.persistence.EntityManager;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class FlushModeTest extends TestCase {
|
||||
|
||||
public void testCreateEMFlushMode() throws Exception {
|
||||
Map<String, String> properties = new HashMap<String, String>();
|
||||
properties.put( "org.hibernate.flushMode", "manual" );
|
||||
EntityManager em = createEntityManager( properties );
|
||||
em.getTransaction().begin();
|
||||
Dress dress = new Dress();
|
||||
dress.name = "long dress";
|
||||
em.persist( dress );
|
||||
em.getTransaction().commit();
|
||||
|
||||
em.clear();
|
||||
|
||||
assertNull( em.find( Dress.class, dress.name ) );
|
||||
|
||||
em.close();
|
||||
}
|
||||
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Race.class,
|
||||
Competitor.class,
|
||||
Dress.class
|
||||
};
|
||||
}
|
||||
}
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.persistence.EntityManager;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class FlushModeTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testCreateEMFlushMode() throws Exception {
|
||||
Map<String, String> properties = new HashMap<String, String>();
|
||||
properties.put( "org.hibernate.flushMode", "manual" );
|
||||
EntityManager em = createEntityManager( properties );
|
||||
em.getTransaction().begin();
|
||||
Dress dress = new Dress();
|
||||
dress.name = "long dress";
|
||||
em.persist( dress );
|
||||
em.getTransaction().commit();
|
||||
|
||||
em.clear();
|
||||
|
||||
assertNull( em.find( Dress.class, dress.name ) );
|
||||
|
||||
em.close();
|
||||
}
|
||||
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Race.class,
|
||||
Competitor.class,
|
||||
Dress.class
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,13 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class FlushTest extends TestCase {
|
||||
public class FlushTest extends BaseEntityManagerFunctionalTestCase {
|
||||
private static Set<String> names= new HashSet<String>();
|
||||
static {
|
||||
names.add("Toonses");
|
||||
|
|
|
@ -1,45 +1,45 @@
|
|||
//$Id$
|
||||
//$Id$
|
||||
package org.hibernate.ejb.test.emops;
|
||||
import javax.persistence.EntityManager;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class GetReferenceTest extends TestCase {
|
||||
|
||||
public void testWrongIdType() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
try {
|
||||
Competitor c = em.getReference( Competitor.class, new String("30") );
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
//success
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
fail("Wrong exception: " + e );
|
||||
}
|
||||
|
||||
try {
|
||||
Mail c = em.getReference( Mail.class, 1 );
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
//success
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
fail("Wrong exception: " + e );
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Competitor.class,
|
||||
Race.class,
|
||||
Mail.class
|
||||
};
|
||||
}
|
||||
}
|
||||
import javax.persistence.EntityManager;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class GetReferenceTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testWrongIdType() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
try {
|
||||
Competitor c = em.getReference( Competitor.class, new String("30") );
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
//success
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
fail("Wrong exception: " + e );
|
||||
}
|
||||
|
||||
try {
|
||||
Mail c = em.getReference( Mail.class, 1 );
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
//success
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
fail("Wrong exception: " + e );
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Competitor.class,
|
||||
Race.class,
|
||||
Mail.class
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,185 +1,185 @@
|
|||
//$Id$
|
||||
//$Id$
|
||||
package org.hibernate.ejb.test.emops;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.persistence.EntityManager;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class MergeTest extends TestCase {
|
||||
public void testMergeWithIndexColumn() {
|
||||
Race race = new Race();
|
||||
race.competitors.add( new Competitor( "Name" ) );
|
||||
race.competitors.add( new Competitor() );
|
||||
race.competitors.add( new Competitor() );
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
em.persist( race );
|
||||
em.flush();
|
||||
em.clear();
|
||||
race.competitors.add( new Competitor() );
|
||||
race.competitors.remove( 2 );
|
||||
race.competitors.remove( 1 );
|
||||
race.competitors.get( 0 ).setName( "Name2" );
|
||||
race = em.merge( race );
|
||||
em.flush();
|
||||
em.clear();
|
||||
race = em.find( Race.class, race.id );
|
||||
assertEquals( 2, race.competitors.size() );
|
||||
assertEquals( "Name2", race.competitors.get( 0 ).getName() );
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testMergeManyToMany() {
|
||||
Competition competition = new Competition();
|
||||
competition.getCompetitors().add( new Competitor( "Name" ) );
|
||||
competition.getCompetitors().add( new Competitor() );
|
||||
competition.getCompetitors().add( new Competitor() );
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
em.persist( competition );
|
||||
em.flush();
|
||||
em.clear();
|
||||
competition.getCompetitors().add( new Competitor() );
|
||||
competition.getCompetitors().remove( 2 );
|
||||
competition.getCompetitors().remove( 1 );
|
||||
competition.getCompetitors().get( 0 ).setName( "Name2" );
|
||||
competition = em.merge( competition );
|
||||
em.flush();
|
||||
em.clear();
|
||||
competition = em.find( Competition.class, competition.getId() );
|
||||
assertEquals( 2, competition.getCompetitors().size() );
|
||||
// we cannot assume that the order in the list is maintained - HHH-4516
|
||||
String changedCompetitorName;
|
||||
if ( competition.getCompetitors().get( 0 ).getName() != null ) {
|
||||
changedCompetitorName = competition.getCompetitors().get( 0 ).getName();
|
||||
}
|
||||
else {
|
||||
changedCompetitorName = competition.getCompetitors().get( 1 ).getName();
|
||||
}
|
||||
assertEquals( "Name2", changedCompetitorName );
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testMergeManyToManyWithDeference() {
|
||||
Competition competition = new Competition();
|
||||
competition.getCompetitors().add( new Competitor( "Name" ) );
|
||||
competition.getCompetitors().add( new Competitor() );
|
||||
competition.getCompetitors().add( new Competitor() );
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
em.persist( competition );
|
||||
em.flush();
|
||||
em.clear();
|
||||
List<Competitor> newComp = new ArrayList<Competitor>();
|
||||
newComp.add( competition.getCompetitors().get( 0 ) );
|
||||
newComp.add( new Competitor() );
|
||||
newComp.get( 0 ).setName( "Name2" );
|
||||
competition.setCompetitors( newComp );
|
||||
competition = em.merge( competition );
|
||||
em.flush();
|
||||
em.clear();
|
||||
competition = em.find( Competition.class, competition.getId() );
|
||||
assertEquals( 2, competition.getCompetitors().size() );
|
||||
// we cannot assume that the order in the list is maintained - HHH-4516
|
||||
String changedCompetitorName;
|
||||
if ( competition.getCompetitors().get( 0 ).getName() != null ) {
|
||||
changedCompetitorName = competition.getCompetitors().get( 0 ).getName();
|
||||
}
|
||||
else {
|
||||
changedCompetitorName = competition.getCompetitors().get( 1 ).getName();
|
||||
}
|
||||
assertEquals( "Name2", changedCompetitorName );
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testRemoveAndMerge() {
|
||||
Race race = new Race();
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
em.persist( race );
|
||||
em.flush();
|
||||
em.clear();
|
||||
race = em.find( Race.class, race.id );
|
||||
em.remove( race );
|
||||
try {
|
||||
race = em.merge( race );
|
||||
em.flush();
|
||||
fail( "Should raise an IllegalArgumentException" );
|
||||
}
|
||||
catch ( IllegalArgumentException e ) {
|
||||
//all good
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
fail( "Should raise an IllegalArgumentException" );
|
||||
}
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testConcurrentMerge() {
|
||||
Race race = new Race();
|
||||
race.name = "Derby";
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
em.persist( race );
|
||||
em.flush();
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
|
||||
race.name = "Magnicourt";
|
||||
|
||||
em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
Race race2 = em.find( Race.class, race.id );
|
||||
race2.name = "Mans";
|
||||
|
||||
race = em.merge( race );
|
||||
em.flush();
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
|
||||
em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
race2 = em.find( Race.class, race.id );
|
||||
assertEquals( "Last commit win in merge", "Magnicourt", race2.name );
|
||||
|
||||
em.remove( race2 );
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testMergeUnidirectionalOneToMany() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
Empire roman = new Empire();
|
||||
em.persist( roman );
|
||||
em.flush();
|
||||
em.clear();
|
||||
roman = em.find( Empire.class, roman.getId() );
|
||||
Colony gaule = new Colony();
|
||||
roman.getColonies().add( gaule );
|
||||
em.merge( roman );
|
||||
em.flush();
|
||||
em.clear();
|
||||
roman = em.find( Empire.class, roman.getId() );
|
||||
assertEquals( 1, roman.getColonies().size() );
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Race.class,
|
||||
Competitor.class,
|
||||
Competition.class,
|
||||
Empire.class,
|
||||
Colony.class
|
||||
};
|
||||
}
|
||||
}
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.persistence.EntityManager;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class MergeTest extends BaseEntityManagerFunctionalTestCase {
|
||||
public void testMergeWithIndexColumn() {
|
||||
Race race = new Race();
|
||||
race.competitors.add( new Competitor( "Name" ) );
|
||||
race.competitors.add( new Competitor() );
|
||||
race.competitors.add( new Competitor() );
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
em.persist( race );
|
||||
em.flush();
|
||||
em.clear();
|
||||
race.competitors.add( new Competitor() );
|
||||
race.competitors.remove( 2 );
|
||||
race.competitors.remove( 1 );
|
||||
race.competitors.get( 0 ).setName( "Name2" );
|
||||
race = em.merge( race );
|
||||
em.flush();
|
||||
em.clear();
|
||||
race = em.find( Race.class, race.id );
|
||||
assertEquals( 2, race.competitors.size() );
|
||||
assertEquals( "Name2", race.competitors.get( 0 ).getName() );
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testMergeManyToMany() {
|
||||
Competition competition = new Competition();
|
||||
competition.getCompetitors().add( new Competitor( "Name" ) );
|
||||
competition.getCompetitors().add( new Competitor() );
|
||||
competition.getCompetitors().add( new Competitor() );
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
em.persist( competition );
|
||||
em.flush();
|
||||
em.clear();
|
||||
competition.getCompetitors().add( new Competitor() );
|
||||
competition.getCompetitors().remove( 2 );
|
||||
competition.getCompetitors().remove( 1 );
|
||||
competition.getCompetitors().get( 0 ).setName( "Name2" );
|
||||
competition = em.merge( competition );
|
||||
em.flush();
|
||||
em.clear();
|
||||
competition = em.find( Competition.class, competition.getId() );
|
||||
assertEquals( 2, competition.getCompetitors().size() );
|
||||
// we cannot assume that the order in the list is maintained - HHH-4516
|
||||
String changedCompetitorName;
|
||||
if ( competition.getCompetitors().get( 0 ).getName() != null ) {
|
||||
changedCompetitorName = competition.getCompetitors().get( 0 ).getName();
|
||||
}
|
||||
else {
|
||||
changedCompetitorName = competition.getCompetitors().get( 1 ).getName();
|
||||
}
|
||||
assertEquals( "Name2", changedCompetitorName );
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testMergeManyToManyWithDeference() {
|
||||
Competition competition = new Competition();
|
||||
competition.getCompetitors().add( new Competitor( "Name" ) );
|
||||
competition.getCompetitors().add( new Competitor() );
|
||||
competition.getCompetitors().add( new Competitor() );
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
em.persist( competition );
|
||||
em.flush();
|
||||
em.clear();
|
||||
List<Competitor> newComp = new ArrayList<Competitor>();
|
||||
newComp.add( competition.getCompetitors().get( 0 ) );
|
||||
newComp.add( new Competitor() );
|
||||
newComp.get( 0 ).setName( "Name2" );
|
||||
competition.setCompetitors( newComp );
|
||||
competition = em.merge( competition );
|
||||
em.flush();
|
||||
em.clear();
|
||||
competition = em.find( Competition.class, competition.getId() );
|
||||
assertEquals( 2, competition.getCompetitors().size() );
|
||||
// we cannot assume that the order in the list is maintained - HHH-4516
|
||||
String changedCompetitorName;
|
||||
if ( competition.getCompetitors().get( 0 ).getName() != null ) {
|
||||
changedCompetitorName = competition.getCompetitors().get( 0 ).getName();
|
||||
}
|
||||
else {
|
||||
changedCompetitorName = competition.getCompetitors().get( 1 ).getName();
|
||||
}
|
||||
assertEquals( "Name2", changedCompetitorName );
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testRemoveAndMerge() {
|
||||
Race race = new Race();
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
em.persist( race );
|
||||
em.flush();
|
||||
em.clear();
|
||||
race = em.find( Race.class, race.id );
|
||||
em.remove( race );
|
||||
try {
|
||||
race = em.merge( race );
|
||||
em.flush();
|
||||
fail( "Should raise an IllegalArgumentException" );
|
||||
}
|
||||
catch ( IllegalArgumentException e ) {
|
||||
//all good
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
fail( "Should raise an IllegalArgumentException" );
|
||||
}
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testConcurrentMerge() {
|
||||
Race race = new Race();
|
||||
race.name = "Derby";
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
em.persist( race );
|
||||
em.flush();
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
|
||||
race.name = "Magnicourt";
|
||||
|
||||
em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
Race race2 = em.find( Race.class, race.id );
|
||||
race2.name = "Mans";
|
||||
|
||||
race = em.merge( race );
|
||||
em.flush();
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
|
||||
em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
race2 = em.find( Race.class, race.id );
|
||||
assertEquals( "Last commit win in merge", "Magnicourt", race2.name );
|
||||
|
||||
em.remove( race2 );
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testMergeUnidirectionalOneToMany() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
Empire roman = new Empire();
|
||||
em.persist( roman );
|
||||
em.flush();
|
||||
em.clear();
|
||||
roman = em.find( Empire.class, roman.getId() );
|
||||
Colony gaule = new Colony();
|
||||
roman.getColonies().add( gaule );
|
||||
em.merge( roman );
|
||||
em.flush();
|
||||
em.clear();
|
||||
roman = em.find( Empire.class, roman.getId() );
|
||||
assertEquals( 1, roman.getColonies().size() );
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Race.class,
|
||||
Competitor.class,
|
||||
Competition.class,
|
||||
Empire.class,
|
||||
Colony.class
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
//$Id$
|
||||
//$Id$
|
||||
package org.hibernate.ejb.test.emops;
|
||||
import javax.persistence.EntityManager;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class RefreshTest extends TestCase {
|
||||
|
||||
public void testRefreshNonManaged() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
Race race = new Race();
|
||||
em.persist( race );
|
||||
em.flush();
|
||||
em.clear();
|
||||
|
||||
try {
|
||||
em.refresh( race );
|
||||
fail("Refresh should fail on a non managed entity");
|
||||
}
|
||||
catch( IllegalArgumentException e) {
|
||||
//success
|
||||
}
|
||||
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Race.class,
|
||||
Competitor.class
|
||||
};
|
||||
}
|
||||
}
|
||||
import javax.persistence.EntityManager;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class RefreshTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testRefreshNonManaged() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
Race race = new Race();
|
||||
em.persist( race );
|
||||
em.flush();
|
||||
em.clear();
|
||||
|
||||
try {
|
||||
em.refresh( race );
|
||||
fail("Refresh should fail on a non managed entity");
|
||||
}
|
||||
catch( IllegalArgumentException e) {
|
||||
//success
|
||||
}
|
||||
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Race.class,
|
||||
Competitor.class
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,13 @@ import static org.hibernate.testing.TestLogger.LOG;
|
|||
import java.util.Map;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.OptimisticLockException;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class RemoveTest extends TestCase {
|
||||
public class RemoveTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testRemove() {
|
||||
Race race = new Race();
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
package org.hibernate.ejb.test.emops.cascade;
|
||||
import javax.persistence.EntityManager;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.stat.Statistics;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class CascadePersistTest extends TestCase {
|
||||
public class CascadePersistTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testLazyCollectionsStayLazyOnPersist() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
|
|
|
@ -7,14 +7,14 @@ import javax.persistence.EntityNotFoundException;
|
|||
import javax.persistence.OptimisticLockException;
|
||||
import javax.persistence.PersistenceException;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.exception.ConstraintViolationException;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ExceptionTest extends TestCase {
|
||||
public class ExceptionTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testOptimisticLockingException() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
|
|
|
@ -1,39 +1,39 @@
|
|||
//$Id$
|
||||
//$Id$
|
||||
package org.hibernate.ejb.test.inheritance;
|
||||
import javax.persistence.EntityManager;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class InheritanceTest extends TestCase {
|
||||
|
||||
public void testFind() throws Exception {
|
||||
EntityManager firstSession = getOrCreateEntityManager( );
|
||||
Strawberry u = new Strawberry();
|
||||
u.setSize( 12l );
|
||||
firstSession.getTransaction().begin();
|
||||
firstSession.persist(u);
|
||||
firstSession.getTransaction().commit();
|
||||
Long newId = u.getId();
|
||||
firstSession.clear();
|
||||
|
||||
firstSession.getTransaction().begin();
|
||||
// 1.
|
||||
Strawberry result1 = firstSession.find(Strawberry.class, newId);
|
||||
assertNotNull( result1 );
|
||||
|
||||
// 2.
|
||||
Strawberry result2 = (Strawberry) firstSession.find(Fruit.class, newId);
|
||||
System.out.println("2. result is:" + result2);
|
||||
|
||||
firstSession.getTransaction().commit();
|
||||
firstSession.close();
|
||||
}
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Fruit.class,
|
||||
Strawberry.class
|
||||
};
|
||||
}
|
||||
}
|
||||
import javax.persistence.EntityManager;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class InheritanceTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testFind() throws Exception {
|
||||
EntityManager firstSession = getOrCreateEntityManager( );
|
||||
Strawberry u = new Strawberry();
|
||||
u.setSize( 12l );
|
||||
firstSession.getTransaction().begin();
|
||||
firstSession.persist(u);
|
||||
firstSession.getTransaction().commit();
|
||||
Long newId = u.getId();
|
||||
firstSession.clear();
|
||||
|
||||
firstSession.getTransaction().begin();
|
||||
// 1.
|
||||
Strawberry result1 = firstSession.find(Strawberry.class, newId);
|
||||
assertNotNull( result1 );
|
||||
|
||||
// 2.
|
||||
Strawberry result2 = (Strawberry) firstSession.find(Fruit.class, newId);
|
||||
System.out.println("2. result is:" + result2);
|
||||
|
||||
firstSession.getTransaction().commit();
|
||||
firstSession.close();
|
||||
}
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Fruit.class,
|
||||
Strawberry.class
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class BlobTest extends TestCase {
|
||||
@RequiresDialectFeature( DialectChecks.SupportsExpectedLobUsagePattern.class )
|
||||
public class BlobTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testBlobSerialization() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
|
@ -39,14 +69,7 @@ public class BlobTest extends TestCase {
|
|||
em.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean appliesTo(Dialect dialect) {
|
||||
return dialect.supportsExpectedLobUsagePattern();
|
||||
}
|
||||
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
ImageReader.class
|
||||
};
|
||||
return new Class[] { ImageReader.class };
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,12 @@ import javax.persistence.QueryTimeoutException;
|
|||
import org.hibernate.dialect.HSQLDialect;
|
||||
import org.hibernate.dialect.Oracle10gDialect;
|
||||
import org.hibernate.ejb.AvailableSettings;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class LockTest extends TestCase {
|
||||
public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testFindWithTimeoutHint() {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.hibernate.LockMode;
|
|||
import org.hibernate.cfg.AnnotationConfiguration;
|
||||
import org.hibernate.ejb.AvailableSettings;
|
||||
import org.hibernate.ejb.QueryImpl;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.impl.SessionImpl;
|
||||
|
||||
/**
|
||||
|
@ -37,7 +37,7 @@ import org.hibernate.impl.SessionImpl;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class QueryLockingTest extends TestCase {
|
||||
public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package org.hibernate.ejb.test.mapping;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class QuotingTest extends TestCase {
|
||||
public class QuotingTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testQuote() {
|
||||
// the configuration was failing
|
||||
|
|
|
@ -38,13 +38,13 @@ import javax.persistence.metamodel.SingularAttribute;
|
|||
import javax.persistence.metamodel.Type;
|
||||
import org.hibernate.cfg.AnnotationConfiguration;
|
||||
import org.hibernate.ejb.metamodel.MetamodelImpl;
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.engine.SessionFactoryImplementor;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class MetadataTest extends TestCase {
|
||||
public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
public void testBaseOfService() throws Exception {
|
||||
EntityManagerFactory emf = factory;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue