Some code-cleanup + javadoc completions

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

Branch: refs/heads/MARMOTTA-556
Commit: 5991d61d91998e65a154d78f35d0ec3d14a6a8a0
Parents: 1d9fa71
Author: Jakob Frank <[email protected]>
Authored: Fri Dec 19 09:35:44 2014 +0100
Committer: Jakob Frank <[email protected]>
Committed: Fri Dec 19 09:35:44 2014 +0100

----------------------------------------------------------------------
 .../kiwi/persistence/KiWiConnection.java        | 261 ++++++++-----------
 .../marmotta/kiwi/persistence/KiWiDialect.java  |  40 +--
 .../kiwi/persistence/KiWiGarbageCollector.java  |  20 +-
 .../kiwi/persistence/KiWiPersistence.java       |  21 +-
 .../persistence/util/ResultSetIteration.java    |   2 +-
 5 files changed, 146 insertions(+), 198 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/5991d61d/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 bb71e02..712973c 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
@@ -54,6 +54,7 @@ import java.util.concurrent.locks.ReentrantLock;
  * <p/>
  * Author: Sebastian Schaffert
  */
+@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
 public class KiWiConnection implements AutoCloseable {
 
     private static Logger log = LoggerFactory.getLogger(KiWiConnection.class);
@@ -107,7 +108,7 @@ public class KiWiConnection implements AutoCloseable {
     /**
      * Cache instances of locales for language tags
      */
-    private static Map<String,Locale> localeMap = new HashMap<String, 
Locale>();
+    private static Map<String,Locale> localeMap = new HashMap<>();
 
     private static Calendar calendarUTC = 
Calendar.getInstance(TimeZone.getTimeZone("UTC"));
 
@@ -171,7 +172,7 @@ public class KiWiConnection implements AutoCloseable {
      * @throws SQLException
      */
     private void initStatementCache() throws SQLException {
-        statementCache = new HashMap<String, PreparedStatement>();
+        statementCache = new HashMap<>();
 
         /*
         for(String key : dialect.getStatementIdentifiers()) {
@@ -190,14 +191,14 @@ public class KiWiConnection implements AutoCloseable {
             connection.setAutoCommit(autoCommit);
         }
         if(tripleBatch == null) {
-            tripleBatch = new TripleTable<KiWiTriple>();
+            tripleBatch = new TripleTable<>();
         }
     }
 
     /**
      * Get direct access to the JDBC connection used by this KiWiConnection.
      *
-     * @return
+     * @return the underlying raw JDBC connection
      */
     public Connection getJDBCConnection() throws SQLException {
         requireJDBCConnection();
@@ -207,7 +208,7 @@ public class KiWiConnection implements AutoCloseable {
 
     /**
      * Return the cache manager used by this connection
-     * @return
+     * @return the CacheManager
      */
     public CacheManager getCacheManager() {
         return cacheManager;
@@ -245,15 +246,12 @@ public class KiWiConnection implements AutoCloseable {
 
         // run the database query and if it yields a result, construct a new 
node; the method call will take care of
         // caching the constructed node for future calls
-        ResultSet result = query.executeQuery();
-        try {
-            if(result.next()) {
+        try (ResultSet result = query.executeQuery()) {
+            if (result.next()) {
                 return constructNamespaceFromDatabase(result);
             } else {
                 return null;
             }
-        } finally {
-            result.close();
         }
     }
 
@@ -281,15 +279,12 @@ public class KiWiConnection implements AutoCloseable {
 
         // run the database query and if it yields a result, construct a new 
node; the method call will take care of
         // caching the constructed node for future calls
-        ResultSet result = query.executeQuery();
-        try {
-            if(result.next()) {
+        try (ResultSet result = query.executeQuery()) {
+            if (result.next()) {
                 return constructNamespaceFromDatabase(result);
             } else {
                 return null;
             }
-        } finally {
-            result.close();
         }
     }
 
@@ -346,49 +341,44 @@ public class KiWiConnection implements AutoCloseable {
 
     /**
      * Count all non-deleted triples in the triple store
-     * @return
+     * @return number of non-deleted triples in the triple store
      * @throws SQLException
      */
     public long getSize() throws SQLException {
         requireJDBCConnection();
 
         PreparedStatement querySize = getPreparedStatement("query.size");
-        ResultSet result = querySize.executeQuery();
-        try {
-            if(result.next()) {
+        try (ResultSet result = querySize.executeQuery()) {
+            if (result.next()) {
                 return result.getLong(1) + (tripleBatch != null ? 
tripleBatch.size() : 0);
             } else {
-                return 0  + (tripleBatch != null ? tripleBatch.size() : 0);
+                return tripleBatch != null ? tripleBatch.size() : 0;
             }
-        } finally {
-            result.close();
         }
     }
 
     /**
      * Count all non-deleted triples in the triple store
-     * @return
+     * @param context the context to count
+     * @return number of non-deleted triples in the provided context
      * @throws SQLException
      */
     public long getSize(KiWiResource context) throws SQLException {
         if(context.getId() < 0) {
             return 0;
-        };
+        }
 
         requireJDBCConnection();
 
         PreparedStatement querySize = getPreparedStatement("query.size_ctx");
         querySize.setLong(1,context.getId());
 
-        ResultSet result = querySize.executeQuery();
-        try {
-            if(result.next()) {
-                return result.getLong(1) + (tripleBatch != null ? 
tripleBatch.listTriples(null,null,null,context, false).size() : 0);
+        try (ResultSet result = querySize.executeQuery()) {
+            if (result.next()) {
+                return result.getLong(1) + (tripleBatch != null ? 
tripleBatch.listTriples(null, null, null, context, false).size() : 0);
             } else {
-                return 0 + (tripleBatch != null ? 
tripleBatch.listTriples(null,null,null,context, false).size() : 0);
+                return tripleBatch != null ? tripleBatch.listTriples(null, 
null, null, context, false).size() : 0;
             }
-        } finally {
-            result.close();
         }
     }
 
@@ -429,22 +419,19 @@ public class KiWiConnection implements AutoCloseable {
         requireJDBCConnection();
 
         // prepare a query; we will only iterate once, read only, and need 
only one result row since the id is unique
-        PreparedStatement query = getPreparedStatement("load.node_by_id");
+        final PreparedStatement query = 
getPreparedStatement("load.node_by_id");
         synchronized (query) {
             query.setLong(1,id);
             query.setMaxRows(1);
 
             // run the database query and if it yields a result, construct a 
new node; the method call will take care of
             // caching the constructed node for future calls
-            ResultSet result = query.executeQuery();
-            try {
-                if(result.next()) {
+            try (ResultSet result = query.executeQuery()) {
+                if (result.next()) {
                     return constructNodeFromDatabase(result);
                 } else {
                     return null;
                 }
-            } finally {
-                result.close();
             }
         }
 
@@ -493,18 +480,15 @@ public class KiWiConnection implements AutoCloseable {
 
                     // run the database query and if it yields a result, 
construct a new node; the method call will take care of
                     // caching the constructed node for future calls
-                    ResultSet rows = query.executeQuery();
-                    try {
-                        while(rows.next()) {
+                    try (ResultSet rows = query.executeQuery()) {
+                        while (rows.next()) {
                             node = constructNodeFromDatabase(rows);
-                            for(int i=0; i<ids.length; i++) {
-                                if(ids[i] == node.getId()) {
+                            for (int i = 0; i < ids.length; i++) {
+                                if (ids[i] == node.getId()) {
                                     result[i] = node;
                                 }
                             }
                         }
-                    } finally {
-                        rows.close();
                     }
 
                     position += nextBatchSize;
@@ -541,15 +525,12 @@ public class KiWiConnection implements AutoCloseable {
 
         // run the database query and if it yields a result, construct a new 
node; the method call will take care of
         // caching the constructed node for future calls
-        ResultSet result = query.executeQuery();
-        try {
-            if(result.next()) {
+        try (ResultSet result = query.executeQuery()) {
+            if (result.next()) {
                 return constructTripleFromDatabase(result);
             } else {
                 return null;
             }
-        } finally {
-            result.close();
         }
 
     }
@@ -585,15 +566,12 @@ public class KiWiConnection implements AutoCloseable {
 
             // run the database query and if it yields a result, construct a 
new node; the method call will take care of
             // caching the constructed node for future calls
-            ResultSet result = query.executeQuery();
-            try {
-                if(result.next()) {
-                    return (KiWiUriResource)constructNodeFromDatabase(result);
+            try (ResultSet result = query.executeQuery()) {
+                if (result.next()) {
+                    return (KiWiUriResource) constructNodeFromDatabase(result);
                 } else {
                     return null;
                 }
-            } finally {
-                result.close();
             }
         } finally {
             uriLock.unlock();
@@ -631,15 +609,12 @@ public class KiWiConnection implements AutoCloseable {
 
             // run the database query and if it yields a result, construct a 
new node; the method call will take care of
             // caching the constructed node for future calls
-            ResultSet result = query.executeQuery();
-            try {
-                if(result.next()) {
-                    return (KiWiAnonResource)constructNodeFromDatabase(result);
+            try (ResultSet result = query.executeQuery()) {
+                if (result.next()) {
+                    return (KiWiAnonResource) 
constructNodeFromDatabase(result);
                 } else {
                     return null;
                 }
-            } finally {
-                result.close();
             }
         } finally {
             bnodeLock.unlock();
@@ -698,15 +673,12 @@ public class KiWiConnection implements AutoCloseable {
 
             // run the database query and if it yields a result, construct a 
new node; the method call will take care of
             // caching the constructed node for future calls
-            ResultSet result = query.executeQuery();
-            try {
-                if(result.next()) {
-                    return (KiWiLiteral)constructNodeFromDatabase(result);
+            try (ResultSet result = query.executeQuery()) {
+                if (result.next()) {
+                    return (KiWiLiteral) constructNodeFromDatabase(result);
                 } else {
                     return null;
                 }
-            } finally {
-                result.close();
             }
         } finally {
             literalLock.unlock();
@@ -752,15 +724,12 @@ public class KiWiConnection implements AutoCloseable {
 
             // run the database query and if it yields a result, construct a 
new node; the method call will take care of
             // caching the constructed node for future calls
-            ResultSet result = query.executeQuery();
-            try {
-                if(result.next()) {
-                    return (KiWiDateLiteral)constructNodeFromDatabase(result);
+            try (ResultSet result = query.executeQuery()) {
+                if (result.next()) {
+                    return (KiWiDateLiteral) constructNodeFromDatabase(result);
                 } else {
                     return null;
                 }
-            } finally {
-                result.close();
             }
         } finally {
             literalLock.unlock();
@@ -808,15 +777,12 @@ public class KiWiConnection implements AutoCloseable {
 
             // run the database query and if it yields a result, construct a 
new node; the method call will take care of
             // caching the constructed node for future calls
-            ResultSet result = query.executeQuery();
-            try {
-                if(result.next()) {
-                    return (KiWiIntLiteral)constructNodeFromDatabase(result);
+            try (ResultSet result = query.executeQuery()) {
+                if (result.next()) {
+                    return (KiWiIntLiteral) constructNodeFromDatabase(result);
                 } else {
                     return null;
                 }
-            } finally {
-                result.close();
             }
         } finally {
             literalLock.unlock();
@@ -862,19 +828,16 @@ public class KiWiConnection implements AutoCloseable {
 
             // run the database query and if it yields a result, construct a 
new node; the method call will take care of
             // caching the constructed node for future calls
-            ResultSet result = query.executeQuery();
             KiWiNode kiWiNode = null;
-            try {
+            try (ResultSet result = query.executeQuery()) {
                 if (result.next()) {
                     return (KiWiDoubleLiteral) 
constructNodeFromDatabase(result);
                 } else {
                     return null;
                 }
             } catch (RuntimeException e) {
-                log.error("Unable to create KiWiDoubleLiteral for node value 
'{}' (id={}): {}", value, kiWiNode.getId(), e.getMessage(), e);
+                log.error("Unable to create KiWiDoubleLiteral for node value 
'{}': {}", value, e.getMessage(), e);
                 throw e;
-            } finally {
-                result.close();
             }
         } finally {
             literalLock.unlock();
@@ -921,15 +884,12 @@ public class KiWiConnection implements AutoCloseable {
 
             // run the database query and if it yields a result, construct a 
new node; the method call will take care of
             // caching the constructed node for future calls
-            ResultSet result = query.executeQuery();
-            try {
-                if(result.next()) {
-                    return 
(KiWiBooleanLiteral)constructNodeFromDatabase(result);
+            try (ResultSet result = query.executeQuery()) {
+                if (result.next()) {
+                    return (KiWiBooleanLiteral) 
constructNodeFromDatabase(result);
                 } else {
                     return null;
                 }
-            } finally {
-                result.close();
             }
         } finally {
             literalLock.unlock();
@@ -944,7 +904,7 @@ public class KiWiConnection implements AutoCloseable {
      * If the node already has an ID, the method will do nothing (assuming 
that it is already persistent)
      *
      *
-     * @param node
+     * @param node the KiWiNode to store
      * @throws SQLException
      */
     public synchronized void storeNode(KiWiNode node) throws SQLException {
@@ -1097,7 +1057,6 @@ public class KiWiConnection implements AutoCloseable {
      * @param triple     the triple to store
      * @throws SQLException
      * @throws NullPointerException in case the subject, predicate, object or 
context have not been persisted
-     * @return true in case the update added a new triple to the database, 
false in case the triple already existed
      */
     public synchronized void storeTriple(final KiWiTriple triple) throws 
SQLException {
         // mutual exclusion: prevent parallel adding and removing of the same 
triple
@@ -1178,11 +1137,11 @@ public class KiWiConnection implements AutoCloseable {
      * Return the identifier of the triple with the given subject, predicate, 
object and context, or null if this
      * triple does not exist. Used for quick existance checks of triples.
      *
-     * @param subject
-     * @param predicate
-     * @param object
-     * @param context
-     * @return
+     * @param subject the subject of the triple
+     * @param predicate the predicate of the triple
+     * @param object the object of the triple
+     * @param context the context of the triple
+     * @return the database-id of the triple or {@code -1} if it does not 
exist.
      */
     public synchronized long getTripleId(final KiWiResource subject, final 
KiWiUriResource predicate, final KiWiNode object, final KiWiResource context) 
throws SQLException {
         if(tripleBatch != null && tripleBatch.size() > 0) {
@@ -1203,16 +1162,13 @@ public class KiWiConnection implements AutoCloseable {
             loadTripleId.setNull(4, Types.BIGINT);
         }
 
-        ResultSet result = loadTripleId.executeQuery();
-        try {
-            if(result.next()) {
+        try (ResultSet result = loadTripleId.executeQuery()) {
+            if (result.next()) {
                 return result.getLong(1);
             } else {
                 return -1L;
             }
 
-        } finally {
-            result.close();
         }
     }
 
@@ -1223,7 +1179,7 @@ public class KiWiConnection implements AutoCloseable {
      * The triple remains in the database, because other entities might still 
reference it (e.g. a version).
      * Use the method cleanupTriples() to fully remove all deleted triples 
without references.
      *
-     * @param triple
+     * @param triple the KiWiTriple to delete
      */
     public void deleteTriple(final KiWiTriple triple) throws SQLException {
         requireJDBCConnection();
@@ -1422,7 +1378,7 @@ public class KiWiConnection implements AutoCloseable {
      * Note that this operation should only be called if the triple was 
deleted before in the same
      * transaction!
      *
-     * @param triple
+     * @param triple the KiWiTriple to restore
      */
     public void undeleteTriple(KiWiTriple triple) throws SQLException {
         if(triple.getId() < 0) {
@@ -1454,7 +1410,7 @@ public class KiWiConnection implements AutoCloseable {
 
     /**
      * List all contexts used in this triple store. See query.contexts .
-     * @return
+     * @return ClosableIteration of contexts
      * @throws SQLException
      */
     public CloseableIteration<KiWiResource, SQLException> listContexts() 
throws SQLException {
@@ -1465,15 +1421,15 @@ public class KiWiConnection implements AutoCloseable {
         final ResultSet result = queryContexts.executeQuery();
 
         if(tripleBatch != null && tripleBatch.size() > 0) {
-            return new DistinctIteration<KiWiResource, SQLException>(
-                    new UnionIteration<KiWiResource, SQLException>(
+            return new DistinctIteration<>(
+                    new UnionIteration<>(
                             new 
ConvertingIteration<Resource,KiWiResource,SQLException>(new 
IteratorIteration<Resource, 
SQLException>(tripleBatch.listContextIDs().iterator())) {
                                 @Override
                                 protected KiWiResource convert(Resource 
sourceObject) throws SQLException {
                                     return (KiWiResource)sourceObject;
                                 }
                             },
-                            new ResultSetIteration<KiWiResource>(result, new 
ResultTransformerFunction<KiWiResource>() {
+                            new ResultSetIteration<>(result, new 
ResultTransformerFunction<KiWiResource>() {
                                 @Override
                                 public KiWiResource apply(ResultSet row) 
throws SQLException {
                                     return 
(KiWiResource)loadNodeById(result.getLong("context"));
@@ -1484,7 +1440,7 @@ public class KiWiConnection implements AutoCloseable {
 
 
         } else {
-            return new ResultSetIteration<KiWiResource>(result, new 
ResultTransformerFunction<KiWiResource>() {
+            return new ResultSetIteration<>(result, new 
ResultTransformerFunction<KiWiResource>() {
                 @Override
                 public KiWiResource apply(ResultSet row) throws SQLException {
                     return 
(KiWiResource)loadNodeById(result.getLong("context"));
@@ -1506,7 +1462,7 @@ public class KiWiConnection implements AutoCloseable {
 
         final ResultSet result = queryContexts.executeQuery();
 
-        return new ResultSetIteration<KiWiResource>(result, new 
ResultTransformerFunction<KiWiResource>() {
+        return new ResultSetIteration<>(result, new 
ResultTransformerFunction<KiWiResource>() {
             @Override
             public KiWiResource apply(ResultSet row) throws SQLException {
                 return (KiWiResource)constructNodeFromDatabase(row);
@@ -1528,7 +1484,7 @@ public class KiWiConnection implements AutoCloseable {
 
         final ResultSet result = queryContexts.executeQuery();
 
-        return new ResultSetIteration<KiWiUriResource>(result, new 
ResultTransformerFunction<KiWiUriResource>() {
+        return new ResultSetIteration<>(result, new 
ResultTransformerFunction<KiWiUriResource>() {
             @Override
             public KiWiUriResource apply(ResultSet row) throws SQLException {
                 return (KiWiUriResource)constructNodeFromDatabase(row);
@@ -1545,7 +1501,7 @@ public class KiWiConnection implements AutoCloseable {
 
         final ResultSet result = queryContexts.executeQuery();
 
-        return new ResultSetIteration<KiWiNamespace>(result, new 
ResultTransformerFunction<KiWiNamespace>() {
+        return new ResultSetIteration<>(result, new 
ResultTransformerFunction<KiWiNamespace>() {
             @Override
             public KiWiNamespace apply(ResultSet input) throws SQLException {
                 return constructNamespaceFromDatabase(result);
@@ -1580,9 +1536,9 @@ public class KiWiConnection implements AutoCloseable {
 
         if(tripleBatch != null && tripleBatch.size() > 0) {
             synchronized (tripleBatch) {
-                return new RepositoryResult<Statement>(
+                return new RepositoryResult<>(
                         new ExceptionConvertingIteration<Statement, 
RepositoryException>(
-                                new UnionIteration<Statement, SQLException>(
+                                new UnionIteration<>(
                                         new IteratorIteration<Statement, 
SQLException>(tripleBatch.listTriples(subject,predicate,object,context, 
wildcardContext).iterator()),
                                         new DelayedIteration<Statement, 
SQLException>() {
                                             @Override
@@ -1602,7 +1558,7 @@ public class KiWiConnection implements AutoCloseable {
                 );
             }
         }  else {
-            return new RepositoryResult<Statement>(
+            return new RepositoryResult<>(
                     new ExceptionConvertingIteration<Statement, 
RepositoryException>(listTriplesInternal(subject,predicate,object,context,inferred,
 wildcardContext)) {
                         @Override
                         protected RepositoryException convert(Exception e) {
@@ -1630,16 +1586,16 @@ public class KiWiConnection implements AutoCloseable {
     private CloseableIteration<Statement, SQLException> 
listTriplesInternal(KiWiResource subject, KiWiUriResource predicate, KiWiNode 
object, KiWiResource context, boolean inferred, final boolean wildcardContext) 
throws SQLException {
         // if one of the database ids is null, there will not be any database 
results, so we can return an empty result
         if(subject != null && subject.getId() < 0) {
-            return new EmptyIteration<Statement, SQLException>();
+            return new EmptyIteration<>();
         }
         if(predicate != null && predicate.getId() < 0) {
-            return new EmptyIteration<Statement, SQLException>();
+            return new EmptyIteration<>();
         }
         if(object != null && object.getId() < 0) {
-            return new EmptyIteration<Statement, SQLException>();
+            return new EmptyIteration<>();
         }
         if(context != null && context.getId() < 0) {
-            return new EmptyIteration<Statement, SQLException>();
+            return new EmptyIteration<>();
         }
 
         requireJDBCConnection();
@@ -1769,8 +1725,8 @@ public class KiWiConnection implements AutoCloseable {
     /**
      * Construct an appropriate KiWiNode from the result of an SQL query. The 
method will not change the
      * ResultSet iterator, only read its values, so it needs to be executed 
for each row separately.
-     * @param row
-     * @return
+     * @param row the ResultSet to read from
+     * @return a KiWiNode
      */
     protected KiWiNode constructNodeFromDatabase(ResultSet row) throws 
SQLException {
         // column order; 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt
@@ -2052,7 +2008,7 @@ public class KiWiConnection implements AutoCloseable {
      * not exist there create a new statement.
      *
      * @param key the id of the statement in statements.properties
-     * @return
+     * @return the PreparedStatement
      * @throws SQLException
      */
     public PreparedStatement getPreparedStatement(String key) throws 
SQLException {
@@ -2076,7 +2032,8 @@ public class KiWiConnection implements AutoCloseable {
      * numbers (e.g. in an IN).
      *
      * @param key the id of the statement in statements.properties
-     * @return
+     * @param numberOfArguments the number of arguments for the prepared 
statement
+     * @return the PreparedStatement
      * @throws SQLException
      */
     public PreparedStatement getPreparedStatement(String key, int 
numberOfArguments) throws SQLException {
@@ -2144,32 +2101,27 @@ public class KiWiConnection implements AutoCloseable {
      * Return a collection of database tables contained in the database. This 
query is used for checking whether
      * the database needs to be created when initialising the system.
      *
-     *
-     *
-     * @return
+     * @return a Set containing te database tables
      * @throws SQLException
      */
     public Set<String> getDatabaseTables() throws SQLException {
         requireJDBCConnection();
 
         PreparedStatement statement = getPreparedStatement("meta.tables");
-        ResultSet result = statement.executeQuery();
-        try {
-            Set<String> tables = new HashSet<String>();
-            while(result.next()) {
+        try (ResultSet result = statement.executeQuery()) {
+            Set<String> tables = new HashSet<>();
+            while (result.next()) {
                 tables.add(result.getString(1).toLowerCase());
             }
             return tables;
-        } finally {
-            result.close();
         }
     }
 
     /**
      * Return the metadata value with the given key; can be used by KiWi 
modules to retrieve module-specific metadata.
      *
-     * @param key
-     * @return
+     * @param key the key to query
+     * @return the value of the given key in the metadata table
      * @throws SQLException
      */
     public String getMetadata(String key) throws SQLException {
@@ -2177,15 +2129,12 @@ public class KiWiConnection implements AutoCloseable {
 
         PreparedStatement statement = getPreparedStatement("meta.get");
         statement.setString(1,key);
-        ResultSet result = statement.executeQuery();
-        try {
-            if(result.next()) {
+        try (ResultSet result = statement.executeQuery()) {
+            if (result.next()) {
                 return result.getString(1);
             } else {
                 return null;
             }
-        } finally {
-            result.close();
         }
     }
 
@@ -2193,17 +2142,16 @@ public class KiWiConnection implements AutoCloseable {
     /**
      * Update the metadata value for the given key; can be used by KiWi 
modules to set module-specific metadata.
      *
-     * @param key
-     * @return
+     * @param key the key to update
+     * @param value the new value
      * @throws SQLException
      */
     public void setMetadata(String key, String value) throws SQLException {
         requireJDBCConnection();
 
         PreparedStatement statement = getPreparedStatement("meta.get");
-        ResultSet result = statement.executeQuery();
-        try {
-            if(result.next()) {
+        try (ResultSet result = statement.executeQuery()) {
+            if (result.next()) {
                 PreparedStatement update = getPreparedStatement("meta.update");
                 update.clearParameters();
                 update.setString(1, value);
@@ -2216,8 +2164,6 @@ public class KiWiConnection implements AutoCloseable {
                 insert.setString(2, value);
                 insert.executeUpdate();
             }
-        } finally {
-            result.close();
         }
     }
 
@@ -2226,21 +2172,18 @@ public class KiWiConnection implements AutoCloseable {
      * Return the KiWi version of the database this connection is operating 
on. This query is necessary for
      * checking proper state of a database when initialising the system.
      *
-     * @return
+     * @return the version of the database schema
      */
     public int getDatabaseVersion() throws SQLException {
         requireJDBCConnection();
 
         PreparedStatement statement = getPreparedStatement("meta.version");
-        ResultSet result = statement.executeQuery();
-        try {
-            if(result.next()) {
+        try (ResultSet result = statement.executeQuery()) {
+            if (result.next()) {
                 return Integer.parseInt(result.getString(1));
             } else {
                 throw new SQLException("no version information available");
             }
-        } finally {
-            result.close();
         }
     }
 
@@ -2305,7 +2248,7 @@ public class KiWiConnection implements AutoCloseable {
     /**
      * Return true if batched commits are enabled. Batched commits will try to 
group database operations and
      * keep a memory log while storing triples. This can considerably improve 
the database performance.
-     * @return
+     * @return {@code true} if batch commits are enabled
      */
     public boolean isBatchCommit() {
         return batchCommit;
@@ -2314,7 +2257,6 @@ public class KiWiConnection implements AutoCloseable {
     /**
      * Enabled batched commits. Batched commits will try to group database 
operations and
      * keep a memory log while storing triples. This can considerably improve 
the database performance.
-     * @return
      */
     public void setBatchCommit(boolean batchCommit) {
         if(dialect.isBatchSupported()) {
@@ -2328,7 +2270,8 @@ public class KiWiConnection implements AutoCloseable {
     /**
      * Return the size of a batch for batched commits. Batched commits will 
try to group database operations and
      * keep a memory log while storing triples. This can considerably improve 
the database performance.
-     * @return
+     * @return the batch size used if batchCommits are enabled
+     * @see #isBatchCommit()
      */
     public int getBatchSize() {
         return batchSize;
@@ -2337,7 +2280,7 @@ public class KiWiConnection implements AutoCloseable {
     /**
      * Set the size of a batch for batched commits. Batched commits will try 
to group database operations and
      * keep a memory log while storing triples. This can considerably improve 
the database performance.
-     * @param batchSize
+     * @param batchSize the batch size
      */
     public void setBatchSize(int batchSize) {
         this.batchSize = batchSize;
@@ -2460,7 +2403,7 @@ public class KiWiConnection implements AutoCloseable {
                 for(Map.Entry<String,PreparedStatement> entry : 
statementCache.entrySet()) {
                     try {
                         entry.getValue().close();
-                    } catch (SQLException ex) {}
+                    } catch (SQLException ignore) {}
                 }
             } catch(AbstractMethodError ex) {
                 log.debug("database system does not allow closing statements");
@@ -2528,7 +2471,7 @@ public class KiWiConnection implements AutoCloseable {
 
     /**
      * Return the current transaction ID
-     * @return
+     * @return the current transaction id
      */
     public long getTransactionId() {
         return transactionId;
@@ -2629,7 +2572,7 @@ public class KiWiConnection implements AutoCloseable {
                         log.warn("{}: temporary conflict, retrying in {} ms 
... (thread={}, retry={})", name, sleep, Thread.currentThread().getName(), 
retries);
                         try {
                             Thread.sleep(sleep);
-                        } catch (InterruptedException e) {}
+                        } catch (InterruptedException ignore) {}
                         retries++;
                         T result = execute(connection, command);
                         retries--;

http://git-wip-us.apache.org/repos/asf/marmotta/blob/5991d61d/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiDialect.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiDialect.java
 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiDialect.java
index 98eb4ea..05670bb 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiDialect.java
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiDialect.java
@@ -64,21 +64,21 @@ public abstract class KiWiDialect {
 
     /**
      * Return the name of the driver class (used for properly initialising 
JDBC connections)
-     * @return
+     * @return the fully-qualified class name of the JDBC driver.
      */
     public abstract String getDriverClass();
 
 
     /**
      * Return true if batched commits are supported by this dialect.
-     * @return
+     * @return {@code true} if batch commits are supported
      */
     public abstract boolean isBatchSupported();
 
 
     /**
      * Return true in case the database supports creating arrays with 
ARRAY[...]
-     * @return
+     * @return {@code true} if {@code ARRAY[]} is supported
      */
     public boolean isArraySupported() {
         return false;
@@ -86,7 +86,7 @@ public abstract class KiWiDialect {
 
     /**
      * Return the contents of the SQL create script used for initialising an 
empty database
-     * @return
+     * @return SQL Command String to create the KiWi Database 
Tables/Indexes/...
      */
     public String getCreateScript(String scriptName) {
         return getScript("create_"+scriptName+"_tables.sql");
@@ -95,7 +95,7 @@ public abstract class KiWiDialect {
 
     /**
      * Return the contents of the SQL drop script used for cleaning up all 
traces of the KiWi triple store
-     * @return
+     * @return SQL Command String to drop the KiWi Database Tables/Indexes/...
      */
     public String getDropScript(String scriptName) {
         return getScript("drop_"+scriptName+"_tables.sql");
@@ -104,7 +104,7 @@ public abstract class KiWiDialect {
 
     /**
      * Return the contents of the SQL script with the given file name 
(relative to the current class)
-     * @return
+     * @return SQL Command String loaded from the script in the classpath
      */
     protected String getScript(String scriptName) {
         try {
@@ -173,10 +173,10 @@ public abstract class KiWiDialect {
      * Return the database specific operator for matching a text against a 
regular expression.
      *
      *
-     * @param text
-     * @param pattern
-     * @param flags
-     * @return
+     * @param text the text to match against
+     * @param pattern the regex-pattern to look for
+     * @param flags regex flags, such as {@code i} of case-insensitiv
+     * @return SQL Operator String for a regex test.
      */
     public abstract String getRegexp(String text, String pattern, String 
flags);
 
@@ -184,24 +184,24 @@ public abstract class KiWiDialect {
     /**
      * Return true in case the SPARQL RE flags contained in the given string 
are supported.
      *
-     * @param flags
-     * @return
+     * @param flags the regex flags to test for
+     * @return {@code true} if the provided regex flags are supported
      */
     public abstract boolean isRegexpSupported(String flags);
 
     /**
      * Return the database specific case insensitive like comparison, e.g. 
ILIKE in Postgres.
      *
-     * @param text
-     * @param pattern
-     * @return
+     * @param text the text to match against
+     * @param pattern the LIKE pattern to match
+     * @return SQL Operator String for a case-insensitive LIKE
      */
     public abstract String getILike(String text, String pattern);
 
 
     /**
      * Return the name of the aggregate function for group concatenation 
(string_agg in postgres, GROUP_CONCAT in MySQL)
-     * @return
+     * @return SQL Operator String for group concatenation
      */
     public abstract String getGroupConcat(String value, String separator, 
boolean distinct);
 
@@ -209,22 +209,22 @@ public abstract class KiWiDialect {
     /**
      * Return the SQL timezone value for a KiWiDateLiteral, corrected by the 
timezone offset. In PostgreSQL, this is
      * e.g. computed by (ALIAS.tvalue + ALIAS.tzoffset * INTERVAL '1 second')
-     * @param alias
-     * @return
+     * @param alias the alias to reslove
+     * @return SQL Operator String to convert a DateLiteral to it's timezone 
specific value
      */
     public abstract String getDateTimeTZ(String alias);
 
     /**
      * Get the query string that can be used for validating that a JDBC 
connection to this database is still valid.
      * Typically, this should be an inexpensive operation like "SELECT 1",
-     * @return
+     * @return SQL Validation Query String
      */
     public abstract String getValidationQuery();
 
 
     /**
      * Return true in case the database system supports using cursors for 
queries over large data tables.
-     * @return
+     * @return {@code true} if cursors are supported
      */
     public boolean isCursorSupported() {
         return false;

http://git-wip-us.apache.org/repos/asf/marmotta/blob/5991d61d/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiGarbageCollector.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiGarbageCollector.java
 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiGarbageCollector.java
index 74f7327..f6a2225 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiGarbageCollector.java
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiGarbageCollector.java
@@ -58,8 +58,8 @@ public class KiWiGarbageCollector extends Thread {
 
         this.persistence = persistence;
 
-        this.tripleTableDependencies = new HashSet<TableDependency>();
-        this.nodeTableDependencies   = new HashSet<TableDependency>();
+        this.tripleTableDependencies = new HashSet<>();
+        this.nodeTableDependencies   = new HashSet<>();
     }
 
     /**
@@ -71,7 +71,7 @@ public class KiWiGarbageCollector extends Thread {
 
     /**
      * Set the interval to wait between garbage collections (milliseconds)
-     * @param interval
+     * @param interval GC interval in milliseconds.
      */
     public void setInterval(long interval) {
         this.interval = interval;
@@ -82,8 +82,8 @@ public class KiWiGarbageCollector extends Thread {
      * is used when cleaning up unreferenced deleted entries in the triples 
table. In theory, we could
      * get this information from the database, but each database has a very 
different way of doing this, so
      * it is easier to simply let dependent modules register this information.
-     * @param tableName
-     * @param columnName
+     * @param tableName name of the depending table in the database
+     * @param columnName name of the depending column in the table
      */
     public void addTripleTableDependency(String tableName, String columnName) {
         tripleTableDependencies.add(new TableDependency(tableName,columnName));
@@ -94,8 +94,8 @@ public class KiWiGarbageCollector extends Thread {
      * is used when cleaning up unreferenced deleted entries in the nodes 
table. In theory, we could
      * get this information from the database, but each database has a very 
different way of doing this, so
      * it is easier to simply let dependent modules register this information.
-     * @param tableName
-     * @param columnName
+     * @param tableName name of the depending table in the database
+     * @param columnName name of the depending column in the table
      */
     public void addNodeTableDependency(String tableName, String columnName) {
         nodeTableDependencies.add(new TableDependency(tableName,columnName));
@@ -104,6 +104,7 @@ public class KiWiGarbageCollector extends Thread {
     protected boolean checkConsistency() throws SQLException {
         boolean consistent = true;
 
+        // FIXME: Should this SQL Query be moved to the SQL-Dialect?
         String checkNodeDuplicatesQuery = "SELECT svalue, ntype, count(id) 
FROM nodes group by svalue, ntype having count(id) > 1";
 
         try(Connection con = persistence.getJDBCConnection()) {
@@ -138,6 +139,7 @@ public class KiWiGarbageCollector extends Thread {
 
 
     protected void fixConsistency() throws SQLException {
+        // FIXME: These queries are never used - and if they are beeing, used 
they should move the the SQL Dialect.
         String checkNodeDuplicatesQuery = "SELECT svalue, ntype, count(id), 
max(id) FROM nodes group by svalue, ntype having count(id) > 1";
         String getNodeIdsQuery = "SELECT id FROM nodes WHERE svalue = ? AND 
ntype = ? AND id != ?";
 
@@ -182,6 +184,7 @@ public class KiWiGarbageCollector extends Thread {
                 }
 
                 // finally we clean up all now unused node ids
+                // FIXME: Should this query be moved to the SQL-Dialect?
                 String deleteDuplicatesQuery = "DELETE FROM nodes WHERE id = 
?";
                 PreparedStatement deleteDuplicatesStatement = 
con.prepareStatement(deleteDuplicatesQuery);
                 for(Long id : ids) {
@@ -268,6 +271,7 @@ public class KiWiGarbageCollector extends Thread {
                     log.info("running garbage collection ...");
                     try {
                         int count = garbageCollect();
+                        log.debug("GC touched {} rows in the DB", count);
                     } catch (SQLException e) {
                         log.error("error while executing garbage collection: 
{}",e.getMessage());
                     }
@@ -275,7 +279,7 @@ public class KiWiGarbageCollector extends Thread {
                 started = true;
                 try {
                     this.wait(interval);
-                } catch (InterruptedException e) {
+                } catch (InterruptedException ignore) {
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/5991d61d/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 c374639..e195bba 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
@@ -105,8 +105,8 @@ public class KiWiPersistence {
 
         try {
             logPoolInfo();
-        } catch (SQLException e) {
-
+        } catch (SQLException ignore) {
+            // must not happen!
         }
 
         idGenerator = new 
SnowflakeIDGenerator(configuration.getDatacenterId());
@@ -359,7 +359,7 @@ public class KiWiPersistence {
 
     /**
      * Return a raw JDBC connection from the connection pool, which already 
has the auto-commit disabled.
-     * @return
+     * @return a raw JDBC connection, with auto-commit disabled
      * @throws SQLException
      */
     public Connection getJDBCConnection() throws SQLException {
@@ -368,7 +368,8 @@ public class KiWiPersistence {
 
     /**
      * Return a raw JDBC connection from the connection pool, which already 
has the auto-commit disabled.
-     * @return
+     * @param maintenance put the database in maintenance mode - further calls 
to this method will block.
+     * @return a raw JDBC connection, with auto-commit disabled
      * @throws SQLException
      */
     public Connection getJDBCConnection(boolean maintenance) throws 
SQLException {
@@ -376,7 +377,7 @@ public class KiWiPersistence {
             if(this.maintenance) {
                 try {
                     this.wait();
-                } catch (InterruptedException e) { }
+                } catch (InterruptedException ignore) { }
             }
             if(maintenance) {
                 this.maintenance = true;
@@ -397,7 +398,7 @@ public class KiWiPersistence {
     /**
      * Release the JDBC connection passed as argument. This method will close 
the connection and release
      * any locks that might be held by the caller.
-     * @param con
+     * @param con the JDBC connection to release
      * @throws SQLException
      */
     public void releaseJDBCConnection(Connection con) throws SQLException {
@@ -426,8 +427,8 @@ public class KiWiPersistence {
      * is used when cleaning up unreferenced deleted entries in the nodes 
table. In theory, we could
      * get this information from the database, but each database has a very 
different way of doing this, so
      * it is easier to simply let dependent modules register this information.
-     * @param tableName
-     * @param columnName
+     * @param tableName name of the depending table in the database
+     * @param columnName name of the depending column in the table
      */
     public void addNodeTableDependency(String tableName, String columnName) {
         garbageCollector.addNodeTableDependency(tableName, columnName);
@@ -438,8 +439,8 @@ public class KiWiPersistence {
      * is used when cleaning up unreferenced deleted entries in the triples 
table. In theory, we could
      * get this information from the database, but each database has a very 
different way of doing this, so
      * it is easier to simply let dependent modules register this information.
-     * @param tableName
-     * @param columnName
+     * @param tableName name of the depending table in the database
+     * @param columnName name of the depending column in the table
      */
     public void addTripleTableDependency(String tableName, String columnName) {
         garbageCollector.addTripleTableDependency(tableName, columnName);

http://git-wip-us.apache.org/repos/asf/marmotta/blob/5991d61d/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/util/ResultSetIteration.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/util/ResultSetIteration.java
 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/util/ResultSetIteration.java
index ffa6f5b..4789d95 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/util/ResultSetIteration.java
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/util/ResultSetIteration.java
@@ -75,7 +75,7 @@ public class ResultSetIteration<E> implements 
CloseableIteration<E,SQLException>
             if(closeStatement)
                 result.getStatement().close();
             closed = true;
-        } catch (SQLException e) {
+        } catch (SQLException ignore) {
         }
     }
 

Reply via email to