Repository: marmotta
Updated Branches:
  refs/heads/develop f45e3ddd6 -> 72bdf01af


more code hygiene, clean up redundant or unnecessary code


Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/72bdf01a
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/72bdf01a
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/72bdf01a

Branch: refs/heads/develop
Commit: 72bdf01afc4e8f944cd7d1e05d1bb43d6fef13b4
Parents: f45e3dd
Author: Sebastian Schaffert <[email protected]>
Authored: Sun Nov 20 14:04:35 2016 +0100
Committer: Sebastian Schaffert <[email protected]>
Committed: Sun Nov 20 14:04:35 2016 +0100

----------------------------------------------------------------------
 .../kiwi/persistence/KiWiConnection.java        | 72 ++++++--------------
 .../kiwi/persistence/KiWiPersistence.java       | 32 +++++----
 .../ldclient/services/ldclient/LDClient.java    |  6 +-
 3 files changed, 42 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/72bdf01a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
index 77110d8..15f2f04 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
@@ -113,29 +113,25 @@ public class KiWiConnection implements AutoCloseable {
     private static Calendar calendarUTC = 
Calendar.getInstance(TimeZone.getTimeZone("UTC"));
 
 
-    private Map<String,PreparedStatement> statementCache;
+    private Map<String,PreparedStatement> statementCache = new HashMap<>();
 
     private boolean autoCommit = false;
-
     private boolean batchCommit = true;
 
     private boolean closed = false;
 
     private int batchSize = 1000;
 
-    private ReentrantLock commitLock;
-
-    private ReentrantLock literalLock;
-    private ReentrantLock uriLock;
-    private ReentrantLock bnodeLock;
+    private ReentrantLock commitLock  = new ReentrantLock();
+    private ReentrantLock literalLock = new ReentrantLock();
+    private ReentrantLock uriLock     = new ReentrantLock();
+    private ReentrantLock bnodeLock   = new ReentrantLock();
 
     // this set keeps track of all statements that have been deleted in the 
active transaction of this connection
     // this is needed to be able to determine if adding the triple again will 
merely undo a deletion or is a
     // completely new addition to the triple store
     private BloomFilter<Long> deletedStatementsLog;
 
-    private static long numberOfCommits = 0;
-
     private long transactionId;
 
     private int QUERY_BATCH_SIZE = 1024;
@@ -144,16 +140,11 @@ public class KiWiConnection implements AutoCloseable {
         this.cacheManager = cacheManager;
         this.dialect      = dialect;
         this.persistence  = persistence;
-        this.commitLock   = new ReentrantLock();
-        this.literalLock   = new ReentrantLock();
-        this.uriLock   = new ReentrantLock();
-        this.bnodeLock   = new ReentrantLock();
         this.batchCommit  = dialect.isBatchSupported();
         this.deletedStatementsLog = BloomFilter.create(Funnels.longFunnel(), 
100000);
         this.transactionId = getNextSequence();
 
         initCachePool();
-        initStatementCache();
     }
 
     private void initCachePool() {
@@ -168,20 +159,6 @@ public class KiWiConnection implements AutoCloseable {
     }
 
     /**
-     * Load all prepared statements of the dialect into the statement cache
-     * @throws SQLException
-     */
-    private void initStatementCache() throws SQLException {
-        statementCache = new HashMap<>();
-
-        /*
-        for(String key : dialect.getStatementIdentifiers()) {
-            
statementCache.put(key,connection.prepareStatement(dialect.getStatement(key)));
-        }
-        */
-    }
-
-    /**
      * This method must be called by all methods as soon as they actually 
require a JDBC connection. This allows
      * more efficient implementations in case the queries can be answered 
directly from the cache.
      */
@@ -250,8 +227,8 @@ public class KiWiConnection implements AutoCloseable {
             if (result.next()) {
                 return constructNamespaceFromDatabase(result);
             }
-            return null;
         }
+        return null;
     }
 
     /**
@@ -282,8 +259,8 @@ public class KiWiConnection implements AutoCloseable {
             if (result.next()) {
                 return constructNamespaceFromDatabase(result);
             }
-            return null;
         }
+        return null;
     }
 
     /**
@@ -350,8 +327,8 @@ public class KiWiConnection implements AutoCloseable {
             if (result.next()) {
                 return result.getLong(1) + (tripleBatch != null ? 
tripleBatch.size() : 0);
             }
-            return tripleBatch != null ? tripleBatch.size() : 0;
         }
+        return tripleBatch != null ? tripleBatch.size() : 0;
     }
 
     /**
@@ -374,8 +351,8 @@ public class KiWiConnection implements AutoCloseable {
             if (result.next()) {
                 return result.getLong(1) + (tripleBatch != null ? 
tripleBatch.listTriples(null, null, null, context, false).size() : 0);
             }
-            return tripleBatch != null ? tripleBatch.listTriples(null, null, 
null, context, false).size() : 0;
         }
+        return tripleBatch != null ? tripleBatch.listTriples(null, null, null, 
context, false).size() : 0;
     }
 
     /**
@@ -426,10 +403,9 @@ public class KiWiConnection implements AutoCloseable {
                 if (result.next()) {
                     return constructNodeFromDatabase(result);
                 }
-                return null;
             }
         }
-
+        return null;
     }
 
     /**
@@ -524,9 +500,8 @@ public class KiWiConnection implements AutoCloseable {
             if (result.next()) {
                 return constructTripleFromDatabase(result);
             }
-            return null;
         }
-
+        return null;
     }
 
     /**
@@ -564,11 +539,11 @@ public class KiWiConnection implements AutoCloseable {
                 if (result.next()) {
                     return (KiWiUriResource) constructNodeFromDatabase(result);
                 }
-                return null;
             }
         } finally {
             uriLock.unlock();
         }
+        return null;
     }
 
     /**
@@ -606,11 +581,11 @@ public class KiWiConnection implements AutoCloseable {
                 if (result.next()) {
                     return (KiWiAnonResource) 
constructNodeFromDatabase(result);
                 }
-                return null;
             }
         } finally {
             bnodeLock.unlock();
         }
+        return null;
     }
 
     /**
@@ -666,11 +641,11 @@ public class KiWiConnection implements AutoCloseable {
                 if (result.next()) {
                     return (KiWiLiteral) constructNodeFromDatabase(result);
                 }
-                return null;
             }
         } finally {
             literalLock.unlock();
         }
+        return null;
     }
 
     /**
@@ -768,11 +743,11 @@ public class KiWiConnection implements AutoCloseable {
                 if (result.next()) {
                     return (KiWiIntLiteral) constructNodeFromDatabase(result);
                 }
-                return null;
             }
         } finally {
             literalLock.unlock();
         }
+        return null;
     }
 
     /**
@@ -818,7 +793,6 @@ public class KiWiConnection implements AutoCloseable {
                 if (result.next()) {
                     return (KiWiDoubleLiteral) 
constructNodeFromDatabase(result);
                 }
-                return null;
             } catch (RuntimeException e) {
                 log.error("Unable to create KiWiDoubleLiteral for node value 
'{}': {}", value, e.getMessage(), e);
                 throw e;
@@ -826,6 +800,7 @@ public class KiWiConnection implements AutoCloseable {
         } finally {
             literalLock.unlock();
         }
+        return null;
     }
 
     /**
@@ -858,7 +833,6 @@ public class KiWiConnection implements AutoCloseable {
         }
 
         literalLock.lock();
-
         try {
 
             // otherwise prepare a query, depending on the parameters given
@@ -872,11 +846,11 @@ public class KiWiConnection implements AutoCloseable {
                 if (result.next()) {
                     return (KiWiBooleanLiteral) 
constructNodeFromDatabase(result);
                 }
-                return null;
             }
         } finally {
             literalLock.unlock();
         }
+        return null;
     }
 
     /**
@@ -1145,11 +1119,9 @@ public class KiWiConnection implements AutoCloseable {
         try (ResultSet result = loadTripleId.executeQuery()) {
             if (result.next()) {
                 return result.getLong(1);
-            } else {
-                return -1L;
             }
-
         }
+        return -1L;
     }
 
     /**
@@ -2107,8 +2079,8 @@ public class KiWiConnection implements AutoCloseable {
             if (result.next()) {
                 return result.getString(1);
             }
-            return null;
         }
+        return null;
     }
 
 
@@ -2270,8 +2242,6 @@ public class KiWiConnection implements AutoCloseable {
      * @see #setAutoCommit
      */
     public synchronized void commit() throws SQLException {
-        numberOfCommits++;
-
         RetryExecution execution = new RetryExecution("COMMIT");
         execution.execute(connection, new RetryCommand<Void>() {
             @Override
@@ -2343,9 +2313,9 @@ public class KiWiConnection implements AutoCloseable {
     public boolean isClosed() throws SQLException {
         if (connection != null) {
             return connection.isClosed();
-        } else {
-            return false;
         }
+
+        return false;
     }
 
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/72bdf01a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
index 585caa7..17c18d0 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
@@ -134,7 +134,8 @@ public class KiWiPersistence {
             Class factory = 
Class.forName(configuration.getCachingBackend().getFactoryClass());
             cacheManager = 
((CacheManagerFactory)factory.newInstance()).createCacheManager(configuration);
         } catch (ClassNotFoundException | InstantiationException | 
IllegalAccessException e) {
-            log.warn("cache manager factory {} not found on classpath (error: 
{}); falling back to Guava in-memory cache backend!", 
configuration.getCachingBackend(), e.getMessage());
+            log.warn("cache manager factory {} not found on classpath (error: 
{}); falling back to Guava in-memory cache backend!",
+                    configuration.getCachingBackend(), e.getMessage());
 
             CacheManagerFactory factory = new GuavaCacheManagerFactory();
             cacheManager = factory.createCacheManager(configuration);
@@ -197,13 +198,14 @@ public class KiWiPersistence {
     }
 
     public void logPoolInfo() throws SQLException {
-        if (connectionPool != null) {
-            log.debug("num_busy_connections:    {}", 
connectionPool.getNumActive());
-            log.debug("num_idle_connections:    {}", 
connectionPool.getNumIdle());
-        } else {
-            log.debug("connection pool not initialized");
+        if (log.isDebugEnabled()) {
+            if (connectionPool != null) {
+                log.debug("num_busy_connections:    {}", 
connectionPool.getNumActive());
+                log.debug("num_idle_connections:    {}", 
connectionPool.getNumIdle());
+            } else {
+                log.debug("connection pool not initialized");
+            }
         }
-
     }
 
 
@@ -345,16 +347,16 @@ public class KiWiPersistence {
             throw new SQLException("persistence backend not initialized; call 
initialise before acquiring a connection");
         }
 
-        if (connectionPool != null) {
-            KiWiConnection con = new 
KiWiConnection(this,configuration.getDialect(),cacheManager);
-            if(getDialect().isBatchSupported()) {
-                con.setBatchCommit(configuration.isTripleBatchCommit());
-                con.setBatchSize(configuration.getTripleBatchSize());
-            }
-            return con;
-        } else {
+        if (connectionPool == null) {
             throw new SQLException("connection pool is closed, database 
connections not available");
         }
+
+        KiWiConnection con = new 
KiWiConnection(this,configuration.getDialect(),cacheManager);
+        if(getDialect().isBatchSupported()) {
+            con.setBatchCommit(configuration.isTripleBatchCommit());
+            con.setBatchSize(configuration.getTripleBatchSize());
+        }
+        return con;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/72bdf01a/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/ldclient/LDClient.java
----------------------------------------------------------------------
diff --git 
a/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/ldclient/LDClient.java
 
b/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/ldclient/LDClient.java
index 069ef0e..c8bef32 100644
--- 
a/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/ldclient/LDClient.java
+++ 
b/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/ldclient/LDClient.java
@@ -54,9 +54,11 @@ import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 
 /**
- * Add file description here!
+ * A service offering Linked Data client functionality for retrieving Linked 
Data resources from the cloud.
+ * Implements retrieval of triples from the cloud depending on the Endpoint 
definitions available for a resource.
+ *
  * <p/>
- * User: sschaffe
+ * User: Sebastian Schaffert
  */
 public final class LDClient implements LDClientService {
 

Reply via email to