HHH-2863 : isolate testing TransactionManager for reuse
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@14213 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
b0bd89df76
commit
f3add4ddda
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2007, Red Hat Middleware LLC 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 Middleware LLC.
|
||||
*
|
||||
* 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.tm;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.connection.ConnectionProvider;
|
||||
import org.hibernate.connection.ConnectionProviderFactory;
|
||||
|
||||
/**
|
||||
* 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 = ConnectionProviderFactory.newConnectionProvider();
|
||||
|
||||
private boolean isTransactional;
|
||||
|
||||
public static ConnectionProvider getActualConnectionProvider() {
|
||||
return actualConnectionProvider;
|
||||
}
|
||||
|
||||
public void configure(Properties props) throws HibernateException {
|
||||
}
|
||||
|
||||
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 {
|
||||
actualConnectionProvider.close();
|
||||
}
|
||||
|
||||
public boolean supportsAggressiveRelease() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2007, Red Hat Middleware LLC 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 Middleware LLC.
|
||||
*
|
||||
* 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.tm;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
import javax.transaction.HeuristicMixedException;
|
||||
import javax.transaction.HeuristicRollbackException;
|
||||
import javax.transaction.RollbackException;
|
||||
import javax.transaction.Status;
|
||||
import javax.transaction.Synchronization;
|
||||
import javax.transaction.SystemException;
|
||||
import javax.transaction.Transaction;
|
||||
import javax.transaction.xa.XAResource;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* SimpleJtaTransactionImpl implementation
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SimpleJtaTransactionImpl implements Transaction {
|
||||
private static final Logger log = LoggerFactory.getLogger( SimpleJtaTransactionImpl.class );
|
||||
|
||||
private int status;
|
||||
private LinkedList synchronizations;
|
||||
private Connection connection; // the only resource we care about is jdbc connection
|
||||
private final SimpleJtaTransactionManagerImpl jtaTransactionManager;
|
||||
|
||||
public SimpleJtaTransactionImpl(SimpleJtaTransactionManagerImpl jtaTransactionManager) {
|
||||
this.jtaTransactionManager = jtaTransactionManager;
|
||||
this.status = Status.STATUS_ACTIVE;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void commit()
|
||||
throws RollbackException, HeuristicMixedException, HeuristicRollbackException, IllegalStateException, SystemException {
|
||||
|
||||
if ( status == Status.STATUS_MARKED_ROLLBACK ) {
|
||||
log.trace( "on commit, status was marked for rollback-only" );
|
||||
rollback();
|
||||
}
|
||||
else {
|
||||
status = Status.STATUS_PREPARING;
|
||||
|
||||
for ( int i = 0; i < synchronizations.size(); i++ ) {
|
||||
Synchronization s = ( Synchronization ) synchronizations.get( i );
|
||||
s.beforeCompletion();
|
||||
}
|
||||
|
||||
status = Status.STATUS_COMMITTING;
|
||||
|
||||
if ( connection != null ) {
|
||||
try {
|
||||
connection.commit();
|
||||
connection.close();
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
status = Status.STATUS_UNKNOWN;
|
||||
throw new SystemException();
|
||||
}
|
||||
}
|
||||
|
||||
status = Status.STATUS_COMMITTED;
|
||||
|
||||
for ( int i = 0; i < synchronizations.size(); i++ ) {
|
||||
Synchronization s = ( Synchronization ) synchronizations.get( i );
|
||||
s.afterCompletion( status );
|
||||
}
|
||||
|
||||
//status = Status.STATUS_NO_TRANSACTION;
|
||||
jtaTransactionManager.endCurrent( this );
|
||||
}
|
||||
}
|
||||
|
||||
public void rollback() throws IllegalStateException, SystemException {
|
||||
status = Status.STATUS_ROLLEDBACK;
|
||||
|
||||
if ( connection != null ) {
|
||||
try {
|
||||
connection.rollback();
|
||||
connection.close();
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
status = Status.STATUS_UNKNOWN;
|
||||
throw new SystemException();
|
||||
}
|
||||
}
|
||||
|
||||
for ( int i = 0; i < synchronizations.size(); i++ ) {
|
||||
Synchronization s = ( Synchronization ) synchronizations.get( i );
|
||||
s.afterCompletion( status );
|
||||
}
|
||||
|
||||
//status = Status.STATUS_NO_TRANSACTION;
|
||||
jtaTransactionManager.endCurrent( this );
|
||||
}
|
||||
|
||||
public void setRollbackOnly() throws IllegalStateException, SystemException {
|
||||
status = Status.STATUS_MARKED_ROLLBACK;
|
||||
}
|
||||
|
||||
public void registerSynchronization(Synchronization synchronization)
|
||||
throws RollbackException, IllegalStateException, SystemException {
|
||||
// todo : find the spec-allowable statuses during which synch can be registered...
|
||||
if ( synchronizations == null ) {
|
||||
synchronizations = new LinkedList();
|
||||
}
|
||||
synchronizations.add( synchronization );
|
||||
}
|
||||
|
||||
public void enlistConnection(Connection connection) {
|
||||
if ( this.connection != null ) {
|
||||
throw new IllegalStateException( "Connection already registered" );
|
||||
}
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
public Connection getEnlistedConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
public boolean enlistResource(XAResource xaResource)
|
||||
throws RollbackException, IllegalStateException, SystemException {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean delistResource(XAResource xaResource, int i) throws IllegalStateException, SystemException {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2007, Red Hat Middleware LLC 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 Middleware LLC.
|
||||
*
|
||||
* 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.tm;
|
||||
|
||||
import javax.transaction.HeuristicMixedException;
|
||||
import javax.transaction.HeuristicRollbackException;
|
||||
import javax.transaction.InvalidTransactionException;
|
||||
import javax.transaction.NotSupportedException;
|
||||
import javax.transaction.RollbackException;
|
||||
import javax.transaction.Status;
|
||||
import javax.transaction.SystemException;
|
||||
import javax.transaction.Transaction;
|
||||
import javax.transaction.TransactionManager;
|
||||
|
||||
/**
|
||||
* TransactionManager implementation specifically designed for use in test suite and simple usage
|
||||
* scenarios. For example, it assumes that there is only ever a single transaction active at a
|
||||
* given time.
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SimpleJtaTransactionManagerImpl implements TransactionManager {
|
||||
private static final SimpleJtaTransactionManagerImpl INSTANCE = new SimpleJtaTransactionManagerImpl();
|
||||
|
||||
private SimpleJtaTransactionImpl currentTransaction;
|
||||
|
||||
public static SimpleJtaTransactionManagerImpl getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public int getStatus() throws SystemException {
|
||||
return currentTransaction == null ? Status.STATUS_NO_TRANSACTION : currentTransaction.getStatus();
|
||||
}
|
||||
|
||||
public Transaction getTransaction() throws SystemException {
|
||||
return currentTransaction;
|
||||
}
|
||||
|
||||
public SimpleJtaTransactionImpl getCurrentTransaction() {
|
||||
return currentTransaction;
|
||||
}
|
||||
|
||||
public void begin() throws NotSupportedException, SystemException {
|
||||
currentTransaction = new SimpleJtaTransactionImpl( this );
|
||||
}
|
||||
|
||||
public Transaction suspend() throws SystemException {
|
||||
SimpleJtaTransactionImpl suspended = currentTransaction;
|
||||
currentTransaction = null;
|
||||
return suspended;
|
||||
}
|
||||
|
||||
public void resume(Transaction transaction)
|
||||
throws InvalidTransactionException, IllegalStateException, SystemException {
|
||||
currentTransaction = ( SimpleJtaTransactionImpl ) transaction;
|
||||
}
|
||||
|
||||
public void commit()
|
||||
throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
|
||||
if ( currentTransaction == null ) {
|
||||
throw new IllegalStateException( "no current transaction to commit" );
|
||||
}
|
||||
currentTransaction.commit();
|
||||
}
|
||||
|
||||
public void rollback() throws IllegalStateException, SecurityException, SystemException {
|
||||
if ( currentTransaction == null ) {
|
||||
throw new IllegalStateException( "no current transaction" );
|
||||
}
|
||||
currentTransaction.rollback();
|
||||
}
|
||||
|
||||
public void setRollbackOnly() throws IllegalStateException, SystemException {
|
||||
if ( currentTransaction == null ) {
|
||||
throw new IllegalStateException( "no current transaction" );
|
||||
}
|
||||
currentTransaction.setRollbackOnly();
|
||||
}
|
||||
|
||||
public void setTransactionTimeout(int i) throws SystemException {
|
||||
}
|
||||
|
||||
void endCurrent(SimpleJtaTransactionImpl transaction) {
|
||||
if ( transaction == currentTransaction ) {
|
||||
currentTransaction = null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2007, Red Hat Middleware LLC 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 Middleware LLC.
|
||||
*
|
||||
* 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.tm;
|
||||
|
||||
import java.util.Properties;
|
||||
import javax.transaction.TransactionManager;
|
||||
|
||||
import org.hibernate.transaction.TransactionManagerLookup;
|
||||
import org.hibernate.HibernateException;
|
||||
|
||||
/**
|
||||
* 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" );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
|
||||
<!--
|
||||
~ Hibernate, Relational Persistence for Idiomatic Java
|
||||
~
|
||||
~ Copyright (c) 2007, Red Hat Middleware LLC 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 Middleware LLC.
|
||||
~
|
||||
~ 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
|
||||
-->
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Package Information - org.hibernate.test.tm</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<p>
|
||||
Defines a simplified JTA TransactionManager and transactional connection pool
|
||||
designed for use in test suite and simple usage scenarios. For example, it
|
||||
is assumed that there is only ever a single transaction active at a given time.
|
||||
Also, the only 'resource' that the transaction tracks is a single JDBC connection.
|
||||
</p>
|
||||
</BODY>
|
||||
</HTML>
|
|
@ -1,6 +1,5 @@
|
|||
package org.hibernate.test.cache;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
@ -11,8 +10,8 @@ import org.hibernate.cfg.Environment;
|
|||
import org.hibernate.junit.functional.FunctionalTestCase;
|
||||
import org.hibernate.stat.SecondLevelCacheStatistics;
|
||||
import org.hibernate.stat.Statistics;
|
||||
import org.hibernate.test.tm.DummyConnectionProvider;
|
||||
import org.hibernate.test.tm.DummyTransactionManagerLookup;
|
||||
import org.hibernate.test.tm.ConnectionProviderImpl;
|
||||
import org.hibernate.test.tm.TransactionManagerLookupImpl;
|
||||
import org.hibernate.transaction.JDBCTransactionFactory;
|
||||
|
||||
/**
|
||||
|
@ -47,8 +46,8 @@ public abstract class BaseCacheProviderTestCase extends FunctionalTestCase {
|
|||
}
|
||||
|
||||
if ( useTransactionManager() ) {
|
||||
cfg.setProperty( Environment.CONNECTION_PROVIDER, DummyConnectionProvider.class.getName() );
|
||||
cfg.setProperty( Environment.TRANSACTION_MANAGER_STRATEGY, DummyTransactionManagerLookup.class.getName() );
|
||||
cfg.setProperty( Environment.CONNECTION_PROVIDER, ConnectionProviderImpl.class.getName() );
|
||||
cfg.setProperty( Environment.TRANSACTION_MANAGER_STRATEGY, TransactionManagerLookupImpl.class.getName() );
|
||||
}
|
||||
else {
|
||||
cfg.setProperty( Environment.TRANSACTION_STRATEGY, JDBCTransactionFactory.class.getName() );
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge;
|
|||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
|
||||
import org.hibernate.test.cache.BaseCacheProviderTestCase;
|
||||
import org.hibernate.test.tm.DummyTransactionManager;
|
||||
import org.hibernate.test.tm.SimpleJtaTransactionManagerImpl;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -59,25 +59,25 @@ public class OptimisticTreeCacheTest extends BaseCacheProviderTestCase {
|
|||
|
||||
try {
|
||||
System.out.println( "****************************************************************" );
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
treeCache.put( fqn, "ITEM", long1, ManualDataVersion.gen( 1 ) );
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
|
||||
System.out.println( "****************************************************************" );
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
treeCache.put( fqn, "ITEM", long2, ManualDataVersion.gen( 2 ) );
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
|
||||
try {
|
||||
System.out.println( "****************************************************************" );
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
treeCache.put( fqn, "ITEM", long1, ManualDataVersion.gen( 1 ) );
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
fail( "stale write allowed" );
|
||||
}
|
||||
catch( Throwable ignore ) {
|
||||
// expected behavior
|
||||
DummyTransactionManager.INSTANCE.rollback();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().rollback();
|
||||
}
|
||||
|
||||
Long current = ( Long ) treeCache.get( fqn, "ITEM" );
|
||||
|
|
|
@ -16,9 +16,9 @@ import org.hibernate.cfg.Configuration;
|
|||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.impl.SessionImpl;
|
||||
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
|
||||
import org.hibernate.test.tm.DummyConnectionProvider;
|
||||
import org.hibernate.test.tm.DummyTransactionManager;
|
||||
import org.hibernate.test.tm.DummyTransactionManagerLookup;
|
||||
import org.hibernate.test.tm.ConnectionProviderImpl;
|
||||
import org.hibernate.test.tm.SimpleJtaTransactionManagerImpl;
|
||||
import org.hibernate.test.tm.TransactionManagerLookupImpl;
|
||||
import org.hibernate.transaction.CMTTransactionFactory;
|
||||
import org.hibernate.util.SerializationHelper;
|
||||
|
||||
|
@ -39,10 +39,10 @@ public class AggressiveReleaseTest extends ConnectionManagementTestCase {
|
|||
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.setProperty( Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.AFTER_STATEMENT.toString() );
|
||||
cfg.setProperty( Environment.CONNECTION_PROVIDER, DummyConnectionProvider.class.getName() );
|
||||
cfg.setProperty( Environment.CONNECTION_PROVIDER, ConnectionProviderImpl.class.getName() );
|
||||
cfg.setProperty( Environment.TRANSACTION_MANAGER_STRATEGY, TransactionManagerLookupImpl.class.getName() );
|
||||
cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
|
||||
cfg.setProperty( Environment.TRANSACTION_MANAGER_STRATEGY, DummyTransactionManagerLookup.class.getName() );
|
||||
cfg.setProperty( Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.AFTER_STATEMENT.toString() );
|
||||
cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
|
||||
cfg.setProperty( Environment.STATEMENT_BATCH_SIZE, "0" );
|
||||
}
|
||||
|
@ -56,11 +56,11 @@ public class AggressiveReleaseTest extends ConnectionManagementTestCase {
|
|||
}
|
||||
|
||||
protected void prepare() throws Throwable {
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
}
|
||||
|
||||
protected void done() throws Throwable {
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
}
|
||||
|
||||
// Some additional tests specifically for the aggressive-release functionality...
|
||||
|
@ -184,7 +184,7 @@ public class AggressiveReleaseTest extends ConnectionManagementTestCase {
|
|||
public void testSuppliedConnection() throws Throwable {
|
||||
prepare();
|
||||
|
||||
Connection originalConnection = DummyTransactionManager.INSTANCE.getCurrent().getConnection();
|
||||
Connection originalConnection = ConnectionProviderImpl.getActualConnectionProvider().getConnection();
|
||||
Session session = getSessions().openSession( originalConnection );
|
||||
|
||||
Silly silly = new Silly( "silly" );
|
||||
|
@ -201,6 +201,8 @@ public class AggressiveReleaseTest extends ConnectionManagementTestCase {
|
|||
|
||||
release( session );
|
||||
done();
|
||||
|
||||
ConnectionProviderImpl.getActualConnectionProvider().closeConnection( originalConnection );
|
||||
}
|
||||
|
||||
public void testBorrowedConnections() throws Throwable {
|
||||
|
|
|
@ -16,7 +16,6 @@ import org.hibernate.Session;
|
|||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.criterion.Order;
|
||||
import org.hibernate.dialect.SybaseDialect;
|
||||
import org.hibernate.junit.functional.FunctionalTestCase;
|
||||
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
|
||||
import org.hibernate.transaction.CMTTransactionFactory;
|
||||
|
@ -36,8 +35,8 @@ public class CMTTest extends FunctionalTestCase {
|
|||
}
|
||||
|
||||
public void configure(Configuration cfg) {
|
||||
cfg.setProperty( Environment.CONNECTION_PROVIDER, DummyConnectionProvider.class.getName() );
|
||||
cfg.setProperty( Environment.TRANSACTION_MANAGER_STRATEGY, DummyTransactionManagerLookup.class.getName() );
|
||||
cfg.setProperty( Environment.CONNECTION_PROVIDER, ConnectionProviderImpl.class.getName() );
|
||||
cfg.setProperty( Environment.TRANSACTION_MANAGER_STRATEGY, TransactionManagerLookupImpl.class.getName() );
|
||||
cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
|
||||
cfg.setProperty( Environment.AUTO_CLOSE_SESSION, "true" );
|
||||
cfg.setProperty( Environment.FLUSH_BEFORE_COMPLETION, "true" );
|
||||
|
@ -58,7 +57,7 @@ public class CMTTest extends FunctionalTestCase {
|
|||
public void testConcurrent() throws Exception {
|
||||
getSessions().getStatistics().clear();
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s = openSession();
|
||||
Map foo = new HashMap();
|
||||
foo.put( "name", "Foo" );
|
||||
|
@ -68,46 +67,46 @@ public class CMTTest extends FunctionalTestCase {
|
|||
bar.put( "name", "Bar" );
|
||||
bar.put( "description", "a small bar" );
|
||||
s.persist( "Item", bar );
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
|
||||
getSessions().evictEntity( "Item" );
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s1 = openSession();
|
||||
foo = ( Map ) s1.get( "Item", "Foo" );
|
||||
//foo.put("description", "a big red foo");
|
||||
//s1.flush();
|
||||
Transaction tx1 = DummyTransactionManager.INSTANCE.suspend();
|
||||
Transaction tx1 = SimpleJtaTransactionManagerImpl.getInstance().suspend();
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s2 = openSession();
|
||||
foo = ( Map ) s2.get( "Item", "Foo" );
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
|
||||
DummyTransactionManager.INSTANCE.resume( tx1 );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().resume( tx1 );
|
||||
tx1.commit();
|
||||
|
||||
getSessions().evictEntity( "Item" );
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s1 = openSession();
|
||||
s1.createCriteria( "Item" ).list();
|
||||
//foo.put("description", "a big red foo");
|
||||
//s1.flush();
|
||||
tx1 = DummyTransactionManager.INSTANCE.suspend();
|
||||
tx1 = SimpleJtaTransactionManagerImpl.getInstance().suspend();
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s2 = openSession();
|
||||
s2.createCriteria( "Item" ).list();
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
|
||||
DummyTransactionManager.INSTANCE.resume( tx1 );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().resume( tx1 );
|
||||
tx1.commit();
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s2 = openSession();
|
||||
s2.createCriteria( "Item" ).list();
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
|
||||
assertEquals( getSessions().getStatistics().getEntityLoadCount(), 7 );
|
||||
assertEquals( getSessions().getStatistics().getEntityFetchCount(), 0 );
|
||||
|
@ -115,15 +114,15 @@ public class CMTTest extends FunctionalTestCase {
|
|||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
|
||||
assertEquals( getSessions().getStatistics().getQueryCacheMissCount(), 0 );
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s = openSession();
|
||||
s.createQuery( "delete from Item" ).executeUpdate();
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
}
|
||||
|
||||
public void testConcurrentCachedQueries() throws Exception {
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s = openSession();
|
||||
Map foo = new HashMap();
|
||||
foo.put( "name", "Foo" );
|
||||
|
@ -133,7 +132,7 @@ public class CMTTest extends FunctionalTestCase {
|
|||
bar.put( "name", "Bar" );
|
||||
bar.put( "description", "a small bar" );
|
||||
s.persist( "Item", bar );
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
|
||||
synchronized ( this ) {
|
||||
wait( 1000 );
|
||||
|
@ -143,23 +142,23 @@ public class CMTTest extends FunctionalTestCase {
|
|||
|
||||
getSessions().evictEntity( "Item" );
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s4 = openSession();
|
||||
Transaction tx4 = DummyTransactionManager.INSTANCE.suspend();
|
||||
Transaction tx4 = SimpleJtaTransactionManagerImpl.getInstance().suspend();
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s1 = openSession();
|
||||
List r1 = s1.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||
.setCacheable( true ).list();
|
||||
assertEquals( r1.size(), 2 );
|
||||
Transaction tx1 = DummyTransactionManager.INSTANCE.suspend();
|
||||
Transaction tx1 = SimpleJtaTransactionManagerImpl.getInstance().suspend();
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s2 = openSession();
|
||||
List r2 = s2.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||
.setCacheable( true ).list();
|
||||
assertEquals( r2.size(), 2 );
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
|
||||
assertEquals( getSessions().getStatistics().getSecondLevelCacheHitCount(), 2 );
|
||||
assertEquals( getSessions().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
||||
|
@ -170,14 +169,14 @@ public class CMTTest extends FunctionalTestCase {
|
|||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 1 );
|
||||
assertEquals( getSessions().getStatistics().getQueryCacheMissCount(), 1 );
|
||||
|
||||
DummyTransactionManager.INSTANCE.resume( tx1 );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().resume( tx1 );
|
||||
tx1.commit();
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s3 = openSession();
|
||||
s3.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||
.setCacheable( true ).list();
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
|
||||
assertEquals( getSessions().getStatistics().getSecondLevelCacheHitCount(), 4 );
|
||||
assertEquals( getSessions().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
||||
|
@ -188,7 +187,7 @@ public class CMTTest extends FunctionalTestCase {
|
|||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 2 );
|
||||
assertEquals( getSessions().getStatistics().getQueryCacheMissCount(), 1 );
|
||||
|
||||
DummyTransactionManager.INSTANCE.resume( tx4 );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().resume( tx4 );
|
||||
List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||
.setCacheable( true ).list();
|
||||
assertEquals( r4.size(), 2 );
|
||||
|
@ -203,10 +202,10 @@ public class CMTTest extends FunctionalTestCase {
|
|||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 3 );
|
||||
assertEquals( getSessions().getStatistics().getQueryCacheMissCount(), 1 );
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s = openSession();
|
||||
s.createQuery( "delete from Item" ).executeUpdate();
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
}
|
||||
|
||||
public void testConcurrentCachedDirtyQueries() throws Exception {
|
||||
|
@ -215,7 +214,7 @@ public class CMTTest extends FunctionalTestCase {
|
|||
return;
|
||||
}
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s = openSession();
|
||||
Map foo = new HashMap();
|
||||
foo.put( "name", "Foo" );
|
||||
|
@ -225,7 +224,7 @@ public class CMTTest extends FunctionalTestCase {
|
|||
bar.put( "name", "Bar" );
|
||||
bar.put( "description", "a small bar" );
|
||||
s.persist( "Item", bar );
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
|
||||
synchronized ( this ) {
|
||||
wait( 1000 );
|
||||
|
@ -235,11 +234,11 @@ public class CMTTest extends FunctionalTestCase {
|
|||
|
||||
getSessions().evictEntity( "Item" );
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s4 = openSession();
|
||||
Transaction tx4 = DummyTransactionManager.INSTANCE.suspend();
|
||||
Transaction tx4 = SimpleJtaTransactionManagerImpl.getInstance().suspend();
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s1 = openSession();
|
||||
List r1 = s1.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||
.setCacheable( true ).list();
|
||||
|
@ -247,14 +246,14 @@ public class CMTTest extends FunctionalTestCase {
|
|||
foo = ( Map ) r1.get( 0 );
|
||||
foo.put( "description", "a big red foo" );
|
||||
s1.flush();
|
||||
Transaction tx1 = DummyTransactionManager.INSTANCE.suspend();
|
||||
Transaction tx1 = SimpleJtaTransactionManagerImpl.getInstance().suspend();
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s2 = openSession();
|
||||
List r2 = s2.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||
.setCacheable( true ).list();
|
||||
assertEquals( r2.size(), 2 );
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
|
||||
assertEquals( getSessions().getStatistics().getSecondLevelCacheHitCount(), 0 );
|
||||
assertEquals( getSessions().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
||||
|
@ -265,14 +264,14 @@ public class CMTTest extends FunctionalTestCase {
|
|||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
|
||||
assertEquals( getSessions().getStatistics().getQueryCacheMissCount(), 2 );
|
||||
|
||||
DummyTransactionManager.INSTANCE.resume( tx1 );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().resume( tx1 );
|
||||
tx1.commit();
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s3 = openSession();
|
||||
s3.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||
.setCacheable( true ).list();
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
|
||||
assertEquals( getSessions().getStatistics().getSecondLevelCacheHitCount(), 0 );
|
||||
assertEquals( getSessions().getStatistics().getSecondLevelCacheMissCount(), 0 );
|
||||
|
@ -283,7 +282,7 @@ public class CMTTest extends FunctionalTestCase {
|
|||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
|
||||
assertEquals( getSessions().getStatistics().getQueryCacheMissCount(), 3 );
|
||||
|
||||
DummyTransactionManager.INSTANCE.resume( tx4 );
|
||||
SimpleJtaTransactionManagerImpl.getInstance().resume( tx4 );
|
||||
List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
|
||||
.setCacheable( true ).list();
|
||||
assertEquals( r4.size(), 2 );
|
||||
|
@ -298,42 +297,42 @@ public class CMTTest extends FunctionalTestCase {
|
|||
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 1 );
|
||||
assertEquals( getSessions().getStatistics().getQueryCacheMissCount(), 3 );
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s = openSession();
|
||||
s.createQuery( "delete from Item" ).executeUpdate();
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
}
|
||||
|
||||
public void testCMT() throws Exception {
|
||||
getSessions().getStatistics().clear();
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s = openSession();
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
assertFalse( s.isOpen() );
|
||||
|
||||
assertEquals( getSessions().getStatistics().getFlushCount(), 0 );
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s = openSession();
|
||||
DummyTransactionManager.INSTANCE.getTransaction().rollback();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().rollback();
|
||||
assertFalse( s.isOpen() );
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s = openSession();
|
||||
Map item = new HashMap();
|
||||
item.put( "name", "The Item" );
|
||||
item.put( "description", "The only item we have" );
|
||||
s.persist( "Item", item );
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
assertFalse( s.isOpen() );
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s = openSession();
|
||||
item = ( Map ) s.createQuery( "from Item" ).uniqueResult();
|
||||
assertNotNull( item );
|
||||
s.delete( item );
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
assertFalse( s.isOpen() );
|
||||
|
||||
assertEquals( getSessions().getStatistics().getTransactionCount(), 4 );
|
||||
|
@ -345,19 +344,19 @@ public class CMTTest extends FunctionalTestCase {
|
|||
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
|
||||
assertEquals( getSessions().getStatistics().getFlushCount(), 2 );
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s = openSession();
|
||||
s.createQuery( "delete from Item" ).executeUpdate();
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().commit();
|
||||
|
||||
}
|
||||
|
||||
public void testCurrentSession() throws Exception {
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s = getSessions().getCurrentSession();
|
||||
Session s2 = getSessions().getCurrentSession();
|
||||
assertSame( s, s2 );
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
assertFalse( s.isOpen() );
|
||||
|
||||
// TODO : would be nice to automate-test that the SF internal map actually gets cleaned up
|
||||
|
@ -365,7 +364,7 @@ public class CMTTest extends FunctionalTestCase {
|
|||
}
|
||||
|
||||
public void testCurrentSessionWithIterate() throws Exception {
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s = openSession();
|
||||
Map item1 = new HashMap();
|
||||
item1.put( "name", "Item - 1" );
|
||||
|
@ -376,11 +375,11 @@ public class CMTTest extends FunctionalTestCase {
|
|||
item2.put( "name", "Item - 2" );
|
||||
item2.put( "description", "The second item" );
|
||||
s.persist( "Item", item2 );
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
|
||||
// First, test iterating the partial iterator; iterate to past
|
||||
// the first, but not the second, item
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s = getSessions().getCurrentSession();
|
||||
Iterator itr = s.createQuery( "from Item" ).iterate();
|
||||
if ( !itr.hasNext() ) {
|
||||
|
@ -390,10 +389,10 @@ public class CMTTest extends FunctionalTestCase {
|
|||
if ( !itr.hasNext() ) {
|
||||
fail( "Only one result in iterator" );
|
||||
}
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
|
||||
// Next, iterate the entire result
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s = getSessions().getCurrentSession();
|
||||
itr = s.createQuery( "from Item" ).iterate();
|
||||
if ( !itr.hasNext() ) {
|
||||
|
@ -402,16 +401,16 @@ public class CMTTest extends FunctionalTestCase {
|
|||
while ( itr.hasNext() ) {
|
||||
itr.next();
|
||||
}
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s = openSession();
|
||||
s.createQuery( "delete from Item" ).executeUpdate();
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
}
|
||||
|
||||
public void testCurrentSessionWithScroll() throws Exception {
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s = getSessions().getCurrentSession();
|
||||
Map item1 = new HashMap();
|
||||
item1.put( "name", "Item - 1" );
|
||||
|
@ -422,50 +421,50 @@ public class CMTTest extends FunctionalTestCase {
|
|||
item2.put( "name", "Item - 2" );
|
||||
item2.put( "description", "The second item" );
|
||||
s.persist( "Item", item2 );
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
|
||||
// First, test partially scrolling the result with out closing
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s = getSessions().getCurrentSession();
|
||||
ScrollableResults results = s.createQuery( "from Item" ).scroll();
|
||||
results.next();
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
|
||||
// Next, test partially scrolling the result with closing
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s = getSessions().getCurrentSession();
|
||||
results = s.createQuery( "from Item" ).scroll();
|
||||
results.next();
|
||||
results.close();
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
|
||||
// Next, scroll the entire result (w/o closing)
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s = getSessions().getCurrentSession();
|
||||
results = s.createQuery( "from Item" ).scroll();
|
||||
while ( !results.isLast() ) {
|
||||
results.next();
|
||||
}
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
|
||||
// Next, scroll the entire result (closing)
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s = getSessions().getCurrentSession();
|
||||
results = s.createQuery( "from Item" ).scroll();
|
||||
while ( !results.isLast() ) {
|
||||
results.next();
|
||||
}
|
||||
results.close();
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s = getSessions().getCurrentSession();
|
||||
s.createQuery( "delete from Item" ).executeUpdate();
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
}
|
||||
|
||||
public void testAggressiveReleaseWithExplicitDisconnectReconnect() throws Exception {
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s = getSessions().getCurrentSession();
|
||||
|
||||
s.createQuery( "from Item" ).list();
|
||||
|
@ -477,11 +476,11 @@ public class CMTTest extends FunctionalTestCase {
|
|||
|
||||
s.createQuery( "from Item" ).list();
|
||||
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
}
|
||||
|
||||
public void testAggressiveReleaseWithConnectionRetreival() throws Exception {
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
Session s = openSession();
|
||||
Map item1 = new HashMap();
|
||||
item1.put( "name", "Item - 1" );
|
||||
|
@ -492,20 +491,20 @@ public class CMTTest extends FunctionalTestCase {
|
|||
item2.put( "name", "Item - 2" );
|
||||
item2.put( "description", "The second item" );
|
||||
s.save( "Item", item2 );
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
|
||||
try {
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s = getSessions().getCurrentSession();
|
||||
s.createQuery( "from Item" ).scroll().next();
|
||||
s.connection();
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
}
|
||||
finally {
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().begin();
|
||||
s = openSession();
|
||||
s.createQuery( "delete from Item" ).executeUpdate();
|
||||
DummyTransactionManager.INSTANCE.getTransaction().commit();
|
||||
SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
//$Id: DummyConnectionProvider.java 6501 2005-04-24 00:18:28Z oneovthafew $
|
||||
package org.hibernate.test.tm;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.connection.ConnectionProvider;
|
||||
import org.hibernate.connection.ConnectionProviderFactory;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class DummyConnectionProvider implements ConnectionProvider {
|
||||
|
||||
ConnectionProvider cp;
|
||||
boolean isTransaction;
|
||||
|
||||
public void configure(Properties props) throws HibernateException {
|
||||
cp = ConnectionProviderFactory.newConnectionProvider();
|
||||
}
|
||||
|
||||
public Connection getConnection() throws SQLException {
|
||||
DummyTransactionManager dtm = DummyTransactionManager.INSTANCE;
|
||||
if ( dtm!=null && dtm.getCurrent()!=null && dtm.getCurrent().getConnection()!=null ) {
|
||||
isTransaction = true;
|
||||
return dtm.getCurrent().getConnection();
|
||||
}
|
||||
else {
|
||||
isTransaction = false;
|
||||
return cp.getConnection();
|
||||
}
|
||||
}
|
||||
|
||||
public void closeConnection(Connection conn) throws SQLException {
|
||||
if (!isTransaction) conn.close();
|
||||
}
|
||||
|
||||
public void close() throws HibernateException {
|
||||
|
||||
}
|
||||
|
||||
public boolean supportsAggressiveRelease() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
package org.hibernate.test.tm;
|
||||
|
||||
import org.hibernate.transaction.TransactionFactory;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.ConnectionReleaseMode;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.util.JTAHelper;
|
||||
import org.hibernate.jdbc.JDBCContext;
|
||||
|
||||
import javax.transaction.SystemException;
|
||||
import javax.transaction.Synchronization;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* todo: describe DummyJTAStyleTransationFactory
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class DummyJTAStyleTransationFactory implements TransactionFactory {
|
||||
public Transaction createTransaction(
|
||||
JDBCContext jdbcContext,
|
||||
Context context) throws HibernateException {
|
||||
return new DummyTransactionAdapter();
|
||||
}
|
||||
|
||||
public void configure(Properties props) throws HibernateException {
|
||||
}
|
||||
|
||||
public ConnectionReleaseMode getDefaultReleaseMode() {
|
||||
return ConnectionReleaseMode.AFTER_STATEMENT;
|
||||
}
|
||||
|
||||
public boolean isTransactionManagerRequired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean areCallbacksLocalToHibernateTransactions() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isTransactionInProgress(
|
||||
JDBCContext jdbcContext,
|
||||
Context transactionContext,
|
||||
Transaction transaction) {
|
||||
try {
|
||||
return JTAHelper.isTransactionInProgress( DummyTransactionManager.INSTANCE.getCurrent() )
|
||||
&& ! JTAHelper.isMarkedForRollback( DummyTransactionManager.INSTANCE.getCurrent() );
|
||||
}
|
||||
catch( SystemException e ) {
|
||||
throw new HibernateException( e );
|
||||
}
|
||||
}
|
||||
|
||||
private static class DummyTransactionAdapter implements Transaction {
|
||||
|
||||
private boolean started;
|
||||
private boolean committed;
|
||||
private boolean rolledback;
|
||||
|
||||
public void begin() throws HibernateException {
|
||||
started = true;
|
||||
committed = false;
|
||||
rolledback = false;
|
||||
try {
|
||||
DummyTransactionManager.INSTANCE.begin();
|
||||
}
|
||||
catch( Throwable t ) {
|
||||
throw new HibernateException( "error on begin()", t );
|
||||
}
|
||||
}
|
||||
|
||||
public void commit() throws HibernateException {
|
||||
if ( !started ) {
|
||||
throw new HibernateException( "not yet started!" );
|
||||
}
|
||||
started = false;
|
||||
rolledback = false;
|
||||
committed = false;
|
||||
try {
|
||||
DummyTransactionManager.INSTANCE.commit();
|
||||
committed = true;
|
||||
}
|
||||
catch( Throwable t ) {
|
||||
throw new HibernateException( "error on commit()", t );
|
||||
}
|
||||
}
|
||||
|
||||
public void rollback() throws HibernateException {
|
||||
if ( !started ) {
|
||||
throw new HibernateException( "not yet started!" );
|
||||
}
|
||||
started = false;
|
||||
rolledback = false;
|
||||
committed = false;
|
||||
try {
|
||||
DummyTransactionManager.INSTANCE.rollback();
|
||||
rolledback = true;
|
||||
}
|
||||
catch( Throwable t ) {
|
||||
throw new HibernateException( "error on rollback()", t );
|
||||
}
|
||||
}
|
||||
|
||||
public boolean wasRolledBack() throws HibernateException {
|
||||
return rolledback;
|
||||
}
|
||||
|
||||
public boolean wasCommitted() throws HibernateException {
|
||||
return committed;
|
||||
}
|
||||
|
||||
public boolean isActive() throws HibernateException {
|
||||
return started;
|
||||
}
|
||||
|
||||
public void registerSynchronization(Synchronization synchronization) throws HibernateException {
|
||||
try {
|
||||
DummyTransactionManager.INSTANCE.getCurrent().registerSynchronization( synchronization );
|
||||
}
|
||||
catch( Throwable t ) {
|
||||
throw new HibernateException( "error on registerSynchronization()", t );
|
||||
}
|
||||
}
|
||||
|
||||
public void setTimeout(int seconds) {
|
||||
// ignore...
|
||||
}
|
||||
}
|
||||
|
||||
public static void setup(Configuration cfg) {
|
||||
cfg.setProperty( Environment.CONNECTION_PROVIDER, DummyConnectionProvider.class.getName() );
|
||||
cfg.setProperty( Environment.TRANSACTION_MANAGER_STRATEGY, DummyTransactionManagerLookup.class.getName() );
|
||||
cfg.setProperty( Environment.TRANSACTION_STRATEGY, DummyJTAStyleTransationFactory.class.getName() );
|
||||
cfg.setProperty( Environment.FLUSH_BEFORE_COMPLETION, "true" );
|
||||
}
|
||||
}
|
|
@ -1,146 +0,0 @@
|
|||
//$Id: DummyTransaction.java 8411 2005-10-14 23:29:04Z maxcsaucdk $
|
||||
package org.hibernate.test.tm;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.transaction.HeuristicMixedException;
|
||||
import javax.transaction.HeuristicRollbackException;
|
||||
import javax.transaction.RollbackException;
|
||||
import javax.transaction.Status;
|
||||
import javax.transaction.Synchronization;
|
||||
import javax.transaction.SystemException;
|
||||
import javax.transaction.Transaction;
|
||||
import javax.transaction.xa.XAResource;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class DummyTransaction implements Transaction {
|
||||
|
||||
int status;
|
||||
private Connection connection;
|
||||
List synchronizations = new ArrayList();
|
||||
private DummyTransactionManager transactionManager;
|
||||
|
||||
DummyTransaction(DummyTransactionManager transactionManager) {
|
||||
status = Status.STATUS_NO_TRANSACTION;
|
||||
this.transactionManager = transactionManager;
|
||||
}
|
||||
|
||||
public void begin() throws SystemException {
|
||||
try {
|
||||
connection = transactionManager.connections.getConnection();
|
||||
}
|
||||
catch (SQLException sqle) {
|
||||
|
||||
sqle.printStackTrace();
|
||||
throw new SystemException(sqle.toString());
|
||||
}
|
||||
status = Status.STATUS_ACTIVE;
|
||||
}
|
||||
|
||||
public void commit() throws RollbackException, HeuristicMixedException,
|
||||
HeuristicRollbackException, SecurityException,
|
||||
IllegalStateException, SystemException {
|
||||
|
||||
if (status == Status.STATUS_MARKED_ROLLBACK) {
|
||||
rollback();
|
||||
}
|
||||
else {
|
||||
status = Status.STATUS_PREPARING;
|
||||
|
||||
for ( int i=0; i<synchronizations.size(); i++ ) {
|
||||
Synchronization s = (Synchronization) synchronizations.get(i);
|
||||
s.beforeCompletion();
|
||||
}
|
||||
|
||||
status = Status.STATUS_COMMITTING;
|
||||
|
||||
try {
|
||||
connection.commit();
|
||||
connection.close();
|
||||
}
|
||||
catch (SQLException sqle) {
|
||||
status = Status.STATUS_UNKNOWN;
|
||||
throw new SystemException();
|
||||
}
|
||||
|
||||
status = Status.STATUS_COMMITTED;
|
||||
|
||||
for ( int i=0; i<synchronizations.size(); i++ ) {
|
||||
Synchronization s = (Synchronization) synchronizations.get(i);
|
||||
s.afterCompletion(status);
|
||||
}
|
||||
|
||||
//status = Status.STATUS_NO_TRANSACTION;
|
||||
transactionManager.endCurrent(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean delistResource(XAResource arg0, int arg1)
|
||||
throws IllegalStateException, SystemException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean enlistResource(XAResource arg0) throws RollbackException,
|
||||
IllegalStateException, SystemException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getStatus() throws SystemException {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void registerSynchronization(Synchronization sync)
|
||||
throws RollbackException, IllegalStateException, SystemException {
|
||||
synchronizations.add(sync);
|
||||
}
|
||||
|
||||
public void rollback() throws IllegalStateException, SystemException {
|
||||
|
||||
status = Status.STATUS_ROLLING_BACK;
|
||||
|
||||
// Synch.beforeCompletion() should *not* be called for rollbacks
|
||||
// for ( int i=0; i<synchronizations.size(); i++ ) {
|
||||
// Synchronization s = (Synchronization) synchronizations.get(i);
|
||||
// s.beforeCompletion();
|
||||
// }
|
||||
|
||||
status = Status.STATUS_ROLLEDBACK;
|
||||
|
||||
try {
|
||||
connection.rollback();
|
||||
connection.close();
|
||||
}
|
||||
catch (SQLException sqle) {
|
||||
status = Status.STATUS_UNKNOWN;
|
||||
throw new SystemException();
|
||||
}
|
||||
|
||||
for ( int i=0; i<synchronizations.size(); i++ ) {
|
||||
Synchronization s = (Synchronization) synchronizations.get(i);
|
||||
s.afterCompletion(status);
|
||||
}
|
||||
|
||||
//status = Status.STATUS_NO_TRANSACTION;
|
||||
transactionManager.endCurrent(this);
|
||||
}
|
||||
|
||||
public void setRollbackOnly() throws IllegalStateException, SystemException {
|
||||
status = Status.STATUS_MARKED_ROLLBACK;
|
||||
}
|
||||
|
||||
void setConnection(Connection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
//$Id: DummyTransactionManager.java 7003 2005-06-03 16:09:59Z steveebersole $
|
||||
package org.hibernate.test.tm;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.transaction.HeuristicMixedException;
|
||||
import javax.transaction.HeuristicRollbackException;
|
||||
import javax.transaction.InvalidTransactionException;
|
||||
import javax.transaction.NotSupportedException;
|
||||
import javax.transaction.RollbackException;
|
||||
import javax.transaction.SystemException;
|
||||
import javax.transaction.Transaction;
|
||||
import javax.transaction.TransactionManager;
|
||||
|
||||
import org.hibernate.connection.ConnectionProvider;
|
||||
import org.hibernate.connection.ConnectionProviderFactory;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class DummyTransactionManager implements TransactionManager {
|
||||
|
||||
public static DummyTransactionManager INSTANCE;
|
||||
|
||||
private DummyTransaction current;
|
||||
ConnectionProvider connections;
|
||||
|
||||
public DummyTransactionManager(Properties props) {
|
||||
connections = ConnectionProviderFactory.newConnectionProvider();
|
||||
}
|
||||
|
||||
public void begin() throws NotSupportedException, SystemException {
|
||||
current = new DummyTransaction(this);
|
||||
current.begin();
|
||||
}
|
||||
|
||||
public void commit() throws RollbackException, HeuristicMixedException,
|
||||
HeuristicRollbackException, SecurityException,
|
||||
IllegalStateException, SystemException {
|
||||
current.commit();
|
||||
}
|
||||
|
||||
|
||||
public int getStatus() throws SystemException {
|
||||
return current.getStatus();
|
||||
}
|
||||
|
||||
public Transaction getTransaction() throws SystemException {
|
||||
return current;
|
||||
}
|
||||
|
||||
public void resume(Transaction tx) throws InvalidTransactionException,
|
||||
IllegalStateException, SystemException {
|
||||
current = (DummyTransaction) tx;
|
||||
}
|
||||
|
||||
public void rollback() throws IllegalStateException, SecurityException,
|
||||
SystemException {
|
||||
current.rollback();
|
||||
|
||||
}
|
||||
|
||||
public void setRollbackOnly() throws IllegalStateException, SystemException {
|
||||
current.setRollbackOnly();
|
||||
}
|
||||
|
||||
public void setTransactionTimeout(int t) throws SystemException {
|
||||
}
|
||||
|
||||
public Transaction suspend() throws SystemException {
|
||||
Transaction result = current;
|
||||
current = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
public DummyTransaction getCurrent() {
|
||||
return current;
|
||||
}
|
||||
|
||||
void endCurrent(DummyTransaction tx) {
|
||||
if (current==tx) current=null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
//$Id: DummyTransactionManagerLookup.java 5693 2005-02-13 01:59:07Z oneovthafew $
|
||||
package org.hibernate.test.tm;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.transaction.TransactionManager;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.transaction.TransactionManagerLookup;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class DummyTransactionManagerLookup implements TransactionManagerLookup {
|
||||
|
||||
public TransactionManager getTransactionManager(Properties props)
|
||||
throws HibernateException {
|
||||
if ( DummyTransactionManager.INSTANCE == null ) {
|
||||
DummyTransactionManager.INSTANCE = new DummyTransactionManager(props);
|
||||
}
|
||||
return DummyTransactionManager.INSTANCE;
|
||||
}
|
||||
|
||||
public String getUserTransactionName() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue