HHH-7266 - Move away from use of Enhydra developed DataSource for JTA testing

This commit is contained in:
Steve Ebersole 2012-04-20 17:07:04 -05:00
parent 6cd7857daa
commit 70847a2331
12 changed files with 748 additions and 467 deletions

View File

@ -34,6 +34,7 @@ import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
import org.hibernate.engine.transaction.spi.TransactionImplementor;
import org.hibernate.test.jpa.AbstractJPATest;
import org.hibernate.testing.jta.TestingJtaBootstrap;
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@ -51,7 +52,7 @@ public class TransactionJoiningTest extends AbstractJPATest {
@Test
public void testExplicitJoining() throws Exception {
assertFalse( JtaStatusHelper.isActive( TestingJtaBootstrap.INSTANCE.getTransactionManager() ) );
assertFalse( JtaStatusHelper.isActive( TestingJtaPlatformImpl.INSTANCE.getTransactionManager() ) );
SessionImplementor session = (SessionImplementor) sessionFactory().withOptions().autoJoinTransactions( false ).openSession();
TransactionImplementor transaction = (TransactionImplementor) ( (Session) session ).getTransaction();
@ -64,16 +65,16 @@ public class TransactionJoiningTest extends AbstractJPATest {
assertFalse( session.getTransactionCoordinator().isSynchronizationRegistered() );
assertFalse( transaction.isParticipating() );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
assertTrue( JtaStatusHelper.isActive( TestingJtaBootstrap.INSTANCE.getTransactionManager() ) );
assertTrue( JtaStatusHelper.isActive( TestingJtaPlatformImpl.INSTANCE.getTransactionManager() ) );
assertTrue( transaction.isActive() );
assertFalse( transaction.isParticipating() );
assertFalse( session.getTransactionCoordinator().isSynchronizationRegistered() );
session.getFlushMode();
assertTrue( JtaStatusHelper.isActive( TestingJtaBootstrap.INSTANCE.getTransactionManager() ) );
assertTrue( JtaStatusHelper.isActive( TestingJtaPlatformImpl.INSTANCE.getTransactionManager() ) );
assertTrue( transaction.isActive() );
assertFalse( session.getTransactionCoordinator().isSynchronizationRegistered() );
assertFalse( transaction.isParticipating() );
@ -82,22 +83,22 @@ public class TransactionJoiningTest extends AbstractJPATest {
transaction.join();
session.getFlushMode();
assertTrue( JtaStatusHelper.isActive( TestingJtaBootstrap.INSTANCE.getTransactionManager() ) );
assertTrue( JtaStatusHelper.isActive( TestingJtaPlatformImpl.INSTANCE.getTransactionManager() ) );
assertTrue( transaction.isActive() );
assertTrue( session.getTransactionCoordinator().isSynchronizationRegistered() );
assertTrue( transaction.isParticipating() );
( (Session) session ).close();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
public void testImplicitJoining() throws Exception {
assertFalse( JtaStatusHelper.isActive( TestingJtaBootstrap.INSTANCE.getTransactionManager() ) );
assertFalse( JtaStatusHelper.isActive( TestingJtaPlatformImpl.INSTANCE.getTransactionManager() ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
assertTrue( JtaStatusHelper.isActive( TestingJtaBootstrap.INSTANCE.getTransactionManager() ) );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
assertTrue( JtaStatusHelper.isActive( TestingJtaPlatformImpl.INSTANCE.getTransactionManager() ) );
SessionImplementor session = (SessionImplementor) sessionFactory().withOptions().autoJoinTransactions( false ).openSession();
@ -106,10 +107,10 @@ public class TransactionJoiningTest extends AbstractJPATest {
@Test
public void control() throws Exception {
assertFalse( JtaStatusHelper.isActive( TestingJtaBootstrap.INSTANCE.getTransactionManager() ) );
assertFalse( JtaStatusHelper.isActive( TestingJtaPlatformImpl.INSTANCE.getTransactionManager() ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
assertTrue( JtaStatusHelper.isActive( TestingJtaBootstrap.INSTANCE.getTransactionManager() ) );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
assertTrue( JtaStatusHelper.isActive( TestingJtaPlatformImpl.INSTANCE.getTransactionManager() ) );
SessionImplementor session = (SessionImplementor) sessionFactory().openSession();
TransactionImplementor transaction = (TransactionImplementor) ( (Session) session ).getTransaction();
@ -119,6 +120,6 @@ public class TransactionJoiningTest extends AbstractJPATest {
( (Session) session ).close();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit(); }
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit(); }
}

View File

@ -35,7 +35,7 @@ import org.hibernate.PersistentObjectException;
import org.hibernate.Session;
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
import org.hibernate.exception.ConstraintViolationException;
import org.hibernate.testing.jta.TestingJtaBootstrap;
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -50,7 +50,7 @@ public class CreateTest extends AbstractOperationTestCase {
public void testNoUpdatesOnCreateVersionedWithCollection() throws Exception {
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
VersionedEntity root = new VersionedEntity( "root", "root" );
@ -63,17 +63,17 @@ public class CreateTest extends AbstractOperationTestCase {
root = ( VersionedEntity ) getOldToNewEntityRefMap().get( root );
applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( VersionedEntity ) getOldToNewEntityRefMap().get( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 2 );
assertUpdateCount( 0 );
assertDeleteCount( 0 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.delete( root );
applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertUpdateCount( 0 );
assertDeleteCount( 2 );
@ -83,7 +83,7 @@ public class CreateTest extends AbstractOperationTestCase {
public void testCreateTree() throws Exception {
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Node root = new Node( "root" );
Node child = new Node( "child" );
@ -91,12 +91,12 @@ public class CreateTest extends AbstractOperationTestCase {
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
s.persist( root );
applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 2 );
assertUpdateCount( 0 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
System.out.println( "getting" );
root = ( Node ) s.get( Node.class, "root" );
@ -106,7 +106,7 @@ public class CreateTest extends AbstractOperationTestCase {
root.addChild( child2 );
System.out.println( "committing" );
applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 3 );
assertUpdateCount( 0 );
@ -117,7 +117,7 @@ public class CreateTest extends AbstractOperationTestCase {
public void testCreateTreeWithGeneratedId() throws Exception {
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
NumberedNode root = new NumberedNode( "root" );
NumberedNode child = new NumberedNode( "child" );
@ -126,12 +126,12 @@ public class CreateTest extends AbstractOperationTestCase {
s.persist( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 2 );
assertUpdateCount( 0 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( NumberedNode ) s.get( NumberedNode.class, Long.valueOf( root.getId() ) );
@ -140,7 +140,7 @@ public class CreateTest extends AbstractOperationTestCase {
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
root.addChild( child2 );
applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 3 );
assertUpdateCount( 0 );
@ -148,7 +148,7 @@ public class CreateTest extends AbstractOperationTestCase {
@Test
public void testCreateException() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Node dupe = new Node( "dupe" );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
@ -157,15 +157,15 @@ public class CreateTest extends AbstractOperationTestCase {
dupe = ( Node ) getOldToNewEntityRefMap().get( dupe );
s.persist( dupe );
applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
s.persist( dupe );
applyNonFlushedChangesToNewSessionCloseOldSession( s );
try {
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
Assert.fail();
}
catch ( ConstraintViolationException cve ) {
@ -176,21 +176,21 @@ public class CreateTest extends AbstractOperationTestCase {
throw (Exception) e.getCause();
}
}
if ( JtaStatusHelper.isActive( TestingJtaBootstrap.INSTANCE.getTransactionManager() ) ) {
if ( JtaStatusHelper.isActive( TestingJtaPlatformImpl.INSTANCE.getTransactionManager() ) ) {
// ugh! really!?!
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().rollback();
}
Node nondupe = new Node( "nondupe" );
nondupe.addChild( dupe );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
s.persist( nondupe );
applyNonFlushedChangesToNewSessionCloseOldSession( s );
try {
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
Assert.fail();
}
catch ( ConstraintViolationException cve ) {
@ -201,15 +201,15 @@ public class CreateTest extends AbstractOperationTestCase {
throw (Exception) e.getCause();
}
}
if ( JtaStatusHelper.isActive( TestingJtaBootstrap.INSTANCE.getTransactionManager() ) ) {
if ( JtaStatusHelper.isActive( TestingJtaPlatformImpl.INSTANCE.getTransactionManager() ) ) {
// ugh! really!?!
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().rollback();
}
}
@Test
public void testCreateExceptionWithGeneratedId() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
NumberedNode dupe = new NumberedNode( "dupe" );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
@ -219,9 +219,9 @@ public class CreateTest extends AbstractOperationTestCase {
s.persist( dupe );
applyNonFlushedChangesToNewSessionCloseOldSession( s );
dupe = ( NumberedNode ) getOldToNewEntityRefMap().get( dupe );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
try {
@ -232,12 +232,12 @@ public class CreateTest extends AbstractOperationTestCase {
catch ( PersistentObjectException poe ) {
//verify that an exception is thrown!
}
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().rollback();
NumberedNode nondupe = new NumberedNode( "nondupe" );
nondupe.addChild( dupe );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
try {
@ -247,14 +247,14 @@ public class CreateTest extends AbstractOperationTestCase {
catch ( PersistentObjectException poe ) {
//verify that an exception is thrown!
}
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().rollback();
}
@Test
@SuppressWarnings( {"unchecked"})
public void testBasic() throws Exception {
Session s;
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
Employer er = new Employer();
Employee ee = new Employee();
@ -271,9 +271,9 @@ public class CreateTest extends AbstractOperationTestCase {
applyNonFlushedChangesToNewSessionCloseOldSession( s );
ee = ( Employee ) getOldToNewEntityRefMap().get( ee );
er = ( Employer ) ee.getEmployers().iterator().next();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
er = ( Employer ) s.load( Employer.class, er.getId() );
assertNotNull( er );
@ -289,6 +289,6 @@ public class CreateTest extends AbstractOperationTestCase {
eeFromDb = ( Employee ) getOldToNewEntityRefMap().get( eeFromDb );
assertEquals( ee.getId(), eeFromDb.getId() );
applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
}

View File

@ -23,11 +23,10 @@
*/
package org.hibernate.test.nonflushedchanges;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.testing.jta.TestingJtaBootstrap;
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
/**
* adapted this from "ops" tests version
@ -40,25 +39,25 @@ public class DeleteTest extends AbstractOperationTestCase {
@SuppressWarnings( {"unchecked"})
public void testDeleteVersionedWithCollectionNoUpdate() throws Exception {
// test adapted from HHH-1564...
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
VersionedEntity c = new VersionedEntity( "c1", "child-1" );
VersionedEntity p = new VersionedEntity( "root", "root" );
p.getChildren().add( c );
c.setParent( p );
s.save( p );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
VersionedEntity loadedParent = ( VersionedEntity ) s.get( VersionedEntity.class, "root" );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
loadedParent = ( VersionedEntity ) getOldToNewEntityRefMap().get( loadedParent );
s.delete( loadedParent );
applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 0 );
assertUpdateCount( 0 );
@ -67,20 +66,20 @@ public class DeleteTest extends AbstractOperationTestCase {
@Test
public void testNoUpdateOnDelete() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Node node = new Node( "test" );
s.persist( node );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
s.delete( node );
applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertUpdateCount( 0 );
assertInsertCount( 0 );
@ -89,24 +88,24 @@ public class DeleteTest extends AbstractOperationTestCase {
@Test
@SuppressWarnings( {"unchecked"})
public void testNoUpdateOnDeleteWithCollection() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Node parent = new Node( "parent" );
Node child = new Node( "child" );
parent.getCascadingChildren().add( child );
s.persist( parent );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
parent = ( Node ) s.get( Node.class, "parent" );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
parent = ( Node ) getOldToNewEntityRefMap().get( parent );
s.delete( parent );
applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertUpdateCount( 0 );
assertInsertCount( 0 );

View File

@ -31,7 +31,7 @@ import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.testing.jta.TestingJtaBootstrap;
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -56,7 +56,7 @@ public class GetLoadTest extends AbstractOperationTestCase {
public void testGetLoad() throws Exception {
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Employer emp = new Employer();
s.persist( emp );
@ -64,9 +64,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
Node parent = new Node( "bar" );
parent.addChild( node );
s.persist( parent );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
emp = ( Employer ) s.get( Employer.class, emp.getId() );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
@ -81,9 +81,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
assertFalse( Hibernate.isInitialized( node.getChildren() ) );
assertFalse( Hibernate.isInitialized( node.getParent() ) );
assertNull( s.get( Node.class, "xyz" ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
emp = ( Employer ) s.load( Employer.class, emp.getId() );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
@ -95,9 +95,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
node = ( Node ) getOldToNewEntityRefMap().get( node );
assertEquals( node.getName(), "foo" );
assertFalse( Hibernate.isInitialized( node ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
emp = ( Employer ) s.get( "org.hibernate.test.nonflushedchanges.Employer", emp.getId() );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
@ -107,9 +107,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
node = ( Node ) getOldToNewEntityRefMap().get( node );
assertTrue( Hibernate.isInitialized( node ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
emp = ( Employer ) s.load( "org.hibernate.test.nonflushedchanges.Employer", emp.getId() );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
@ -122,25 +122,25 @@ public class GetLoadTest extends AbstractOperationTestCase {
node = ( Node ) getOldToNewEntityRefMap().get( node );
assertEquals( node.getName(), "foo" );
assertFalse( Hibernate.isInitialized( node ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertFetchCount( 0 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.createQuery( "delete from Employer" ).executeUpdate();
List list = s.createQuery( "from Node" ).list();
for ( Object aList : list ) {
s.delete( aList );
}
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
public void testGetReadOnly() throws Exception {
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Employer emp = new Employer();
s.persist( emp );
@ -148,9 +148,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
Node parent = new Node( "bar" );
parent.addChild( node );
s.persist( parent );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
assertFalse( s.isDefaultReadOnly() );
s.setDefaultReadOnly( true );
@ -180,9 +180,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
}
assertFalse( Hibernate.isInitialized( node.getParent() ) );
assertNull( s.get( Node.class, "xyz" ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
assertFalse( s.isDefaultReadOnly() );
emp = ( Employer ) s.get( "org.hibernate.test.nonflushedchanges.Employer", emp.getId() );
@ -201,25 +201,25 @@ public class GetLoadTest extends AbstractOperationTestCase {
node = ( Node ) getOldToNewEntityRefMap().get( node );
assertTrue( Hibernate.isInitialized( node ) );
assertTrue( s.isReadOnly( node ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertFetchCount( 0 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.createQuery( "delete from Employer" ).executeUpdate();
List list = s.createQuery( "from Node" ).list();
for ( Object aList : list ) {
s.delete( aList );
}
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
public void testLoadReadOnly() throws Exception {
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Employer emp = new Employer();
s.persist( emp );
@ -227,9 +227,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
Node parent = new Node( "bar" );
parent.addChild( node );
s.persist( parent );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
assertFalse( s.isDefaultReadOnly() );
s.setDefaultReadOnly( true );
@ -242,34 +242,34 @@ public class GetLoadTest extends AbstractOperationTestCase {
emp = ( Employer ) getOldToNewEntityRefMap().get( emp );
assertFalse( Hibernate.isInitialized( emp ) );
assertTrue( s.isReadOnly( emp ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.createQuery( "delete from Employer" ).executeUpdate();
List list = s.createQuery( "from Node" ).list();
for ( Object aList : list ) {
s.delete( aList );
}
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
public void testGetAfterDelete() throws Exception {
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Employer emp = new Employer();
s.persist( emp );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.delete( emp );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
emp = ( Employer ) s.get( Employee.class, emp.getId() );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertNull( "get did not return null after delete", emp );
}

View File

@ -12,7 +12,7 @@ import org.hibernate.NonUniqueObjectException;
import org.hibernate.Session;
import org.hibernate.StaleObjectStateException;
import org.hibernate.criterion.Projections;
import org.hibernate.testing.jta.TestingJtaBootstrap;
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -34,34 +34,34 @@ public class MergeTest extends AbstractOperationTestCase {
public void testMergeStaleVersionFails() throws Exception {
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
VersionedEntity entity = new VersionedEntity( "entity", "entity" );
s.persist( entity );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
// make the detached 'entity' reference stale...
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
VersionedEntity entity2 = ( VersionedEntity ) s.get( VersionedEntity.class, entity.getId() );
entity2.setName( "entity-name" );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
// now try to reattach it
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
try {
s.merge( entity );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
entity = ( VersionedEntity ) getOldToNewEntityRefMap().get( entity );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
fail( "was expecting staleness error" );
}
catch ( StaleObjectStateException expected ) {
// expected outcome...
}
finally {
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().rollback();
}
}
@ -69,84 +69,84 @@ public class MergeTest extends AbstractOperationTestCase {
@SuppressWarnings( {"UnusedAssignment"})
public void testMergeBidiPrimayKeyOneToOne() throws Exception {
rebuildSessionFactory();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Person p = new Person( "steve" );
new PersonalDetails( "I have big feet", p );
s.persist( p );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
clearCounts();
p.getDetails().setSomePersonalDetail( p.getDetails().getSomePersonalDetail() + " and big hands too" );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
p = ( Person ) s.merge( p );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
p = ( Person ) getOldToNewEntityRefMap().get( p );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 0 );
assertUpdateCount( 1 );
assertDeleteCount( 0 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.delete( p );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
@SuppressWarnings( {"UnusedAssignment"})
public void testMergeBidiForeignKeyOneToOne() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Person p = new Person( "steve" );
Address a = new Address( "123 Main", "Austin", "US", p );
s.persist( a );
s.persist( p );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
clearCounts();
p.getAddress().setStreetAddress( "321 Main" );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
p = ( Person ) s.merge( p );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 0 );
assertUpdateCount( 0 ); // no cascade
assertDeleteCount( 0 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.delete( a );
s.delete( p );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
@SuppressWarnings( {"UnusedAssignment"})
public void testNoExtraUpdatesOnMerge() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Node node = new Node( "test" );
s.persist( node );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
clearCounts();
// node is now detached, but we have made no changes. so attempt to merge it
// into this new session; this should cause no updates...
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
node = ( Node ) s.merge( node );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertUpdateCount( 0 );
assertInsertCount( 0 );
@ -155,11 +155,11 @@ public class MergeTest extends AbstractOperationTestCase {
// as a control measure, now update the node while it is detached and
// make sure we get an update as a result...
node.setDescription( "new description" );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
node = ( Node ) s.merge( node );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertUpdateCount( 1 );
assertInsertCount( 0 );
///////////////////////////////////////////////////////////////////////
@ -170,24 +170,24 @@ public class MergeTest extends AbstractOperationTestCase {
@Test
@SuppressWarnings( {"unchecked", "UnusedAssignment"})
public void testNoExtraUpdatesOnMergeWithCollection() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Node parent = new Node( "parent" );
Node child = new Node( "child" );
parent.getChildren().add( child );
child.setParent( parent );
s.persist( parent );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
clearCounts();
// parent is now detached, but we have made no changes. so attempt to merge it
// into this new session; this should cause no updates...
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
parent = ( Node ) s.merge( parent );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertUpdateCount( 0 );
assertInsertCount( 0 );
@ -197,11 +197,11 @@ public class MergeTest extends AbstractOperationTestCase {
// make sure we get an update as a result...
( ( Node ) parent.getChildren().iterator().next() ).setDescription( "child's new description" );
parent.addChild( new Node( "second child" ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
parent = ( Node ) s.merge( parent );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertUpdateCount( 1 );
assertInsertCount( 1 );
///////////////////////////////////////////////////////////////////////
@ -212,22 +212,22 @@ public class MergeTest extends AbstractOperationTestCase {
@Test
@SuppressWarnings( {"UnusedAssignment"})
public void testNoExtraUpdatesOnMergeVersioned() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
VersionedEntity entity = new VersionedEntity( "entity", "entity" );
s.persist( entity );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
clearCounts();
// entity is now detached, but we have made no changes. so attempt to merge it
// into this new session; this should cause no updates...
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
VersionedEntity mergedEntity = ( VersionedEntity ) s.merge( entity );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
mergedEntity = ( VersionedEntity ) getOldToNewEntityRefMap().get( mergedEntity );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertUpdateCount( 0 );
assertInsertCount( 0 );
@ -238,11 +238,11 @@ public class MergeTest extends AbstractOperationTestCase {
// as a control measure, now update the node while it is detached and
// make sure we get an update as a result...
entity.setName( "new name" );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
entity = ( VersionedEntity ) s.merge( entity );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertUpdateCount( 1 );
assertInsertCount( 0 );
///////////////////////////////////////////////////////////////////////
@ -253,25 +253,25 @@ public class MergeTest extends AbstractOperationTestCase {
@Test
@SuppressWarnings( {"unchecked", "UnusedAssignment"})
public void testNoExtraUpdatesOnMergeVersionedWithCollection() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
VersionedEntity parent = new VersionedEntity( "parent", "parent" );
VersionedEntity child = new VersionedEntity( "child", "child" );
parent.getChildren().add( child );
child.setParent( parent );
s.persist( parent );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
clearCounts();
// parent is now detached, but we have made no changes. so attempt to merge it
// into this new session; this should cause no updates...
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
VersionedEntity mergedParent = ( VersionedEntity ) s.merge( parent );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
mergedParent = ( VersionedEntity ) getOldToNewEntityRefMap().get( mergedParent );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertUpdateCount( 0 );
assertInsertCount( 0 );
@ -284,12 +284,12 @@ public class MergeTest extends AbstractOperationTestCase {
// make sure we get an update as a result...
mergedParent.setName( "new name" );
mergedParent.getChildren().add( new VersionedEntity( "child2", "new child" ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
parent = ( VersionedEntity ) s.merge( mergedParent );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
parent = ( VersionedEntity ) getOldToNewEntityRefMap().get( parent );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertUpdateCount( 1 );
assertInsertCount( 1 );
///////////////////////////////////////////////////////////////////////
@ -300,20 +300,20 @@ public class MergeTest extends AbstractOperationTestCase {
@Test
@SuppressWarnings( {"unchecked", "UnusedAssignment"})
public void testNoExtraUpdatesOnPersistentMergeVersionedWithCollection() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
VersionedEntity parent = new VersionedEntity( "parent", "parent" );
VersionedEntity child = new VersionedEntity( "child", "child" );
parent.getChildren().add( child );
child.setParent( parent );
s.persist( parent );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
clearCounts();
// parent is now detached, but we have made no changes. so attempt to merge it
// into this new session; this should cause no updates...
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
// load parent so that merge will follow entityIsPersistent path
VersionedEntity persistentParent = ( VersionedEntity ) s.get( VersionedEntity.class, parent.getId() );
@ -326,7 +326,7 @@ public class MergeTest extends AbstractOperationTestCase {
VersionedEntity mergedParent = ( VersionedEntity ) s.merge( persistentParent ); // <-- This merge leads to failure
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
mergedParent = ( VersionedEntity ) getOldToNewEntityRefMap().get( mergedParent );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertUpdateCount( 0 );
assertInsertCount( 0 );
@ -337,7 +337,7 @@ public class MergeTest extends AbstractOperationTestCase {
///////////////////////////////////////////////////////////////////////
// as a control measure, now update the node once it is loaded and
// make sure we get an update as a result...
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
persistentParent = ( VersionedEntity ) s.get( VersionedEntity.class, parent.getId() );
persistentParent.setName( "new name" );
@ -346,7 +346,7 @@ public class MergeTest extends AbstractOperationTestCase {
persistentParent = ( VersionedEntity ) getOldToNewEntityRefMap().get( persistentParent );
persistentParent = ( VersionedEntity ) s.merge( persistentParent );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertUpdateCount( 1 );
assertInsertCount( 1 );
///////////////////////////////////////////////////////////////////////
@ -356,7 +356,7 @@ public class MergeTest extends AbstractOperationTestCase {
@Test
public void testPersistThenMergeInSameTxnWithVersion() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
VersionedEntity entity = new VersionedEntity( "test", "test" );
s.persist( entity );
@ -373,14 +373,14 @@ public class MergeTest extends AbstractOperationTestCase {
// expected behavior
}
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
public void testPersistThenMergeInSameTxnWithTimestamp() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
TimestampedEntity entity = new TimestampedEntity( "test", "test" );
s.persist( entity );
@ -397,7 +397,7 @@ public class MergeTest extends AbstractOperationTestCase {
// expected behavior
}
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@ -408,7 +408,7 @@ public class MergeTest extends AbstractOperationTestCase {
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Node root = new Node( "root" );
Node child = new Node( "child" );
@ -417,7 +417,7 @@ public class MergeTest extends AbstractOperationTestCase {
child.addChild( grandchild );
s.merge( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 3 );
assertUpdateCount( 0 );
@ -427,11 +427,11 @@ public class MergeTest extends AbstractOperationTestCase {
Node grandchild2 = new Node( "grandchild2" );
child.addChild( grandchild2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.merge( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 1 );
assertUpdateCount( 1 );
@ -442,17 +442,17 @@ public class MergeTest extends AbstractOperationTestCase {
child2.addChild( grandchild3 );
root.addChild( child2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.merge( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 2 );
assertUpdateCount( 0 );
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.delete( grandchild );
s.delete( grandchild2 );
@ -460,7 +460,7 @@ public class MergeTest extends AbstractOperationTestCase {
s.delete( child );
s.delete( child2 );
s.delete( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@ -469,7 +469,7 @@ public class MergeTest extends AbstractOperationTestCase {
public void testMergeDeepTreeWithGeneratedId() throws Exception {
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
NumberedNode root = new NumberedNode( "root" );
NumberedNode child = new NumberedNode( "child" );
@ -479,7 +479,7 @@ public class MergeTest extends AbstractOperationTestCase {
root = ( NumberedNode ) s.merge( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 3 );
assertUpdateCount( 0 );
@ -491,12 +491,12 @@ public class MergeTest extends AbstractOperationTestCase {
NumberedNode grandchild2 = new NumberedNode( "grandchild2" );
child.addChild( grandchild2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
root = ( NumberedNode ) s.merge( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 1 );
assertUpdateCount( 1 );
@ -509,23 +509,23 @@ public class MergeTest extends AbstractOperationTestCase {
child2.addChild( grandchild3 );
root.addChild( child2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
root = ( NumberedNode ) s.merge( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 2 );
assertUpdateCount( 0 );
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.createQuery( "delete from NumberedNode where name like 'grand%'" ).executeUpdate();
s.createQuery( "delete from NumberedNode where name like 'child%'" ).executeUpdate();
s.createQuery( "delete from NumberedNode" ).executeUpdate();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@ -534,7 +534,7 @@ public class MergeTest extends AbstractOperationTestCase {
public void testMergeTree() throws Exception {
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Node root = new Node( "root" );
Node child = new Node( "child" );
@ -543,7 +543,7 @@ public class MergeTest extends AbstractOperationTestCase {
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( Node ) getOldToNewEntityRefMap().get( root );
child = ( Node ) root.getChildren().iterator().next();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 2 );
clearCounts();
@ -555,10 +555,10 @@ public class MergeTest extends AbstractOperationTestCase {
root.addChild( secondChild );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.merge( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 1 );
assertUpdateCount( 2 );
@ -571,7 +571,7 @@ public class MergeTest extends AbstractOperationTestCase {
public void testMergeTreeWithGeneratedId() throws Exception {
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
NumberedNode root = new NumberedNode( "root" );
NumberedNode child = new NumberedNode( "child" );
@ -580,7 +580,7 @@ public class MergeTest extends AbstractOperationTestCase {
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
child = ( NumberedNode ) root.getChildren().iterator().next();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 2 );
clearCounts();
@ -592,10 +592,10 @@ public class MergeTest extends AbstractOperationTestCase {
root.addChild( secondChild );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.merge( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 1 );
assertUpdateCount( 2 );
@ -607,17 +607,17 @@ public class MergeTest extends AbstractOperationTestCase {
@SuppressWarnings( {"UnusedAssignment", "UnnecessaryBoxing"})
public void testMergeManaged() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
NumberedNode root = new NumberedNode( "root" );
s.persist( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
NumberedNode child = new NumberedNode( "child" );
root = ( NumberedNode ) s.merge( root );
@ -635,7 +635,7 @@ public class MergeTest extends AbstractOperationTestCase {
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
mergedChild = root.getChildren().iterator().next();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 1 );
assertUpdateCount( 0 );
@ -643,7 +643,7 @@ public class MergeTest extends AbstractOperationTestCase {
assertEquals( root.getChildren().size(), 1 );
assertTrue( root.getChildren().contains( mergedChild ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
assertEquals(
Long.valueOf( 2 ),
@ -652,7 +652,7 @@ public class MergeTest extends AbstractOperationTestCase {
.uniqueResult()
);
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@ -661,19 +661,19 @@ public class MergeTest extends AbstractOperationTestCase {
@SuppressWarnings( {"UnnecessaryBoxing"})
public void testMergeManagedUninitializedCollection() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
NumberedNode root = new NumberedNode( "root" );
root.addChild( new NumberedNode( "child" ) );
s.persist( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
clearCounts();
NumberedNode newRoot = new NumberedNode( "root" );
newRoot.setId( root.getId() );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
root = ( NumberedNode ) s.get( NumberedNode.class, root.getId() );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
@ -687,13 +687,13 @@ public class MergeTest extends AbstractOperationTestCase {
assertSame( root, s.merge( newRoot ) );
assertSame( managedChildren, root.getChildren() );
assertFalse( Hibernate.isInitialized( managedChildren ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 0 );
assertUpdateCount( 0 );
assertDeleteCount( 0 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
assertEquals(
Long.valueOf( 2 ),
@ -701,7 +701,7 @@ public class MergeTest extends AbstractOperationTestCase {
.setProjection( Projections.rowCount() )
.uniqueResult()
);
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@ -710,19 +710,19 @@ public class MergeTest extends AbstractOperationTestCase {
@SuppressWarnings( {"UnnecessaryBoxing"})
public void testMergeManagedInitializedCollection() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
NumberedNode root = new NumberedNode( "root" );
root.addChild( new NumberedNode( "child" ) );
s.persist( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
clearCounts();
NumberedNode newRoot = new NumberedNode( "root" );
newRoot.setId( root.getId() );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
root = ( NumberedNode ) s.get( NumberedNode.class, root.getId() );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
@ -737,13 +737,13 @@ public class MergeTest extends AbstractOperationTestCase {
assertSame( root, s.merge( newRoot ) );
assertSame( managedChildren, root.getChildren() );
assertTrue( Hibernate.isInitialized( managedChildren ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 0 );
assertUpdateCount( 0 );
assertDeleteCount( 0 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
assertEquals(
Long.valueOf( 2 ),
@ -751,7 +751,7 @@ public class MergeTest extends AbstractOperationTestCase {
.setProjection( Projections.rowCount() )
.uniqueResult()
);
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@ -760,7 +760,7 @@ public class MergeTest extends AbstractOperationTestCase {
@SuppressWarnings( {"unchecked"})
public void testRecursiveMergeTransient() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Employer jboss = new Employer();
Employee gavin = new Employee();
@ -775,7 +775,7 @@ public class MergeTest extends AbstractOperationTestCase {
assertEquals( 1, jboss.getEmployees().size() );
s.clear();
s.merge( jboss.getEmployees().iterator().next() );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@ -783,25 +783,25 @@ public class MergeTest extends AbstractOperationTestCase {
@Test
@SuppressWarnings( {"UnnecessaryBoxing", "UnusedAssignment"})
public void testDeleteAndMerge() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Employer jboss = new Employer();
s.persist( jboss );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
Employer otherJboss;
otherJboss = ( Employer ) s.get( Employer.class, jboss.getId() );
s.delete( otherJboss );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
jboss.setVers( Integer.valueOf( 1 ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.merge( jboss );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@ -810,18 +810,18 @@ public class MergeTest extends AbstractOperationTestCase {
@SuppressWarnings( {"unchecked", "UnusedAssignment"})
public void testMergeManyToManyWithCollectionDeference() throws Exception {
// setup base data...
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Competition competition = new Competition();
competition.getCompetitors().add( new Competitor( "Name" ) );
competition.getCompetitors().add( new Competitor() );
competition.getCompetitors().add( new Competitor() );
s.persist( competition );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
// the competition graph is now detached:
// 1) create a new List reference to represent the competitors
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
List newComp = new ArrayList();
Competitor originalCompetitor = ( Competitor ) competition.getCompetitors().get( 0 );
@ -835,7 +835,7 @@ public class MergeTest extends AbstractOperationTestCase {
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
Competition competition2copy = ( Competition ) getOldToNewEntityRefMap().get( competition2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertFalse( competition == competition2 );
assertFalse( competition2 == competition2copy );
@ -843,18 +843,18 @@ public class MergeTest extends AbstractOperationTestCase {
assertEquals( 2, competition2.getCompetitors().size() );
assertEquals( 2, competition2copy.getCompetitors().size() );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
competition = ( Competition ) s.get( Competition.class, competition.getId() );
assertEquals( 2, competition.getCompetitors().size() );
s.delete( competition );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@SuppressWarnings( {"unchecked"})
protected void cleanupTestData() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
s.createQuery( "delete from NumberedNode where parent is not null" ).executeUpdate();
s.createQuery( "delete from NumberedNode" ).executeUpdate();
@ -873,7 +873,7 @@ public class MergeTest extends AbstractOperationTestCase {
s.delete( employer );
}
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Override

View File

@ -33,7 +33,7 @@ import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Projections;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.testing.jta.TestingJtaBootstrap;
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -63,7 +63,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
public void testSaveOrUpdateDeepTree() throws Exception {
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Node root = new Node( "root" );
Node child = new Node( "child" );
@ -75,7 +75,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
root = ( Node ) getOldToNewEntityRefMap().get( root );
child = ( Node ) getOldToNewEntityRefMap().get( child );
grandchild = ( Node ) getOldToNewEntityRefMap().get( grandchild );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 3 );
assertUpdateCount( 0 );
@ -85,12 +85,12 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
Node grandchild2 = new Node( "grandchild2" );
child.addChild( grandchild2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.saveOrUpdate( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( Node ) getOldToNewEntityRefMap().get( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 1 );
assertUpdateCount( 1 );
@ -101,17 +101,17 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
child2.addChild( grandchild3 );
root.addChild( child2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.saveOrUpdate( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 2 );
assertUpdateCount( 0 );
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.delete( grandchild );
s.delete( grandchild2 );
@ -119,7 +119,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
s.delete( child );
s.delete( child2 );
s.delete( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
@ -128,7 +128,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
boolean instrumented = FieldInterceptionHelper.isInstrumented( new NumberedNode() );
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
NumberedNode root = new NumberedNode( "root" );
NumberedNode child = new NumberedNode( "child" );
@ -140,7 +140,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
child = ( NumberedNode ) getOldToNewEntityRefMap().get( child );
grandchild = ( NumberedNode ) getOldToNewEntityRefMap().get( grandchild );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 3 );
assertUpdateCount( 0 );
@ -152,12 +152,12 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
NumberedNode grandchild2 = new NumberedNode( "grandchild2" );
child.addChild( grandchild2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.saveOrUpdate( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 1 );
assertUpdateCount( instrumented ? 1 : 3 );
@ -168,22 +168,22 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
child2.addChild( grandchild3 );
root.addChild( child2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.saveOrUpdate( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 2 );
assertUpdateCount( instrumented ? 0 : 4 );
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.createQuery( "delete from NumberedNode where name like 'grand%'" ).executeUpdate();
s.createQuery( "delete from NumberedNode where name like 'child%'" ).executeUpdate();
s.createQuery( "delete from NumberedNode" ).executeUpdate();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
@ -191,7 +191,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
public void testSaveOrUpdateTree() throws Exception {
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Node root = new Node( "root" );
Node child = new Node( "child" );
@ -200,7 +200,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( Node ) getOldToNewEntityRefMap().get( root );
child = ( Node ) getOldToNewEntityRefMap().get( child );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 2 );
clearCounts();
@ -212,20 +212,20 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
root.addChild( secondChild );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.saveOrUpdate( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 1 );
assertUpdateCount( 2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.createQuery( "delete from Node where parent is not null" ).executeUpdate();
s.createQuery( "delete from Node" ).executeUpdate();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
@ -233,7 +233,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
public void testSaveOrUpdateTreeWithGeneratedId() throws Exception {
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
NumberedNode root = new NumberedNode( "root" );
NumberedNode child = new NumberedNode( "child" );
@ -242,7 +242,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
child = ( NumberedNode ) getOldToNewEntityRefMap().get( child );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 2 );
clearCounts();
@ -254,34 +254,34 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
root.addChild( secondChild );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.saveOrUpdate( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 1 );
assertUpdateCount( 2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.createQuery( "delete from NumberedNode where parent is not null" ).executeUpdate();
s.createQuery( "delete from NumberedNode" ).executeUpdate();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
@SuppressWarnings( {"UnusedAssignment", "UnnecessaryBoxing"})
public void testSaveOrUpdateManaged() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
NumberedNode root = new NumberedNode( "root" );
s.saveOrUpdate( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
root = ( NumberedNode ) s.get( NumberedNode.class, root.getId() );
NumberedNode child = new NumberedNode( "child" );
@ -299,12 +299,12 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
child = ( NumberedNode ) getOldToNewEntityRefMap().get( child );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertTrue( root.getChildren().contains( child ) );
assertEquals( root.getChildren().size(), 1 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
assertEquals(
Long.valueOf( 2 ),
@ -314,7 +314,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
);
s.delete( root );
s.delete( child );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
@ -324,29 +324,29 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
NumberedNode root = new NumberedNode( "root" );
s.saveOrUpdate( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 1 );
assertUpdateCount( 0 );
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.saveOrUpdate( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 0 );
assertUpdateCount( instrumented ? 0 : 1 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
root = ( NumberedNode ) s.get( NumberedNode.class, Long.valueOf( root.getId() ) );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
@ -354,11 +354,11 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
Hibernate.initialize( root.getChildren() );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
NumberedNode child = new NumberedNode( "child" );
root.addChild( child );
@ -368,12 +368,12 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
assertTrue( Hibernate.isInitialized( root.getChildren() ) );
child = ( NumberedNode ) root.getChildren().iterator().next();
assertTrue( s.contains( child ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 1 );
assertUpdateCount( instrumented ? 0 : 1 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
assertEquals(
s.createCriteria( NumberedNode.class )
@ -383,7 +383,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
);
s.delete( root );
s.delete( child );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
@ -391,29 +391,29 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
public void testSaveOrUpdateGotWithMutableProp() throws Exception {
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Node root = new Node( "root" );
s.saveOrUpdate( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( Node ) getOldToNewEntityRefMap().get( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 1 );
assertUpdateCount( 0 );
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.saveOrUpdate( root );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( Node ) getOldToNewEntityRefMap().get( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 0 );
assertUpdateCount( 0 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
root = ( Node ) s.get( Node.class, "root" );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
@ -421,11 +421,11 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
Hibernate.initialize( root.getChildren() );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( Node ) getOldToNewEntityRefMap().get( root );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
clearCounts();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
Node child = new Node( "child" );
root.addChild( child );
@ -437,12 +437,12 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
root = ( Node ) getOldToNewEntityRefMap().get( root );
child = ( Node ) getOldToNewEntityRefMap().get( child );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertInsertCount( 1 );
//assertUpdateCount( 1 ); //note: will fail here if no second-level cache
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
assertEquals(
Long.valueOf( 2 ),
@ -452,13 +452,13 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
);
s.delete( root );
s.delete( child );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
@SuppressWarnings( {"UnusedAssignment"})
public void testEvictThenSaveOrUpdate() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Node parent = new Node( "1:parent" );
Node child = new Node( "2:child" );
@ -467,9 +467,9 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
child.addChild( grandchild );
s.saveOrUpdate( parent );
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s1 = openSession();
child = ( Node ) s1.load( Node.class, "2:child" );
s1 = applyNonFlushedChangesToNewSessionCloseOldSession( s1 );
@ -492,9 +492,9 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
assertFalse( s1.contains( child ) );
assertTrue( s1.contains( child.getParent() ) );
javax.transaction.Transaction tx1 = TestingJtaBootstrap.INSTANCE.getTransactionManager().suspend();
javax.transaction.Transaction tx1 = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s2 = openSession();
try {
s2.getTransaction().begin();
@ -505,13 +505,13 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
// expected because parent is connected to s1
}
finally {
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().rollback();
}
s1.evict( child.getParent() );
assertFalse( s1.contains( child.getParent() ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s2 = openSession();
s2.saveOrUpdate( child );
s2 = applyNonFlushedChangesToNewSessionCloseOldSession( s2 );
@ -530,18 +530,18 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
assertTrue( Hibernate.isInitialized( child.getParent() ) );
s1 = applyNonFlushedChangesToNewSessionCloseOldSession( s1 );
s2 = applyNonFlushedChangesToNewSessionCloseOldSession( s2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx1 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx1 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
// tx1.commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.delete( s.get( Node.class, "3:grandchild" ) );
s.delete( s.get( Node.class, "2:child" ) );
s.delete( s.get( Node.class, "1:parent" ) );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
}

View File

@ -42,6 +42,7 @@ import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.jta.TestingJtaBootstrap;
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertEquals;
@ -86,7 +87,7 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
assertNotNull( sessionFactory().getEntityPersister( "Item" ).getCacheAccessStrategy() );
assertEquals( 0, sessionFactory().getStatistics().getEntityLoadCount() );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Map foo = new HashMap();
foo.put( "name", "Foo" );
@ -96,49 +97,49 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
bar.put( "name", "Bar" );
bar.put( "description", "a small bar" );
s.persist( "Item", bar );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertEquals(0, sessionFactory().getStatistics().getUpdateTimestampsCacheHitCount());
assertEquals(3, sessionFactory().getStatistics().getUpdateTimestampsCachePutCount()); // Twice preinvalidate & one invalidate
assertEquals(0, sessionFactory().getStatistics().getUpdateTimestampsCacheMissCount());
sessionFactory().getCache().evictEntityRegion( "Item" );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s1 = openSession();
foo = ( Map ) s1.get( "Item", "Foo" );
//foo.put("description", "a big red foo");
//s1.flush();
Transaction tx = TestingJtaBootstrap.INSTANCE.getTransactionManager().suspend();
Transaction tx = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s2 = openSession();
foo = ( Map ) s2.get( "Item", "Foo" );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
sessionFactory().getCache().evictEntityRegion( "Item" );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s1 = openSession();
s1.createCriteria( "Item" ).list();
//foo.put("description", "a big red foo");
//s1.flush();
tx = TestingJtaBootstrap.INSTANCE.getTransactionManager().suspend();
tx = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s2 = openSession();
s2.createCriteria( "Item" ).list();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s2 = openSession();
s2.createCriteria( "Item" ).list();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertEquals( 7, sessionFactory().getStatistics().getEntityLoadCount() );
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
@ -148,17 +149,17 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
assertEquals( 0, sessionFactory().getStatistics().getUpdateTimestampsCacheHitCount() );
assertEquals( 3, sessionFactory().getStatistics().getUpdateTimestampsCachePutCount() );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.createQuery( "delete from Item" ).executeUpdate();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
public void testConcurrentCachedQueries() throws Exception {
sessionFactory().getStatistics().clear();
cleanupCache();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Map foo = new HashMap();
foo.put( "name", "Foo" );
@ -168,7 +169,7 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
bar.put( "name", "Bar" );
bar.put( "description", "a small bar" );
s.persist( "Item", bar );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
synchronized ( this ) {
wait( 1000 );
@ -178,23 +179,23 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
sessionFactory().getCache().evictEntityRegion( "Item" );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s4 = openSession();
Transaction tx4 = TestingJtaBootstrap.INSTANCE.getTransactionManager().suspend();
Transaction tx4 = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s1 = openSession();
List r1 = s1.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
assertEquals( r1.size(), 2 );
Transaction tx1 = TestingJtaBootstrap.INSTANCE.getTransactionManager().suspend();
Transaction tx1 = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s2 = openSession();
List r2 = s2.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
assertEquals( r2.size(), 2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 2 );
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
@ -207,14 +208,14 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
assertEquals( sessionFactory().getStatistics().getUpdateTimestampsCacheHitCount(), 1 );
assertEquals( sessionFactory().getStatistics().getUpdateTimestampsCachePutCount(), 0 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx1 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx1 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s3 = openSession();
s3.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 4 );
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
@ -228,11 +229,11 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
assertEquals( sessionFactory().getStatistics().getUpdateTimestampsCachePutCount(), 0 );
assertEquals( sessionFactory().getStatistics().getUpdateTimestampsCacheMissCount(), 0 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx4 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx4 );
List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
assertEquals( r4.size(), 2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 6 );
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
@ -246,10 +247,10 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
assertEquals( sessionFactory().getStatistics().getUpdateTimestampsCachePutCount(), 0 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.createQuery( "delete from Item" ).executeUpdate();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
@ -258,7 +259,7 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
comment = "write locks block readers"
)
public void testConcurrentCachedDirtyQueries() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Map foo = new HashMap();
foo.put( "name", "Foo" );
@ -268,7 +269,7 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
bar.put( "name", "Bar" );
bar.put( "description", "a small bar" );
s.persist( "Item", bar );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
synchronized ( this ) {
wait( 1000 );
@ -278,12 +279,12 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
cleanupCache(); // we need a clean 2L cache here.
// open a TX and suspend it
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s4 = openSession();
Transaction tx4 = TestingJtaBootstrap.INSTANCE.getTransactionManager().suspend();
Transaction tx4 = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
// open a new TX and execute a query, this would fill the query cache.
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s1 = openSession();
List r1 = s1.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
@ -292,17 +293,17 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
// update data and make query cache stale, but TX is suspended
foo.put( "description", "a big red foo" );
s1.flush();
Transaction tx1 = TestingJtaBootstrap.INSTANCE.getTransactionManager().suspend();
Transaction tx1 = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
// open a new TX and run query again
// this TX is committed after query
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s2 = openSession();
List r2 = s2.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
assertEquals( r2.size(), 2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertEquals( 0, sessionFactory().getStatistics().getSecondLevelCacheHitCount() );
assertEquals( 0, sessionFactory().getStatistics().getSecondLevelCacheMissCount() );
@ -324,19 +325,19 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
// since there is only 1 update action
assertEquals( 1, sessionFactory().getStatistics().getUpdateTimestampsCacheHitCount() );
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx1 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx1 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
// update action's TX committed, so, invalidate is called, put new timestamp into UpdateTimestampsCache
assertEquals( 2, sessionFactory().getStatistics().getUpdateTimestampsCachePutCount() );
// but no more query cache lookup here, so it should still 1
assertEquals( 1, sessionFactory().getStatistics().getUpdateTimestampsCacheHitCount() );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s3 = openSession();
s3.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertEquals( 0, sessionFactory().getStatistics().getSecondLevelCacheHitCount() );
assertEquals( 0, sessionFactory().getStatistics().getSecondLevelCacheMissCount() );
@ -349,11 +350,11 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
// a new query cache hit and one more update timestamps cache hit, so should be 2
assertEquals( 2, sessionFactory().getStatistics().getUpdateTimestampsCacheHitCount() );
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx4 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx4 );
List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
assertEquals( r4.size(), 2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertEquals( 2, sessionFactory().getStatistics().getSecondLevelCacheHitCount() );
assertEquals( 0, sessionFactory().getStatistics().getSecondLevelCacheMissCount() );
@ -365,46 +366,46 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
assertEquals( 3, sessionFactory().getStatistics().getQueryCacheMissCount() );
assertEquals( 3, sessionFactory().getStatistics().getUpdateTimestampsCacheHitCount() );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.createQuery( "delete from Item" ).executeUpdate();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
public void testCMT() throws Exception {
sessionFactory().getStatistics().clear();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertFalse( s.isOpen() );
assertEquals( sessionFactory().getStatistics().getFlushCount(), 0 );
assertEquals( sessionFactory().getStatistics().getEntityInsertCount(), 0 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().rollback();
assertFalse( s.isOpen() );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
Map item = new HashMap();
item.put( "name", "The Item" );
item.put( "description", "The only item we have" );
s.persist( "Item", item );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertFalse( s.isOpen() );
assertEquals( sessionFactory().getStatistics().getFlushCount(), 1 );
assertEquals( sessionFactory().getStatistics().getEntityInsertCount(), 1 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
item = ( Map ) s.createQuery( "from Item" ).uniqueResult();
assertNotNull( item );
s.delete( item );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertFalse( s.isOpen() );
assertEquals( sessionFactory().getStatistics().getTransactionCount(), 4 );
@ -416,19 +417,19 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 1 );
assertEquals( sessionFactory().getStatistics().getFlushCount(), 2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.createQuery( "delete from Item" ).executeUpdate();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
public void testCurrentSession() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = sessionFactory().getCurrentSession();
Session s2 = sessionFactory().getCurrentSession();
assertSame( s, s2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertFalse( s.isOpen() );
// TODO : would be nice to automate-test that the SF internal map actually gets cleaned up
@ -437,7 +438,7 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
@Test
public void testCurrentSessionWithIterate() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Map item1 = new HashMap();
item1.put( "name", "Item - 1" );
@ -448,11 +449,11 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
item2.put( "name", "Item - 2" );
item2.put( "description", "The second item" );
s.persist( "Item", item2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
// First, test iterating the partial iterator; iterate to past
// the first, but not the second, item
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = sessionFactory().getCurrentSession();
Iterator itr = s.createQuery( "from Item" ).iterate();
if ( !itr.hasNext() ) {
@ -462,10 +463,10 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
if ( !itr.hasNext() ) {
fail( "Only one result in iterator" );
}
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
// Next, iterate the entire result
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = sessionFactory().getCurrentSession();
itr = s.createQuery( "from Item" ).iterate();
if ( !itr.hasNext() ) {
@ -474,17 +475,17 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
while ( itr.hasNext() ) {
itr.next();
}
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = openSession();
s.createQuery( "delete from Item" ).executeUpdate();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
@Test
public void testCurrentSessionWithScroll() throws Exception {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = sessionFactory().getCurrentSession();
Map item1 = new HashMap();
item1.put( "name", "Item - 1" );
@ -495,46 +496,46 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
item2.put( "name", "Item - 2" );
item2.put( "description", "The second item" );
s.persist( "Item", item2 );
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
// First, test partially scrolling the result with out closing
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = sessionFactory().getCurrentSession();
ScrollableResults results = s.createQuery( "from Item" ).scroll();
results.next();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
// Next, test partially scrolling the result with closing
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = sessionFactory().getCurrentSession();
results = s.createQuery( "from Item" ).scroll();
results.next();
results.close();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
// Next, scroll the entire result (w/o closing)
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = sessionFactory().getCurrentSession();
results = s.createQuery( "from Item" ).scroll();
while ( results.next() ) {
// do nothing
}
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
// Next, scroll the entire result (closing)
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = sessionFactory().getCurrentSession();
results = s.createQuery( "from Item" ).scroll();
while ( results.next() ) {
// do nothing
}
results.close();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
s = sessionFactory().getCurrentSession();
s.createQuery( "delete from Item" ).executeUpdate();
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
}

View File

@ -18,6 +18,7 @@ import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
import org.hibernate.internal.util.SerializationHelper;
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.testing.jta.TestingJtaBootstrap;
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@ -50,12 +51,12 @@ public class AggressiveReleaseTest extends ConnectionManagementTestCase {
@Override
protected void prepare() throws Throwable {
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
}
@Override
protected void done() throws Throwable {
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
// Some additional tests specifically for the aggressive-release functionality...

View File

@ -0,0 +1,269 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, 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.testing.jta;
import javax.sql.DataSource;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator;
import org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.service.spi.Configurable;
import org.hibernate.service.spi.Stoppable;
/**
* A {@link DataSource} implementation intended for testing Hibernate/JTA interaction. In that limited scope we
* only ever have one single resource (the database connection) so we do not at all care about full-blown XA
* semantics. This class behaves accordingly. This class also assumes usage of and access to JBossTS/Arjuna.
*
* @author Steve Ebersole
* @author Jonathan Halliday
*/
public class JtaAwareConnectionProviderImpl implements ConnectionProvider, Configurable, Stoppable {
private static final String CONNECTION_KEY = "_database_connection";
private DriverManagerConnectionProviderImpl delegate;
private List<Connection> nonEnlistedConnections = new ArrayList<Connection>();
@Override
public void configure(Map configurationValues) {
Properties connectionSettings = new Properties();
transferSetting( Environment.DRIVER, configurationValues, connectionSettings );
transferSetting( Environment.URL, configurationValues, connectionSettings );
transferSetting( Environment.USER, configurationValues, connectionSettings );
transferSetting( Environment.PASS, configurationValues, connectionSettings );
transferSetting( Environment.ISOLATION, configurationValues, connectionSettings );
Properties passThroughSettings = ConnectionProviderInitiator.getConnectionProperties( configurationValues );
if ( passThroughSettings != null ) {
for ( String setting : passThroughSettings.stringPropertyNames() ) {
transferSetting( Environment.CONNECTION_PREFIX + '.' + setting, configurationValues, connectionSettings );
}
}
delegate = new DriverManagerConnectionProviderImpl();
delegate.configure( connectionSettings );
}
@SuppressWarnings("unchecked")
private static void transferSetting(String settingName, Map source, Map target) {
Object value = source.get( settingName );
if ( value != null ) {
target.put( settingName, value );
}
}
@Override
public void stop() {
delegate.stop();
}
@Override
public Connection getConnection() throws SQLException {
Transaction currentTransaction = findCurrentTransaction();
try {
if ( currentTransaction == null ) {
// this block handles non enlisted connections ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Connection connection = delegate.getConnection();
nonEnlistedConnections.add( connection );
return connection;
}
// this portion handles enlisted connections ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Connection connection = (Connection) TestingJtaPlatformImpl.synchronizationRegistry().getResource(
CONNECTION_KEY
);
if ( connection == null ) {
connection = delegate.getConnection();
TestingJtaPlatformImpl.synchronizationRegistry().putResource( CONNECTION_KEY, connection );
XAResourceWrapper xaResourceWrapper = new XAResourceWrapper( this, connection );
currentTransaction.enlistResource( xaResourceWrapper );
}
return connection;
}
catch (SQLException e) {
throw e;
}
catch (Exception e) {
throw new SQLException(e);
}
}
@Override
public void closeConnection(Connection conn) throws SQLException {
if ( conn == null ) {
return;
}
if ( nonEnlistedConnections.contains( conn ) ) {
nonEnlistedConnections.remove( conn );
delegate.closeConnection( conn );
}
else {
// do nothing. part of the enlistment contract here is that the XAResource wrapper
// takes that responsibility.
}
}
@Override
public boolean supportsAggressiveRelease() {
return true;
}
protected Transaction findCurrentTransaction() {
try {
return TestingJtaPlatformImpl.transactionManager().getTransaction();
}
catch (SystemException e) {
throw new IllegalStateException( "Could not locate current transaction" );
}
}
@Override
public boolean isUnwrappableAs(Class unwrapType) {
return delegate.isUnwrappableAs( unwrapType );
}
@Override
public <T> T unwrap(Class<T> unwrapType) {
return delegate.unwrap( unwrapType );
}
private void delist(Connection connection) {
// todo : verify the incoming connection is the currently enlisted one?
TestingJtaPlatformImpl.synchronizationRegistry().putResource( CONNECTION_KEY, null );
try {
delegate.closeConnection( connection );
}
catch (SQLException e) {
System.err.println( "!!!Error trying to close JDBC connection from delist callbacks!!!" );
}
}
public static class XAResourceWrapper implements XAResource {
private final JtaAwareConnectionProviderImpl pool;
private final Connection connection;
private int transactionTimeout;
public XAResourceWrapper(JtaAwareConnectionProviderImpl pool, Connection connection) {
this.pool = pool;
this.connection = connection;
}
@Override
public int prepare(Xid xid) throws XAException {
throw new RuntimeException("this should never be called");
}
@Override
public void commit(Xid xid, boolean onePhase) throws XAException {
if (!onePhase) {
throw new IllegalArgumentException( "must be one phase" );
}
try {
connection.commit();
}
catch(SQLException e) {
throw new XAException( e.toString() );
}
finally {
try {
pool.delist( connection );
}
catch (Exception ignore) {
}
}
}
@Override
public void rollback(Xid xid) throws XAException {
try {
connection.rollback();
}
catch(SQLException e) {
throw new XAException( e.toString() );
}
finally {
try {
pool.delist( connection );
}
catch (Exception ignore) {
}
}
}
@Override
public void end(Xid xid, int i) throws XAException {
// noop
}
@Override
public void start(Xid xid, int i) throws XAException {
// noop
}
@Override
public void forget(Xid xid) throws XAException {
// noop
}
@Override
public int getTransactionTimeout() throws XAException {
return transactionTimeout;
}
@Override
public boolean setTransactionTimeout(int i) throws XAException {
transactionTimeout = i;
return true;
}
@Override
public boolean isSameRM(XAResource xaResource) throws XAException {
return xaResource != null && xaResource == this;
}
@Override
public Xid[] recover(int i) throws XAException {
return new Xid[0];
}
}
}

View File

@ -27,20 +27,10 @@ import javax.sql.DataSource;
import javax.transaction.Status;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Map;
import java.util.Properties;
import com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean;
import com.arjuna.ats.internal.arjuna.objectstore.VolatileStore;
import com.arjuna.common.internal.util.propertyservice.BeanPopulator;
import org.enhydra.jdbc.standard.StandardXADataSource;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl;
import org.hibernate.service.jta.platform.internal.AbstractJtaPlatform;
/**
* Manages the {@link TransactionManager}, {@link UserTransaction} and {@link DataSource} instances used for testing.
@ -50,60 +40,11 @@ import org.hibernate.service.jta.platform.internal.AbstractJtaPlatform;
public class TestingJtaBootstrap {
public static final TestingJtaBootstrap INSTANCE = new TestingJtaBootstrap();
private TransactionManager transactionManager;
private UserTransaction userTransaction;
private DataSource dataSource;
private TestingJtaBootstrap() {
BeanPopulator
.getDefaultInstance( ObjectStoreEnvironmentBean.class )
.setObjectStoreType( VolatileStore.class.getName() );
BeanPopulator
.getNamedInstance( ObjectStoreEnvironmentBean.class, "communicationStore" )
.setObjectStoreType( VolatileStore.class.getName() );
BeanPopulator
.getNamedInstance( ObjectStoreEnvironmentBean.class, "stateStore" )
.setObjectStoreType( VolatileStore.class.getName() );
this.transactionManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
this.userTransaction = com.arjuna.ats.jta.UserTransaction.userTransaction();
Properties environmentProperties = Environment.getProperties();
JtaAwareDataSource dataSource = new JtaAwareDataSource();
dataSource.setTransactionManager( transactionManager );
try {
dataSource.setDriverName( environmentProperties.getProperty( Environment.DRIVER ) );
}
catch (SQLException e) {
throw new RuntimeException( "Unable to set DataSource JDBC driver name", e );
}
dataSource.setUrl( environmentProperties.getProperty( Environment.URL ) );
dataSource.setUser( environmentProperties.getProperty( Environment.USER ) );
dataSource.setPassword( environmentProperties.getProperty( Environment.PASS ) );
environmentProperties.remove( Environment.USER );
environmentProperties.remove( Environment.PASS );
final String isolationString = environmentProperties.getProperty( Environment.ISOLATION );
if ( isolationString != null ) {
dataSource.setTransactionIsolation( Integer.valueOf( isolationString ) );
}
this.dataSource = dataSource;
}
public TransactionManager getTransactionManager() {
return transactionManager;
}
public DataSource getDataSource() {
return dataSource;
}
@SuppressWarnings("unchecked")
public static void prepare(Map configValues) {
configValues.put( AvailableSettings.JTA_PLATFORM, TestingJtaPlatformImpl.INSTANCE );
configValues.put( Environment.CONNECTION_PROVIDER, JtaAwareDataSourceConnectionProvider.class.getName() );
configValues.put( Environment.DATASOURCE, INSTANCE.getDataSource() );
configValues.put( Environment.CONNECTION_PROVIDER, JtaAwareConnectionProviderImpl.class.getName() );
configValues.put( "javax.persistence.transactionType", "JTA" );
}
@ -111,58 +52,11 @@ public class TestingJtaBootstrap {
* Used by envers...
*/
public static void tryCommit() throws Exception {
if ( INSTANCE.transactionManager.getStatus() == Status.STATUS_MARKED_ROLLBACK ) {
INSTANCE.transactionManager.rollback();
if ( TestingJtaPlatformImpl.transactionManager().getStatus() == Status.STATUS_MARKED_ROLLBACK ) {
TestingJtaPlatformImpl.transactionManager().rollback();
}
else {
INSTANCE.transactionManager.commit();
}
}
// ReTarDed
public static class JtaAwareDataSource extends StandardXADataSource {
@Override
public Connection getConnection() throws SQLException {
if ( getTransactionManager() == null ) {
setTransactionManager( TestingJtaBootstrap.INSTANCE.transactionManager );
}
final Connection connection = getXAConnection().getConnection();
connection.setAutoCommit( false );
return connection;
}
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
return null; // JDK6 stuff
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
return false; // JDK6 stuff
}
}
public static class TestingJtaPlatformImpl extends AbstractJtaPlatform {
public static final TestingJtaPlatformImpl INSTANCE = new TestingJtaPlatformImpl();
@Override
protected TransactionManager locateTransactionManager() {
return TestingJtaBootstrap.INSTANCE.transactionManager;
}
@Override
protected UserTransaction locateUserTransaction() {
return TestingJtaBootstrap.INSTANCE.userTransaction;
}
}
public static class JtaAwareDataSourceConnectionProvider extends DatasourceConnectionProviderImpl {
public static final JtaAwareDataSourceConnectionProvider INSTANCE = new JtaAwareDataSourceConnectionProvider();
@Override
public Connection getConnection() throws SQLException {
// ignore username/password as it can cause infinite looping in the Enhydra code lol
return TestingJtaBootstrap.INSTANCE.dataSource.getConnection();
TestingJtaPlatformImpl.transactionManager().commit();
}
}
}

View File

@ -0,0 +1,116 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, 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.testing.jta;
import javax.transaction.TransactionManager;
import javax.transaction.TransactionSynchronizationRegistry;
import javax.transaction.UserTransaction;
import com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean;
import com.arjuna.ats.internal.arjuna.objectstore.VolatileStore;
import com.arjuna.common.internal.util.propertyservice.BeanPopulator;
import org.hibernate.service.jta.platform.internal.AbstractJtaPlatform;
import org.hibernate.service.jta.platform.internal.JtaSynchronizationStrategy;
import org.hibernate.service.jta.platform.internal.SynchronizationRegistryAccess;
import org.hibernate.service.jta.platform.internal.SynchronizationRegistryBasedSynchronizationStrategy;
/**
* @author Steve Ebersole
*/
public class TestingJtaPlatformImpl extends AbstractJtaPlatform {
public static final TestingJtaPlatformImpl INSTANCE = new TestingJtaPlatformImpl();
private final TransactionManager transactionManager;
private final UserTransaction userTransaction;
private final TransactionSynchronizationRegistry synchronizationRegistry;
private final JtaSynchronizationStrategy synchronizationStrategy;
public TestingJtaPlatformImpl() {
BeanPopulator
.getDefaultInstance( ObjectStoreEnvironmentBean.class )
.setObjectStoreType( VolatileStore.class.getName() );
BeanPopulator
.getNamedInstance( ObjectStoreEnvironmentBean.class, "communicationStore" )
.setObjectStoreType( VolatileStore.class.getName() );
BeanPopulator
.getNamedInstance( ObjectStoreEnvironmentBean.class, "stateStore" )
.setObjectStoreType( VolatileStore.class.getName() );
transactionManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
userTransaction = com.arjuna.ats.jta.UserTransaction.userTransaction();
synchronizationRegistry =
new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple();
synchronizationStrategy = new SynchronizationRegistryBasedSynchronizationStrategy(
new SynchronizationRegistryAccess() {
@Override
public TransactionSynchronizationRegistry getSynchronizationRegistry() {
return synchronizationRegistry;
}
}
);
}
public static TransactionManager transactionManager() {
return INSTANCE.retrieveTransactionManager();
}
public static UserTransaction userTransaction() {
return INSTANCE.retrieveUserTransaction();
}
public static TransactionSynchronizationRegistry synchronizationRegistry() {
return INSTANCE.synchronizationRegistry;
}
@Override
protected TransactionManager locateTransactionManager() {
return transactionManager;
}
@Override
protected boolean canCacheTransactionManager() {
return true;
}
@Override
protected UserTransaction locateUserTransaction() {
return userTransaction;
}
@Override
protected boolean canCacheUserTransaction() {
return true;
}
@Override
protected JtaSynchronizationStrategy getSynchronizationStrategy() {
return synchronizationStrategy;
}
}

View File

@ -30,7 +30,7 @@ import org.junit.After;
import org.junit.runner.RunWith;
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
import org.hibernate.testing.jta.TestingJtaBootstrap;
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
/**
* The base unit test adapter.
@ -43,10 +43,10 @@ public abstract class BaseUnitTestCase {
@After
public void releaseTransactions() {
if ( JtaStatusHelper.isActive( TestingJtaBootstrap.INSTANCE.getTransactionManager() ) ) {
if ( JtaStatusHelper.isActive( TestingJtaPlatformImpl.INSTANCE.getTransactionManager() ) ) {
log.warn( "Cleaning up unfinished transaction" );
try {
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().rollback();
}
catch (SystemException ignored) {
}