openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r675811 - /openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
Date Thu, 10 Jul 2008 23:54:22 GMT
Author: ppoddar
Date: Thu Jul 10 16:54:22 2008
New Revision: 675811

URL: http://svn.apache.org/viewvc?rev=675811&view=rev
Log:
OPENJPA-644 Merge 675806 from trunk to 1.0.x

Modified:
    openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java

Modified: openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java?rev=675811&r1=675810&r2=675811&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
(original)
+++ openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
Thu Jul 10 16:54:22 2008
@@ -68,8 +68,8 @@
     private static final String useKeepExclusiveLockClause
         = "USE AND KEEP EXCLUSIVE LOCKS";
     private 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;
 
@@ -216,8 +216,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
@@ -358,51 +358,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
@@ -413,17 +394,37 @@
         // ISeries                               DB2 UDB for AS/400
         //   (Native)                            V5R4M0
         if (databaseProductName.indexOf("AS") != -1) {
-            String s = databaseProductVersion.substring(databaseProductVersion
-                .indexOf('V'));
-            s = s.toUpperCase();
-
-            StringTokenizer stringtokenizer = new StringTokenizer(s, "VRM"
-                , false);
-            if (stringtokenizer.countTokens() == 3) {
-                String s1 = stringtokenizer.nextToken();
-                maj = Integer.parseInt(s1);
-                String s2 =  stringtokenizer.nextToken();
-                min = Integer.parseInt(s2);
+            // default to V5R4
+            maj = 5;
+            min = 4;
+            int index = databaseProductVersion.indexOf('V');
+            if (index != -1) {
+            	String s = databaseProductVersion.substring(index);
+            	s = s.toUpperCase();
+
+            	StringTokenizer stringtokenizer = new StringTokenizer(s, "VRM"
+            			, false);
+            	if (stringtokenizer.countTokens() == 3) {
+            		String s1 = stringtokenizer.nextToken();
+            		maj = Integer.parseInt(s1);
+            		String s2 =  stringtokenizer.nextToken();
+            		min = Integer.parseInt(s2);
+            	}
+            }
+            else {
+            	index = databaseProductVersion.indexOf('0');
+            	if (index != -1) {
+            		String s = databaseProductVersion.substring(index);
+            		s = s.toUpperCase();
+           			StringTokenizer stringtokenizer = new StringTokenizer(s, "0"
+           					, false);                    
+           			if (stringtokenizer.countTokens() == 2) {
+           				String s1 = stringtokenizer.nextToken();
+           				maj = Integer.parseInt(s1);
+           				String s2 =  stringtokenizer.nextToken();
+           				min = Integer.parseInt(s2);
+           			}
+                }
             }
         }
     }
@@ -772,4 +773,8 @@
             idx.addColumn(pkColumn);
         }
     }
+    
+    String nullSafe(String s) {
+    	return s == null ? "" : s;
+    }
 }



Mime
View raw message