[cvs] expresso commit by lhamel: allow setConnection() to accept a null

JCorporate Ltd jcorp at jcorporate.com
Thu Jan 6 06:57:36 UTC 2005


Log Message:
-----------
allow setConnection() to accept a null connection, to reset this objects local connection to null

Modified Files:
--------------
    expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj:
        DBObject.java

Revision Data
-------------
Index: DBObject.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/DBObject.java,v
retrieving revision 1.236
retrieving revision 1.237
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/DBObject.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/DBObject.java -u -r1.236 -r1.237
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/DBObject.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/DBObject.java
@@ -1186,8 +1186,8 @@
         DBConnection myConnection = null;
 
         try {
-            if (localConnection != null) {
-                myConnection = localConnection;
+            if (getLocalConnection() != null) {
+                myConnection = getLocalConnection();
             } else {
                 myConnection = getConnectionPool().getConnection(myClassName);
             }
@@ -1199,7 +1199,7 @@
                     forKey() + ":" + de.getMessage() + " (" +
                     sqlCommand + ")", de.getDBMessage());
         } finally {
-            if (localConnection == null) {
+            if (getLocalConnection() == null) {
                 myConnection.release();
             }
         }
@@ -1707,8 +1707,8 @@
         DBConnection myConnection = null;
 
         try {
-            if (localConnection != null) {
-                myConnection = localConnection;
+            if (getLocalConnection() != null) {
+                myConnection = getLocalConnection();
             } else {
                 myConnection = getConnectionPool().getConnection(myClassName);
             }
@@ -1725,7 +1725,7 @@
             log.error("Error counting field", t);
             throw new DBException("Error counting field", t);
         } finally {
-            if (localConnection == null) {
+            if (getLocalConnection() == null) {
                 if (myConnection != null) {
                     myConnection.release();
                 }
@@ -1797,8 +1797,8 @@
         boolean detailsRequireCommittment = false;
 
         try {
-            if (localConnection != null) {
-                myConnection = localConnection;
+            if (getLocalConnection() != null) {
+                myConnection = getLocalConnection();
             } else {
                 myConnection = getConnectionPool().getConnection(myClassName);
             }
@@ -1845,15 +1845,15 @@
              */
 
             // roll back any details deletion if we are in control of
-            // the db connection, i.e., if there was no localConnection
+            // the db connection, i.e., if there was no getLocalConnection()
             // provided to us
-            if (detailsRequireCommittment && localConnection == null && myConnection.getAutoCommit() == false) {
+            if (detailsRequireCommittment && getLocalConnection() == null && myConnection.getAutoCommit() == false) {
                 myConnection.rollback();
             }
 
             throw ((DBException) e.fillInStackTrace());
         } finally {
-            if (localConnection == null) {
+            if (getLocalConnection() == null) {
                 myConnection.release();
             }
         }
@@ -1986,7 +1986,7 @@
 //            log.error("Error performing deleteAll", t);
 //            throw new DBException("Error performing deleteAll", t);
 //        } finally {
-//            if (localConnection == null) {
+//            if (getLocalConnection() == null) {
 //                if (listingConnection != null) {
 //                    getConnectionPool().release(listingConnection);
 //                }
@@ -2058,8 +2058,8 @@
         DBConnection myConnection = null;
 
         try {
-            if (localConnection != null) {
-                myConnection = localConnection;
+            if (getLocalConnection() != null) {
+                myConnection = getLocalConnection();
             } else {
                 myConnection = getConnectionPool().getConnection(myClassName);
             }
@@ -2079,7 +2079,7 @@
 
             throw ((DBException) e.fillInStackTrace());
         } finally {
-            if (localConnection == null) {
+            if (getLocalConnection() == null) {
                 myConnection.release();
             }
         }
@@ -2353,8 +2353,8 @@
         DBConnection myConnection = null;
 
         try {
-            if (localConnection != null) {
-                myConnection = localConnection;
+            if (getLocalConnection() != null) {
+                myConnection = getLocalConnection();
             } else {
                 myConnection = getConnectionPool().getConnection(myClassName);
             }
@@ -2475,7 +2475,7 @@
             log.error("Error in find: " + de.getMessage(), de);
             throw de;
         } finally {
-            if (localConnection == null) {
+            if (getLocalConnection() == null) {
                 if (myConnection != null) {
                     myConnection.release();
                 }
@@ -3252,9 +3252,9 @@
     public void saveBinaryField(String fieldName,
                                 byte[] incomingData) throws DBException {
         DBConnectionPool connectionPool = null;
-        DBConnection myConnection = localConnection;
+        DBConnection myConnection = getLocalConnection();
 
-        if (localConnection == null) {
+        if (getLocalConnection() == null) {
             connectionPool = DBConnectionPool.getInstance(getDataContext());
             myConnection = connectionPool.getConnection();
         }
@@ -3264,7 +3264,7 @@
                     incomingData,
                     myConnection);
         } finally {
-            if (localConnection == null) {
+            if (getLocalConnection() == null) {
                 if (connectionPool != null) {
                     connectionPool.release(myConnection);
                 }
@@ -3418,7 +3418,7 @@
      * @return com.jcorporate.expresso.core.db.DBConnection or null
      */
     public DBConnection getLocalConnection() {
-        return localConnection;
+        return getLocalConnection();
     }
 
 
@@ -3440,8 +3440,8 @@
         String returnValue = null;
 
         try {
-            if (localConnection != null) {
-                myConnection = localConnection;
+            if (getLocalConnection() != null) {
+                myConnection = getLocalConnection();
             } else {
                 myConnection = getConnectionPool().getConnection(myClassName);
             }
@@ -3472,7 +3472,7 @@
         } catch (DBException de) {
             throw de;
         } finally {
-            if (localConnection == null) {
+            if (getLocalConnection() == null) {
                 myConnection.release();
             }
         }
@@ -3669,8 +3669,8 @@
      * @throws DBException upon error
      */
     protected void copyAttributes(DBObject returnObj) throws DBException {
-        if (localConnection != null) {
-            returnObj.setConnection(localConnection);
+        if (getLocalConnection() != null) {
+            returnObj.setConnection(getLocalConnection());
         } else {
             returnObj.setDataContext(getDataContext());
         }
@@ -3852,8 +3852,8 @@
 
                     if (o instanceof DBObject) {
                         DBObject dbo = (DBObject) o;
-                        if (localConnection != null) {
-                            dbo.setConnection(localConnection);
+                        if (getLocalConnection() != null) {
+                            dbo.setConnection(getLocalConnection());
                         }
                     } else if (o instanceof MultiDBObject) {
                         MultiDBObject mdo = (MultiDBObject) o;
@@ -4048,7 +4048,7 @@
             //
             // Do not use cache if in Transaction. and a localconnection has been set
             //
-            if (localConnection == null || localConnection.getAutoCommit() == false) {
+            if (getLocalConnection() == null || getLocalConnection().getAutoCommit() == false) {
                 java.util.List temp = cs.getItems(cacheName);
                 if (temp != null) {
                     if (temp instanceof Vector) {
@@ -4256,7 +4256,7 @@
             //
             // Do not use cache if in Transaction. and a localconnection has been set
             //
-            if (localConnection == null || localConnection.getAutoCommit() == false) {
+            if (getLocalConnection() == null || getLocalConnection().getAutoCommit() == false) {
                 if (cs != null) {
                     java.util.List temp = cs.getItems(cacheName);
                     if (!(temp instanceof Vector)) {
@@ -5222,8 +5222,8 @@
         DBConnection myConnection = null;
 
         try {
-            if (localConnection != null) {
-                myConnection = localConnection;
+            if (getLocalConnection() != null) {
+                myConnection = getLocalConnection();
             } else {
                 myConnection = getConnectionPool().getConnection(myClassName);
             }
@@ -5263,7 +5263,7 @@
         } catch (DBException de) {
             throw de;
         } finally {
-            if (localConnection == null && myConnection != null) {
+            if (getLocalConnection() == null && myConnection != null) {
                 myConnection.release();
             }
         }
@@ -5341,7 +5341,7 @@
             log.error("Error performing searchAndRetrieveList", t);
             throw new DBException("Error performing searchAndRetrieveList", t);
         } finally {
-            if (localConnection == null) {
+            if (getLocalConnection() == null) {
                 if (myConnection != null) {
                     getConnectionPool().release(myConnection);
                 }
@@ -5576,12 +5576,18 @@
      * add, update, etc). It is important to use your own explicit connection when
      * dealing with a database transactional environment (e.g. commit(), rollback()).
      *
-     * @param newConnection The new DBConnection object to be used by this DB Object
+     * SIDE-EFFECT: sets DB context of this object to the newConnection.getDataContext()
+     *
+     * @param newConnection The new DBConnection object to be used by this DB Object; pass in null to reset to "no local connection"
      * @throws DBException upon error.
      */
     public synchronized void setConnection(DBConnection newConnection)
             throws DBException {
-        setConnection(newConnection, newConnection.getDataContext());
+        localConnection = newConnection;
+        if (localConnection != null) {
+            setDataContext(localConnection.getDataContext());
+        }
+
     } /* setConnection(DBConnection) */
 
     /**
@@ -5597,6 +5603,8 @@
      * a dbconnection from your other pool, but the setup tables are in a different
      * context</p>
      *
+     * SIDE-EFFECT: sets DB context of this object to the parameter value
+     *
      * @param newConnection      The new DBConnection object to be used by this DB Object
      * @param setupTablesContext the data context that is used for the expresso setup tables.
      * @throws DBException upon error.
@@ -5605,7 +5613,9 @@
     public synchronized void setConnection(DBConnection newConnection,
                                            String setupTablesContext) throws DBException {
         localConnection = newConnection;
-        setDataContext(setupTablesContext);
+        if ( setupTablesContext != null ) {
+            setDataContext(setupTablesContext);
+        }
     }
 
 
@@ -6491,8 +6501,8 @@
         }
         DBConnection myConnection = null;
         try {
-            if (localConnection != null) {
-                myConnection = localConnection;
+            if (getLocalConnection() != null) {
+                myConnection = getLocalConnection();
             } else {
                 myConnection = getConnectionPool().getConnection(myClassName);
             }
@@ -6505,7 +6515,7 @@
         } catch (DBException de) {
             throw de;
         } finally {
-            if (localConnection == null) {
+            if (getLocalConnection() == null) {
                 myConnection.release();
             }
         }
@@ -6766,7 +6776,7 @@
             //set instead.
             //
             DBConnectionPool myPool = DBConnectionPool.getInstance(getMappedDataContext());
-            DBConnection localConnection = getLocalConnection();
+            DBConnection aLocalConn = getLocalConnection();
 
             List lobFieldOrder = null;
             List lobUpdates = null;
@@ -6896,8 +6906,8 @@
             DBConnection myConnection = null;
 
             try {
-                if (localConnection != null) {
-                    myConnection = localConnection;
+                if (getLocalConnection() != null) {
+                    myConnection = getLocalConnection();
                 } else {
                     myConnection = myPool.getConnection(getClass().getName());
                 }
@@ -6939,7 +6949,7 @@
                 npe.printStackTrace();
                 throw new DataException(npe);
             } finally {
-                if (localConnection == null) {
+                if (getLocalConnection() == null) {
                     if (myPool != null && myConnection != null) {
                         myPool.release(myConnection);
                     }


More information about the cvs mailing list