changeset 544:0e3ecf7cd461 3.2.0

issue1847 Remove locking parallel access is not the problem here.
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 03 Sep 2015 17:49:05 +0200
parents e9abf747f6ce
children a173ecf4e537
files artifact-database/src/main/java/org/dive4elements/artifactdatabase/db/SQLExecutor.java
diffstat 1 files changed, 29 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- 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) {

http://dive4elements.wald.intevation.org