[PATCH 2 of 2] issue1847 Remove locking parallel access is not the problem here

Wald Commits scm-commit at wald.intevation.org
Thu Sep 3 17:49:08 CEST 2015


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1441295345 -7200
# Node ID 0e3ecf7cd461d69e83c1a777ac368d9d4b7217ae
# Parent  e9abf747f6cea0bd0814fc83f5f6a8ca4745d120
issue1847 Remove locking parallel access is not the problem here.

diff -r e9abf747f6ce -r 0e3ecf7cd461 artifact-database/src/main/java/org/dive4elements/artifactdatabase/db/SQLExecutor.java
--- a/artifact-database/src/main/java/org/dive4elements/artifactdatabase/db/SQLExecutor.java	Thu Sep 03 17:45:16 2015 +0200
+++ b/artifact-database/src/main/java/org/dive4elements/artifactdatabase/db/SQLExecutor.java	Thu Sep 03 17:49:05 2015 +0200
@@ -5,8 +5,6 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
 import javax.sql.DataSource;
 
 import org.apache.log4j.Logger;
@@ -56,79 +54,61 @@
         }
 
         public boolean runWriteNoRollback() {
-            rwLock.writeLock().lock();
+            DataSource dataSource = dbConnection.getDataSource();
             try {
-                DataSource dataSource = dbConnection.getDataSource();
+                conn = dataSource.getConnection();
                 try {
-                    conn = dataSource.getConnection();
-                    try {
-                        conn.setAutoCommit(false);
-                        return doIt();
-                    }
-                    catch (SQLException sqle) {
-                        throw sqle;
-                    }
+                    conn.setAutoCommit(false);
+                    return doIt();
                 }
                 catch (SQLException sqle) {
-                    logger.error(sqle.getLocalizedMessage(), sqle);
+                    throw sqle;
                 }
-                finally {
-                    close();
-                }
-                return false;
+            }
+            catch (SQLException sqle) {
+                logger.error(sqle.getLocalizedMessage(), sqle);
             }
             finally {
-                rwLock.writeLock().unlock();
+                close();
             }
+            return false;
         }
 
         public boolean runWrite() {
-            rwLock.writeLock().lock();
+            DataSource dataSource = dbConnection.getDataSource();
             try {
-                DataSource dataSource = dbConnection.getDataSource();
+                conn = dataSource.getConnection();
                 try {
-                    conn = dataSource.getConnection();
-                    try {
-                        conn.setAutoCommit(false);
-                        return doIt();
-                    }
-                    catch (SQLException sqle) {
-                        conn.rollback();
-                        throw sqle;
-                    }
+                    conn.setAutoCommit(false);
+                    return doIt();
                 }
                 catch (SQLException sqle) {
-                    logger.error(sqle.getLocalizedMessage(), sqle);
+                    conn.rollback();
+                    throw sqle;
                 }
-                finally {
-                    close();
-                }
-                return false;
+            }
+            catch (SQLException sqle) {
+                logger.error(sqle.getLocalizedMessage(), sqle);
             }
             finally {
-                rwLock.writeLock().unlock();
+                close();
             }
+            return false;
         }
 
         public boolean runRead() {
-            rwLock.readLock().lock();
+            DataSource dataSource = dbConnection.getDataSource();
             try {
-                DataSource dataSource = dbConnection.getDataSource();
-                try {
-                    conn = dataSource.getConnection();
-                    return doIt();
-                }
-                catch (SQLException sqle) {
-                    logger.error(sqle.getLocalizedMessage(), sqle);
-                }
-                finally {
-                    close();
-                }
-                return false;
+                conn = dataSource.getConnection();
+                return doIt();
+            }
+            catch (SQLException sqle) {
+                logger.error(sqle.getLocalizedMessage(), sqle);
             }
             finally {
-                rwLock.readLock().unlock();
+                close();
             }
+            return false;
         }
 
         public boolean doIt() throws SQLException {
@@ -137,10 +117,8 @@
     } // class Instance
 
     protected DBConnection           dbConnection;
-    protected ReentrantReadWriteLock rwLock;
 
     public SQLExecutor() {
-        rwLock = new ReentrantReadWriteLock();
     }
 
     public SQLExecutor(DBConnection dbConnection) {


More information about the Dive4Elements-commits mailing list