You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2020/06/17 08:07:06 UTC

[ofbiz-framework] branch trunk updated: Improved: Clean code according to SpotBugs and Eclipse (OFBIZ-11824)

This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 50fa929  Improved: Clean code according to SpotBugs and Eclipse (OFBIZ-11824)
50fa929 is described below

commit 50fa929b8318fe30c0a5fcab4a40e865fd047be6
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Wed Jun 17 10:07:00 2020 +0200

    Improved: Clean code according to SpotBugs and Eclipse (OFBIZ-11824)
    
    Handles 2 possible NPR reported by SpotBugs
    Removes the unused createPrimaryKeyFetcher method as reported by Eclipse
    Reformats modified code to stay into 150 chars by line and other style issues
    Sets tasks.checkstyleMain.maxErrors to 26759 (-1)
---
 build.gradle                                       |  2 +-
 .../org/apache/ofbiz/entity/jdbc/DatabaseUtil.java | 77 ++++++++++------------
 2 files changed, 37 insertions(+), 42 deletions(-)

diff --git a/build.gradle b/build.gradle
index cef4afd..649a4b5 100644
--- a/build.gradle
+++ b/build.gradle
@@ -287,7 +287,7 @@ checkstyle {
     // the sum of errors found last time it was changed after using the
     // ‘checkstyle’ tool present in the framework and in the official
     // plugins.
-    tasks.checkstyleMain.maxErrors = 26760
+    tasks.checkstyleMain.maxErrors = 26759
     // Currently there are a lot of errors so we need to temporarily
     // hide them to avoid polluting the terminal output.
     showViolations = false
diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/DatabaseUtil.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/DatabaseUtil.java
index ccc9ca9..ab7687f 100644
--- a/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/DatabaseUtil.java
+++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/DatabaseUtil.java
@@ -961,37 +961,44 @@ public class DatabaseUtil {
                 Debug.logError(message, MODULE);
                 if (messages != null) messages.add(message);
             }
-            while (tableSet.next()) {
-                try {
-                    String tableName = tableSet.getString("TABLE_NAME");
-                    // for those databases which do not return the schema name with the table name (pgsql 7.3)
-                    boolean appendSchemaName = false;
-                    if (tableName != null && lookupSchemaName != null && !tableName.startsWith(lookupSchemaName + "\\.")) {
-                        appendSchemaName = true;
-                    }
-                    if (needsUpperCase && tableName != null) {
-                        tableName = tableName.toUpperCase();
-                    }
-                    if (appendSchemaName) {
-                        tableName = lookupSchemaName + "." + tableName;
-                    }
+            if (tableSet != null) {
+                while (tableSet.next()) {
+                    try {
+                        String tableName = tableSet.getString("TABLE_NAME");
+                        // for those databases which do not return the schema name with the table name (pgsql 7.3)
+                        boolean appendSchemaName = false;
+                        if (tableName != null && lookupSchemaName != null && !tableName.startsWith(lookupSchemaName + "\\.")) {
+                            appendSchemaName = true;
+                        }
+                        if (needsUpperCase && tableName != null) {
+                            tableName = tableName.toUpperCase();
+                        }
+                        if (appendSchemaName) {
+                            tableName = lookupSchemaName + "." + tableName;
+                        }
+
+                        // NOTE: this may need a toUpperCase in some cases, keep an eye on it, okay for now just do a compare with equalsIgnoreCase
+                        String tableType = tableSet.getString("TABLE_TYPE");
+                        // only allow certain table types
+                        if (tableType != null 
+                                && !"TABLE".equalsIgnoreCase(tableType)
+                                && !"VIEW".equalsIgnoreCase(tableType)
+                                && !"ALIAS".equalsIgnoreCase(tableType)
+                                && !"SYNONYM".equalsIgnoreCase(tableType)
+                                && !"BASE TABLE".equalsIgnoreCase(tableType)) {
+                            continue;
+                        }
 
-                    // NOTE: this may need a toUpperCase in some cases, keep an eye on it, okay for now just do a compare with equalsIgnoreCase
-                    String tableType = tableSet.getString("TABLE_TYPE");
-                    // only allow certain table types
-                    if (tableType != null && !"TABLE".equalsIgnoreCase(tableType) && !"VIEW".equalsIgnoreCase(tableType)
-                            && !"ALIAS".equalsIgnoreCase(tableType) && !"SYNONYM".equalsIgnoreCase(tableType) && !"BASE TABLE".equalsIgnoreCase(tableType)) {
+                        // String remarks = tableSet.getString("REMARKS");
+                        tableNames.add(tableName);
+                        // if (Debug.infoOn()) Debug.logInfo("Found table named [" + tableName + "] 
+                        // of type [" + tableType + "] with remarks: " + remarks, MODULE);
+                    } catch (SQLException e) {
+                        String message = "Error getting table information... Error was:" + e.toString();
+                        Debug.logError(message, MODULE);
+                        if (messages != null) messages.add(message);
                         continue;
                     }
-
-                    // String remarks = tableSet.getString("REMARKS");
-                    tableNames.add(tableName);
-                    // if (Debug.infoOn()) Debug.logInfo("Found table named [" + tableName + "] of type [" + tableType + "] with remarks: " + remarks, MODULE);
-                } catch (SQLException e) {
-                    String message = "Error getting table information... Error was:" + e.toString();
-                    Debug.logError(message, MODULE);
-                    if (messages != null) messages.add(message);
-                    continue;
                 }
             }
         } catch (SQLException e) {
@@ -1018,18 +1025,6 @@ public class DatabaseUtil {
         return tableNames;
     }
 
-    private AbstractCountingCallable createPrimaryKeyFetcher(final DatabaseMetaData dbData, final String lookupSchemaName, final boolean needsUpperCase, final Map<String, Map<String, ColumnCheckInfo>> colInfo, final Collection<String> messages, final String curTable) {
-        return new AbstractCountingCallable(null, null) {
-            @Override
-            public AbstractCountingCallable call() throws Exception {
-                if (Debug.verboseOn()) Debug.logVerbose("Fetching primary keys for " + curTable, MODULE);
-                ResultSet rsPks = dbData.getPrimaryKeys(null, lookupSchemaName, curTable);
-                count = checkPrimaryKeyInfo(rsPks, lookupSchemaName, needsUpperCase, colInfo, messages);
-                return this;
-            }
-        };
-    }
-
     private Map<String, Map<String, ColumnCheckInfo>> getColumnInfo(Set<String> tableNames, boolean getPks, Collection<String> messages, ExecutorService executor) {
         // if there are no tableNames, don't even try to get the columns
         if (tableNames.size() == 0) {
@@ -1445,7 +1440,7 @@ public class DatabaseUtil {
                         if (needsUpperCase[0] && indexName != null) {
                             indexName = indexName.toUpperCase();
                         }
-                        if (indexName.startsWith("PK_") || indexName.startsWith("pk_")) continue;
+                        if (indexName != null && indexName.toUpperCase().startsWith("PK_")) continue;
 
                         Set<String> tableIndexList = indexInfo.get(tableName);
                         if (tableIndexList == null) {