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
|
install.dependsOn installTesting
|
||||||
uploadTesting.dependsOn installTesting
|
uploadTesting.dependsOn installTesting
|
||||||
|
|
||||||
// temporary
|
|
||||||
test {
|
|
||||||
ignoreFailures = true
|
|
||||||
}
|
|
||||||
|
|
|
@ -145,7 +145,9 @@ public class JdbcServicesImpl implements JdbcServices, Configurable {
|
||||||
LOG.unableToObtainConnectionMetadata(sqle.getMessage());
|
LOG.unableToObtainConnectionMetadata(sqle.getMessage());
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
connectionProvider.closeConnection( conn );
|
if ( conn != null ) {
|
||||||
|
connectionProvider.closeConnection( conn );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( SQLException sqle ) {
|
catch ( SQLException sqle ) {
|
||||||
|
|
|
@ -28,30 +28,27 @@ import org.hibernate.service.jta.platform.spi.JtaPlatformException;
|
||||||
|
|
||||||
import javax.transaction.TransactionManager;
|
import javax.transaction.TransactionManager;
|
||||||
import javax.transaction.UserTransaction;
|
import javax.transaction.UserTransaction;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a standalone JTA transaction manager for JBoss Transactions
|
* 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 Emmanuel Bernard
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class JBossStandAloneJtaPlatform extends AbstractJtaPlatform {
|
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 );
|
private final JtaSynchronizationStrategy synchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TransactionManager locateTransactionManager() {
|
protected TransactionManager locateTransactionManager() {
|
||||||
try {
|
try {
|
||||||
final Class propertyManagerClass = serviceRegistry()
|
final Class jbossTmClass = serviceRegistry()
|
||||||
.getService( ClassLoaderService.class )
|
.getService( ClassLoaderService.class )
|
||||||
.classForName( PROPERTY_MANAGER_CLASS_NAME );
|
.classForName( JBOSS_TM_CLASS_NAME );
|
||||||
final Method getJTAEnvironmentBeanMethod = propertyManagerClass.getMethod( "getJTAEnvironmentBean" );
|
return (TransactionManager) jbossTmClass.getMethod( "transactionManager" ).invoke( null );
|
||||||
final Object jtaEnvironmentBean = getJTAEnvironmentBeanMethod.invoke( null );
|
|
||||||
final Method getTransactionManagerMethod = jtaEnvironmentBean.getClass().getMethod( "getTransactionManager" );
|
|
||||||
return ( TransactionManager ) getTransactionManagerMethod.invoke( jtaEnvironmentBean );
|
|
||||||
}
|
}
|
||||||
catch ( Exception e ) {
|
catch ( Exception e ) {
|
||||||
throw new JtaPlatformException( "Could not obtain JBoss Transactions transaction manager instance", e );
|
throw new JtaPlatformException( "Could not obtain JBoss Transactions transaction manager instance", e );
|
||||||
|
@ -60,7 +57,15 @@ public class JBossStandAloneJtaPlatform extends AbstractJtaPlatform {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected UserTransaction locateUserTransaction() {
|
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
|
@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.impl.SessionImpl;
|
||||||
import org.hibernate.internal.util.SerializationHelper;
|
import org.hibernate.internal.util.SerializationHelper;
|
||||||
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
|
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.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.test.common.jta.AtomikosDataSourceConnectionProvider;
|
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||||
import org.hibernate.test.common.jta.AtomikosJtaPlatform;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
@ -38,8 +35,7 @@ public class AggressiveReleaseTest extends ConnectionManagementTestCase {
|
||||||
@Override
|
@Override
|
||||||
public void configure(Configuration cfg) {
|
public void configure(Configuration cfg) {
|
||||||
super.configure( cfg );
|
super.configure( cfg );
|
||||||
cfg.getProperties().put( JtaPlatformInitiator.JTA_PLATFORM, AtomikosJtaPlatform.class.getName() );
|
TestingJtaBootstrap.prepare( cfg.getProperties() );
|
||||||
cfg.getProperties().put( Environment.CONNECTION_PROVIDER, AtomikosDataSourceConnectionProvider.class.getName() );
|
|
||||||
cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
|
cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
|
||||||
cfg.setProperty( Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.AFTER_STATEMENT.toString() );
|
cfg.setProperty( Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.AFTER_STATEMENT.toString() );
|
||||||
cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
|
cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
|
||||||
|
@ -57,12 +53,12 @@ public class AggressiveReleaseTest extends ConnectionManagementTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void prepare() throws Throwable {
|
protected void prepare() throws Throwable {
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void done() throws Throwable {
|
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...
|
// 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.engine.transaction.internal.jta.CMTTransactionFactory;
|
||||||
import org.hibernate.internal.util.SerializationHelper;
|
import org.hibernate.internal.util.SerializationHelper;
|
||||||
|
|
||||||
|
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
import org.hibernate.testing.tm.ConnectionProviderImpl;
|
|
||||||
import org.hibernate.testing.tm.TransactionManagerLookupImpl;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -54,8 +53,7 @@ public abstract class AbstractOperationTestCase extends BaseCoreFunctionalTestCa
|
||||||
|
|
||||||
public void configure(Configuration cfg) {
|
public void configure(Configuration cfg) {
|
||||||
super.configure( cfg );
|
super.configure( cfg );
|
||||||
cfg.setProperty( Environment.CONNECTION_PROVIDER, ConnectionProviderImpl.class.getName() );
|
TestingJtaBootstrap.prepare( cfg.getProperties() );
|
||||||
cfg.setProperty( Environment.TRANSACTION_MANAGER_STRATEGY, TransactionManagerLookupImpl.class.getName() );
|
|
||||||
cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
|
cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
|
||||||
cfg.setProperty( Environment.AUTO_CLOSE_SESSION, "true" );
|
cfg.setProperty( Environment.AUTO_CLOSE_SESSION, "true" );
|
||||||
cfg.setProperty( Environment.FLUSH_BEFORE_COMPLETION, "true" );
|
cfg.setProperty( Environment.FLUSH_BEFORE_COMPLETION, "true" );
|
||||||
|
|
|
@ -23,17 +23,20 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.nonflushedchanges;
|
package org.hibernate.test.nonflushedchanges;
|
||||||
|
|
||||||
|
import javax.transaction.RollbackException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.PersistentObjectException;
|
import org.hibernate.PersistentObjectException;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
|
||||||
import org.hibernate.exception.ConstraintViolationException;
|
import org.hibernate.exception.ConstraintViolationException;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
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.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
@ -48,7 +51,7 @@ public class CreateTest extends AbstractOperationTestCase {
|
||||||
public void testNoUpdatesOnCreateVersionedWithCollection() throws Exception {
|
public void testNoUpdatesOnCreateVersionedWithCollection() throws Exception {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
VersionedEntity root = new VersionedEntity( "root", "root" );
|
VersionedEntity root = new VersionedEntity( "root", "root" );
|
||||||
|
@ -61,17 +64,17 @@ public class CreateTest extends AbstractOperationTestCase {
|
||||||
root = ( VersionedEntity ) getOldToNewEntityRefMap().get( root );
|
root = ( VersionedEntity ) getOldToNewEntityRefMap().get( root );
|
||||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( VersionedEntity ) getOldToNewEntityRefMap().get( root );
|
root = ( VersionedEntity ) getOldToNewEntityRefMap().get( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 2 );
|
assertInsertCount( 2 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
assertDeleteCount( 0 );
|
assertDeleteCount( 0 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.delete( root );
|
s.delete( root );
|
||||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
assertDeleteCount( 2 );
|
assertDeleteCount( 2 );
|
||||||
|
@ -81,7 +84,7 @@ public class CreateTest extends AbstractOperationTestCase {
|
||||||
public void testCreateTree() throws Exception {
|
public void testCreateTree() throws Exception {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Node root = new Node( "root" );
|
Node root = new Node( "root" );
|
||||||
Node child = new Node( "child" );
|
Node child = new Node( "child" );
|
||||||
|
@ -89,12 +92,12 @@ public class CreateTest extends AbstractOperationTestCase {
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
s.persist( root );
|
s.persist( root );
|
||||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 2 );
|
assertInsertCount( 2 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
System.out.println( "getting" );
|
System.out.println( "getting" );
|
||||||
root = ( Node ) s.get( Node.class, "root" );
|
root = ( Node ) s.get( Node.class, "root" );
|
||||||
|
@ -104,7 +107,7 @@ public class CreateTest extends AbstractOperationTestCase {
|
||||||
root.addChild( child2 );
|
root.addChild( child2 );
|
||||||
System.out.println( "committing" );
|
System.out.println( "committing" );
|
||||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 3 );
|
assertInsertCount( 3 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
|
@ -115,7 +118,7 @@ public class CreateTest extends AbstractOperationTestCase {
|
||||||
public void testCreateTreeWithGeneratedId() throws Exception {
|
public void testCreateTreeWithGeneratedId() throws Exception {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
NumberedNode root = new NumberedNode( "root" );
|
NumberedNode root = new NumberedNode( "root" );
|
||||||
NumberedNode child = new NumberedNode( "child" );
|
NumberedNode child = new NumberedNode( "child" );
|
||||||
|
@ -123,12 +126,12 @@ public class CreateTest extends AbstractOperationTestCase {
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
s.persist( root );
|
s.persist( root );
|
||||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 2 );
|
assertInsertCount( 2 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( NumberedNode ) s.get( NumberedNode.class, Long.valueOf( root.getId() ) );
|
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 = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||||
root.addChild( child2 );
|
root.addChild( child2 );
|
||||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 3 );
|
assertInsertCount( 3 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
|
@ -145,7 +148,7 @@ public class CreateTest extends AbstractOperationTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateException() throws Exception {
|
public void testCreateException() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Node dupe = new Node( "dupe" );
|
Node dupe = new Node( "dupe" );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
|
@ -154,43 +157,59 @@ public class CreateTest extends AbstractOperationTestCase {
|
||||||
dupe = ( Node ) getOldToNewEntityRefMap().get( dupe );
|
dupe = ( Node ) getOldToNewEntityRefMap().get( dupe );
|
||||||
s.persist( dupe );
|
s.persist( dupe );
|
||||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
s.persist( dupe );
|
s.persist( dupe );
|
||||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
try {
|
try {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
assertFalse( true );
|
Assert.fail();
|
||||||
}
|
}
|
||||||
catch ( ConstraintViolationException cve ) {
|
catch ( ConstraintViolationException cve ) {
|
||||||
//verify that an exception is thrown!
|
//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" );
|
Node nondupe = new Node( "nondupe" );
|
||||||
nondupe.addChild( dupe );
|
nondupe.addChild( dupe );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
s.persist( nondupe );
|
s.persist( nondupe );
|
||||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
try {
|
try {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
assertFalse( true );
|
Assert.fail();
|
||||||
}
|
}
|
||||||
catch ( ConstraintViolationException cve ) {
|
catch ( ConstraintViolationException cve ) {
|
||||||
//verify that an exception is thrown!
|
//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
|
@Test
|
||||||
public void testCreateExceptionWithGeneratedId() throws Exception {
|
public void testCreateExceptionWithGeneratedId() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
NumberedNode dupe = new NumberedNode( "dupe" );
|
NumberedNode dupe = new NumberedNode( "dupe" );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
|
@ -199,9 +218,9 @@ public class CreateTest extends AbstractOperationTestCase {
|
||||||
dupe = ( NumberedNode ) getOldToNewEntityRefMap().get( dupe );
|
dupe = ( NumberedNode ) getOldToNewEntityRefMap().get( dupe );
|
||||||
s.persist( dupe );
|
s.persist( dupe );
|
||||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
try {
|
try {
|
||||||
|
@ -211,12 +230,12 @@ public class CreateTest extends AbstractOperationTestCase {
|
||||||
catch ( PersistentObjectException poe ) {
|
catch ( PersistentObjectException poe ) {
|
||||||
//verify that an exception is thrown!
|
//verify that an exception is thrown!
|
||||||
}
|
}
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().rollback();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
|
||||||
|
|
||||||
NumberedNode nondupe = new NumberedNode( "nondupe" );
|
NumberedNode nondupe = new NumberedNode( "nondupe" );
|
||||||
nondupe.addChild( dupe );
|
nondupe.addChild( dupe );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
try {
|
try {
|
||||||
|
@ -226,14 +245,14 @@ public class CreateTest extends AbstractOperationTestCase {
|
||||||
catch ( PersistentObjectException poe ) {
|
catch ( PersistentObjectException poe ) {
|
||||||
//verify that an exception is thrown!
|
//verify that an exception is thrown!
|
||||||
}
|
}
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().rollback();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
public void testBasic() throws Exception {
|
public void testBasic() throws Exception {
|
||||||
Session s;
|
Session s;
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
Employer er = new Employer();
|
Employer er = new Employer();
|
||||||
Employee ee = new Employee();
|
Employee ee = new Employee();
|
||||||
|
@ -250,9 +269,9 @@ public class CreateTest extends AbstractOperationTestCase {
|
||||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
ee = ( Employee ) getOldToNewEntityRefMap().get( ee );
|
ee = ( Employee ) getOldToNewEntityRefMap().get( ee );
|
||||||
er = ( Employer ) ee.getEmployers().iterator().next();
|
er = ( Employer ) ee.getEmployers().iterator().next();
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
er = ( Employer ) s.load( Employer.class, er.getId() );
|
er = ( Employer ) s.load( Employer.class, er.getId() );
|
||||||
assertNotNull( er );
|
assertNotNull( er );
|
||||||
|
@ -268,6 +287,6 @@ public class CreateTest extends AbstractOperationTestCase {
|
||||||
eeFromDb = ( Employee ) getOldToNewEntityRefMap().get( eeFromDb );
|
eeFromDb = ( Employee ) getOldToNewEntityRefMap().get( eeFromDb );
|
||||||
assertEquals( ee.getId(), eeFromDb.getId() );
|
assertEquals( ee.getId(), eeFromDb.getId() );
|
||||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -28,7 +28,7 @@ import org.hibernate.Session;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.testing.tm.SimpleJtaTransactionManagerImpl;
|
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* adapted this from "ops" tests version
|
* adapted this from "ops" tests version
|
||||||
|
@ -41,25 +41,25 @@ public class DeleteTest extends AbstractOperationTestCase {
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
public void testDeleteVersionedWithCollectionNoUpdate() throws Exception {
|
public void testDeleteVersionedWithCollectionNoUpdate() throws Exception {
|
||||||
// test adapted from HHH-1564...
|
// test adapted from HHH-1564...
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
VersionedEntity c = new VersionedEntity( "c1", "child-1" );
|
VersionedEntity c = new VersionedEntity( "c1", "child-1" );
|
||||||
VersionedEntity p = new VersionedEntity( "root", "root" );
|
VersionedEntity p = new VersionedEntity( "root", "root" );
|
||||||
p.getChildren().add( c );
|
p.getChildren().add( c );
|
||||||
c.setParent( p );
|
c.setParent( p );
|
||||||
s.save( p );
|
s.save( p );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
VersionedEntity loadedParent = ( VersionedEntity ) s.get( VersionedEntity.class, "root" );
|
VersionedEntity loadedParent = ( VersionedEntity ) s.get( VersionedEntity.class, "root" );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
loadedParent = ( VersionedEntity ) getOldToNewEntityRefMap().get( loadedParent );
|
loadedParent = ( VersionedEntity ) getOldToNewEntityRefMap().get( loadedParent );
|
||||||
s.delete( loadedParent );
|
s.delete( loadedParent );
|
||||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 0 );
|
assertInsertCount( 0 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
|
@ -68,20 +68,20 @@ public class DeleteTest extends AbstractOperationTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoUpdateOnDelete() throws Exception {
|
public void testNoUpdateOnDelete() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Node node = new Node( "test" );
|
Node node = new Node( "test" );
|
||||||
s.persist( node );
|
s.persist( node );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
s.delete( node );
|
s.delete( node );
|
||||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
assertInsertCount( 0 );
|
assertInsertCount( 0 );
|
||||||
|
@ -90,24 +90,24 @@ public class DeleteTest extends AbstractOperationTestCase {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
public void testNoUpdateOnDeleteWithCollection() throws Exception {
|
public void testNoUpdateOnDeleteWithCollection() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Node parent = new Node( "parent" );
|
Node parent = new Node( "parent" );
|
||||||
Node child = new Node( "child" );
|
Node child = new Node( "child" );
|
||||||
parent.getCascadingChildren().add( child );
|
parent.getCascadingChildren().add( child );
|
||||||
s.persist( parent );
|
s.persist( parent );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
parent = ( Node ) s.get( Node.class, "parent" );
|
parent = ( Node ) s.get( Node.class, "parent" );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
parent = ( Node ) getOldToNewEntityRefMap().get( parent );
|
parent = ( Node ) getOldToNewEntityRefMap().get( parent );
|
||||||
s.delete( parent );
|
s.delete( parent );
|
||||||
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
assertInsertCount( 0 );
|
assertInsertCount( 0 );
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.nonflushedchanges;
|
package org.hibernate.test.nonflushedchanges;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
|
@ -32,7 +31,7 @@ import org.hibernate.cfg.Environment;
|
||||||
|
|
||||||
import org.junit.Test;
|
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.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
@ -57,7 +56,7 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
||||||
public void testGetLoad() throws Exception {
|
public void testGetLoad() throws Exception {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Employer emp = new Employer();
|
Employer emp = new Employer();
|
||||||
s.persist( emp );
|
s.persist( emp );
|
||||||
|
@ -65,9 +64,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
||||||
Node parent = new Node( "bar" );
|
Node parent = new Node( "bar" );
|
||||||
parent.addChild( node );
|
parent.addChild( node );
|
||||||
s.persist( parent );
|
s.persist( parent );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
emp = ( Employer ) s.get( Employer.class, emp.getId() );
|
emp = ( Employer ) s.get( Employer.class, emp.getId() );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
|
@ -82,9 +81,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
||||||
assertFalse( Hibernate.isInitialized( node.getChildren() ) );
|
assertFalse( Hibernate.isInitialized( node.getChildren() ) );
|
||||||
assertFalse( Hibernate.isInitialized( node.getParent() ) );
|
assertFalse( Hibernate.isInitialized( node.getParent() ) );
|
||||||
assertNull( s.get( Node.class, "xyz" ) );
|
assertNull( s.get( Node.class, "xyz" ) );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
emp = ( Employer ) s.load( Employer.class, emp.getId() );
|
emp = ( Employer ) s.load( Employer.class, emp.getId() );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
|
@ -96,9 +95,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
||||||
node = ( Node ) getOldToNewEntityRefMap().get( node );
|
node = ( Node ) getOldToNewEntityRefMap().get( node );
|
||||||
assertEquals( node.getName(), "foo" );
|
assertEquals( node.getName(), "foo" );
|
||||||
assertFalse( Hibernate.isInitialized( node ) );
|
assertFalse( Hibernate.isInitialized( node ) );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
emp = ( Employer ) s.get( "org.hibernate.test.nonflushedchanges.Employer", emp.getId() );
|
emp = ( Employer ) s.get( "org.hibernate.test.nonflushedchanges.Employer", emp.getId() );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
|
@ -108,9 +107,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
node = ( Node ) getOldToNewEntityRefMap().get( node );
|
node = ( Node ) getOldToNewEntityRefMap().get( node );
|
||||||
assertTrue( Hibernate.isInitialized( node ) );
|
assertTrue( Hibernate.isInitialized( node ) );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
emp = ( Employer ) s.load( "org.hibernate.test.nonflushedchanges.Employer", emp.getId() );
|
emp = ( Employer ) s.load( "org.hibernate.test.nonflushedchanges.Employer", emp.getId() );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
|
@ -123,25 +122,25 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
||||||
node = ( Node ) getOldToNewEntityRefMap().get( node );
|
node = ( Node ) getOldToNewEntityRefMap().get( node );
|
||||||
assertEquals( node.getName(), "foo" );
|
assertEquals( node.getName(), "foo" );
|
||||||
assertFalse( Hibernate.isInitialized( node ) );
|
assertFalse( Hibernate.isInitialized( node ) );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertFetchCount( 0 );
|
assertFetchCount( 0 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.createQuery( "delete from Employer" ).executeUpdate();
|
s.createQuery( "delete from Employer" ).executeUpdate();
|
||||||
List list = s.createQuery( "from Node" ).list();
|
List list = s.createQuery( "from Node" ).list();
|
||||||
for ( Object aList : list ) {
|
for ( Object aList : list ) {
|
||||||
s.delete( aList );
|
s.delete( aList );
|
||||||
}
|
}
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetReadOnly() throws Exception {
|
public void testGetReadOnly() throws Exception {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Employer emp = new Employer();
|
Employer emp = new Employer();
|
||||||
s.persist( emp );
|
s.persist( emp );
|
||||||
|
@ -149,9 +148,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
||||||
Node parent = new Node( "bar" );
|
Node parent = new Node( "bar" );
|
||||||
parent.addChild( node );
|
parent.addChild( node );
|
||||||
s.persist( parent );
|
s.persist( parent );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
assertFalse( s.isDefaultReadOnly() );
|
assertFalse( s.isDefaultReadOnly() );
|
||||||
s.setDefaultReadOnly( true );
|
s.setDefaultReadOnly( true );
|
||||||
|
@ -181,9 +180,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
||||||
}
|
}
|
||||||
assertFalse( Hibernate.isInitialized( node.getParent() ) );
|
assertFalse( Hibernate.isInitialized( node.getParent() ) );
|
||||||
assertNull( s.get( Node.class, "xyz" ) );
|
assertNull( s.get( Node.class, "xyz" ) );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
assertFalse( s.isDefaultReadOnly() );
|
assertFalse( s.isDefaultReadOnly() );
|
||||||
emp = ( Employer ) s.get( "org.hibernate.test.nonflushedchanges.Employer", emp.getId() );
|
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 );
|
node = ( Node ) getOldToNewEntityRefMap().get( node );
|
||||||
assertTrue( Hibernate.isInitialized( node ) );
|
assertTrue( Hibernate.isInitialized( node ) );
|
||||||
assertTrue( s.isReadOnly( node ) );
|
assertTrue( s.isReadOnly( node ) );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertFetchCount( 0 );
|
assertFetchCount( 0 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.createQuery( "delete from Employer" ).executeUpdate();
|
s.createQuery( "delete from Employer" ).executeUpdate();
|
||||||
List list = s.createQuery( "from Node" ).list();
|
List list = s.createQuery( "from Node" ).list();
|
||||||
for ( Object aList : list ) {
|
for ( Object aList : list ) {
|
||||||
s.delete( aList );
|
s.delete( aList );
|
||||||
}
|
}
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadReadOnly() throws Exception {
|
public void testLoadReadOnly() throws Exception {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Employer emp = new Employer();
|
Employer emp = new Employer();
|
||||||
s.persist( emp );
|
s.persist( emp );
|
||||||
|
@ -228,9 +227,9 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
||||||
Node parent = new Node( "bar" );
|
Node parent = new Node( "bar" );
|
||||||
parent.addChild( node );
|
parent.addChild( node );
|
||||||
s.persist( parent );
|
s.persist( parent );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
assertFalse( s.isDefaultReadOnly() );
|
assertFalse( s.isDefaultReadOnly() );
|
||||||
s.setDefaultReadOnly( true );
|
s.setDefaultReadOnly( true );
|
||||||
|
@ -243,34 +242,34 @@ public class GetLoadTest extends AbstractOperationTestCase {
|
||||||
emp = ( Employer ) getOldToNewEntityRefMap().get( emp );
|
emp = ( Employer ) getOldToNewEntityRefMap().get( emp );
|
||||||
assertFalse( Hibernate.isInitialized( emp ) );
|
assertFalse( Hibernate.isInitialized( emp ) );
|
||||||
assertTrue( s.isReadOnly( emp ) );
|
assertTrue( s.isReadOnly( emp ) );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.createQuery( "delete from Employer" ).executeUpdate();
|
s.createQuery( "delete from Employer" ).executeUpdate();
|
||||||
List list = s.createQuery( "from Node" ).list();
|
List list = s.createQuery( "from Node" ).list();
|
||||||
for ( Object aList : list ) {
|
for ( Object aList : list ) {
|
||||||
s.delete( aList );
|
s.delete( aList );
|
||||||
}
|
}
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAfterDelete() throws Exception {
|
public void testGetAfterDelete() throws Exception {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Employer emp = new Employer();
|
Employer emp = new Employer();
|
||||||
s.persist( emp );
|
s.persist( emp );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.delete( emp );
|
s.delete( emp );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
emp = ( Employer ) s.get( Employee.class, emp.getId() );
|
emp = ( Employer ) s.get( Employee.class, emp.getId() );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertNull( "get did not return null after delete", emp );
|
assertNull( "get did not return null after delete", emp );
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,8 @@ import org.hibernate.criterion.Projections;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.testing.tm.SimpleJtaTransactionManagerImpl;
|
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,116 +28,116 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
public void testMergeStaleVersionFails() throws Exception {
|
public void testMergeStaleVersionFails() throws Exception {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
VersionedEntity entity = new VersionedEntity( "entity", "entity" );
|
VersionedEntity entity = new VersionedEntity( "entity", "entity" );
|
||||||
s.persist( entity );
|
s.persist( entity );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
// make the detached 'entity' reference stale...
|
// make the detached 'entity' reference stale...
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
VersionedEntity entity2 = ( VersionedEntity ) s.get( VersionedEntity.class, entity.getId() );
|
VersionedEntity entity2 = ( VersionedEntity ) s.get( VersionedEntity.class, entity.getId() );
|
||||||
entity2.setName( "entity-name" );
|
entity2.setName( "entity-name" );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
// now try to reattach it
|
// now try to reattach it
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
try {
|
try {
|
||||||
s.merge( entity );
|
s.merge( entity );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
entity = ( VersionedEntity ) getOldToNewEntityRefMap().get( entity );
|
entity = ( VersionedEntity ) getOldToNewEntityRefMap().get( entity );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
fail( "was expecting staleness error" );
|
fail( "was expecting staleness error" );
|
||||||
}
|
}
|
||||||
catch ( StaleObjectStateException expected ) {
|
catch ( StaleObjectStateException expected ) {
|
||||||
// expected outcome...
|
// expected outcome...
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().rollback();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"UnusedAssignment"})
|
@SuppressWarnings( {"UnusedAssignment"})
|
||||||
public void testMergeBidiPrimayKeyOneToOne() throws Exception {
|
public void testMergeBidiPrimayKeyOneToOne() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Person p = new Person( "steve" );
|
Person p = new Person( "steve" );
|
||||||
new PersonalDetails( "I have big feet", p );
|
new PersonalDetails( "I have big feet", p );
|
||||||
s.persist( p );
|
s.persist( p );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
p.getDetails().setSomePersonalDetail( p.getDetails().getSomePersonalDetail() + " and big hands too" );
|
p.getDetails().setSomePersonalDetail( p.getDetails().getSomePersonalDetail() + " and big hands too" );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
p = ( Person ) s.merge( p );
|
p = ( Person ) s.merge( p );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
p = ( Person ) getOldToNewEntityRefMap().get( p );
|
p = ( Person ) getOldToNewEntityRefMap().get( p );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 0 );
|
assertInsertCount( 0 );
|
||||||
assertUpdateCount( 1 );
|
assertUpdateCount( 1 );
|
||||||
assertDeleteCount( 0 );
|
assertDeleteCount( 0 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.delete( p );
|
s.delete( p );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"UnusedAssignment"})
|
@SuppressWarnings( {"UnusedAssignment"})
|
||||||
public void testMergeBidiForeignKeyOneToOne() throws Exception {
|
public void testMergeBidiForeignKeyOneToOne() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Person p = new Person( "steve" );
|
Person p = new Person( "steve" );
|
||||||
Address a = new Address( "123 Main", "Austin", "US", p );
|
Address a = new Address( "123 Main", "Austin", "US", p );
|
||||||
s.persist( a );
|
s.persist( a );
|
||||||
s.persist( p );
|
s.persist( p );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
p.getAddress().setStreetAddress( "321 Main" );
|
p.getAddress().setStreetAddress( "321 Main" );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
p = ( Person ) s.merge( p );
|
p = ( Person ) s.merge( p );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 0 );
|
assertInsertCount( 0 );
|
||||||
assertUpdateCount( 0 ); // no cascade
|
assertUpdateCount( 0 ); // no cascade
|
||||||
assertDeleteCount( 0 );
|
assertDeleteCount( 0 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.delete( a );
|
s.delete( a );
|
||||||
s.delete( p );
|
s.delete( p );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"UnusedAssignment"})
|
@SuppressWarnings( {"UnusedAssignment"})
|
||||||
public void testNoExtraUpdatesOnMerge() throws Exception {
|
public void testNoExtraUpdatesOnMerge() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Node node = new Node( "test" );
|
Node node = new Node( "test" );
|
||||||
s.persist( node );
|
s.persist( node );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
// node is now detached, but we have made no changes. so attempt to merge it
|
// node is now detached, but we have made no changes. so attempt to merge it
|
||||||
// into this new session; this should cause no updates...
|
// into this new session; this should cause no updates...
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
node = ( Node ) s.merge( node );
|
node = ( Node ) s.merge( node );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
assertInsertCount( 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
|
// as a control measure, now update the node while it is detached and
|
||||||
// make sure we get an update as a result...
|
// make sure we get an update as a result...
|
||||||
node.setDescription( "new description" );
|
node.setDescription( "new description" );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
node = ( Node ) s.merge( node );
|
node = ( Node ) s.merge( node );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
assertUpdateCount( 1 );
|
assertUpdateCount( 1 );
|
||||||
assertInsertCount( 0 );
|
assertInsertCount( 0 );
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
@ -160,24 +161,24 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"unchecked", "UnusedAssignment"})
|
@SuppressWarnings( {"unchecked", "UnusedAssignment"})
|
||||||
public void testNoExtraUpdatesOnMergeWithCollection() throws Exception {
|
public void testNoExtraUpdatesOnMergeWithCollection() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Node parent = new Node( "parent" );
|
Node parent = new Node( "parent" );
|
||||||
Node child = new Node( "child" );
|
Node child = new Node( "child" );
|
||||||
parent.getChildren().add( child );
|
parent.getChildren().add( child );
|
||||||
child.setParent( parent );
|
child.setParent( parent );
|
||||||
s.persist( parent );
|
s.persist( parent );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
// parent is now detached, but we have made no changes. so attempt to merge it
|
// parent is now detached, but we have made no changes. so attempt to merge it
|
||||||
// into this new session; this should cause no updates...
|
// into this new session; this should cause no updates...
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
parent = ( Node ) s.merge( parent );
|
parent = ( Node ) s.merge( parent );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
assertInsertCount( 0 );
|
assertInsertCount( 0 );
|
||||||
|
@ -187,11 +188,11 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
// make sure we get an update as a result...
|
// make sure we get an update as a result...
|
||||||
( ( Node ) parent.getChildren().iterator().next() ).setDescription( "child's new description" );
|
( ( Node ) parent.getChildren().iterator().next() ).setDescription( "child's new description" );
|
||||||
parent.addChild( new Node( "second child" ) );
|
parent.addChild( new Node( "second child" ) );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
parent = ( Node ) s.merge( parent );
|
parent = ( Node ) s.merge( parent );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
assertUpdateCount( 1 );
|
assertUpdateCount( 1 );
|
||||||
assertInsertCount( 1 );
|
assertInsertCount( 1 );
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
@ -202,22 +203,22 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"UnusedAssignment"})
|
@SuppressWarnings( {"UnusedAssignment"})
|
||||||
public void testNoExtraUpdatesOnMergeVersioned() throws Exception {
|
public void testNoExtraUpdatesOnMergeVersioned() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
VersionedEntity entity = new VersionedEntity( "entity", "entity" );
|
VersionedEntity entity = new VersionedEntity( "entity", "entity" );
|
||||||
s.persist( entity );
|
s.persist( entity );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
// entity is now detached, but we have made no changes. so attempt to merge it
|
// entity is now detached, but we have made no changes. so attempt to merge it
|
||||||
// into this new session; this should cause no updates...
|
// into this new session; this should cause no updates...
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
VersionedEntity mergedEntity = ( VersionedEntity ) s.merge( entity );
|
VersionedEntity mergedEntity = ( VersionedEntity ) s.merge( entity );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
mergedEntity = ( VersionedEntity ) getOldToNewEntityRefMap().get( mergedEntity );
|
mergedEntity = ( VersionedEntity ) getOldToNewEntityRefMap().get( mergedEntity );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
assertInsertCount( 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
|
// as a control measure, now update the node while it is detached and
|
||||||
// make sure we get an update as a result...
|
// make sure we get an update as a result...
|
||||||
entity.setName( "new name" );
|
entity.setName( "new name" );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
entity = ( VersionedEntity ) s.merge( entity );
|
entity = ( VersionedEntity ) s.merge( entity );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
assertUpdateCount( 1 );
|
assertUpdateCount( 1 );
|
||||||
assertInsertCount( 0 );
|
assertInsertCount( 0 );
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
@ -243,25 +244,25 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"unchecked", "UnusedAssignment"})
|
@SuppressWarnings( {"unchecked", "UnusedAssignment"})
|
||||||
public void testNoExtraUpdatesOnMergeVersionedWithCollection() throws Exception {
|
public void testNoExtraUpdatesOnMergeVersionedWithCollection() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
VersionedEntity parent = new VersionedEntity( "parent", "parent" );
|
VersionedEntity parent = new VersionedEntity( "parent", "parent" );
|
||||||
VersionedEntity child = new VersionedEntity( "child", "child" );
|
VersionedEntity child = new VersionedEntity( "child", "child" );
|
||||||
parent.getChildren().add( child );
|
parent.getChildren().add( child );
|
||||||
child.setParent( parent );
|
child.setParent( parent );
|
||||||
s.persist( parent );
|
s.persist( parent );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
// parent is now detached, but we have made no changes. so attempt to merge it
|
// parent is now detached, but we have made no changes. so attempt to merge it
|
||||||
// into this new session; this should cause no updates...
|
// into this new session; this should cause no updates...
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
VersionedEntity mergedParent = ( VersionedEntity ) s.merge( parent );
|
VersionedEntity mergedParent = ( VersionedEntity ) s.merge( parent );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
mergedParent = ( VersionedEntity ) getOldToNewEntityRefMap().get( mergedParent );
|
mergedParent = ( VersionedEntity ) getOldToNewEntityRefMap().get( mergedParent );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
assertInsertCount( 0 );
|
assertInsertCount( 0 );
|
||||||
|
@ -274,12 +275,12 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
// make sure we get an update as a result...
|
// make sure we get an update as a result...
|
||||||
mergedParent.setName( "new name" );
|
mergedParent.setName( "new name" );
|
||||||
mergedParent.getChildren().add( new VersionedEntity( "child2", "new child" ) );
|
mergedParent.getChildren().add( new VersionedEntity( "child2", "new child" ) );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
parent = ( VersionedEntity ) s.merge( mergedParent );
|
parent = ( VersionedEntity ) s.merge( mergedParent );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
parent = ( VersionedEntity ) getOldToNewEntityRefMap().get( parent );
|
parent = ( VersionedEntity ) getOldToNewEntityRefMap().get( parent );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
assertUpdateCount( 1 );
|
assertUpdateCount( 1 );
|
||||||
assertInsertCount( 1 );
|
assertInsertCount( 1 );
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
@ -290,20 +291,20 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"unchecked", "UnusedAssignment"})
|
@SuppressWarnings( {"unchecked", "UnusedAssignment"})
|
||||||
public void testNoExtraUpdatesOnPersistentMergeVersionedWithCollection() throws Exception {
|
public void testNoExtraUpdatesOnPersistentMergeVersionedWithCollection() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
VersionedEntity parent = new VersionedEntity( "parent", "parent" );
|
VersionedEntity parent = new VersionedEntity( "parent", "parent" );
|
||||||
VersionedEntity child = new VersionedEntity( "child", "child" );
|
VersionedEntity child = new VersionedEntity( "child", "child" );
|
||||||
parent.getChildren().add( child );
|
parent.getChildren().add( child );
|
||||||
child.setParent( parent );
|
child.setParent( parent );
|
||||||
s.persist( parent );
|
s.persist( parent );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
// parent is now detached, but we have made no changes. so attempt to merge it
|
// parent is now detached, but we have made no changes. so attempt to merge it
|
||||||
// into this new session; this should cause no updates...
|
// into this new session; this should cause no updates...
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
// load parent so that merge will follow entityIsPersistent path
|
// load parent so that merge will follow entityIsPersistent path
|
||||||
VersionedEntity persistentParent = ( VersionedEntity ) s.get( VersionedEntity.class, parent.getId() );
|
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
|
VersionedEntity mergedParent = ( VersionedEntity ) s.merge( persistentParent ); // <-- This merge leads to failure
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
mergedParent = ( VersionedEntity ) getOldToNewEntityRefMap().get( mergedParent );
|
mergedParent = ( VersionedEntity ) getOldToNewEntityRefMap().get( mergedParent );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
assertInsertCount( 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
|
// as a control measure, now update the node once it is loaded and
|
||||||
// make sure we get an update as a result...
|
// make sure we get an update as a result...
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
persistentParent = ( VersionedEntity ) s.get( VersionedEntity.class, parent.getId() );
|
persistentParent = ( VersionedEntity ) s.get( VersionedEntity.class, parent.getId() );
|
||||||
persistentParent.setName( "new name" );
|
persistentParent.setName( "new name" );
|
||||||
|
@ -336,7 +337,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
persistentParent = ( VersionedEntity ) getOldToNewEntityRefMap().get( persistentParent );
|
persistentParent = ( VersionedEntity ) getOldToNewEntityRefMap().get( persistentParent );
|
||||||
persistentParent = ( VersionedEntity ) s.merge( persistentParent );
|
persistentParent = ( VersionedEntity ) s.merge( persistentParent );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
assertUpdateCount( 1 );
|
assertUpdateCount( 1 );
|
||||||
assertInsertCount( 1 );
|
assertInsertCount( 1 );
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
@ -346,7 +347,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistThenMergeInSameTxnWithVersion() throws Exception {
|
public void testPersistThenMergeInSameTxnWithVersion() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
VersionedEntity entity = new VersionedEntity( "test", "test" );
|
VersionedEntity entity = new VersionedEntity( "test", "test" );
|
||||||
s.persist( entity );
|
s.persist( entity );
|
||||||
|
@ -363,14 +364,14 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
// expected behavior
|
// expected behavior
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistThenMergeInSameTxnWithTimestamp() throws Exception {
|
public void testPersistThenMergeInSameTxnWithTimestamp() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
TimestampedEntity entity = new TimestampedEntity( "test", "test" );
|
TimestampedEntity entity = new TimestampedEntity( "test", "test" );
|
||||||
s.persist( entity );
|
s.persist( entity );
|
||||||
|
@ -387,7 +388,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
// expected behavior
|
// expected behavior
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
@ -398,7 +399,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
|
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Node root = new Node( "root" );
|
Node root = new Node( "root" );
|
||||||
Node child = new Node( "child" );
|
Node child = new Node( "child" );
|
||||||
|
@ -407,7 +408,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
child.addChild( grandchild );
|
child.addChild( grandchild );
|
||||||
s.merge( root );
|
s.merge( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 3 );
|
assertInsertCount( 3 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
|
@ -417,11 +418,11 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
Node grandchild2 = new Node( "grandchild2" );
|
Node grandchild2 = new Node( "grandchild2" );
|
||||||
child.addChild( grandchild2 );
|
child.addChild( grandchild2 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.merge( root );
|
s.merge( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 1 );
|
assertInsertCount( 1 );
|
||||||
assertUpdateCount( 1 );
|
assertUpdateCount( 1 );
|
||||||
|
@ -432,17 +433,17 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
child2.addChild( grandchild3 );
|
child2.addChild( grandchild3 );
|
||||||
root.addChild( child2 );
|
root.addChild( child2 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.merge( root );
|
s.merge( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 2 );
|
assertInsertCount( 2 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.delete( grandchild );
|
s.delete( grandchild );
|
||||||
s.delete( grandchild2 );
|
s.delete( grandchild2 );
|
||||||
|
@ -450,7 +451,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
s.delete( child );
|
s.delete( child );
|
||||||
s.delete( child2 );
|
s.delete( child2 );
|
||||||
s.delete( root );
|
s.delete( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,7 +460,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
public void testMergeDeepTreeWithGeneratedId() throws Exception {
|
public void testMergeDeepTreeWithGeneratedId() throws Exception {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
NumberedNode root = new NumberedNode( "root" );
|
NumberedNode root = new NumberedNode( "root" );
|
||||||
NumberedNode child = new NumberedNode( "child" );
|
NumberedNode child = new NumberedNode( "child" );
|
||||||
|
@ -469,7 +470,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
root = ( NumberedNode ) s.merge( root );
|
root = ( NumberedNode ) s.merge( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 3 );
|
assertInsertCount( 3 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
|
@ -481,12 +482,12 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
NumberedNode grandchild2 = new NumberedNode( "grandchild2" );
|
NumberedNode grandchild2 = new NumberedNode( "grandchild2" );
|
||||||
child.addChild( grandchild2 );
|
child.addChild( grandchild2 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
root = ( NumberedNode ) s.merge( root );
|
root = ( NumberedNode ) s.merge( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 1 );
|
assertInsertCount( 1 );
|
||||||
assertUpdateCount( 1 );
|
assertUpdateCount( 1 );
|
||||||
|
@ -499,23 +500,23 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
child2.addChild( grandchild3 );
|
child2.addChild( grandchild3 );
|
||||||
root.addChild( child2 );
|
root.addChild( child2 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
root = ( NumberedNode ) s.merge( root );
|
root = ( NumberedNode ) s.merge( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 2 );
|
assertInsertCount( 2 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.createQuery( "delete from NumberedNode where name like 'grand%'" ).executeUpdate();
|
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 where name like 'child%'" ).executeUpdate();
|
||||||
s.createQuery( "delete from NumberedNode" ).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 {
|
public void testMergeTree() throws Exception {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Node root = new Node( "root" );
|
Node root = new Node( "root" );
|
||||||
Node child = new Node( "child" );
|
Node child = new Node( "child" );
|
||||||
|
@ -533,7 +534,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
||||||
child = ( Node ) root.getChildren().iterator().next();
|
child = ( Node ) root.getChildren().iterator().next();
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 2 );
|
assertInsertCount( 2 );
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
@ -545,10 +546,10 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
|
|
||||||
root.addChild( secondChild );
|
root.addChild( secondChild );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.merge( root );
|
s.merge( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 1 );
|
assertInsertCount( 1 );
|
||||||
assertUpdateCount( 2 );
|
assertUpdateCount( 2 );
|
||||||
|
@ -561,7 +562,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
public void testMergeTreeWithGeneratedId() throws Exception {
|
public void testMergeTreeWithGeneratedId() throws Exception {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
NumberedNode root = new NumberedNode( "root" );
|
NumberedNode root = new NumberedNode( "root" );
|
||||||
NumberedNode child = new NumberedNode( "child" );
|
NumberedNode child = new NumberedNode( "child" );
|
||||||
|
@ -570,7 +571,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||||
child = ( NumberedNode ) root.getChildren().iterator().next();
|
child = ( NumberedNode ) root.getChildren().iterator().next();
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 2 );
|
assertInsertCount( 2 );
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
@ -582,10 +583,10 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
|
|
||||||
root.addChild( secondChild );
|
root.addChild( secondChild );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.merge( root );
|
s.merge( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 1 );
|
assertInsertCount( 1 );
|
||||||
assertUpdateCount( 2 );
|
assertUpdateCount( 2 );
|
||||||
|
@ -597,17 +598,17 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
@SuppressWarnings( {"UnusedAssignment", "UnnecessaryBoxing"})
|
@SuppressWarnings( {"UnusedAssignment", "UnnecessaryBoxing"})
|
||||||
public void testMergeManaged() throws Exception {
|
public void testMergeManaged() throws Exception {
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
NumberedNode root = new NumberedNode( "root" );
|
NumberedNode root = new NumberedNode( "root" );
|
||||||
s.persist( root );
|
s.persist( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
NumberedNode child = new NumberedNode( "child" );
|
NumberedNode child = new NumberedNode( "child" );
|
||||||
root = ( NumberedNode ) s.merge( root );
|
root = ( NumberedNode ) s.merge( root );
|
||||||
|
@ -625,7 +626,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||||
mergedChild = root.getChildren().iterator().next();
|
mergedChild = root.getChildren().iterator().next();
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 1 );
|
assertInsertCount( 1 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
|
@ -633,7 +634,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
assertEquals( root.getChildren().size(), 1 );
|
assertEquals( root.getChildren().size(), 1 );
|
||||||
assertTrue( root.getChildren().contains( mergedChild ) );
|
assertTrue( root.getChildren().contains( mergedChild ) );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
assertEquals(
|
assertEquals(
|
||||||
Long.valueOf( 2 ),
|
Long.valueOf( 2 ),
|
||||||
|
@ -642,7 +643,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
.uniqueResult()
|
.uniqueResult()
|
||||||
);
|
);
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
@ -651,19 +652,19 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
@SuppressWarnings( {"UnnecessaryBoxing"})
|
@SuppressWarnings( {"UnnecessaryBoxing"})
|
||||||
public void testMergeManagedUninitializedCollection() throws Exception {
|
public void testMergeManagedUninitializedCollection() throws Exception {
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
NumberedNode root = new NumberedNode( "root" );
|
NumberedNode root = new NumberedNode( "root" );
|
||||||
root.addChild( new NumberedNode( "child" ) );
|
root.addChild( new NumberedNode( "child" ) );
|
||||||
s.persist( root );
|
s.persist( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
NumberedNode newRoot = new NumberedNode( "root" );
|
NumberedNode newRoot = new NumberedNode( "root" );
|
||||||
newRoot.setId( root.getId() );
|
newRoot.setId( root.getId() );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
root = ( NumberedNode ) s.get( NumberedNode.class, root.getId() );
|
root = ( NumberedNode ) s.get( NumberedNode.class, root.getId() );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
|
@ -677,13 +678,13 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
assertSame( root, s.merge( newRoot ) );
|
assertSame( root, s.merge( newRoot ) );
|
||||||
assertSame( managedChildren, root.getChildren() );
|
assertSame( managedChildren, root.getChildren() );
|
||||||
assertFalse( Hibernate.isInitialized( managedChildren ) );
|
assertFalse( Hibernate.isInitialized( managedChildren ) );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 0 );
|
assertInsertCount( 0 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
assertDeleteCount( 0 );
|
assertDeleteCount( 0 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
assertEquals(
|
assertEquals(
|
||||||
Long.valueOf( 2 ),
|
Long.valueOf( 2 ),
|
||||||
|
@ -691,7 +692,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
.setProjection( Projections.rowCount() )
|
.setProjection( Projections.rowCount() )
|
||||||
.uniqueResult()
|
.uniqueResult()
|
||||||
);
|
);
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
@ -700,19 +701,19 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
@SuppressWarnings( {"UnnecessaryBoxing"})
|
@SuppressWarnings( {"UnnecessaryBoxing"})
|
||||||
public void testMergeManagedInitializedCollection() throws Exception {
|
public void testMergeManagedInitializedCollection() throws Exception {
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
NumberedNode root = new NumberedNode( "root" );
|
NumberedNode root = new NumberedNode( "root" );
|
||||||
root.addChild( new NumberedNode( "child" ) );
|
root.addChild( new NumberedNode( "child" ) );
|
||||||
s.persist( root );
|
s.persist( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
NumberedNode newRoot = new NumberedNode( "root" );
|
NumberedNode newRoot = new NumberedNode( "root" );
|
||||||
newRoot.setId( root.getId() );
|
newRoot.setId( root.getId() );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
root = ( NumberedNode ) s.get( NumberedNode.class, root.getId() );
|
root = ( NumberedNode ) s.get( NumberedNode.class, root.getId() );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
|
@ -727,13 +728,13 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
assertSame( root, s.merge( newRoot ) );
|
assertSame( root, s.merge( newRoot ) );
|
||||||
assertSame( managedChildren, root.getChildren() );
|
assertSame( managedChildren, root.getChildren() );
|
||||||
assertTrue( Hibernate.isInitialized( managedChildren ) );
|
assertTrue( Hibernate.isInitialized( managedChildren ) );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 0 );
|
assertInsertCount( 0 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
assertDeleteCount( 0 );
|
assertDeleteCount( 0 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
assertEquals(
|
assertEquals(
|
||||||
Long.valueOf( 2 ),
|
Long.valueOf( 2 ),
|
||||||
|
@ -741,7 +742,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
.setProjection( Projections.rowCount() )
|
.setProjection( Projections.rowCount() )
|
||||||
.uniqueResult()
|
.uniqueResult()
|
||||||
);
|
);
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
@ -750,7 +751,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
public void testRecursiveMergeTransient() throws Exception {
|
public void testRecursiveMergeTransient() throws Exception {
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Employer jboss = new Employer();
|
Employer jboss = new Employer();
|
||||||
Employee gavin = new Employee();
|
Employee gavin = new Employee();
|
||||||
|
@ -765,7 +766,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
assertEquals( 1, jboss.getEmployees().size() );
|
assertEquals( 1, jboss.getEmployees().size() );
|
||||||
s.clear();
|
s.clear();
|
||||||
s.merge( jboss.getEmployees().iterator().next() );
|
s.merge( jboss.getEmployees().iterator().next() );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
@ -773,25 +774,25 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"UnnecessaryBoxing", "UnusedAssignment"})
|
@SuppressWarnings( {"UnnecessaryBoxing", "UnusedAssignment"})
|
||||||
public void testDeleteAndMerge() throws Exception {
|
public void testDeleteAndMerge() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Employer jboss = new Employer();
|
Employer jboss = new Employer();
|
||||||
s.persist( jboss );
|
s.persist( jboss );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
Employer otherJboss;
|
Employer otherJboss;
|
||||||
otherJboss = ( Employer ) s.get( Employer.class, jboss.getId() );
|
otherJboss = ( Employer ) s.get( Employer.class, jboss.getId() );
|
||||||
s.delete( otherJboss );
|
s.delete( otherJboss );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
jboss.setVers( Integer.valueOf( 1 ) );
|
jboss.setVers( Integer.valueOf( 1 ) );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.merge( jboss );
|
s.merge( jboss );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
@ -800,18 +801,18 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
@SuppressWarnings( {"unchecked", "UnusedAssignment"})
|
@SuppressWarnings( {"unchecked", "UnusedAssignment"})
|
||||||
public void testMergeManyToManyWithCollectionDeference() throws Exception {
|
public void testMergeManyToManyWithCollectionDeference() throws Exception {
|
||||||
// setup base data...
|
// setup base data...
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Competition competition = new Competition();
|
Competition competition = new Competition();
|
||||||
competition.getCompetitors().add( new Competitor( "Name" ) );
|
competition.getCompetitors().add( new Competitor( "Name" ) );
|
||||||
competition.getCompetitors().add( new Competitor() );
|
competition.getCompetitors().add( new Competitor() );
|
||||||
competition.getCompetitors().add( new Competitor() );
|
competition.getCompetitors().add( new Competitor() );
|
||||||
s.persist( competition );
|
s.persist( competition );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
// the competition graph is now detached:
|
// the competition graph is now detached:
|
||||||
// 1) create a new List reference to represent the competitors
|
// 1) create a new List reference to represent the competitors
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
List newComp = new ArrayList();
|
List newComp = new ArrayList();
|
||||||
Competitor originalCompetitor = ( Competitor ) competition.getCompetitors().get( 0 );
|
Competitor originalCompetitor = ( Competitor ) competition.getCompetitors().get( 0 );
|
||||||
|
@ -825,7 +826,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
Competition competition2copy = ( Competition ) getOldToNewEntityRefMap().get( competition2 );
|
Competition competition2copy = ( Competition ) getOldToNewEntityRefMap().get( competition2 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertFalse( competition == competition2 );
|
assertFalse( competition == competition2 );
|
||||||
assertFalse( competition2 == competition2copy );
|
assertFalse( competition2 == competition2copy );
|
||||||
|
@ -833,19 +834,19 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
assertEquals( 2, competition2.getCompetitors().size() );
|
assertEquals( 2, competition2.getCompetitors().size() );
|
||||||
assertEquals( 2, competition2copy.getCompetitors().size() );
|
assertEquals( 2, competition2copy.getCompetitors().size() );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
competition = ( Competition ) s.get( Competition.class, competition.getId() );
|
competition = ( Competition ) s.get( Competition.class, competition.getId() );
|
||||||
assertEquals( 2, competition.getCompetitors().size() );
|
assertEquals( 2, competition.getCompetitors().size() );
|
||||||
s.delete( competition );
|
s.delete( competition );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
private void cleanup() throws Exception {
|
private void cleanup() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
s.createQuery( "delete from NumberedNode where parent is not null" ).executeUpdate();
|
s.createQuery( "delete from NumberedNode where parent is not null" ).executeUpdate();
|
||||||
s.createQuery( "delete from NumberedNode" ).executeUpdate();
|
s.createQuery( "delete from NumberedNode" ).executeUpdate();
|
||||||
|
@ -864,7 +865,7 @@ public class MergeTest extends AbstractOperationTestCase {
|
||||||
s.delete( employer );
|
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.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.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
@ -64,7 +64,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
public void testSaveOrUpdateDeepTree() throws Exception {
|
public void testSaveOrUpdateDeepTree() throws Exception {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Node root = new Node( "root" );
|
Node root = new Node( "root" );
|
||||||
Node child = new Node( "child" );
|
Node child = new Node( "child" );
|
||||||
|
@ -76,7 +76,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
||||||
child = ( Node ) getOldToNewEntityRefMap().get( child );
|
child = ( Node ) getOldToNewEntityRefMap().get( child );
|
||||||
grandchild = ( Node ) getOldToNewEntityRefMap().get( grandchild );
|
grandchild = ( Node ) getOldToNewEntityRefMap().get( grandchild );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 3 );
|
assertInsertCount( 3 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
|
@ -86,12 +86,12 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
Node grandchild2 = new Node( "grandchild2" );
|
Node grandchild2 = new Node( "grandchild2" );
|
||||||
child.addChild( grandchild2 );
|
child.addChild( grandchild2 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.saveOrUpdate( root );
|
s.saveOrUpdate( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 1 );
|
assertInsertCount( 1 );
|
||||||
assertUpdateCount( 1 );
|
assertUpdateCount( 1 );
|
||||||
|
@ -102,17 +102,17 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
child2.addChild( grandchild3 );
|
child2.addChild( grandchild3 );
|
||||||
root.addChild( child2 );
|
root.addChild( child2 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.saveOrUpdate( root );
|
s.saveOrUpdate( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 2 );
|
assertInsertCount( 2 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.delete( grandchild );
|
s.delete( grandchild );
|
||||||
s.delete( grandchild2 );
|
s.delete( grandchild2 );
|
||||||
|
@ -120,7 +120,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
s.delete( child );
|
s.delete( child );
|
||||||
s.delete( child2 );
|
s.delete( child2 );
|
||||||
s.delete( root );
|
s.delete( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -129,7 +129,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
boolean instrumented = FieldInterceptionHelper.isInstrumented( new NumberedNode() );
|
boolean instrumented = FieldInterceptionHelper.isInstrumented( new NumberedNode() );
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
NumberedNode root = new NumberedNode( "root" );
|
NumberedNode root = new NumberedNode( "root" );
|
||||||
NumberedNode child = new NumberedNode( "child" );
|
NumberedNode child = new NumberedNode( "child" );
|
||||||
|
@ -141,7 +141,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||||
child = ( NumberedNode ) getOldToNewEntityRefMap().get( child );
|
child = ( NumberedNode ) getOldToNewEntityRefMap().get( child );
|
||||||
grandchild = ( NumberedNode ) getOldToNewEntityRefMap().get( grandchild );
|
grandchild = ( NumberedNode ) getOldToNewEntityRefMap().get( grandchild );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 3 );
|
assertInsertCount( 3 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
|
@ -153,12 +153,12 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
NumberedNode grandchild2 = new NumberedNode( "grandchild2" );
|
NumberedNode grandchild2 = new NumberedNode( "grandchild2" );
|
||||||
child.addChild( grandchild2 );
|
child.addChild( grandchild2 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.saveOrUpdate( root );
|
s.saveOrUpdate( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 1 );
|
assertInsertCount( 1 );
|
||||||
assertUpdateCount( instrumented ? 1 : 3 );
|
assertUpdateCount( instrumented ? 1 : 3 );
|
||||||
|
@ -169,22 +169,22 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
child2.addChild( grandchild3 );
|
child2.addChild( grandchild3 );
|
||||||
root.addChild( child2 );
|
root.addChild( child2 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.saveOrUpdate( root );
|
s.saveOrUpdate( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 2 );
|
assertInsertCount( 2 );
|
||||||
assertUpdateCount( instrumented ? 0 : 4 );
|
assertUpdateCount( instrumented ? 0 : 4 );
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.createQuery( "delete from NumberedNode where name like 'grand%'" ).executeUpdate();
|
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 where name like 'child%'" ).executeUpdate();
|
||||||
s.createQuery( "delete from NumberedNode" ).executeUpdate();
|
s.createQuery( "delete from NumberedNode" ).executeUpdate();
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -192,7 +192,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
public void testSaveOrUpdateTree() throws Exception {
|
public void testSaveOrUpdateTree() throws Exception {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Node root = new Node( "root" );
|
Node root = new Node( "root" );
|
||||||
Node child = new Node( "child" );
|
Node child = new Node( "child" );
|
||||||
|
@ -201,7 +201,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
||||||
child = ( Node ) getOldToNewEntityRefMap().get( child );
|
child = ( Node ) getOldToNewEntityRefMap().get( child );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 2 );
|
assertInsertCount( 2 );
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
@ -213,20 +213,20 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
|
|
||||||
root.addChild( secondChild );
|
root.addChild( secondChild );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.saveOrUpdate( root );
|
s.saveOrUpdate( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 1 );
|
assertInsertCount( 1 );
|
||||||
assertUpdateCount( 2 );
|
assertUpdateCount( 2 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.createQuery( "delete from Node where parent is not null" ).executeUpdate();
|
s.createQuery( "delete from Node where parent is not null" ).executeUpdate();
|
||||||
s.createQuery( "delete from Node" ).executeUpdate();
|
s.createQuery( "delete from Node" ).executeUpdate();
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -234,7 +234,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
public void testSaveOrUpdateTreeWithGeneratedId() throws Exception {
|
public void testSaveOrUpdateTreeWithGeneratedId() throws Exception {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
NumberedNode root = new NumberedNode( "root" );
|
NumberedNode root = new NumberedNode( "root" );
|
||||||
NumberedNode child = new NumberedNode( "child" );
|
NumberedNode child = new NumberedNode( "child" );
|
||||||
|
@ -243,7 +243,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||||
child = ( NumberedNode ) getOldToNewEntityRefMap().get( child );
|
child = ( NumberedNode ) getOldToNewEntityRefMap().get( child );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 2 );
|
assertInsertCount( 2 );
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
@ -255,34 +255,34 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
|
|
||||||
root.addChild( secondChild );
|
root.addChild( secondChild );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.saveOrUpdate( root );
|
s.saveOrUpdate( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 1 );
|
assertInsertCount( 1 );
|
||||||
assertUpdateCount( 2 );
|
assertUpdateCount( 2 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.createQuery( "delete from NumberedNode where parent is not null" ).executeUpdate();
|
s.createQuery( "delete from NumberedNode where parent is not null" ).executeUpdate();
|
||||||
s.createQuery( "delete from NumberedNode" ).executeUpdate();
|
s.createQuery( "delete from NumberedNode" ).executeUpdate();
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"UnusedAssignment", "UnnecessaryBoxing"})
|
@SuppressWarnings( {"UnusedAssignment", "UnnecessaryBoxing"})
|
||||||
public void testSaveOrUpdateManaged() throws Exception {
|
public void testSaveOrUpdateManaged() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
NumberedNode root = new NumberedNode( "root" );
|
NumberedNode root = new NumberedNode( "root" );
|
||||||
s.saveOrUpdate( root );
|
s.saveOrUpdate( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
root = ( NumberedNode ) s.get( NumberedNode.class, root.getId() );
|
root = ( NumberedNode ) s.get( NumberedNode.class, root.getId() );
|
||||||
NumberedNode child = new NumberedNode( "child" );
|
NumberedNode child = new NumberedNode( "child" );
|
||||||
|
@ -300,12 +300,12 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||||
child = ( NumberedNode ) getOldToNewEntityRefMap().get( child );
|
child = ( NumberedNode ) getOldToNewEntityRefMap().get( child );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertTrue( root.getChildren().contains( child ) );
|
assertTrue( root.getChildren().contains( child ) );
|
||||||
assertEquals( root.getChildren().size(), 1 );
|
assertEquals( root.getChildren().size(), 1 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
assertEquals(
|
assertEquals(
|
||||||
Long.valueOf( 2 ),
|
Long.valueOf( 2 ),
|
||||||
|
@ -315,7 +315,7 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
);
|
);
|
||||||
s.delete( root );
|
s.delete( root );
|
||||||
s.delete( child );
|
s.delete( child );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -323,29 +323,31 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
public void testSaveOrUpdateGot() throws Exception {
|
public void testSaveOrUpdateGot() throws Exception {
|
||||||
boolean instrumented = FieldInterceptionHelper.isInstrumented( new NumberedNode() );
|
boolean instrumented = FieldInterceptionHelper.isInstrumented( new NumberedNode() );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
clearCounts();
|
||||||
|
|
||||||
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
NumberedNode root = new NumberedNode( "root" );
|
NumberedNode root = new NumberedNode( "root" );
|
||||||
s.saveOrUpdate( root );
|
s.saveOrUpdate( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 1 );
|
assertInsertCount( 1 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.saveOrUpdate( root );
|
s.saveOrUpdate( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 0 );
|
assertInsertCount( 0 );
|
||||||
assertUpdateCount( instrumented ? 0 : 1 );
|
assertUpdateCount( instrumented ? 0 : 1 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
root = ( NumberedNode ) s.get( NumberedNode.class, Long.valueOf( root.getId() ) );
|
root = ( NumberedNode ) s.get( NumberedNode.class, Long.valueOf( root.getId() ) );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
|
@ -353,11 +355,11 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
Hibernate.initialize( root.getChildren() );
|
Hibernate.initialize( root.getChildren() );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
root = ( NumberedNode ) getOldToNewEntityRefMap().get( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
NumberedNode child = new NumberedNode( "child" );
|
NumberedNode child = new NumberedNode( "child" );
|
||||||
root.addChild( child );
|
root.addChild( child );
|
||||||
|
@ -367,12 +369,12 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
assertTrue( Hibernate.isInitialized( root.getChildren() ) );
|
assertTrue( Hibernate.isInitialized( root.getChildren() ) );
|
||||||
child = ( NumberedNode ) root.getChildren().iterator().next();
|
child = ( NumberedNode ) root.getChildren().iterator().next();
|
||||||
assertTrue( s.contains( child ) );
|
assertTrue( s.contains( child ) );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 1 );
|
assertInsertCount( 1 );
|
||||||
assertUpdateCount( instrumented ? 0 : 1 );
|
assertUpdateCount( instrumented ? 0 : 1 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
assertEquals(
|
assertEquals(
|
||||||
s.createCriteria( NumberedNode.class )
|
s.createCriteria( NumberedNode.class )
|
||||||
|
@ -382,35 +384,37 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
);
|
);
|
||||||
s.delete( root );
|
s.delete( root );
|
||||||
s.delete( child );
|
s.delete( child );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"UnusedAssignment", "UnnecessaryBoxing"})
|
@SuppressWarnings( {"UnusedAssignment", "UnnecessaryBoxing"})
|
||||||
public void testSaveOrUpdateGotWithMutableProp() throws Exception {
|
public void testSaveOrUpdateGotWithMutableProp() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
clearCounts();
|
||||||
|
|
||||||
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Node root = new Node( "root" );
|
Node root = new Node( "root" );
|
||||||
s.saveOrUpdate( root );
|
s.saveOrUpdate( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 1 );
|
assertInsertCount( 1 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.saveOrUpdate( root );
|
s.saveOrUpdate( root );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 0 );
|
assertInsertCount( 0 );
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
root = ( Node ) s.get( Node.class, "root" );
|
root = ( Node ) s.get( Node.class, "root" );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
|
@ -418,11 +422,11 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
Hibernate.initialize( root.getChildren() );
|
Hibernate.initialize( root.getChildren() );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
Node child = new Node( "child" );
|
Node child = new Node( "child" );
|
||||||
root.addChild( child );
|
root.addChild( child );
|
||||||
|
@ -434,12 +438,12 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
root = ( Node ) getOldToNewEntityRefMap().get( root );
|
||||||
child = ( Node ) getOldToNewEntityRefMap().get( child );
|
child = ( Node ) getOldToNewEntityRefMap().get( child );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertInsertCount( 1 );
|
assertInsertCount( 1 );
|
||||||
//assertUpdateCount( 1 ); //note: will fail here if no second-level cache
|
//assertUpdateCount( 1 ); //note: will fail here if no second-level cache
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
assertEquals(
|
assertEquals(
|
||||||
Long.valueOf( 2 ),
|
Long.valueOf( 2 ),
|
||||||
|
@ -449,13 +453,13 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
);
|
);
|
||||||
s.delete( root );
|
s.delete( root );
|
||||||
s.delete( child );
|
s.delete( child );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"UnusedAssignment"})
|
@SuppressWarnings( {"UnusedAssignment"})
|
||||||
public void testEvictThenSaveOrUpdate() throws Exception {
|
public void testEvictThenSaveOrUpdate() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Node parent = new Node( "1:parent" );
|
Node parent = new Node( "1:parent" );
|
||||||
Node child = new Node( "2:child" );
|
Node child = new Node( "2:child" );
|
||||||
|
@ -464,9 +468,9 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
child.addChild( grandchild );
|
child.addChild( grandchild );
|
||||||
s.saveOrUpdate( parent );
|
s.saveOrUpdate( parent );
|
||||||
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s1 = openSession();
|
Session s1 = openSession();
|
||||||
child = ( Node ) s1.load( Node.class, "2:child" );
|
child = ( Node ) s1.load( Node.class, "2:child" );
|
||||||
s1 = applyNonFlushedChangesToNewSessionCloseOldSession( s1 );
|
s1 = applyNonFlushedChangesToNewSessionCloseOldSession( s1 );
|
||||||
|
@ -489,9 +493,9 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
assertFalse( s1.contains( child ) );
|
assertFalse( s1.contains( child ) );
|
||||||
assertTrue( s1.contains( child.getParent() ) );
|
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();
|
Session s2 = openSession();
|
||||||
try {
|
try {
|
||||||
s2.getTransaction().begin();
|
s2.getTransaction().begin();
|
||||||
|
@ -502,13 +506,13 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
// expected because parent is connected to s1
|
// expected because parent is connected to s1
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().rollback();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
s1.evict( child.getParent() );
|
s1.evict( child.getParent() );
|
||||||
assertFalse( s1.contains( child.getParent() ) );
|
assertFalse( s1.contains( child.getParent() ) );
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s2 = openSession();
|
s2 = openSession();
|
||||||
s2.saveOrUpdate( child );
|
s2.saveOrUpdate( child );
|
||||||
s2 = applyNonFlushedChangesToNewSessionCloseOldSession( s2 );
|
s2 = applyNonFlushedChangesToNewSessionCloseOldSession( s2 );
|
||||||
|
@ -527,20 +531,18 @@ public class SaveOrUpdateTest extends AbstractOperationTestCase {
|
||||||
assertTrue( Hibernate.isInitialized( child.getParent() ) );
|
assertTrue( Hibernate.isInitialized( child.getParent() ) );
|
||||||
s1 = applyNonFlushedChangesToNewSessionCloseOldSession( s1 );
|
s1 = applyNonFlushedChangesToNewSessionCloseOldSession( s1 );
|
||||||
s2 = applyNonFlushedChangesToNewSessionCloseOldSession( s2 );
|
s2 = applyNonFlushedChangesToNewSessionCloseOldSession( s2 );
|
||||||
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
javax.transaction.Transaction tx2 = SimpleJtaTransactionManagerImpl.getInstance().suspend();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx1 );
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().resume( tx1 );
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
tx1.commit();
|
// tx1.commit();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().resume( tx2 );
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
tx2.commit();
|
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.delete( s.get( Node.class, "3:grandchild" ) );
|
s.delete( s.get( Node.class, "3:grandchild" ) );
|
||||||
s.delete( s.get( Node.class, "2:child" ) );
|
s.delete( s.get( Node.class, "2:child" ) );
|
||||||
s.delete( s.get( Node.class, "1:parent" ) );
|
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.cfg.Environment;
|
||||||
import org.hibernate.criterion.Order;
|
import org.hibernate.criterion.Order;
|
||||||
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
|
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.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.testing.DialectChecks;
|
import org.hibernate.testing.DialectChecks;
|
||||||
import org.hibernate.testing.RequiresDialectFeature;
|
import org.hibernate.testing.RequiresDialectFeature;
|
||||||
|
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
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.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
@ -65,8 +62,7 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure(Configuration cfg) {
|
public void configure(Configuration cfg) {
|
||||||
cfg.getProperties().put( JtaPlatformInitiator.JTA_PLATFORM, AtomikosJtaPlatform.class.getName() );
|
TestingJtaBootstrap.prepare( cfg.getProperties() );
|
||||||
cfg.getProperties().put( Environment.CONNECTION_PROVIDER, AtomikosDataSourceConnectionProvider.class.getName() );
|
|
||||||
cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
|
cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
|
||||||
cfg.setProperty( Environment.AUTO_CLOSE_SESSION, "true" );
|
cfg.setProperty( Environment.AUTO_CLOSE_SESSION, "true" );
|
||||||
cfg.setProperty( Environment.FLUSH_BEFORE_COMPLETION, "true" );
|
cfg.setProperty( Environment.FLUSH_BEFORE_COMPLETION, "true" );
|
||||||
|
@ -87,7 +83,7 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
assertNotNull( sessionFactory().getEntityPersister( "Item" ).getCacheAccessStrategy() );
|
assertNotNull( sessionFactory().getEntityPersister( "Item" ).getCacheAccessStrategy() );
|
||||||
assertEquals( 0, sessionFactory().getStatistics().getEntityLoadCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getEntityLoadCount() );
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Map foo = new HashMap();
|
Map foo = new HashMap();
|
||||||
foo.put( "name", "Foo" );
|
foo.put( "name", "Foo" );
|
||||||
|
@ -97,46 +93,46 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
bar.put( "name", "Bar" );
|
bar.put( "name", "Bar" );
|
||||||
bar.put( "description", "a small bar" );
|
bar.put( "description", "a small bar" );
|
||||||
s.persist( "Item", bar );
|
s.persist( "Item", bar );
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
sessionFactory().evictEntity( "Item" );
|
sessionFactory().evictEntity( "Item" );
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s1 = openSession();
|
Session s1 = openSession();
|
||||||
foo = ( Map ) s1.get( "Item", "Foo" );
|
foo = ( Map ) s1.get( "Item", "Foo" );
|
||||||
//foo.put("description", "a big red foo");
|
//foo.put("description", "a big red foo");
|
||||||
//s1.flush();
|
//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();
|
Session s2 = openSession();
|
||||||
foo = ( Map ) s2.get( "Item", "Foo" );
|
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 );
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx );
|
||||||
tx1.commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
sessionFactory().evictEntity( "Item" );
|
sessionFactory().evictEntity( "Item" );
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s1 = openSession();
|
s1 = openSession();
|
||||||
s1.createCriteria( "Item" ).list();
|
s1.createCriteria( "Item" ).list();
|
||||||
//foo.put("description", "a big red foo");
|
//foo.put("description", "a big red foo");
|
||||||
//s1.flush();
|
//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 = openSession();
|
||||||
s2.createCriteria( "Item" ).list();
|
s2.createCriteria( "Item" ).list();
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().resume( tx1 );
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx );
|
||||||
tx1.commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s2 = openSession();
|
s2 = openSession();
|
||||||
s2.createCriteria( "Item" ).list();
|
s2.createCriteria( "Item" ).list();
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertEquals( 7, sessionFactory().getStatistics().getEntityLoadCount() );
|
assertEquals( 7, sessionFactory().getStatistics().getEntityLoadCount() );
|
||||||
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() );
|
||||||
|
@ -144,15 +140,15 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
assertEquals( 0, sessionFactory().getStatistics().getQueryCacheHitCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getQueryCacheHitCount() );
|
||||||
assertEquals( 0, sessionFactory().getStatistics().getQueryCacheMissCount() );
|
assertEquals( 0, sessionFactory().getStatistics().getQueryCacheMissCount() );
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.createQuery( "delete from Item" ).executeUpdate();
|
s.createQuery( "delete from Item" ).executeUpdate();
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConcurrentCachedQueries() throws Exception {
|
public void testConcurrentCachedQueries() throws Exception {
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Map foo = new HashMap();
|
Map foo = new HashMap();
|
||||||
foo.put( "name", "Foo" );
|
foo.put( "name", "Foo" );
|
||||||
|
@ -162,7 +158,7 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
bar.put( "name", "Bar" );
|
bar.put( "name", "Bar" );
|
||||||
bar.put( "description", "a small bar" );
|
bar.put( "description", "a small bar" );
|
||||||
s.persist( "Item", bar );
|
s.persist( "Item", bar );
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
synchronized ( this ) {
|
synchronized ( this ) {
|
||||||
wait( 1000 );
|
wait( 1000 );
|
||||||
|
@ -172,23 +168,23 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
sessionFactory().evictEntity( "Item" );
|
sessionFactory().evictEntity( "Item" );
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s4 = openSession();
|
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();
|
Session s1 = openSession();
|
||||||
List r1 = s1.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
List r1 = s1.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||||
.setCacheable( true ).list();
|
.setCacheable( true ).list();
|
||||||
assertEquals( r1.size(), 2 );
|
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();
|
Session s2 = openSession();
|
||||||
List r2 = s2.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
List r2 = s2.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||||
.setCacheable( true ).list();
|
.setCacheable( true ).list();
|
||||||
assertEquals( r2.size(), 2 );
|
assertEquals( r2.size(), 2 );
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 2 );
|
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 2 );
|
||||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
||||||
|
@ -199,14 +195,14 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 1 );
|
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 1 );
|
||||||
assertEquals( sessionFactory().getStatistics().getQueryCacheMissCount(), 1 );
|
assertEquals( sessionFactory().getStatistics().getQueryCacheMissCount(), 1 );
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().resume( tx1 );
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx1 );
|
||||||
tx1.commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s3 = openSession();
|
Session s3 = openSession();
|
||||||
s3.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
s3.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||||
.setCacheable( true ).list();
|
.setCacheable( true ).list();
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 4 );
|
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 4 );
|
||||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
||||||
|
@ -217,11 +213,11 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 2 );
|
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 2 );
|
||||||
assertEquals( sessionFactory().getStatistics().getQueryCacheMissCount(), 1 );
|
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" ) )
|
List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||||
.setCacheable( true ).list();
|
.setCacheable( true ).list();
|
||||||
assertEquals( r4.size(), 2 );
|
assertEquals( r4.size(), 2 );
|
||||||
tx4.commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 6 );
|
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 6 );
|
||||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
||||||
|
@ -232,10 +228,10 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 3 );
|
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 3 );
|
||||||
assertEquals( sessionFactory().getStatistics().getQueryCacheMissCount(), 1 );
|
assertEquals( sessionFactory().getStatistics().getQueryCacheMissCount(), 1 );
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.createQuery( "delete from Item" ).executeUpdate();
|
s.createQuery( "delete from Item" ).executeUpdate();
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -244,7 +240,7 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
comment = "write locks block readers"
|
comment = "write locks block readers"
|
||||||
)
|
)
|
||||||
public void testConcurrentCachedDirtyQueries() throws Exception {
|
public void testConcurrentCachedDirtyQueries() throws Exception {
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Map foo = new HashMap();
|
Map foo = new HashMap();
|
||||||
foo.put( "name", "Foo" );
|
foo.put( "name", "Foo" );
|
||||||
|
@ -254,7 +250,7 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
bar.put( "name", "Bar" );
|
bar.put( "name", "Bar" );
|
||||||
bar.put( "description", "a small bar" );
|
bar.put( "description", "a small bar" );
|
||||||
s.persist( "Item", bar );
|
s.persist( "Item", bar );
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
synchronized ( this ) {
|
synchronized ( this ) {
|
||||||
wait( 1000 );
|
wait( 1000 );
|
||||||
|
@ -264,11 +260,11 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
sessionFactory().evictEntity( "Item" );
|
sessionFactory().evictEntity( "Item" );
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s4 = openSession();
|
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();
|
Session s1 = openSession();
|
||||||
List r1 = s1.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
List r1 = s1.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||||
.setCacheable( true ).list();
|
.setCacheable( true ).list();
|
||||||
|
@ -276,14 +272,14 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
foo = ( Map ) r1.get( 0 );
|
foo = ( Map ) r1.get( 0 );
|
||||||
foo.put( "description", "a big red foo" );
|
foo.put( "description", "a big red foo" );
|
||||||
s1.flush();
|
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();
|
Session s2 = openSession();
|
||||||
List r2 = s2.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
List r2 = s2.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||||
.setCacheable( true ).list();
|
.setCacheable( true ).list();
|
||||||
assertEquals( r2.size(), 2 );
|
assertEquals( r2.size(), 2 );
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 0 );
|
||||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
||||||
|
@ -294,14 +290,14 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 0 );
|
||||||
assertEquals( sessionFactory().getStatistics().getQueryCacheMissCount(), 2 );
|
assertEquals( sessionFactory().getStatistics().getQueryCacheMissCount(), 2 );
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().resume( tx1 );
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().resume( tx1 );
|
||||||
tx1.commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s3 = openSession();
|
Session s3 = openSession();
|
||||||
s3.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
s3.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||||
.setCacheable( true ).list();
|
.setCacheable( true ).list();
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 0 );
|
||||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
||||||
|
@ -312,11 +308,11 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 0 );
|
||||||
assertEquals( sessionFactory().getStatistics().getQueryCacheMissCount(), 3 );
|
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" ) )
|
List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||||
.setCacheable( true ).list();
|
.setCacheable( true ).list();
|
||||||
assertEquals( r4.size(), 2 );
|
assertEquals( r4.size(), 2 );
|
||||||
tx4.commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 2 );
|
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheHitCount(), 2 );
|
||||||
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
||||||
|
@ -327,43 +323,43 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 1 );
|
assertEquals( sessionFactory().getStatistics().getQueryCacheHitCount(), 1 );
|
||||||
assertEquals( sessionFactory().getStatistics().getQueryCacheMissCount(), 3 );
|
assertEquals( sessionFactory().getStatistics().getQueryCacheMissCount(), 3 );
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.createQuery( "delete from Item" ).executeUpdate();
|
s.createQuery( "delete from Item" ).executeUpdate();
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCMT() throws Exception {
|
public void testCMT() throws Exception {
|
||||||
sessionFactory().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
assertFalse( s.isOpen() );
|
assertFalse( s.isOpen() );
|
||||||
|
|
||||||
assertEquals( sessionFactory().getStatistics().getFlushCount(), 0 );
|
assertEquals( sessionFactory().getStatistics().getFlushCount(), 0 );
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().rollback();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().rollback();
|
||||||
assertFalse( s.isOpen() );
|
assertFalse( s.isOpen() );
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
Map item = new HashMap();
|
Map item = new HashMap();
|
||||||
item.put( "name", "The Item" );
|
item.put( "name", "The Item" );
|
||||||
item.put( "description", "The only item we have" );
|
item.put( "description", "The only item we have" );
|
||||||
s.persist( "Item", item );
|
s.persist( "Item", item );
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
assertFalse( s.isOpen() );
|
assertFalse( s.isOpen() );
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
item = ( Map ) s.createQuery( "from Item" ).uniqueResult();
|
item = ( Map ) s.createQuery( "from Item" ).uniqueResult();
|
||||||
assertNotNull( item );
|
assertNotNull( item );
|
||||||
s.delete( item );
|
s.delete( item );
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
assertFalse( s.isOpen() );
|
assertFalse( s.isOpen() );
|
||||||
|
|
||||||
assertEquals( sessionFactory().getStatistics().getTransactionCount(), 4 );
|
assertEquals( sessionFactory().getStatistics().getTransactionCount(), 4 );
|
||||||
|
@ -375,19 +371,19 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 1 );
|
assertEquals( sessionFactory().getStatistics().getQueryExecutionCount(), 1 );
|
||||||
assertEquals( sessionFactory().getStatistics().getFlushCount(), 2 );
|
assertEquals( sessionFactory().getStatistics().getFlushCount(), 2 );
|
||||||
|
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.createQuery( "delete from Item" ).executeUpdate();
|
s.createQuery( "delete from Item" ).executeUpdate();
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCurrentSession() throws Exception {
|
public void testCurrentSession() throws Exception {
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = sessionFactory().getCurrentSession();
|
Session s = sessionFactory().getCurrentSession();
|
||||||
Session s2 = sessionFactory().getCurrentSession();
|
Session s2 = sessionFactory().getCurrentSession();
|
||||||
assertSame( s, s2 );
|
assertSame( s, s2 );
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
assertFalse( s.isOpen() );
|
assertFalse( s.isOpen() );
|
||||||
|
|
||||||
// TODO : would be nice to automate-test that the SF internal map actually gets cleaned up
|
// 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
|
@Test
|
||||||
public void testCurrentSessionWithIterate() throws Exception {
|
public void testCurrentSessionWithIterate() throws Exception {
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Map item1 = new HashMap();
|
Map item1 = new HashMap();
|
||||||
item1.put( "name", "Item - 1" );
|
item1.put( "name", "Item - 1" );
|
||||||
|
@ -407,11 +403,11 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
item2.put( "name", "Item - 2" );
|
item2.put( "name", "Item - 2" );
|
||||||
item2.put( "description", "The second item" );
|
item2.put( "description", "The second item" );
|
||||||
s.persist( "Item", item2 );
|
s.persist( "Item", item2 );
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
// First, test iterating the partial iterator; iterate to past
|
// First, test iterating the partial iterator; iterate to past
|
||||||
// the first, but not the second, item
|
// the first, but not the second, item
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = sessionFactory().getCurrentSession();
|
s = sessionFactory().getCurrentSession();
|
||||||
Iterator itr = s.createQuery( "from Item" ).iterate();
|
Iterator itr = s.createQuery( "from Item" ).iterate();
|
||||||
if ( !itr.hasNext() ) {
|
if ( !itr.hasNext() ) {
|
||||||
|
@ -421,10 +417,10 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
if ( !itr.hasNext() ) {
|
if ( !itr.hasNext() ) {
|
||||||
fail( "Only one result in iterator" );
|
fail( "Only one result in iterator" );
|
||||||
}
|
}
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
// Next, iterate the entire result
|
// Next, iterate the entire result
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = sessionFactory().getCurrentSession();
|
s = sessionFactory().getCurrentSession();
|
||||||
itr = s.createQuery( "from Item" ).iterate();
|
itr = s.createQuery( "from Item" ).iterate();
|
||||||
if ( !itr.hasNext() ) {
|
if ( !itr.hasNext() ) {
|
||||||
|
@ -433,17 +429,17 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
while ( itr.hasNext() ) {
|
while ( itr.hasNext() ) {
|
||||||
itr.next();
|
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 = openSession();
|
||||||
s.createQuery( "delete from Item" ).executeUpdate();
|
s.createQuery( "delete from Item" ).executeUpdate();
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCurrentSessionWithScroll() throws Exception {
|
public void testCurrentSessionWithScroll() throws Exception {
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = sessionFactory().getCurrentSession();
|
Session s = sessionFactory().getCurrentSession();
|
||||||
Map item1 = new HashMap();
|
Map item1 = new HashMap();
|
||||||
item1.put( "name", "Item - 1" );
|
item1.put( "name", "Item - 1" );
|
||||||
|
@ -454,51 +450,51 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
item2.put( "name", "Item - 2" );
|
item2.put( "name", "Item - 2" );
|
||||||
item2.put( "description", "The second item" );
|
item2.put( "description", "The second item" );
|
||||||
s.persist( "Item", item2 );
|
s.persist( "Item", item2 );
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
// First, test partially scrolling the result with out closing
|
// First, test partially scrolling the result with out closing
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = sessionFactory().getCurrentSession();
|
s = sessionFactory().getCurrentSession();
|
||||||
ScrollableResults results = s.createQuery( "from Item" ).scroll();
|
ScrollableResults results = s.createQuery( "from Item" ).scroll();
|
||||||
results.next();
|
results.next();
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
// Next, test partially scrolling the result with closing
|
// Next, test partially scrolling the result with closing
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = sessionFactory().getCurrentSession();
|
s = sessionFactory().getCurrentSession();
|
||||||
results = s.createQuery( "from Item" ).scroll();
|
results = s.createQuery( "from Item" ).scroll();
|
||||||
results.next();
|
results.next();
|
||||||
results.close();
|
results.close();
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
// Next, scroll the entire result (w/o closing)
|
// Next, scroll the entire result (w/o closing)
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = sessionFactory().getCurrentSession();
|
s = sessionFactory().getCurrentSession();
|
||||||
results = s.createQuery( "from Item" ).scroll();
|
results = s.createQuery( "from Item" ).scroll();
|
||||||
while ( results.next() ) {
|
while ( results.next() ) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
// Next, scroll the entire result (closing)
|
// Next, scroll the entire result (closing)
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = sessionFactory().getCurrentSession();
|
s = sessionFactory().getCurrentSession();
|
||||||
results = s.createQuery( "from Item" ).scroll();
|
results = s.createQuery( "from Item" ).scroll();
|
||||||
while ( results.next() ) {
|
while ( results.next() ) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
results.close();
|
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 = sessionFactory().getCurrentSession();
|
||||||
s.createQuery( "delete from Item" ).executeUpdate();
|
s.createQuery( "delete from Item" ).executeUpdate();
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAggressiveReleaseWithConnectionRetreival() throws Exception {
|
public void testAggressiveReleaseWithConnectionRetreival() throws Exception {
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Map item1 = new HashMap();
|
Map item1 = new HashMap();
|
||||||
item1.put( "name", "Item - 1" );
|
item1.put( "name", "Item - 1" );
|
||||||
|
@ -509,20 +505,20 @@ public class CMTTest extends BaseCoreFunctionalTestCase {
|
||||||
item2.put( "name", "Item - 2" );
|
item2.put( "name", "Item - 2" );
|
||||||
item2.put( "description", "The second item" );
|
item2.put( "description", "The second item" );
|
||||||
s.save( "Item", item2 );
|
s.save( "Item", item2 );
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = sessionFactory().getCurrentSession();
|
s = sessionFactory().getCurrentSession();
|
||||||
s.createQuery( "from Item" ).scroll().next();
|
s.createQuery( "from Item" ).scroll().next();
|
||||||
s.connection();
|
s.connection();
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
sessionFactory().getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.createQuery( "delete from Item" ).executeUpdate();
|
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.HashMap;
|
||||||
import java.util.Map;
|
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.cfg.Environment;
|
||||||
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
|
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
|
||||||
import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
|
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.engine.transaction.spi.TransactionImplementor;
|
||||||
import org.hibernate.service.internal.ServiceProxy;
|
import org.hibernate.service.internal.ServiceProxy;
|
||||||
import org.hibernate.service.internal.ServiceRegistryImpl;
|
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.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.env.ConnectionProviderBuilder;
|
||||||
|
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
import org.hibernate.test.common.JournalingTransactionObserver;
|
import org.hibernate.test.common.JournalingTransactionObserver;
|
||||||
import org.hibernate.test.common.TransactionContextImpl;
|
import org.hibernate.test.common.TransactionContextImpl;
|
||||||
import org.hibernate.test.common.TransactionEnvironmentImpl;
|
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.
|
* Testing transaction handling when the JTA transaction facade is the driver.
|
||||||
|
@ -71,8 +70,7 @@ public class BasicDrivingTest extends BaseUnitTestCase {
|
||||||
Map configValues = new HashMap();
|
Map configValues = new HashMap();
|
||||||
configValues.putAll( ConnectionProviderBuilder.getConnectionProviderProperties() );
|
configValues.putAll( ConnectionProviderBuilder.getConnectionProviderProperties() );
|
||||||
configValues.put( Environment.TRANSACTION_STRATEGY, JtaTransactionFactory.class.getName() );
|
configValues.put( Environment.TRANSACTION_STRATEGY, JtaTransactionFactory.class.getName() );
|
||||||
configValues.put( JtaPlatformInitiator.JTA_PLATFORM, AtomikosJtaPlatform.class.getName() );
|
TestingJtaBootstrap.prepare( configValues );
|
||||||
configValues.put( Environment.CONNECTION_PROVIDER, AtomikosDataSourceConnectionProvider.class.getName() );
|
|
||||||
serviceRegistry = new ServiceRegistryImpl( 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.engine.transaction.spi.TransactionImplementor;
|
||||||
import org.hibernate.service.internal.ServiceProxy;
|
import org.hibernate.service.internal.ServiceProxy;
|
||||||
import org.hibernate.service.internal.ServiceRegistryImpl;
|
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.jta.platform.spi.JtaPlatform;
|
||||||
import org.hibernate.service.spi.StandardServiceInitiators;
|
import org.hibernate.service.spi.StandardServiceInitiators;
|
||||||
|
|
||||||
|
@ -48,13 +47,11 @@ import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
import org.hibernate.testing.env.ConnectionProviderBuilder;
|
|
||||||
import org.hibernate.test.common.JournalingTransactionObserver;
|
import org.hibernate.test.common.JournalingTransactionObserver;
|
||||||
import org.hibernate.test.common.TransactionContextImpl;
|
import org.hibernate.test.common.TransactionContextImpl;
|
||||||
import org.hibernate.test.common.TransactionEnvironmentImpl;
|
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.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
@ -73,10 +70,9 @@ public class ManagedDrivingTest extends BaseUnitTestCase {
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
Map configValues = new HashMap();
|
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( 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 );
|
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() {
|
useTestNG() {
|
||||||
suites 'src/test/resources/testng.xml'
|
suites 'src/test/resources/testng.xml'
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// temporary
|
||||||
|
test {
|
||||||
|
ignoreFailures = true
|
||||||
}
|
}
|
|
@ -22,10 +22,19 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.envers.test;
|
package org.hibernate.envers.test;
|
||||||
import java.io.IOException;
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
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.cfg.Environment;
|
||||||
|
import org.hibernate.dialect.H2Dialect;
|
||||||
import org.hibernate.ejb.AvailableSettings;
|
import org.hibernate.ejb.AvailableSettings;
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.AuditReader;
|
import org.hibernate.envers.AuditReader;
|
||||||
|
@ -37,13 +46,9 @@ import org.hibernate.event.PostInsertEventListener;
|
||||||
import org.hibernate.event.PostUpdateEventListener;
|
import org.hibernate.event.PostUpdateEventListener;
|
||||||
import org.hibernate.event.PreCollectionRemoveEventListener;
|
import org.hibernate.event.PreCollectionRemoveEventListener;
|
||||||
import org.hibernate.event.PreCollectionUpdateEventListener;
|
import org.hibernate.event.PreCollectionUpdateEventListener;
|
||||||
import org.hibernate.testing.tm.ConnectionProviderImpl;
|
import org.hibernate.service.internal.ServiceRegistryImpl;
|
||||||
import org.hibernate.testing.tm.TransactionManagerLookupImpl;
|
|
||||||
import org.testng.annotations.AfterClass;
|
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||||
import org.testng.annotations.BeforeClass;
|
|
||||||
import org.testng.annotations.BeforeMethod;
|
|
||||||
import org.testng.annotations.Optional;
|
|
||||||
import org.testng.annotations.Parameters;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -53,6 +58,7 @@ public abstract class AbstractEntityTest {
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
private AuditReader auditReader;
|
private AuditReader auditReader;
|
||||||
private Ejb3Configuration cfg;
|
private Ejb3Configuration cfg;
|
||||||
|
private ServiceRegistryImpl serviceRegistry;
|
||||||
private boolean audited;
|
private boolean audited;
|
||||||
|
|
||||||
public abstract void configure(Ejb3Configuration cfg);
|
public abstract void configure(Ejb3Configuration cfg);
|
||||||
|
@ -99,17 +105,22 @@ public abstract class AbstractEntityTest {
|
||||||
initListeners();
|
initListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.configure("hibernate.test.cfg.xml");
|
cfg.configure( "hibernate.test.cfg.xml" );
|
||||||
|
|
||||||
if (auditStrategy != null && !"".equals(auditStrategy)) {
|
if (auditStrategy != null && !"".equals(auditStrategy)) {
|
||||||
cfg.setProperty("org.hibernate.envers.audit_strategy", auditStrategy);
|
cfg.setProperty("org.hibernate.envers.audit_strategy", auditStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Separate database for each test class
|
// 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);
|
configure( cfg );
|
||||||
emf = cfg.buildEntityManagerFactory();
|
|
||||||
|
cfg.configure( cfg.getHibernateConfiguration().getProperties() );
|
||||||
|
|
||||||
|
serviceRegistry = new ServiceRegistryImpl( cfg.getProperties() );
|
||||||
|
|
||||||
|
emf = cfg.buildEntityManagerFactory( serviceRegistry );
|
||||||
|
|
||||||
newEntityManager();
|
newEntityManager();
|
||||||
}
|
}
|
||||||
|
@ -118,6 +129,7 @@ public abstract class AbstractEntityTest {
|
||||||
public void close() {
|
public void close() {
|
||||||
closeEntityManager();
|
closeEntityManager();
|
||||||
emf.close();
|
emf.close();
|
||||||
|
serviceRegistry.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityManager getEntityManager() {
|
public EntityManager getEntityManager() {
|
||||||
|
@ -132,9 +144,10 @@ public abstract class AbstractEntityTest {
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addJTAConfig(Ejb3Configuration cfg) {
|
protected void addJTAConfig(Ejb3Configuration cfg) {
|
||||||
cfg.setProperty("connection.provider_class", ConnectionProviderImpl.class.getName());
|
TestingJtaBootstrap.prepare( cfg.getProperties() );
|
||||||
cfg.setProperty(Environment.TRANSACTION_MANAGER_STRATEGY, TransactionManagerLookupImpl.class.getName());
|
cfg.getProperties().remove( Environment.USER );
|
||||||
cfg.setProperty(AvailableSettings.TRANSACTION_TYPE, "JTA");
|
cfg.getProperties().remove( Environment.PASS );
|
||||||
|
cfg.setProperty( AvailableSettings.TRANSACTION_TYPE, "JTA" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ public abstract class AbstractOneSessionTest {
|
||||||
|
|
||||||
this.initMappings();
|
this.initMappings();
|
||||||
|
|
||||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(Environment.getProperties());
|
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() );
|
||||||
sessionFactory = config.buildSessionFactory( serviceRegistry );
|
sessionFactory = config.buildSessionFactory( serviceRegistry );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public abstract class AbstractSessionTest {
|
||||||
|
|
||||||
this.initMappings();
|
this.initMappings();
|
||||||
|
|
||||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
|
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() );
|
||||||
sessionFactory = config.buildSessionFactory( serviceRegistry );
|
sessionFactory = config.buildSessionFactory( serviceRegistry );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,13 +22,17 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.envers.test.integration.jta;
|
package org.hibernate.envers.test.integration.jta;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.entities.StrTestEntity;
|
import org.hibernate.envers.test.entities.StrTestEntity;
|
||||||
import org.hibernate.envers.test.integration.reventity.ExceptionListenerRevEntity;
|
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.
|
* 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)
|
@Test(expectedExceptions = RuntimeException.class)
|
||||||
public void testTransactionRollback() throws Exception {
|
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
|
// Trying to persist an entity - however the listener should throw an exception, so the entity
|
||||||
// shouldn't be persisted
|
// shouldn't be persisted
|
||||||
|
@ -54,12 +58,12 @@ public class JtaExceptionListener extends AbstractEntityTest {
|
||||||
StrTestEntity te = new StrTestEntity("x");
|
StrTestEntity te = new StrTestEntity("x");
|
||||||
em.persist(te);
|
em.persist(te);
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testTransactionRollback")
|
@Test(dependsOnMethods = "testTransactionRollback")
|
||||||
public void testDataNotPersisted() throws Exception {
|
public void testDataNotPersisted() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
|
|
||||||
// Checking if the entity became persisted
|
// Checking if the entity became persisted
|
||||||
newEntityManager();
|
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();
|
Long count = (Long) em.createQuery("select count(s) from StrTestEntity s where s.str = 'x'").getSingleResult();
|
||||||
assert count == 0l;
|
assert count == 0l;
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
package org.hibernate.envers.test.integration.jta;
|
package org.hibernate.envers.test.integration.jta;
|
||||||
import java.util.Arrays;
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.entities.IntTestEntity;
|
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.
|
* 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
|
@Test
|
||||||
public void initData() throws Exception {
|
public void initData() throws Exception {
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
|
|
||||||
newEntityManager();
|
newEntityManager();
|
||||||
EntityManager em = getEntityManager();
|
EntityManager em = getEntityManager();
|
||||||
|
@ -31,18 +35,18 @@ public class JtaTransaction extends AbstractEntityTest {
|
||||||
em.persist(ite);
|
em.persist(ite);
|
||||||
id1 = ite.getId();
|
id1 = ite.getId();
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().begin();
|
||||||
|
|
||||||
newEntityManager();
|
newEntityManager();
|
||||||
em = getEntityManager();
|
em = getEntityManager();
|
||||||
ite = em.find(IntTestEntity.class, id1);
|
ite = em.find(IntTestEntity.class, id1);
|
||||||
ite.setNumber(20);
|
ite.setNumber(20);
|
||||||
|
|
||||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
TestingJtaBootstrap.INSTANCE.getTransactionManager().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "initData")
|
@Test(dependsOnMethods = "initData")
|
||||||
|
|
|
@ -26,4 +26,8 @@ apply plugin: 'java'
|
||||||
dependencies {
|
dependencies {
|
||||||
compile( project( ':hibernate-core' ) )
|
compile( project( ':hibernate-core' ) )
|
||||||
compile( [group: 'junit', name: 'junit', version: '4.8.2'] )
|
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;
|
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.Rule;
|
||||||
import org.junit.runner.RunWith;
|
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.
|
* 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 {
|
public abstract class BaseUnitTestCase {
|
||||||
@Rule
|
@Rule
|
||||||
public Processor processor = new Processor();
|
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