ibatis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgbut...@apache.org
Subject svn commit: r467774 - in /ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator: config/AbatorContext.java config/GeneratedKey.java internal/db/DatabaseDialects.java
Date Wed, 25 Oct 2006 21:43:10 GMT
Author: jgbutler
Date: Wed Oct 25 14:43:09 2006
New Revision: 467774

URL: http://svn.apache.org/viewvc?view=rev&rev=467774
Log: (empty)

Modified:
    ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/AbatorContext.java
    ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/GeneratedKey.java
    ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/db/DatabaseDialects.java

Modified: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/AbatorContext.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/AbatorContext.java?view=diff&rev=467774&r1=467773&r2=467774
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/AbatorContext.java
(original)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/AbatorContext.java
Wed Oct 25 14:43:09 2006
@@ -397,4 +397,8 @@
         
         return xmlElement;
     }
+
+    public List getTableConfigurations() {
+        return tableConfigurations;
+    }
 }

Modified: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/GeneratedKey.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/GeneratedKey.java?view=diff&rev=467774&r1=467773&r2=467774
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/GeneratedKey.java
(original)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/GeneratedKey.java
Wed Oct 25 14:43:09 2006
@@ -43,26 +43,11 @@
         this.isIdentity = isIdentity;
         this.configuredSqlStatement = configuredSqlStatement;
 
-        if ("DB2".equalsIgnoreCase(configuredSqlStatement)) { //$NON-NLS-1$
-            this.runtimeSqlStatement = DatabaseDialects
-                    .getIdentityClause(DatabaseDialects.DB2);
-        } else if ("MySQL".equalsIgnoreCase(configuredSqlStatement)) { //$NON-NLS-1$
-            this.runtimeSqlStatement = DatabaseDialects
-                    .getIdentityClause(DatabaseDialects.MYSQL);
-        } else if ("SqlServer".equalsIgnoreCase(configuredSqlStatement)) { //$NON-NLS-1$
-            this.runtimeSqlStatement = DatabaseDialects
-                    .getIdentityClause(DatabaseDialects.SQLSERVER);
-        } else if ("Cloudscape".equalsIgnoreCase(configuredSqlStatement)) { //$NON-NLS-1$
-            this.runtimeSqlStatement = DatabaseDialects
-                    .getIdentityClause(DatabaseDialects.CLOUDSCAPE);
-        } else if ("Derby".equalsIgnoreCase(configuredSqlStatement)) { //$NON-NLS-1$
-            this.runtimeSqlStatement = DatabaseDialects
-                    .getIdentityClause(DatabaseDialects.DERBY);
-        } else if ("HSQLDB".equalsIgnoreCase(configuredSqlStatement)) { //$NON-NLS-1$
-            this.runtimeSqlStatement = DatabaseDialects
-                    .getIdentityClause(DatabaseDialects.HSQLDB);
-        } else {
+        DatabaseDialects dialect = DatabaseDialects.getDatabaseDialect(configuredSqlStatement);
+        if (dialect == null) {
             this.runtimeSqlStatement = configuredSqlStatement;
+        } else {
+            this.runtimeSqlStatement = dialect.getIdentityRetrievalStatement();
         }
     }
 

Modified: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/db/DatabaseDialects.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/db/DatabaseDialects.java?view=diff&rev=467774&r1=467773&r2=467774
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/db/DatabaseDialects.java
(original)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/db/DatabaseDialects.java
Wed Oct 25 14:43:09 2006
@@ -15,46 +15,63 @@
  */
 package org.apache.ibatis.abator.internal.db;
 
-import java.util.HashMap;
-import java.util.Map;
-
 /**
+ * Typesafe enum of known database dialects
+ * 
  * @author Jeff Butler
  */
 public class DatabaseDialects {
-    public static final Integer DB2 = new Integer(1);
+    
+    public static final DatabaseDialects DB2 = new DatabaseDialects("VALUES IDENTITY_VAL_LOCAL()");
//$NON-NLS-1$
 
-    public static final Integer MYSQL = new Integer(2);
+    public static final DatabaseDialects MYSQL = new DatabaseDialects("SELECT LAST_INSERT_ID()");
//$NON-NLS-1$
 
-    public static final Integer SQLSERVER = new Integer(3);
+    public static final DatabaseDialects SQLSERVER = new DatabaseDialects("SELECT SCOPE_IDENTITY()");
//$NON-NLS-1$
 
-    public static final Integer CLOUDSCAPE = new Integer(4);
+    public static final DatabaseDialects CLOUDSCAPE = new DatabaseDialects("VALUES IDENTITY_VAL_LOCAL()");
//$NON-NLS-1$
 
-    public static final Integer DERBY = new Integer(5);
+    public static final DatabaseDialects DERBY = new DatabaseDialects("VALUES IDENTITY_VAL_LOCAL()");
//$NON-NLS-1$
     
-    public static final Integer HSQLDB = new Integer(6);
+    public static final DatabaseDialects HSQLDB = new DatabaseDialects("CALL IDENTITY()");
//$NON-NLS-1$
     
-    private static final Map identityClauses;
-
-    static {
-        identityClauses = new HashMap();
+    private String identityRetrievalStatement;
 
-        identityClauses.put(DB2, "VALUES IDENTITY_VAL_LOCAL()"); //$NON-NLS-1$
-        identityClauses.put(MYSQL, "SELECT LAST_INSERT_ID()"); //$NON-NLS-1$
-        identityClauses.put(SQLSERVER, "SELECT SCOPE_IDENTITY()"); //$NON-NLS-1$
-        identityClauses.put(CLOUDSCAPE, "VALUES IDENTITY_VAL_LOCAL()"); //$NON-NLS-1$
-        identityClauses.put(DERBY, "VALUES IDENTITY_VAL_LOCAL()"); //$NON-NLS-1$
-        identityClauses.put(HSQLDB, "CALL IDENTITY()"); //$NON-NLS-1$
+    /**
+     *  
+     */
+    private DatabaseDialects(String identityRetrievalStatement) {
+        super();
+        this.identityRetrievalStatement = identityRetrievalStatement;
     }
 
-    public static String getIdentityClause(Integer dialect) {
-        return (String) identityClauses.get(dialect);
+    public String getIdentityRetrievalStatement() {
+        return identityRetrievalStatement;
     }
 
     /**
-     *  
+     * 
+     * @param database
+     * @return the database dialect for the selected database.  May return null
+     * if there is no known dialect for the selected db
      */
-    private DatabaseDialects() {
-        super();
+    public static DatabaseDialects getDatabaseDialect(String database) {
+        DatabaseDialects returnValue = null;
+        
+        if ("DB2".equalsIgnoreCase(database)) { //$NON-NLS-1$
+            returnValue = DB2;
+        } else if ("MySQL".equalsIgnoreCase(database)) { //$NON-NLS-1$
+            returnValue = MYSQL;
+        } else if ("SqlServer".equalsIgnoreCase(database)) { //$NON-NLS-1$
+            returnValue = SQLSERVER;
+        } else if ("Cloudscape".equalsIgnoreCase(database)) { //$NON-NLS-1$
+            returnValue = CLOUDSCAPE;
+        } else if ("Derby".equalsIgnoreCase(database)) { //$NON-NLS-1$
+            returnValue = DERBY;
+        } else if ("HSQLDB".equalsIgnoreCase(database)) { //$NON-NLS-1$
+            returnValue = HSQLDB;
+        }
+        
+        return returnValue;
     }
+
 }



Mime
View raw message