db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r711917 - in /db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform: JdbcModelReader.java mssql/MSSqlModelReader.java oracle/Oracle8Platform.java
Date Thu, 06 Nov 2008 17:31:06 GMT
Author: tomdz
Date: Thu Nov  6 09:30:12 2008
New Revision: 711917

URL: http://svn.apache.org/viewvc?rev=711917&view=rev
Log:
Tweaks to the cascade action reading code
Fix for Oracle platforms

Modified:
    db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/JdbcModelReader.java
    db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java
    db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/oracle/Oracle8Platform.java

Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/JdbcModelReader.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/JdbcModelReader.java?rev=711917&r1=711916&r2=711917&view=diff
==============================================================================
--- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/JdbcModelReader.java (original)
+++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/JdbcModelReader.java Thu
Nov  6 09:30:12 2008
@@ -929,8 +929,22 @@
         {
             fk = new ForeignKey(fkName);
             fk.setForeignTableName((String)values.get("PKTABLE_NAME"));
-            fk.setOnUpdate(convertAction((Short)values.get("UPDATE_RULE"), getPlatformInfo().getDefaultOnUpdateAction()));
-            fk.setOnDelete(convertAction((Short)values.get("DELETE_RULE"), getPlatformInfo().getDefaultOnDeleteAction()));
+
+            CascadeActionEnum onUpdateAction = convertAction((Short)values.get("UPDATE_RULE"));
+            CascadeActionEnum onDeleteAction = convertAction((Short)values.get("DELETE_RULE"));
+
+            // Some JDBC drivers lie and return actions that the DB not actually supports
+            if ((onUpdateAction == null) || !getPlatformInfo().isActionSupportedForOnUpdate(onUpdateAction))
+            {
+                onUpdateAction = getPlatformInfo().getDefaultOnUpdateAction();
+            }
+            if ((onDeleteAction == null) || !getPlatformInfo().isActionSupportedForOnDelete(onDeleteAction))
+            {
+                onDeleteAction = getPlatformInfo().getDefaultOnDeleteAction();
+            }
+
+            fk.setOnUpdate(onUpdateAction);
+            fk.setOnDelete(onDeleteAction);
             knownFks.put(fkName, fk);
         }
 
@@ -950,12 +964,11 @@
      * {@link DatabaseMetaData} class) to a {@link CascadeActionEnum}.
      * 
      * @param jdbcActionValue The jdbc action value
-     * @param defaultAction   The default action
      * @return The enum value
      */
-    protected CascadeActionEnum convertAction(Short jdbcActionValue, CascadeActionEnum defaultAction)
+    protected CascadeActionEnum convertAction(Short jdbcActionValue)
     {
-        CascadeActionEnum action = defaultAction;
+        CascadeActionEnum action = null;
 
         if (jdbcActionValue != null)
         {

Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java?rev=711917&r1=711916&r2=711917&view=diff
==============================================================================
--- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java
(original)
+++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java
Thu Nov  6 09:30:12 2008
@@ -19,7 +19,6 @@
  * under the License.
  */
 
-import java.sql.DatabaseMetaData;
 import java.sql.Date;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -33,7 +32,6 @@
 
 import org.apache.ddlutils.DdlUtilsException;
 import org.apache.ddlutils.Platform;
-import org.apache.ddlutils.model.CascadeActionEnum;
 import org.apache.ddlutils.model.Column;
 import org.apache.ddlutils.model.Index;
 import org.apache.ddlutils.model.Table;
@@ -230,19 +228,4 @@
 
 		return column;
 	}
-
-    /**
-     * {@inheritDoc}
-     */
-    protected CascadeActionEnum convertAction(Short jdbcActionValue, CascadeActionEnum defaultAction)
-    {
-        CascadeActionEnum action = defaultAction;
-
-        // for whatever reason, the sql server jdbc driver returns restrict even though the
DB does not support RESTRICT
-        if ((jdbcActionValue != null) && (jdbcActionValue.shortValue() == DatabaseMetaData.importedKeyCascade))
-        {
-            action = CascadeActionEnum.CASCADE;
-        }
-        return action;
-    }
 }

Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/oracle/Oracle8Platform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/oracle/Oracle8Platform.java?rev=711917&r1=711916&r2=711917&view=diff
==============================================================================
--- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/oracle/Oracle8Platform.java
(original)
+++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/oracle/Oracle8Platform.java
Thu Nov  6 09:30:12 2008
@@ -31,6 +31,7 @@
 import org.apache.ddlutils.alteration.RemovePrimaryKeyChange;
 import org.apache.ddlutils.alteration.TableChange;
 import org.apache.ddlutils.alteration.TableDefinitionChangesPredicate;
+import org.apache.ddlutils.model.CascadeActionEnum;
 import org.apache.ddlutils.model.Column;
 import org.apache.ddlutils.model.Database;
 import org.apache.ddlutils.model.Table;
@@ -71,6 +72,8 @@
         info.setMaxIdentifierLength(30);
         info.setIdentityStatusReadingSupported(false);
         info.setPrimaryKeyColumnAutomaticallyRequired(true);
+        info.setSupportedOnUpdateActions(new CascadeActionEnum[] { CascadeActionEnum.NONE
});
+        info.setSupportedOnDeleteActions(new CascadeActionEnum[] { CascadeActionEnum.CASCADE,
CascadeActionEnum.SET_NULL, CascadeActionEnum.NONE });
 
         // Note that the back-mappings are partially done by the model reader, not the driver
         info.addNativeTypeMapping(Types.ARRAY,         "BLOB",             Types.BLOB);



Mime
View raw message