You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2004/04/29 10:55:46 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer ConnectionManagerImpl.java
arminw 2004/04/29 01:55:46
Modified: src/java/org/apache/ojb/broker/core
PersistenceBrokerImpl.java
src/java/org/apache/ojb/broker/accesslayer
ConnectionManagerImpl.java
Log:
- made ConnectionManagerImpl#releaseConnection more strict
- decouple PB tx status from ConnectionManagerImpl
local tx status
Revision Changes Path
1.79 +53 -29 db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
Index: PersistenceBrokerImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -r1.78 -r1.79
--- PersistenceBrokerImpl.java 14 Apr 2004 18:56:41 -0000 1.78
+++ PersistenceBrokerImpl.java 29 Apr 2004 08:55:46 -0000 1.79
@@ -99,6 +99,10 @@
*/
private boolean isClosed;
/**
+ * Reflects the transaction status of this instance.
+ */
+ private boolean inTransaction;
+ /**
* m_ObjectCache caches object already loaded from db and protects the uniqueness
* of objects. When an object is loaded from the db it is stored in the cache.
* Any later lookups with the same pk values will return the cached object
@@ -256,6 +260,8 @@
*/
public void refresh()
{
+ // guarantee that refreshed use initial status
+ setInTransaction(false);
this.descriptorRepository = MetadataManager.getInstance().getRepository();
}
@@ -267,9 +273,13 @@
public void destroy()
{
removeAllListeners();
- if (this.connectionManager != null)
+ if (connectionManager != null)
{
- this.connectionManager.releaseConnection();
+ if(connectionManager.isInLocalTransaction())
+ {
+ connectionManager.localRollback();
+ }
+ connectionManager.releaseConnection();
}
this.setClosed(true);
@@ -305,6 +315,7 @@
*/
if (isInTransaction())
{
+ logger.error("Try to close a ");
abortTransaction();
}
if (logger.isDebugEnabled())
@@ -350,26 +361,21 @@
*/
public synchronized void abortTransaction() throws TransactionNotInProgressException
{
- /*
- arminw:
- TODO: does it make sense to prevent rollback call??
- by default ConnectionManager does an internal rollback when an
- SQLException occur, thus this check will fail
- */
-// if (!this.connectionManager.isInLocalTransaction())
-// {
-// throw new TransactionNotInProgressException("ConnectionManager is NOT in transaction");
-// }
-
- fireBrokerEvent(BEFORE_ROLLBACK_EVENT);
- clearRegistrationLists();
- referencesBroker.removePrefetchingListeners();
- /*
- check if we in local tx, before do local rollback
- Necessary, because ConnectionManager may do a rollback by itself
- */
- if(isInTransaction()) this.connectionManager.localRollback();
- fireBrokerEvent(AFTER_ROLLBACK_EVENT);
+ if(isInTransaction())
+ {
+ fireBrokerEvent(BEFORE_ROLLBACK_EVENT);
+ setInTransaction(false);
+ clearRegistrationLists();
+ referencesBroker.removePrefetchingListeners();
+ /*
+ arminw:
+ check if we in local tx, before do local rollback
+ Necessary, because ConnectionManager may do a rollback by itself
+ or in managed environments the used connection is already be closed
+ */
+ if(connectionManager.isInLocalTransaction()) this.connectionManager.localRollback();
+ fireBrokerEvent(AFTER_ROLLBACK_EVENT);
+ }
}
/**
@@ -381,11 +387,12 @@
*/
public synchronized void beginTransaction() throws TransactionInProgressException, TransactionAbortedException
{
- if (this.connectionManager.isInLocalTransaction())
+ if (isInTransaction())
{
- throw new TransactionInProgressException("ConnectionManager is already in transaction");
+ throw new TransactionInProgressException("PersistenceBroker is already in transaction");
}
fireBrokerEvent(BEFORE_BEGIN_EVENT);
+ setInTransaction(true);
this.connectionManager.localBegin();
fireBrokerEvent(AFTER_BEGIN_EVENT);
}
@@ -401,14 +408,25 @@
*/
public synchronized void commitTransaction() throws TransactionNotInProgressException, TransactionAbortedException
{
- if (!this.connectionManager.isInLocalTransaction())
+ if (!isInTransaction())
{
- throw new TransactionNotInProgressException("ConnectionManager is NOT in transaction");
+ throw new TransactionNotInProgressException("PersistenceBroker is NOT in transaction, can't commit");
}
fireBrokerEvent(BEFORE_COMMIT_EVENT);
+ setInTransaction(false);
clearRegistrationLists();
referencesBroker.removePrefetchingListeners();
- this.connectionManager.localCommit();
+ /*
+ arminw:
+ In managed environments it should be possible to close a used connection before
+ the tx was commited, thus it will be possible that the PB instance is in PB-tx, but
+ the connection is already closed. To avoid problems check if CM is in local tx before
+ do the CM.commit call
+ */
+ if(connectionManager.isInLocalTransaction())
+ {
+ this.connectionManager.localCommit();
+ }
fireBrokerEvent(AFTER_COMMIT_EVENT);
}
@@ -1652,7 +1670,13 @@
*/
public boolean isInTransaction()
{
- return this.connectionManager.isInLocalTransaction();
+ // return this.connectionManager.isInLocalTransaction();
+ return inTransaction;
+ }
+
+ public void setInTransaction(boolean inTransaction)
+ {
+ this.inTransaction = inTransaction;
}
/**
1.15 +14 -5 db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionManagerImpl.java
Index: ConnectionManagerImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionManagerImpl.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ConnectionManagerImpl.java 4 Apr 2004 23:53:30 -0000 1.14
+++ ConnectionManagerImpl.java 29 Apr 2004 08:55:46 -0000 1.15
@@ -227,7 +227,7 @@
finally
{
restoreAutoCommitState();
- this.releaseConnection();
+ releaseConnection();
}
}
@@ -283,9 +283,18 @@
//if (log.isDebugEnabled()) log.debug("No connection to release");
return;
}
- this.connectionFactory.releaseConnection(this.jcd, this.con);
- this.con = null;
- this.batchCon = null;
+ if(isInLocalTransaction())
+ {
+ log.error("Connection is in local transaction, do a 'localCommit' or 'localRollback' before" +
+ "perform the connection release - rollback the connection now");
+ localRollback();
+ }
+ else
+ {
+ this.connectionFactory.releaseConnection(this.jcd, this.con);
+ this.con = null;
+ this.batchCon = null;
+ }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org