HHH-6013 - Consolidate on single JTA impl for testing
This commit is contained in:
parent
5fb8b92eef
commit
718d56e267
|
@ -99,7 +99,3 @@ task installTesting(type:Upload, dependsOn: [testingJar,testingSourcesJar]) {
|
|||
install.dependsOn installTesting
|
||||
uploadTesting.dependsOn installTesting
|
||||
|
||||
// temporary
|
||||
test {
|
||||
ignoreFailures = true
|
||||
}
|
||||
|
|
|
@ -145,7 +145,9 @@ public class JdbcServicesImpl implements JdbcServices, Configurable {
|
|||
LOG.unableToObtainConnectionMetadata(sqle.getMessage());
|
||||
}
|
||||
finally {
|
||||
connectionProvider.closeConnection( conn );
|
||||
if ( conn != null ) {
|
||||
connectionProvider.closeConnection( conn );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
|
|
|
@ -28,30 +28,27 @@ import org.hibernate.service.jta.platform.spi.JtaPlatformException;
|
|||
|
||||
import javax.transaction.TransactionManager;
|
||||
import javax.transaction.UserTransaction;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Return a standalone JTA transaction manager for JBoss Transactions
|
||||
* Known to work for org.jboss.jbossts:jbossjta:4.11.0.Final
|
||||
* Known to work for org.jboss.jbossts:jbossjta:4.9.0.GA
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class JBossStandAloneJtaPlatform extends AbstractJtaPlatform {
|
||||
private static final String PROPERTY_MANAGER_CLASS_NAME = "com.arjuna.ats.jta.common.jtaPropertyManager";
|
||||
private static final String JBOSS_TM_CLASS_NAME = "com.arjuna.ats.jta.TransactionManager";
|
||||
private static final String JBOSS_UT_CLASS_NAME = "com.arjuna.ats.jta.UserTransaction";
|
||||
|
||||
private final JtaSynchronizationStrategy synchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
|
||||
|
||||
@Override
|
||||
protected TransactionManager locateTransactionManager() {
|
||||
try {
|
||||
final Class propertyManagerClass = serviceRegistry()
|
||||
final Class jbossTmClass = serviceRegistry()
|
||||
.getService( ClassLoaderService.class )
|
||||
.classForName( PROPERTY_MANAGER_CLASS_NAME );
|
||||
final Method getJTAEnvironmentBeanMethod = propertyManagerClass.getMethod( "getJTAEnvironmentBean" );
|
||||
final Object jtaEnvironmentBean = getJTAEnvironmentBeanMethod.invoke( null );
|
||||
final Method getTransactionManagerMethod = jtaEnvironmentBean.getClass().getMethod( "getTransactionManager" );
|
||||
return ( TransactionManager ) getTransactionManagerMethod.invoke( jtaEnvironmentBean );
|
||||
.classForName( JBOSS_TM_CLASS_NAME );
|
||||
return (TransactionManager) jbossTmClass.getMethod( "transactionManager" ).invoke( null );
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
throw new JtaPlatformException( "Could not obtain JBoss Transactions transaction manager instance", e );
|
||||
|
@ -60,7 +57,15 @@ public class JBossStandAloneJtaPlatform extends AbstractJtaPlatform {
|
|||
|
||||
@Override
|
||||
protected UserTransaction locateUserTransaction() {
|
||||
return null;
|
||||
try {
|
||||
final Class jbossUtClass = serviceRegistry()
|
||||
.getService( ClassLoaderService.class )
|
||||
.classForName( JBOSS_UT_CLASS_NAME );
|
||||
return (UserTransaction) jbossUtClass.getMethod( "userTransaction" ).invoke( null );
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
throw new JtaPlatformException( "Could not obtain JBoss Transactions user transaction instance", e );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.common.jta;
|
||||
|
||||
import org.hibernate.service.internal.ServiceProxy;
|
||||
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.service.jta.platform.spi.JtaPlatform;
|
||||
import org.hibernate.service.spi.ServiceRegistry;
|
||||
import org.hibernate.service.spi.ServiceRegistryAwareService;
|
||||
import org.hibernate.service.spi.UnknownUnwrapTypeException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class AtomikosDataSourceConnectionProvider implements ConnectionProvider, ServiceRegistryAwareService {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
return dataSource.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeConnection(Connection conn) throws SQLException {
|
||||
conn.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsAggressiveRelease() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnwrappableAs(Class unwrapType) {
|
||||
return ConnectionProvider.class.equals( unwrapType )
|
||||
|| unwrapType.isInstance( this )
|
||||
|| DataSource.class.isAssignableFrom( unwrapType );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public <T> T unwrap(Class<T> unwrapType) {
|
||||
if ( ConnectionProvider.class.equals( unwrapType ) || unwrapType.isInstance( this ) ) {
|
||||
return (T) this;
|
||||
}
|
||||
if ( DataSource.class.isAssignableFrom( unwrapType ) ) {
|
||||
return (T) dataSource;
|
||||
}
|
||||
throw new UnknownUnwrapTypeException( unwrapType );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectServices(ServiceRegistry serviceRegistry) {
|
||||
AtomikosJtaPlatform jtaPlatform = (AtomikosJtaPlatform) ( (ServiceProxy) serviceRegistry.getService( JtaPlatform.class ) ).getTargetInstance();
|
||||
dataSource = jtaPlatform.getDataSource();
|
||||
}
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.common.jta;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import javax.transaction.TransactionManager;
|
||||
import javax.transaction.UserTransaction;
|
||||
import org.hibernate.HibernateLogger;
|
||||
import org.hibernate.service.jta.platform.internal.AbstractJtaPlatform;
|
||||
import org.hibernate.service.jta.platform.internal.JtaSynchronizationStrategy;
|
||||
import org.hibernate.service.jta.platform.internal.TransactionManagerBasedSynchronizationStrategy;
|
||||
import org.hibernate.service.jta.platform.spi.JtaPlatformException;
|
||||
import org.hibernate.service.spi.Startable;
|
||||
import org.hibernate.service.spi.Stoppable;
|
||||
import org.hibernate.testing.env.ConnectionProviderBuilder;
|
||||
import org.jboss.logging.Logger;
|
||||
import com.atomikos.icatch.jta.UserTransactionImp;
|
||||
import com.atomikos.icatch.jta.UserTransactionManager;
|
||||
import com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class AtomikosJtaPlatform extends AbstractJtaPlatform implements Startable, Stoppable {
|
||||
|
||||
private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, AtomikosJtaPlatform.class.getName());
|
||||
|
||||
private final JtaSynchronizationStrategy synchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
|
||||
|
||||
private UserTransactionManager transactionManager;
|
||||
private AtomikosNonXADataSourceBean dataSourceBean;
|
||||
|
||||
public DataSource getDataSource() {
|
||||
return dataSourceBean;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TransactionManager locateTransactionManager() {
|
||||
return transactionManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UserTransaction locateUserTransaction() {
|
||||
return new UserTransactionImp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JtaSynchronizationStrategy getSynchronizationStrategy() {
|
||||
return synchronizationStrategy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
if ( transactionManager == null ) {
|
||||
transactionManager = new UserTransactionManager();
|
||||
try {
|
||||
transactionManager.init();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new JtaPlatformException( "Unable to init Atomikos UserTransactionManager", e );
|
||||
}
|
||||
}
|
||||
|
||||
if ( dataSourceBean == null ) {
|
||||
// todo : extract sys props to handle functional testing...
|
||||
dataSourceBean = new AtomikosNonXADataSourceBean();
|
||||
dataSourceBean.setUniqueResourceName( "h2" );
|
||||
dataSourceBean.setDriverClassName( ConnectionProviderBuilder.DRIVER );
|
||||
dataSourceBean.setUrl( ConnectionProviderBuilder.URL );
|
||||
dataSourceBean.setUser( ConnectionProviderBuilder.USER );
|
||||
dataSourceBean.setPassword( ConnectionProviderBuilder.PASS );
|
||||
dataSourceBean.setPoolSize( 3 );
|
||||
try {
|
||||
dataSourceBean.init();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new JtaPlatformException( "Unable to init Atomikos DataSourceBean", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if ( dataSourceBean != null ) {
|
||||
try {
|
||||
dataSourceBean.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.debug("Error closing DataSourceBean", e);
|
||||
}
|
||||
}
|
||||
|
||||
if ( transactionManager != null ) {
|
||||
try {
|
||||
transactionManager.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.debug("Error closing UserTransactionManager", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,13 +16,10 @@ import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
|
|||
import org.hibernate.impl.SessionImpl;
|
||||
import org.hibernate.internal.util.SerializationHelper;
|
||||
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator;
|
||||
import org.hibernate.service.jta.platform.spi.JtaPlatform;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.test.common.jta.AtomikosDataSourceConnectionProvider;
|
||||
import org.hibernate.test.common.jta.AtomikosJtaPlatform;
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -38,8 +35,7 @@ public class AggressiveReleaseTest extends ConnectionManagementTestCase {
|
|||
@Override
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.getProperties().put( JtaPlatformInitiator.JTA_PLATFORM, AtomikosJtaPlatform.class.getName() );
|
||||
cfg.getProperties().put( Environment.CONNECTION_PROVIDER, AtomikosDataSourceConnectionProvider.class.getName() );
|
||||
TestingJtaBootstrap.prepare( cfg.getProperties() );
|
||||
cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
|
||||
cfg.setProperty( Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.AFTER_STATEMENT.toString() );
|
||||
cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
|
||||
|
@ -57,12 +53,12 @@ public class AggressiveReleaseTest extends ConnectionManagementTestCase {
|
|||
|
||||
@Override
|
||||
protected void prepare() throws Throwable {
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() throws Throwable {
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
// Some additional tests specifically for the aggressive-release functionality...
|
||||
|
|
|
@ -37,9 +37,8 @@ import org.hibernate.engine.StatefulPersistenceContext;
|
|||
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
|
||||
import org.hibernate.internal.util.SerializationHelper;
|
||||
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.tm.ConnectionProviderImpl;
|
||||
import org.hibernate.testing.tm.TransactionManagerLookupImpl;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
@ -54,8 +53,7 @@ public abstract class AbstractOperationTestCase extends BaseCoreFunctionalTestCa
|
|||
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.setProperty( Environment.CONNECTION_PROVIDER, ConnectionProviderImpl.class.getName() );
|
||||
cfg.setProperty( Environment.TRANSACTION_MANAGER_STRATEGY, TransactionManagerLookupImpl.class.getName() );
|
||||
TestingJtaBootstrap.prepare( cfg.getProperties() );
|
||||
cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
|
||||
cfg.setProperty( Environment.AUTO_CLOSE_SESSION, "true" );
|
||||
cfg.setProperty( Environment.FLUSH_BEFORE_COMPLETION, "true" );
|
||||
|
|
|
@ -23,17 +23,20 @@
|
|||
*/
|
||||
package org.hibernate.test.nonflushedchanges;
|
||||
|
||||
import javax.transaction.RollbackException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.PersistentObjectException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
|
||||
import org.hibernate.exception.ConstraintViolationException;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.tm.SimpleJtaTransactionManagerImpl;
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -48,7 +51,7 @@ public class CreateTest extends AbstractOperationTestCase {
|
|||
public void testNoUpdatesOnCreateVersionedWithCollection() throws Exception {
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
VersionedEntity root = new VersionedEntity( "root", "root" );
|
||||
|
@ -61,17 +64,17 @@ public class CreateTest extends AbstractOperationTestCase {
|
|||
root = ( VersionedEntity ) getOldToNewEntityRefMap().get( root );
|
||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( VersionedEntity ) getOldToNewEntityRefMap().get( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 2 );
|
||||
assertUpdateCount( 0 );
|
||||
assertDeleteCount( 0 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.delete( root );
|
||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertUpdateCount( 0 );
|
||||
assertDeleteCount( 2 );
|
||||
|
@ -81,7 +84,7 @@ public class CreateTest extends AbstractOperationTestCase {
|
|||
public void testCreateTree() throws Exception {
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Node root = new Node( "root" );
|
||||
Node child = new Node( "child" );
|
||||
|
@ -89,12 +92,12 @@ public class CreateTest extends AbstractOperationTestCase {
|
|||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
s.persist( root );
|
||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 2 );
|
||||
assertUpdateCount( 0 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
System.out.println( "getting" );
|
||||
root = ( Node ) s.get( Node.class, "root" );
|
||||
|
@ -104,7 +107,7 @@ public class CreateTest extends AbstractOperationTestCase {
|
|||
root.addChild( child2 );
|
||||
System.out.println( "committing" );
|
||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 3 );
|
||||
assertUpdateCount( 0 );
|
||||
|
@ -115,7 +118,7 @@ public class CreateTest extends AbstractOperationTestCase {
|
|||
public void testCreateTreeWithGeneratedId() throws Exception {
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
NumberedNode root = new NumberedNode( "root" );
|
||||
NumberedNode child = new NumberedNode( "child" );
|
||||
|
@ -123,12 +126,12 @@ public class CreateTest extends AbstractOperationTestCase {
|
|||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
s.persist( root );
|
||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 2 );
|
||||
assertUpdateCount( 0 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( NumberedNode ) s.get( NumberedNode.class, Long.valueOf( root.getId() ) );
|
||||
|
@ -137,7 +140,7 @@ public class CreateTest extends AbstractOperationTestCase {
|
|||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||
root.addChild( child2 );
|
||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 3 );
|
||||
assertUpdateCount( 0 );
|
||||
|
@ -145,7 +148,7 @@ public class CreateTest extends AbstractOperationTestCase {
|
|||
|
||||
@Test
|
||||
public void testCreateException() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Node dupe = new Node( "dupe" );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
|
@ -154,43 +157,59 @@ public class CreateTest extends AbstractOperationTestCase {
|
|||
dupe = ( Node ) getOldToNewEntityRefMap().get( dupe );
|
||||
s.persist( dupe );
|
||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
s.persist( dupe );
|
||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
try {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
assertFalse( true );
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
Assert.fail();
|
||||
}
|
||||
catch ( ConstraintViolationException cve ) {
|
||||
//verify that an exception is thrown!
|
||||
}
|
||||
SimpleJtaTransactionManagerImpl.getInstance().rollback();
|
||||
catch ( RollbackException e ) {
|
||||
if ( ! ConstraintViolationException.class.isInstance( e.getCause() ) ) {
|
||||
throw (Exception) e.getCause();
|
||||
}
|
||||
}
|
||||
if ( JtaStatusHelper.isActive( TestingJtaBootstrap.INSTANCE.getTransactionManager() ) ) {
|
||||
// ugh! really!?!
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
|
||||
}
|
||||
|
||||
Node nondupe = new Node( "nondupe" );
|
||||
nondupe.addChild( dupe );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
s.persist( nondupe );
|
||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
try {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
assertFalse( true );
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
Assert.fail();
|
||||
}
|
||||
catch ( ConstraintViolationException cve ) {
|
||||
//verify that an exception is thrown!
|
||||
}
|
||||
SimpleJtaTransactionManagerImpl.getInstance().rollback();
|
||||
catch ( RollbackException e ) {
|
||||
if ( ! ConstraintViolationException.class.isInstance( e.getCause() ) ) {
|
||||
throw (Exception) e.getCause();
|
||||
}
|
||||
}
|
||||
if ( JtaStatusHelper.isActive( TestingJtaBootstrap.INSTANCE.getTransactionManager() ) ) {
|
||||
// ugh! really!?!
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateExceptionWithGeneratedId() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
NumberedNode dupe = new NumberedNode( "dupe" );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
|
@ -199,9 +218,9 @@ public class CreateTest extends AbstractOperationTestCase {
|
|||
dupe = ( NumberedNode ) getOldToNewEntityRefMap().get( dupe );
|
||||
s.persist( dupe );
|
||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
try {
|
||||
|
@ -211,12 +230,12 @@ public class CreateTest extends AbstractOperationTestCase {
|
|||
catch ( PersistentObjectException poe ) {
|
||||
//verify that an exception is thrown!
|
||||
}
|
||||
SimpleJtaTransactionManagerImpl.getInstance().rollback();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
|
||||
|
||||
NumberedNode nondupe = new NumberedNode( "nondupe" );
|
||||
nondupe.addChild( dupe );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
try {
|
||||
|
@ -226,14 +245,14 @@ public class CreateTest extends AbstractOperationTestCase {
|
|||
catch ( PersistentObjectException poe ) {
|
||||
//verify that an exception is thrown!
|
||||
}
|
||||
SimpleJtaTransactionManagerImpl.getInstance().rollback();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public void testBasic() throws Exception {
|
||||
Session s;
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
Employer er = new Employer();
|
||||
Employee ee = new Employee();
|
||||
|
@ -250,9 +269,9 @@ public class CreateTest extends AbstractOperationTestCase {
|
|||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
ee = ( Employee ) getOldToNewEntityRefMap().get( ee );
|
||||
er = ( Employer ) ee.getEmployers().iterator().next();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
er = ( Employer ) s.load( Employer.class, er.getId() );
|
||||
assertNotNull( er );
|
||||
|
@ -268,6 +287,6 @@ public class CreateTest extends AbstractOperationTestCase {
|
|||
eeFromDb = ( Employee ) getOldToNewEntityRefMap().get( eeFromDb );
|
||||
assertEquals( ee.getId(), eeFromDb.getId() );
|
||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ import org.hibernate.Session;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.tm.SimpleJtaTransactionManagerImpl;
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
|
||||
/**
|
||||
* adapted this from "ops" tests version
|
||||
|
@ -41,25 +41,25 @@ public class DeleteTest extends AbstractOperationTestCase {
|
|||
@SuppressWarnings( {"unchecked"})
|
||||
public void testDeleteVersionedWithCollectionNoUpdate() throws Exception {
|
||||
// test adapted from HHH-1564...
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.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 );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.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 );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 0 );
|
||||
assertUpdateCount( 0 );
|
||||
|
@ -68,20 +68,20 @@ public class DeleteTest extends AbstractOperationTestCase {
|
|||
|
||||
@Test
|
||||
public void testNoUpdateOnDelete() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Node node = new Node( "test" );
|
||||
s.persist( node );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
s.delete( node );
|
||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertUpdateCount( 0 );
|
||||
assertInsertCount( 0 );
|
||||
|
@ -90,24 +90,24 @@ public class DeleteTest extends AbstractOperationTestCase {
|
|||
@Test
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public void testNoUpdateOnDeleteWithCollection() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Node parent = new Node( "parent" );
|
||||
Node child = new Node( "child" );
|
||||
parent.getCascadingChildren().add( child );
|
||||
s.persist( parent );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.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 );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertUpdateCount( 0 );
|
||||
assertInsertCount( 0 );
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.nonflushedchanges;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
|
@ -32,7 +31,7 @@ import org.hibernate.cfg.Environment;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.tm.SimpleJtaTransactionManagerImpl;
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -57,7 +56,7 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
|||
public void testGetLoad() throws Exception {
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Employer emp = new Employer();
|
||||
s.persist( emp );
|
||||
|
@ -65,9 +64,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
|||
Node parent = new Node( "bar" );
|
||||
parent.addChild( node );
|
||||
s.persist( parent );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
emp = ( Employer ) s.get( Employer.class, emp.getId() );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
|
@ -82,9 +81,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
|||
assertFalse( Hibernate.isInitialized( node.getChildren() ) );
|
||||
assertFalse( Hibernate.isInitialized( node.getParent() ) );
|
||||
assertNull( s.get( Node.class, "xyz" ) );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
emp = ( Employer ) s.load( Employer.class, emp.getId() );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
|
@ -96,9 +95,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
|||
node = ( Node ) getOldToNewEntityRefMap().get( node );
|
||||
assertEquals( node.getName(), "foo" );
|
||||
assertFalse( Hibernate.isInitialized( node ) );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
emp = ( Employer ) s.get( "org.hibernate.test.nonflushedchanges.Employer", emp.getId() );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
|
@ -108,9 +107,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
|||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
node = ( Node ) getOldToNewEntityRefMap().get( node );
|
||||
assertTrue( Hibernate.isInitialized( node ) );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
emp = ( Employer ) s.load( "org.hibernate.test.nonflushedchanges.Employer", emp.getId() );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
|
@ -123,25 +122,25 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
|||
node = ( Node ) getOldToNewEntityRefMap().get( node );
|
||||
assertEquals( node.getName(), "foo" );
|
||||
assertFalse( Hibernate.isInitialized( node ) );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertFetchCount( 0 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.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 );
|
||||
}
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetReadOnly() throws Exception {
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Employer emp = new Employer();
|
||||
s.persist( emp );
|
||||
|
@ -149,9 +148,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
|||
Node parent = new Node( "bar" );
|
||||
parent.addChild( node );
|
||||
s.persist( parent );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
assertFalse( s.isDefaultReadOnly() );
|
||||
s.setDefaultReadOnly( true );
|
||||
|
@ -181,9 +180,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
|||
}
|
||||
assertFalse( Hibernate.isInitialized( node.getParent() ) );
|
||||
assertNull( s.get( Node.class, "xyz" ) );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
assertFalse( s.isDefaultReadOnly() );
|
||||
emp = ( Employer ) s.get( "org.hibernate.test.nonflushedchanges.Employer", emp.getId() );
|
||||
|
@ -202,25 +201,25 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
|||
node = ( Node ) getOldToNewEntityRefMap().get( node );
|
||||
assertTrue( Hibernate.isInitialized( node ) );
|
||||
assertTrue( s.isReadOnly( node ) );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertFetchCount( 0 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.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 );
|
||||
}
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadReadOnly() throws Exception {
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Employer emp = new Employer();
|
||||
s.persist( emp );
|
||||
|
@ -228,9 +227,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
|||
Node parent = new Node( "bar" );
|
||||
parent.addChild( node );
|
||||
s.persist( parent );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
assertFalse( s.isDefaultReadOnly() );
|
||||
s.setDefaultReadOnly( true );
|
||||
|
@ -243,34 +242,34 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
|||
emp = ( Employer ) getOldToNewEntityRefMap().get( emp );
|
||||
assertFalse( Hibernate.isInitialized( emp ) );
|
||||
assertTrue( s.isReadOnly( emp ) );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.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 );
|
||||
}
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAfterDelete() throws Exception {
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Employer emp = new Employer();
|
||||
s.persist( emp );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.delete( emp );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
emp = ( Employer ) s.get( Employee.class, emp.getId() );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertNull( "get did not return null after delete", emp );
|
||||
}
|
||||
|
|
|
@ -12,7 +12,8 @@ import org.hibernate.criterion.Projections;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.tm.SimpleJtaTransactionManagerImpl;
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
|
@ -27,116 +28,116 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
public void testMergeStaleVersionFails() throws Exception {
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
VersionedEntity entity = new VersionedEntity( "entity", "entity" );
|
||||
s.persist( entity );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
// make the detached 'entity' reference stale...
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
VersionedEntity entity2 = ( VersionedEntity ) s.get( VersionedEntity.class, entity.getId() );
|
||||
entity2.setName( "entity-name" );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
// now try to reattach it
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
try {
|
||||
s.merge( entity );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
entity = ( VersionedEntity ) getOldToNewEntityRefMap().get( entity );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
fail( "was expecting staleness error" );
|
||||
}
|
||||
catch ( StaleObjectStateException expected ) {
|
||||
// expected outcome...
|
||||
}
|
||||
finally {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().rollback();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings( {"UnusedAssignment"})
|
||||
public void testMergeBidiPrimayKeyOneToOne() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Person p = new Person( "steve" );
|
||||
new PersonalDetails( "I have big feet", p );
|
||||
s.persist( p );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
clearCounts();
|
||||
|
||||
p.getDetails().setSomePersonalDetail( p.getDetails().getSomePersonalDetail() + " and big hands too" );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
p = ( Person ) s.merge( p );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
p = ( Person ) getOldToNewEntityRefMap().get( p );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 0 );
|
||||
assertUpdateCount( 1 );
|
||||
assertDeleteCount( 0 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.delete( p );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings( {"UnusedAssignment"})
|
||||
public void testMergeBidiForeignKeyOneToOne() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.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 );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
clearCounts();
|
||||
|
||||
p.getAddress().setStreetAddress( "321 Main" );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
p = ( Person ) s.merge( p );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 0 );
|
||||
assertUpdateCount( 0 ); // no cascade
|
||||
assertDeleteCount( 0 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.delete( a );
|
||||
s.delete( p );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings( {"UnusedAssignment"})
|
||||
public void testNoExtraUpdatesOnMerge() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Node node = new Node( "test" );
|
||||
s.persist( node );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.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...
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
node = ( Node ) s.merge( node );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertUpdateCount( 0 );
|
||||
assertInsertCount( 0 );
|
||||
|
@ -145,11 +146,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" );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
node = ( Node ) s.merge( node );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
assertUpdateCount( 1 );
|
||||
assertInsertCount( 0 );
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
@ -160,24 +161,24 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
@Test
|
||||
@SuppressWarnings( {"unchecked", "UnusedAssignment"})
|
||||
public void testNoExtraUpdatesOnMergeWithCollection() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.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 );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.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...
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
parent = ( Node ) s.merge( parent );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertUpdateCount( 0 );
|
||||
assertInsertCount( 0 );
|
||||
|
@ -187,11 +188,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" ) );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
parent = ( Node ) s.merge( parent );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
assertUpdateCount( 1 );
|
||||
assertInsertCount( 1 );
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
@ -202,22 +203,22 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
@Test
|
||||
@SuppressWarnings( {"UnusedAssignment"})
|
||||
public void testNoExtraUpdatesOnMergeVersioned() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
VersionedEntity entity = new VersionedEntity( "entity", "entity" );
|
||||
s.persist( entity );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.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...
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
VersionedEntity mergedEntity = ( VersionedEntity ) s.merge( entity );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
mergedEntity = ( VersionedEntity ) getOldToNewEntityRefMap().get( mergedEntity );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertUpdateCount( 0 );
|
||||
assertInsertCount( 0 );
|
||||
|
@ -228,11 +229,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" );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
entity = ( VersionedEntity ) s.merge( entity );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
assertUpdateCount( 1 );
|
||||
assertInsertCount( 0 );
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
@ -243,25 +244,25 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
@Test
|
||||
@SuppressWarnings( {"unchecked", "UnusedAssignment"})
|
||||
public void testNoExtraUpdatesOnMergeVersionedWithCollection() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.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 );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.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...
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
VersionedEntity mergedParent = ( VersionedEntity ) s.merge( parent );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
mergedParent = ( VersionedEntity ) getOldToNewEntityRefMap().get( mergedParent );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertUpdateCount( 0 );
|
||||
assertInsertCount( 0 );
|
||||
|
@ -274,12 +275,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" ) );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
parent = ( VersionedEntity ) s.merge( mergedParent );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
parent = ( VersionedEntity ) getOldToNewEntityRefMap().get( parent );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
assertUpdateCount( 1 );
|
||||
assertInsertCount( 1 );
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
@ -290,20 +291,20 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
@Test
|
||||
@SuppressWarnings( {"unchecked", "UnusedAssignment"})
|
||||
public void testNoExtraUpdatesOnPersistentMergeVersionedWithCollection() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.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 );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.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...
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
// load parent so that merge will follow entityIsPersistent path
|
||||
VersionedEntity persistentParent = ( VersionedEntity ) s.get( VersionedEntity.class, parent.getId() );
|
||||
|
@ -316,7 +317,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 );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertUpdateCount( 0 );
|
||||
assertInsertCount( 0 );
|
||||
|
@ -327,7 +328,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...
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
persistentParent = ( VersionedEntity ) s.get( VersionedEntity.class, parent.getId() );
|
||||
persistentParent.setName( "new name" );
|
||||
|
@ -336,7 +337,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
persistentParent = ( VersionedEntity ) getOldToNewEntityRefMap().get( persistentParent );
|
||||
persistentParent = ( VersionedEntity ) s.merge( persistentParent );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
assertUpdateCount( 1 );
|
||||
assertInsertCount( 1 );
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
@ -346,7 +347,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
|
||||
@Test
|
||||
public void testPersistThenMergeInSameTxnWithVersion() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
VersionedEntity entity = new VersionedEntity( "test", "test" );
|
||||
s.persist( entity );
|
||||
|
@ -363,14 +364,14 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
// expected behavior
|
||||
}
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersistThenMergeInSameTxnWithTimestamp() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
TimestampedEntity entity = new TimestampedEntity( "test", "test" );
|
||||
s.persist( entity );
|
||||
|
@ -387,7 +388,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
// expected behavior
|
||||
}
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
@ -398,7 +399,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Node root = new Node( "root" );
|
||||
Node child = new Node( "child" );
|
||||
|
@ -407,7 +408,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
child.addChild( grandchild );
|
||||
s.merge( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 3 );
|
||||
assertUpdateCount( 0 );
|
||||
|
@ -417,11 +418,11 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
Node grandchild2 = new Node( "grandchild2" );
|
||||
child.addChild( grandchild2 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.merge( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 1 );
|
||||
assertUpdateCount( 1 );
|
||||
|
@ -432,17 +433,17 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
child2.addChild( grandchild3 );
|
||||
root.addChild( child2 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.merge( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 2 );
|
||||
assertUpdateCount( 0 );
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.delete( grandchild );
|
||||
s.delete( grandchild2 );
|
||||
|
@ -450,7 +451,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
s.delete( child );
|
||||
s.delete( child2 );
|
||||
s.delete( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
}
|
||||
|
||||
|
@ -459,7 +460,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
public void testMergeDeepTreeWithGeneratedId() throws Exception {
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
NumberedNode root = new NumberedNode( "root" );
|
||||
NumberedNode child = new NumberedNode( "child" );
|
||||
|
@ -469,7 +470,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
root = ( NumberedNode ) s.merge( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 3 );
|
||||
assertUpdateCount( 0 );
|
||||
|
@ -481,12 +482,12 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
NumberedNode grandchild2 = new NumberedNode( "grandchild2" );
|
||||
child.addChild( grandchild2 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
root = ( NumberedNode ) s.merge( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 1 );
|
||||
assertUpdateCount( 1 );
|
||||
|
@ -499,23 +500,23 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
child2.addChild( grandchild3 );
|
||||
root.addChild( child2 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
root = ( NumberedNode ) s.merge( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 2 );
|
||||
assertUpdateCount( 0 );
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.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();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
}
|
||||
|
||||
|
@ -524,7 +525,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
public void testMergeTree() throws Exception {
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Node root = new Node( "root" );
|
||||
Node child = new Node( "child" );
|
||||
|
@ -533,7 +534,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
||||
child = ( Node ) root.getChildren().iterator().next();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 2 );
|
||||
clearCounts();
|
||||
|
@ -545,10 +546,10 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
|
||||
root.addChild( secondChild );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.merge( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 1 );
|
||||
assertUpdateCount( 2 );
|
||||
|
@ -561,7 +562,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
public void testMergeTreeWithGeneratedId() throws Exception {
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
NumberedNode root = new NumberedNode( "root" );
|
||||
NumberedNode child = new NumberedNode( "child" );
|
||||
|
@ -570,7 +571,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||
child = ( NumberedNode ) root.getChildren().iterator().next();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 2 );
|
||||
clearCounts();
|
||||
|
@ -582,10 +583,10 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
|
||||
root.addChild( secondChild );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.merge( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 1 );
|
||||
assertUpdateCount( 2 );
|
||||
|
@ -597,17 +598,17 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
@SuppressWarnings( {"UnusedAssignment", "UnnecessaryBoxing"})
|
||||
public void testMergeManaged() throws Exception {
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
NumberedNode root = new NumberedNode( "root" );
|
||||
s.persist( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
NumberedNode child = new NumberedNode( "child" );
|
||||
root = ( NumberedNode ) s.merge( root );
|
||||
|
@ -625,7 +626,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||
mergedChild = root.getChildren().iterator().next();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 1 );
|
||||
assertUpdateCount( 0 );
|
||||
|
@ -633,7 +634,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
assertEquals( root.getChildren().size(), 1 );
|
||||
assertTrue( root.getChildren().contains( mergedChild ) );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
assertEquals(
|
||||
Long.valueOf( 2 ),
|
||||
|
@ -642,7 +643,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
.uniqueResult()
|
||||
);
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
@ -651,19 +652,19 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
@SuppressWarnings( {"UnnecessaryBoxing"})
|
||||
public void testMergeManagedUninitializedCollection() throws Exception {
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
NumberedNode root = new NumberedNode( "root" );
|
||||
root.addChild( new NumberedNode( "child" ) );
|
||||
s.persist( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
clearCounts();
|
||||
|
||||
NumberedNode newRoot = new NumberedNode( "root" );
|
||||
newRoot.setId( root.getId() );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
root = ( NumberedNode ) s.get( NumberedNode.class, root.getId() );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
|
@ -677,13 +678,13 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
assertSame( root, s.merge( newRoot ) );
|
||||
assertSame( managedChildren, root.getChildren() );
|
||||
assertFalse( Hibernate.isInitialized( managedChildren ) );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 0 );
|
||||
assertUpdateCount( 0 );
|
||||
assertDeleteCount( 0 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
assertEquals(
|
||||
Long.valueOf( 2 ),
|
||||
|
@ -691,7 +692,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
.setProjection( Projections.rowCount() )
|
||||
.uniqueResult()
|
||||
);
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
@ -700,19 +701,19 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
@SuppressWarnings( {"UnnecessaryBoxing"})
|
||||
public void testMergeManagedInitializedCollection() throws Exception {
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
NumberedNode root = new NumberedNode( "root" );
|
||||
root.addChild( new NumberedNode( "child" ) );
|
||||
s.persist( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
clearCounts();
|
||||
|
||||
NumberedNode newRoot = new NumberedNode( "root" );
|
||||
newRoot.setId( root.getId() );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
root = ( NumberedNode ) s.get( NumberedNode.class, root.getId() );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
|
@ -727,13 +728,13 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
assertSame( root, s.merge( newRoot ) );
|
||||
assertSame( managedChildren, root.getChildren() );
|
||||
assertTrue( Hibernate.isInitialized( managedChildren ) );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 0 );
|
||||
assertUpdateCount( 0 );
|
||||
assertDeleteCount( 0 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
assertEquals(
|
||||
Long.valueOf( 2 ),
|
||||
|
@ -741,7 +742,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
.setProjection( Projections.rowCount() )
|
||||
.uniqueResult()
|
||||
);
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
@ -750,7 +751,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
@SuppressWarnings( {"unchecked"})
|
||||
public void testRecursiveMergeTransient() throws Exception {
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Employer jboss = new Employer();
|
||||
Employee gavin = new Employee();
|
||||
|
@ -765,7 +766,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
assertEquals( 1, jboss.getEmployees().size() );
|
||||
s.clear();
|
||||
s.merge( jboss.getEmployees().iterator().next() );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
@ -773,25 +774,25 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
@Test
|
||||
@SuppressWarnings( {"UnnecessaryBoxing", "UnusedAssignment"})
|
||||
public void testDeleteAndMerge() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Employer jboss = new Employer();
|
||||
s.persist( jboss );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
Employer otherJboss;
|
||||
otherJboss = ( Employer ) s.get( Employer.class, jboss.getId() );
|
||||
s.delete( otherJboss );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
jboss.setVers( Integer.valueOf( 1 ) );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.merge( jboss );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
@ -800,18 +801,18 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
@SuppressWarnings( {"unchecked", "UnusedAssignment"})
|
||||
public void testMergeManyToManyWithCollectionDeference() throws Exception {
|
||||
// setup base data...
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.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 );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
// the competition graph is now detached:
|
||||
// 1) create a new List reference to represent the competitors
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
List newComp = new ArrayList();
|
||||
Competitor originalCompetitor = ( Competitor ) competition.getCompetitors().get( 0 );
|
||||
|
@ -825,7 +826,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
Competition competition2copy = ( Competition ) getOldToNewEntityRefMap().get( competition2 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertFalse( competition == competition2 );
|
||||
assertFalse( competition2 == competition2copy );
|
||||
|
@ -833,19 +834,19 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
assertEquals( 2, competition2.getCompetitors().size() );
|
||||
assertEquals( 2, competition2copy.getCompetitors().size() );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
competition = ( Competition ) s.get( Competition.class, competition.getId() );
|
||||
assertEquals( 2, competition.getCompetitors().size() );
|
||||
s.delete( competition );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
private void cleanup() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
s.createQuery( "delete from NumberedNode where parent is not null" ).executeUpdate();
|
||||
s.createQuery( "delete from NumberedNode" ).executeUpdate();
|
||||
|
@ -864,7 +865,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
|||
s.delete( employer );
|
||||
}
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.hibernate.proxy.HibernateProxy;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.tm.SimpleJtaTransactionManagerImpl;
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -64,7 +64,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
public void testSaveOrUpdateDeepTree() throws Exception {
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Node root = new Node( "root" );
|
||||
Node child = new Node( "child" );
|
||||
|
@ -76,7 +76,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
||||
child = ( Node ) getOldToNewEntityRefMap().get( child );
|
||||
grandchild = ( Node ) getOldToNewEntityRefMap().get( grandchild );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 3 );
|
||||
assertUpdateCount( 0 );
|
||||
|
@ -86,12 +86,12 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
Node grandchild2 = new Node( "grandchild2" );
|
||||
child.addChild( grandchild2 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.saveOrUpdate( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 1 );
|
||||
assertUpdateCount( 1 );
|
||||
|
@ -102,17 +102,17 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
child2.addChild( grandchild3 );
|
||||
root.addChild( child2 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.saveOrUpdate( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 2 );
|
||||
assertUpdateCount( 0 );
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.delete( grandchild );
|
||||
s.delete( grandchild2 );
|
||||
|
@ -120,7 +120,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
s.delete( child );
|
||||
s.delete( child2 );
|
||||
s.delete( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -129,7 +129,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
boolean instrumented = FieldInterceptionHelper.isInstrumented( new NumberedNode() );
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
NumberedNode root = new NumberedNode( "root" );
|
||||
NumberedNode child = new NumberedNode( "child" );
|
||||
|
@ -141,7 +141,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||
child = ( NumberedNode ) getOldToNewEntityRefMap().get( child );
|
||||
grandchild = ( NumberedNode ) getOldToNewEntityRefMap().get( grandchild );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 3 );
|
||||
assertUpdateCount( 0 );
|
||||
|
@ -153,12 +153,12 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
NumberedNode grandchild2 = new NumberedNode( "grandchild2" );
|
||||
child.addChild( grandchild2 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.saveOrUpdate( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 1 );
|
||||
assertUpdateCount( instrumented ? 1 : 3 );
|
||||
|
@ -169,22 +169,22 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
child2.addChild( grandchild3 );
|
||||
root.addChild( child2 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.saveOrUpdate( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 2 );
|
||||
assertUpdateCount( instrumented ? 0 : 4 );
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.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();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -192,7 +192,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
public void testSaveOrUpdateTree() throws Exception {
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Node root = new Node( "root" );
|
||||
Node child = new Node( "child" );
|
||||
|
@ -201,7 +201,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
||||
child = ( Node ) getOldToNewEntityRefMap().get( child );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 2 );
|
||||
clearCounts();
|
||||
|
@ -213,20 +213,20 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
|
||||
root.addChild( secondChild );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.saveOrUpdate( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 1 );
|
||||
assertUpdateCount( 2 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.createQuery( "delete from Node where parent is not null" ).executeUpdate();
|
||||
s.createQuery( "delete from Node" ).executeUpdate();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -234,7 +234,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
public void testSaveOrUpdateTreeWithGeneratedId() throws Exception {
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
NumberedNode root = new NumberedNode( "root" );
|
||||
NumberedNode child = new NumberedNode( "child" );
|
||||
|
@ -243,7 +243,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||
child = ( NumberedNode ) getOldToNewEntityRefMap().get( child );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 2 );
|
||||
clearCounts();
|
||||
|
@ -255,34 +255,34 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
|
||||
root.addChild( secondChild );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.saveOrUpdate( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 1 );
|
||||
assertUpdateCount( 2 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.createQuery( "delete from NumberedNode where parent is not null" ).executeUpdate();
|
||||
s.createQuery( "delete from NumberedNode" ).executeUpdate();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings( {"UnusedAssignment", "UnnecessaryBoxing"})
|
||||
public void testSaveOrUpdateManaged() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
NumberedNode root = new NumberedNode( "root" );
|
||||
s.saveOrUpdate( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
root = ( NumberedNode ) s.get( NumberedNode.class, root.getId() );
|
||||
NumberedNode child = new NumberedNode( "child" );
|
||||
|
@ -300,12 +300,12 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||
child = ( NumberedNode ) getOldToNewEntityRefMap().get( child );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertTrue( root.getChildren().contains( child ) );
|
||||
assertEquals( root.getChildren().size(), 1 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
assertEquals(
|
||||
Long.valueOf( 2 ),
|
||||
|
@ -315,7 +315,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
);
|
||||
s.delete( root );
|
||||
s.delete( child );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -323,29 +323,31 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
public void testSaveOrUpdateGot() throws Exception {
|
||||
boolean instrumented = FieldInterceptionHelper.isInstrumented( new NumberedNode() );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
clearCounts();
|
||||
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
NumberedNode root = new NumberedNode( "root" );
|
||||
s.saveOrUpdate( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 1 );
|
||||
assertUpdateCount( 0 );
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.saveOrUpdate( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 0 );
|
||||
assertUpdateCount( instrumented ? 0 : 1 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
root = ( NumberedNode ) s.get( NumberedNode.class, Long.valueOf( root.getId() ) );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
|
@ -353,11 +355,11 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
Hibernate.initialize( root.getChildren() );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
NumberedNode child = new NumberedNode( "child" );
|
||||
root.addChild( child );
|
||||
|
@ -367,12 +369,12 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
assertTrue( Hibernate.isInitialized( root.getChildren() ) );
|
||||
child = ( NumberedNode ) root.getChildren().iterator().next();
|
||||
assertTrue( s.contains( child ) );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 1 );
|
||||
assertUpdateCount( instrumented ? 0 : 1 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
assertEquals(
|
||||
s.createCriteria( NumberedNode.class )
|
||||
|
@ -382,35 +384,37 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
);
|
||||
s.delete( root );
|
||||
s.delete( child );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings( {"UnusedAssignment", "UnnecessaryBoxing"})
|
||||
public void testSaveOrUpdateGotWithMutableProp() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
clearCounts();
|
||||
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Node root = new Node( "root" );
|
||||
s.saveOrUpdate( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 1 );
|
||||
assertUpdateCount( 0 );
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.saveOrUpdate( root );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 0 );
|
||||
assertUpdateCount( 0 );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
root = ( Node ) s.get( Node.class, "root" );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
|
@ -418,11 +422,11 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
Hibernate.initialize( root.getChildren() );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
clearCounts();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
Node child = new Node( "child" );
|
||||
root.addChild( child );
|
||||
|
@ -434,12 +438,12 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
||||
child = ( Node ) getOldToNewEntityRefMap().get( child );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertInsertCount( 1 );
|
||||
//assertUpdateCount( 1 ); //note: will fail here if no second-level cache
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
assertEquals(
|
||||
Long.valueOf( 2 ),
|
||||
|
@ -449,13 +453,13 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
);
|
||||
s.delete( root );
|
||||
s.delete( child );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings( {"UnusedAssignment"})
|
||||
public void testEvictThenSaveOrUpdate() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Node parent = new Node( "1:parent" );
|
||||
Node child = new Node( "2:child" );
|
||||
|
@ -464,9 +468,9 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
child.addChild( grandchild );
|
||||
s.saveOrUpdate( parent );
|
||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s1 = openSession();
|
||||
child = ( Node ) s1.load( Node.class, "2:child" );
|
||||
s1 = applyNonFlushedChangesToNewSessionCloseOldSession( s1 );
|
||||
|
@ -489,9 +493,9 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
assertFalse( s1.contains( child ) );
|
||||
assertTrue( s1.contains( child.getParent() ) );
|
||||
|
||||
javax.transaction.Transaction tx1 = SimpleJtaTransactionManagerImpl.getInstance().suspend();
|
||||
javax.transaction.Transaction tx1 = TestingJtaBootstrap.INSTANCE.getTransactionManager().suspend();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s2 = openSession();
|
||||
try {
|
||||
s2.getTransaction().begin();
|
||||
|
@ -502,13 +506,13 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
// expected because parent is connected to s1
|
||||
}
|
||||
finally {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().rollback();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
|
||||
}
|
||||
|
||||
s1.evict( child.getParent() );
|
||||
assertFalse( s1.contains( child.getParent() ) );
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s2 = openSession();
|
||||
s2.saveOrUpdate( child );
|
||||
s2 = applyNonFlushedChangesToNewSessionCloseOldSession( s2 );
|
||||
|
@ -527,20 +531,18 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
|||
assertTrue( Hibernate.isInitialized( child.getParent() ) );
|
||||
s1 = applyNonFlushedChangesToNewSessionCloseOldSession( s1 );
|
||||
s2 = applyNonFlushedChangesToNewSessionCloseOldSession( s2 );
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
javax.transaction.Transaction tx2 = SimpleJtaTransactionManagerImpl.getInstance().suspend();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().resume( tx1 );
|
||||
tx1.commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx1 );
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
// tx1.commit();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().resume( tx2 );
|
||||
tx2.commit();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.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" ) );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,16 +37,13 @@ import org.hibernate.cfg.Configuration;
|
|||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.criterion.Order;
|
||||
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
|
||||
import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator;
|
||||
import org.hibernate.service.jta.platform.spi.JtaPlatform;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.test.common.jta.AtomikosDataSourceConnectionProvider;
|
||||
import org.hibernate.test.common.jta.AtomikosJtaPlatform;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -65,8 +62,7 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Override
|
||||
public void configure(Configuration cfg) {
|
||||
cfg.getProperties().put( JtaPlatformInitiator.JTA_PLATFORM, AtomikosJtaPlatform.class.getName() );
|
||||
cfg.getProperties().put( Environment.CONNECTION_PROVIDER, AtomikosDataSourceConnectionProvider.class.getName() );
|
||||
TestingJtaBootstrap.prepare( cfg.getProperties() );
|
||||
cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
|
||||
cfg.setProperty( Environment.AUTO_CLOSE_SESSION, "true" );
|
||||
cfg.setProperty( Environment.FLUSH_BEFORE_COMPLETION, "true" );
|
||||
|
@ -87,7 +83,7 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
assertNotNull( sessionFactory().getEntityPersister( "Item" ).getCacheAccessStrategy() );
|
||||
assertEquals( 0, sessionFactory().getStatistics().getEntityLoadCount() );
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Map foo = new HashMap();
|
||||
foo.put( "name", "Foo" );
|
||||
|
@ -97,46 +93,46 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
bar.put( "name", "Bar" );
|
||||
bar.put( "description", "a small bar" );
|
||||
s.persist( "Item", bar );
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
sessionFactory().evictEntity( "Item" );
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s1 = openSession();
|
||||
foo = ( Map ) s1.get( "Item", "Foo" );
|
||||
//foo.put("description", "a big red foo");
|
||||
//s1.flush();
|
||||
Transaction tx1 = sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().suspend();
|
||||
Transaction tx = TestingJtaBootstrap.INSTANCE.getTransactionManager().suspend();
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s2 = openSession();
|
||||
foo = ( Map ) s2.get( "Item", "Foo" );
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().resume( tx1 );
|
||||
tx1.commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx );
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
sessionFactory().evictEntity( "Item" );
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s1 = openSession();
|
||||
s1.createCriteria( "Item" ).list();
|
||||
//foo.put("description", "a big red foo");
|
||||
//s1.flush();
|
||||
tx1 = sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().suspend();
|
||||
tx = TestingJtaBootstrap.INSTANCE.getTransactionManager().suspend();
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s2 = openSession();
|
||||
s2.createCriteria( "Item" ).list();
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().resume( tx1 );
|
||||
tx1.commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx );
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s2 = openSession();
|
||||
s2.createCriteria( "Item" ).list();
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertEquals( 7, sessionFactory().getStatistics().getEntityLoadCount() );
|
||||
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||
|
@ -144,15 +140,15 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
assertEquals( 0, sessionFactory().getStatistics().getQueryCacheHitCount() );
|
||||
assertEquals( 0, sessionFactory().getStatistics().getQueryCacheMissCount() );
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.createQuery( "delete from Item" ).executeUpdate();
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConcurrentCachedQueries() throws Exception {
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Map foo = new HashMap();
|
||||
foo.put( "name", "Foo" );
|
||||
|
@ -162,7 +158,7 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
bar.put( "name", "Bar" );
|
||||
bar.put( "description", "a small bar" );
|
||||
s.persist( "Item", bar );
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
synchronized ( this ) {
|
||||
wait( 1000 );
|
||||
|
@ -172,23 +168,23 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
sessionFactory().evictEntity( "Item" );
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s4 = openSession();
|
||||
Transaction tx4 = sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().suspend();
|
||||
Transaction tx4 = TestingJtaBootstrap.INSTANCE.getTransactionManager().suspend();
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s1 = openSession();
|
||||
List r1 = s1.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||
.setCacheable( true ).list();
|
||||
assertEquals( r1.size(), 2 );
|
||||
Transaction tx1 = sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().suspend();
|
||||
Transaction tx1 = TestingJtaBootstrap.INSTANCE.getTransactionManager().suspend();
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s2 = openSession();
|
||||
List r2 = s2.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||
.setCacheable( true ).list();
|
||||
assertEquals( r2.size(), 2 );
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 2 );
|
||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
||||
|
@ -199,14 +195,14 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 1 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryCacheMissCount(), 1 );
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().resume( tx1 );
|
||||
tx1.commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx1 );
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s3 = openSession();
|
||||
s3.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||
.setCacheable( true ).list();
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 4 );
|
||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
||||
|
@ -217,11 +213,11 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 2 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryCacheMissCount(), 1 );
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().resume( tx4 );
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx4 );
|
||||
List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||
.setCacheable( true ).list();
|
||||
assertEquals( r4.size(), 2 );
|
||||
tx4.commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 6 );
|
||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
||||
|
@ -232,10 +228,10 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 3 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryCacheMissCount(), 1 );
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.createQuery( "delete from Item" ).executeUpdate();
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -244,7 +240,7 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
comment = "write locks block readers"
|
||||
)
|
||||
public void testConcurrentCachedDirtyQueries() throws Exception {
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Map foo = new HashMap();
|
||||
foo.put( "name", "Foo" );
|
||||
|
@ -254,7 +250,7 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
bar.put( "name", "Bar" );
|
||||
bar.put( "description", "a small bar" );
|
||||
s.persist( "Item", bar );
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
synchronized ( this ) {
|
||||
wait( 1000 );
|
||||
|
@ -264,11 +260,11 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
sessionFactory().evictEntity( "Item" );
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s4 = openSession();
|
||||
Transaction tx4 = sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().suspend();
|
||||
Transaction tx4 = TestingJtaBootstrap.INSTANCE.getTransactionManager().suspend();
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s1 = openSession();
|
||||
List r1 = s1.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||
.setCacheable( true ).list();
|
||||
|
@ -276,14 +272,14 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
foo = ( Map ) r1.get( 0 );
|
||||
foo.put( "description", "a big red foo" );
|
||||
s1.flush();
|
||||
Transaction tx1 = sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().suspend();
|
||||
Transaction tx1 = TestingJtaBootstrap.INSTANCE.getTransactionManager().suspend();
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s2 = openSession();
|
||||
List r2 = s2.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||
.setCacheable( true ).list();
|
||||
assertEquals( r2.size(), 2 );
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 0 );
|
||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
||||
|
@ -294,14 +290,14 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 0 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryCacheMissCount(), 2 );
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().resume( tx1 );
|
||||
tx1.commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx1 );
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s3 = openSession();
|
||||
s3.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||
.setCacheable( true ).list();
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 0 );
|
||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
||||
|
@ -312,11 +308,11 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 0 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryCacheMissCount(), 3 );
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().resume( tx4 );
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx4 );
|
||||
List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||
.setCacheable( true ).list();
|
||||
assertEquals( r4.size(), 2 );
|
||||
tx4.commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 2 );
|
||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
||||
|
@ -327,43 +323,43 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 1 );
|
||||
assertEquals( sessionFactory().getStatistics().getQueryCacheMissCount(), 3 );
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.createQuery( "delete from Item" ).executeUpdate();
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCMT() throws Exception {
|
||||
sessionFactory().getStatistics().clear();
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
assertFalse( s.isOpen() );
|
||||
|
||||
assertEquals( sessionFactory().getStatistics().getFlushCount(), 0 );
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().rollback();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
|
||||
assertFalse( s.isOpen() );
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.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 );
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
assertFalse( s.isOpen() );
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
item = ( Map ) s.createQuery( "from Item" ).uniqueResult();
|
||||
assertNotNull( item );
|
||||
s.delete( item );
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
assertFalse( s.isOpen() );
|
||||
|
||||
assertEquals( sessionFactory().getStatistics().getTransactionCount(), 4 );
|
||||
|
@ -375,19 +371,19 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 1 );
|
||||
assertEquals( sessionFactory().getStatistics().getFlushCount(), 2 );
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.createQuery( "delete from Item" ).executeUpdate();
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrentSession() throws Exception {
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = sessionFactory().getCurrentSession();
|
||||
Session s2 = sessionFactory().getCurrentSession();
|
||||
assertSame( s, s2 );
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
assertFalse( s.isOpen() );
|
||||
|
||||
// TODO : would be nice to automate-test that the SF internal map actually gets cleaned up
|
||||
|
@ -396,7 +392,7 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testCurrentSessionWithIterate() throws Exception {
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Map item1 = new HashMap();
|
||||
item1.put( "name", "Item - 1" );
|
||||
|
@ -407,11 +403,11 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
item2.put( "name", "Item - 2" );
|
||||
item2.put( "description", "The second item" );
|
||||
s.persist( "Item", item2 );
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
// First, test iterating the partial iterator; iterate to past
|
||||
// the first, but not the second, item
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = sessionFactory().getCurrentSession();
|
||||
Iterator itr = s.createQuery( "from Item" ).iterate();
|
||||
if ( !itr.hasNext() ) {
|
||||
|
@ -421,10 +417,10 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
if ( !itr.hasNext() ) {
|
||||
fail( "Only one result in iterator" );
|
||||
}
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
// Next, iterate the entire result
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = sessionFactory().getCurrentSession();
|
||||
itr = s.createQuery( "from Item" ).iterate();
|
||||
if ( !itr.hasNext() ) {
|
||||
|
@ -433,17 +429,17 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
while ( itr.hasNext() ) {
|
||||
itr.next();
|
||||
}
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.createQuery( "delete from Item" ).executeUpdate();
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrentSessionWithScroll() throws Exception {
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = sessionFactory().getCurrentSession();
|
||||
Map item1 = new HashMap();
|
||||
item1.put( "name", "Item - 1" );
|
||||
|
@ -454,51 +450,51 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
item2.put( "name", "Item - 2" );
|
||||
item2.put( "description", "The second item" );
|
||||
s.persist( "Item", item2 );
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
// First, test partially scrolling the result with out closing
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = sessionFactory().getCurrentSession();
|
||||
ScrollableResults results = s.createQuery( "from Item" ).scroll();
|
||||
results.next();
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
// Next, test partially scrolling the result with closing
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = sessionFactory().getCurrentSession();
|
||||
results = s.createQuery( "from Item" ).scroll();
|
||||
results.next();
|
||||
results.close();
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
// Next, scroll the entire result (w/o closing)
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = sessionFactory().getCurrentSession();
|
||||
results = s.createQuery( "from Item" ).scroll();
|
||||
while ( results.next() ) {
|
||||
// do nothing
|
||||
}
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
// Next, scroll the entire result (closing)
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = sessionFactory().getCurrentSession();
|
||||
results = s.createQuery( "from Item" ).scroll();
|
||||
while ( results.next() ) {
|
||||
// do nothing
|
||||
}
|
||||
results.close();
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = sessionFactory().getCurrentSession();
|
||||
s.createQuery( "delete from Item" ).executeUpdate();
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAggressiveReleaseWithConnectionRetreival() throws Exception {
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
Session s = openSession();
|
||||
Map item1 = new HashMap();
|
||||
item1.put( "name", "Item - 1" );
|
||||
|
@ -509,20 +505,20 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
|||
item2.put( "name", "Item - 2" );
|
||||
item2.put( "description", "The second item" );
|
||||
s.save( "Item", item2 );
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
try {
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = sessionFactory().getCurrentSession();
|
||||
s.createQuery( "from Item" ).scroll().next();
|
||||
s.connection();
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
finally {
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
s = openSession();
|
||||
s.createQuery( "delete from Item" ).executeUpdate();
|
||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,14 +30,6 @@ import java.sql.Statement;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
|
||||
import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
|
||||
|
@ -46,16 +38,23 @@ import org.hibernate.engine.transaction.spi.TransactionContext;
|
|||
import org.hibernate.engine.transaction.spi.TransactionImplementor;
|
||||
import org.hibernate.service.internal.ServiceProxy;
|
||||
import org.hibernate.service.internal.ServiceRegistryImpl;
|
||||
import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator;
|
||||
import org.hibernate.service.jta.platform.spi.JtaPlatform;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.env.ConnectionProviderBuilder;
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.test.common.JournalingTransactionObserver;
|
||||
import org.hibernate.test.common.TransactionContextImpl;
|
||||
import org.hibernate.test.common.TransactionEnvironmentImpl;
|
||||
import org.hibernate.test.common.jta.AtomikosDataSourceConnectionProvider;
|
||||
import org.hibernate.test.common.jta.AtomikosJtaPlatform;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Testing transaction handling when the JTA transaction facade is the driver.
|
||||
|
@ -71,8 +70,7 @@ public class BasicDrivingTest extends BaseUnitTestCase {
|
|||
Map configValues = new HashMap();
|
||||
configValues.putAll( ConnectionProviderBuilder.getConnectionProviderProperties() );
|
||||
configValues.put( Environment.TRANSACTION_STRATEGY, JtaTransactionFactory.class.getName() );
|
||||
configValues.put( JtaPlatformInitiator.JTA_PLATFORM, AtomikosJtaPlatform.class.getName() );
|
||||
configValues.put( Environment.CONNECTION_PROVIDER, AtomikosDataSourceConnectionProvider.class.getName() );
|
||||
TestingJtaBootstrap.prepare( configValues );
|
||||
serviceRegistry = new ServiceRegistryImpl( configValues );
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ import org.hibernate.engine.transaction.spi.TransactionContext;
|
|||
import org.hibernate.engine.transaction.spi.TransactionImplementor;
|
||||
import org.hibernate.service.internal.ServiceProxy;
|
||||
import org.hibernate.service.internal.ServiceRegistryImpl;
|
||||
import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator;
|
||||
import org.hibernate.service.jta.platform.spi.JtaPlatform;
|
||||
import org.hibernate.service.spi.StandardServiceInitiators;
|
||||
|
||||
|
@ -48,13 +47,11 @@ import org.junit.After;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.testing.env.ConnectionProviderBuilder;
|
||||
import org.hibernate.test.common.JournalingTransactionObserver;
|
||||
import org.hibernate.test.common.TransactionContextImpl;
|
||||
import org.hibernate.test.common.TransactionEnvironmentImpl;
|
||||
import org.hibernate.test.common.jta.AtomikosDataSourceConnectionProvider;
|
||||
import org.hibernate.test.common.jta.AtomikosJtaPlatform;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -73,10 +70,9 @@ public class ManagedDrivingTest extends BaseUnitTestCase {
|
|||
@SuppressWarnings( {"unchecked"})
|
||||
public void setUp() throws Exception {
|
||||
Map configValues = new HashMap();
|
||||
configValues.putAll( ConnectionProviderBuilder.getConnectionProviderProperties() );
|
||||
TestingJtaBootstrap.prepare( configValues );
|
||||
// configValues.putAll( ConnectionProviderBuilder.getConnectionProviderProperties() );
|
||||
configValues.put( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
|
||||
configValues.put( JtaPlatformInitiator.JTA_PLATFORM, AtomikosJtaPlatform.class.getName() );
|
||||
configValues.put( Environment.CONNECTION_PROVIDER, AtomikosDataSourceConnectionProvider.class.getName() );
|
||||
|
||||
serviceRegistry = new ServiceRegistryImpl( StandardServiceInitiators.LIST, configValues );
|
||||
}
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.testing.tm;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.service.spi.Stoppable;
|
||||
import org.hibernate.service.spi.UnknownUnwrapTypeException;
|
||||
|
||||
import org.hibernate.testing.env.ConnectionProviderBuilder;
|
||||
|
||||
/**
|
||||
* A {@link ConnectionProvider} implementation adding JTA-style transactionality
|
||||
* around the returned connections using the {@link SimpleJtaTransactionManagerImpl}.
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ConnectionProviderImpl implements ConnectionProvider {
|
||||
private static ConnectionProvider actualConnectionProvider = ConnectionProviderBuilder.buildConnectionProvider();
|
||||
|
||||
private boolean isTransactional;
|
||||
|
||||
public static ConnectionProvider getActualConnectionProvider() {
|
||||
return actualConnectionProvider;
|
||||
}
|
||||
|
||||
public void configure(Properties props) throws HibernateException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnwrappableAs(Class unwrapType) {
|
||||
return ConnectionProviderImpl.class.isAssignableFrom( unwrapType ) ||
|
||||
ConnectionProvider.class.isAssignableFrom( unwrapType ) ||
|
||||
getActualConnectionProvider().getClass().isAssignableFrom( unwrapType );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public <T> T unwrap(Class<T> unwrapType) {
|
||||
if ( ConnectionProviderImpl.class.isAssignableFrom( unwrapType ) ) {
|
||||
return (T) this;
|
||||
}
|
||||
else if ( ConnectionProvider.class.isAssignableFrom( unwrapType ) ||
|
||||
getActualConnectionProvider().getClass().isAssignableFrom( unwrapType ) ) {
|
||||
return (T) getActualConnectionProvider();
|
||||
}
|
||||
else {
|
||||
throw new UnknownUnwrapTypeException( unwrapType );
|
||||
}
|
||||
}
|
||||
|
||||
public Connection getConnection() throws SQLException {
|
||||
SimpleJtaTransactionImpl currentTransaction = SimpleJtaTransactionManagerImpl.getInstance().getCurrentTransaction();
|
||||
if ( currentTransaction == null ) {
|
||||
isTransactional = false;
|
||||
return actualConnectionProvider.getConnection();
|
||||
}
|
||||
else {
|
||||
isTransactional = true;
|
||||
Connection connection = currentTransaction.getEnlistedConnection();
|
||||
if ( connection == null ) {
|
||||
connection = actualConnectionProvider.getConnection();
|
||||
currentTransaction.enlistConnection( connection );
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
|
||||
public void closeConnection(Connection conn) throws SQLException {
|
||||
if ( !isTransactional ) {
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void close() throws HibernateException {
|
||||
if ( actualConnectionProvider instanceof Stoppable ) {
|
||||
( ( Stoppable ) actualConnectionProvider ).stop();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean supportsAggressiveRelease() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.testing.tm;
|
||||
import java.util.Properties;
|
||||
import javax.transaction.Transaction;
|
||||
import javax.transaction.TransactionManager;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.transaction.TransactionManagerLookup;
|
||||
|
||||
/**
|
||||
* TransactionManagerLookupImpl implementation
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class TransactionManagerLookupImpl implements TransactionManagerLookup {
|
||||
public TransactionManager getTransactionManager(Properties props) throws HibernateException {
|
||||
return SimpleJtaTransactionManagerImpl.getInstance();
|
||||
}
|
||||
|
||||
public String getUserTransactionName() {
|
||||
throw new UnsupportedOperationException( "jndi currently not implemented for these tests" );
|
||||
}
|
||||
|
||||
public Object getTransactionIdentifier(Transaction transaction) {
|
||||
return transaction;
|
||||
}
|
||||
}
|
|
@ -24,4 +24,9 @@ test {
|
|||
useTestNG() {
|
||||
suites 'src/test/resources/testng.xml'
|
||||
}
|
||||
}
|
||||
|
||||
// temporary
|
||||
test {
|
||||
ignoreFailures = true
|
||||
}
|
|
@ -22,10 +22,19 @@
|
|||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.envers.test;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Optional;
|
||||
import org.testng.annotations.Parameters;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.ejb.AvailableSettings;
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.envers.AuditReader;
|
||||
|
@ -37,13 +46,9 @@ import org.hibernate.event.PostInsertEventListener;
|
|||
import org.hibernate.event.PostUpdateEventListener;
|
||||
import org.hibernate.event.PreCollectionRemoveEventListener;
|
||||
import org.hibernate.event.PreCollectionUpdateEventListener;
|
||||
import org.hibernate.testing.tm.ConnectionProviderImpl;
|
||||
import org.hibernate.testing.tm.TransactionManagerLookupImpl;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Optional;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.hibernate.service.internal.ServiceRegistryImpl;
|
||||
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
|
@ -53,6 +58,7 @@ public abstract class AbstractEntityTest {
|
|||
private EntityManager entityManager;
|
||||
private AuditReader auditReader;
|
||||
private Ejb3Configuration cfg;
|
||||
private ServiceRegistryImpl serviceRegistry;
|
||||
private boolean audited;
|
||||
|
||||
public abstract void configure(Ejb3Configuration cfg);
|
||||
|
@ -99,17 +105,22 @@ public abstract class AbstractEntityTest {
|
|||
initListeners();
|
||||
}
|
||||
|
||||
cfg.configure("hibernate.test.cfg.xml");
|
||||
cfg.configure( "hibernate.test.cfg.xml" );
|
||||
|
||||
if (auditStrategy != null && !"".equals(auditStrategy)) {
|
||||
cfg.setProperty("org.hibernate.envers.audit_strategy", auditStrategy);
|
||||
}
|
||||
|
||||
// Separate database for each test class
|
||||
cfg.setProperty("hibernate.connection.url", "jdbc:h2:mem:" + this.getClass().getName());
|
||||
cfg.setProperty( Environment.URL, "jdbc:h2:mem:" + this.getClass().getName() );
|
||||
|
||||
configure(cfg);
|
||||
emf = cfg.buildEntityManagerFactory();
|
||||
configure( cfg );
|
||||
|
||||
cfg.configure( cfg.getHibernateConfiguration().getProperties() );
|
||||
|
||||
serviceRegistry = new ServiceRegistryImpl( cfg.getProperties() );
|
||||
|
||||
emf = cfg.buildEntityManagerFactory( serviceRegistry );
|
||||
|
||||
newEntityManager();
|
||||
}
|
||||
|
@ -118,6 +129,7 @@ public abstract class AbstractEntityTest {
|
|||
public void close() {
|
||||
closeEntityManager();
|
||||
emf.close();
|
||||
serviceRegistry.destroy();
|
||||
}
|
||||
|
||||
public EntityManager getEntityManager() {
|
||||
|
@ -132,9 +144,10 @@ public abstract class AbstractEntityTest {
|
|||
return cfg;
|
||||
}
|
||||
|
||||
protected void addJTAConfig(Ejb3Configuration cfg) {
|
||||
cfg.setProperty("connection.provider_class", ConnectionProviderImpl.class.getName());
|
||||
cfg.setProperty(Environment.TRANSACTION_MANAGER_STRATEGY, TransactionManagerLookupImpl.class.getName());
|
||||
cfg.setProperty(AvailableSettings.TRANSACTION_TYPE, "JTA");
|
||||
protected void addJTAConfig(Ejb3Configuration cfg) {
|
||||
TestingJtaBootstrap.prepare( cfg.getProperties() );
|
||||
cfg.getProperties().remove( Environment.USER );
|
||||
cfg.getProperties().remove( Environment.PASS );
|
||||
cfg.setProperty( AvailableSettings.TRANSACTION_TYPE, "JTA" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public abstract class AbstractOneSessionTest {
|
|||
|
||||
this.initMappings();
|
||||
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(Environment.getProperties());
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() );
|
||||
sessionFactory = config.buildSessionFactory( serviceRegistry );
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public abstract class AbstractSessionTest {
|
|||
|
||||
this.initMappings();
|
||||
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() );
|
||||
sessionFactory = config.buildSessionFactory( serviceRegistry );
|
||||
}
|
||||
|
||||
|
|
|
@ -22,13 +22,17 @@
|
|||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.envers.test.integration.jta;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.entities.StrTestEntity;
|
||||
import org.hibernate.envers.test.integration.reventity.ExceptionListenerRevEntity;
|
||||
import org.hibernate.testing.tm.SimpleJtaTransactionManagerImpl;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
|
||||
/**
|
||||
* Same as {@link org.hibernate.envers.test.integration.reventity.ExceptionListener}, but in a JTA environment.
|
||||
|
@ -44,7 +48,7 @@ public class JtaExceptionListener extends AbstractEntityTest {
|
|||
|
||||
@Test(expectedExceptions = RuntimeException.class)
|
||||
public void testTransactionRollback() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
|
||||
// Trying to persist an entity - however the listener should throw an exception, so the entity
|
||||
// shouldn't be persisted
|
||||
|
@ -54,12 +58,12 @@ public class JtaExceptionListener extends AbstractEntityTest {
|
|||
StrTestEntity te = new StrTestEntity("x");
|
||||
em.persist(te);
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testTransactionRollback")
|
||||
public void testDataNotPersisted() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
|
||||
// Checking if the entity became persisted
|
||||
newEntityManager();
|
||||
|
@ -67,6 +71,6 @@ public class JtaExceptionListener extends AbstractEntityTest {
|
|||
Long count = (Long) em.createQuery("select count(s) from StrTestEntity s where s.str = 'x'").getSingleResult();
|
||||
assert count == 0l;
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package org.hibernate.envers.test.integration.jta;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.entities.IntTestEntity;
|
||||
import org.hibernate.testing.tm.SimpleJtaTransactionManagerImpl;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
|
||||
/**
|
||||
* Same as {@link org.hibernate.envers.test.integration.basic.Simple}, but in a JTA environment.
|
||||
|
@ -22,7 +26,7 @@ public class JtaTransaction extends AbstractEntityTest {
|
|||
|
||||
@Test
|
||||
public void initData() throws Exception {
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
|
||||
newEntityManager();
|
||||
EntityManager em = getEntityManager();
|
||||
|
@ -31,18 +35,18 @@ public class JtaTransaction extends AbstractEntityTest {
|
|||
em.persist(ite);
|
||||
id1 = ite.getId();
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
|
||||
//
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||
|
||||
newEntityManager();
|
||||
em = getEntityManager();
|
||||
ite = em.find(IntTestEntity.class, id1);
|
||||
ite.setNumber(20);
|
||||
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "initData")
|
||||
|
|
|
@ -26,4 +26,8 @@ apply plugin: 'java'
|
|||
dependencies {
|
||||
compile( project( ':hibernate-core' ) )
|
||||
compile( [group: 'junit', name: 'junit', version: '4.8.2'] )
|
||||
compile([group: 'com.experlog', name: 'xapool', version: '1.5.0'])
|
||||
compile([group: 'org.jboss.jbossts', name: 'jbossjta', version: '4.14.0.Final']) {
|
||||
transitive=false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.testing.jta;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import javax.transaction.TransactionManager;
|
||||
import javax.transaction.UserTransaction;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean;
|
||||
import com.arjuna.ats.arjuna.common.arjPropertyManager;
|
||||
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.Environment;
|
||||
import org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl;
|
||||
import org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform;
|
||||
import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator;
|
||||
|
||||
/**
|
||||
* Manages the {@link TransactionManager}, {@link UserTransaction} and {@link DataSource} instances used for testing.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@SuppressWarnings( {"UnusedDeclaration", "unchecked"})
|
||||
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();
|
||||
StandardXADataSource dataSource = new StandardXADataSource();
|
||||
dataSource.setTransactionManager( com.arjuna.ats.jta.TransactionManager.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 ) );
|
||||
final String isolationString = environmentProperties.getProperty( Environment.ISOLATION );
|
||||
if ( isolationString != null ) {
|
||||
dataSource.setTransactionIsolation( Integer.valueOf( isolationString ) );
|
||||
}
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
public TransactionManager getTransactionManager() {
|
||||
return transactionManager;
|
||||
}
|
||||
|
||||
public UserTransaction getUserTransaction() {
|
||||
return userTransaction;
|
||||
}
|
||||
|
||||
public DataSource getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
public static void prepare(Map configValues) {
|
||||
configValues.put( JtaPlatformInitiator.JTA_PLATFORM, new JBossStandAloneJtaPlatform() );
|
||||
configValues.put( Environment.CONNECTION_PROVIDER, DatasourceConnectionProviderImpl.class.getName() );
|
||||
configValues.put( Environment.DATASOURCE, INSTANCE.getDataSource() );
|
||||
}
|
||||
}
|
|
@ -23,9 +23,17 @@
|
|||
*/
|
||||
package org.hibernate.testing.junit4;
|
||||
|
||||
import javax.transaction.SystemException;
|
||||
|
||||
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.hibernate.testing.TestLogger;
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
|
||||
/**
|
||||
* The most test adapter. Applies both the {@link CustomRunner} and {@link Processor} rule.
|
||||
*
|
||||
|
@ -35,4 +43,16 @@ import org.junit.runner.RunWith;
|
|||
public abstract class BaseUnitTestCase {
|
||||
@Rule
|
||||
public Processor processor = new Processor();
|
||||
|
||||
@After
|
||||
public void releaseTransactions() {
|
||||
if ( JtaStatusHelper.isActive( TestingJtaBootstrap.INSTANCE.getTransactionManager() ) ) {
|
||||
TestLogger.LOG.warn( "Cleaning up unfinished transaction" );
|
||||
try {
|
||||
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
|
||||
}
|
||||
catch (SystemException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue