openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r675387 - /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
Date Thu, 10 Jul 2008 00:16:25 GMT
Author: ppoddar
Date: Wed Jul  9 17:16:25 2008
New Revision: 675387

URL: http://svn.apache.org/viewvc?rev=675387&view=rev
Log:
Initialize Database Prodcut/Vendor name to empty string to avoid NPE

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java?rev=675387&r1=675386&r2=675387&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
Wed Jul  9 17:16:25 2008
@@ -72,8 +72,8 @@
     protected static final String useKeepExclusiveLockClause
         = "USE AND KEEP EXCLUSIVE LOCKS";
     protected static final String forReadOnlyClause = "FOR READ ONLY";
-    protected String databaseProductName = null;
-    protected String databaseProductVersion = null;
+    protected String databaseProductName = "";
+    protected String databaseProductVersion = "";
     protected int maj = 0;
     protected int min = 0;
     
@@ -242,8 +242,8 @@
     	super.connectedConfiguration(conn);
 
     	DatabaseMetaData metaData = conn.getMetaData();
-        databaseProductName = metaData.getDatabaseProductName();
-        databaseProductVersion = metaData.getDatabaseProductVersion();
+        databaseProductName = nullSafe(metaData.getDatabaseProductName());
+        databaseProductVersion = nullSafe(metaData.getDatabaseProductVersion());
         
         // Determine the type of DB2 database
         // First check for AS/400
@@ -384,51 +384,32 @@
     }
 
     public boolean isDB2UDBV82OrLater() {
-        boolean match = false;
-        if (databaseProductName != null &&
-            (databaseProductVersion.indexOf("SQL") != -1
-            || databaseProductName.indexOf("DB2/") != -1)
-            && ((maj == 8 && min >= 2) || (maj >= 9)))
-            match = true;
-        return match;
+        return (databaseProductVersion.indexOf("SQL") != -1
+             || databaseProductName.indexOf("DB2/") != -1)
+             && ((maj == 8 && min >= 2) || (maj >= 9));
     }
 
     public boolean isDB2ZOSV8xOrLater() {
-       boolean match = false;
-       if (databaseProductName != null &&
-           (databaseProductVersion.indexOf("DSN") != -1
-           || databaseProductName.indexOf("DB2/") == -1)
-           && maj >= 8)
-           match = true;
-        return match;
+       return (databaseProductVersion.indexOf("DSN") != -1
+            || databaseProductName.indexOf("DB2/") == -1)
+            && maj >= 8;
+           
     }
 
     public boolean isDB2ISeriesV5R3OrEarlier() {
-       boolean match = false;
-       if (databaseProductName != null &&
-           databaseProductName.indexOf("AS") != -1
-           && ((maj == 5 && min <=3) || maj < 5))
-           match = true;
-       return match;
+       return (databaseProductName.indexOf("AS") != -1
+           && ((maj == 5 && min <=3) || maj < 5));
     }
 
     public boolean isDB2ISeriesV5R4OrLater() {
-       boolean match = false;
-       if (databaseProductName != null &&
-           databaseProductName.indexOf("AS") != -1
-           && (maj >=6 || (maj == 5 && min >=4)))
-           match = true;
-      return match;
+       return databaseProductName.indexOf("AS") != -1
+           && (maj >=6 || (maj == 5 && min >=4));
     }
 
     public boolean isDB2UDBV81OrEarlier() {
-        boolean match = false;
-        if (databaseProductName != null &&
-            (databaseProductVersion.indexOf("SQL") != -1 
-            || databaseProductName.indexOf("DB2/") != -1) &&
-            ((maj == 8 && min <= 1) || maj < 8))
-            match = true;
-        return match;
+        return (databaseProductVersion.indexOf("SQL") != -1 
+            || databaseProductName.indexOf("DB2/") != -1) 
+            && ((maj == 8 && min <= 1) || maj < 8);
     }
 
     /** Get the version Major/Minor for the ISeries
@@ -456,8 +437,7 @@
                     String s2 =  stringtokenizer.nextToken();
                     min = Integer.parseInt(s2);
                 }
-            }
-            else {
+            } else {
                 index = databaseProductVersion.indexOf('0');
                 if (index != -1) {
                     String s = databaseProductVersion.substring(index);
@@ -844,4 +824,8 @@
             idx.addColumn(pkColumn);
         }
     }
+    
+    String nullSafe(String s) {
+    	return s == null ? "" : s;
+    }
 }



Mime
View raw message