db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r405865 - in /db/ddlutils/trunk/src: doc/src/documentation/content/xdocs/ant-tasks.xml java/org/apache/ddlutils/io/DataToDatabaseSink.java java/org/apache/ddlutils/task/WriteDataToDatabaseCommand.java
Date Fri, 12 May 2006 20:36:04 GMT
Author: tomdz
Date: Fri May 12 13:36:03 2006
New Revision: 405865

URL: http://svn.apache.org/viewcvs?rev=405865&view=rev
Log:
Fix for DDLUTILS-107

Modified:
    db/ddlutils/trunk/src/doc/src/documentation/content/xdocs/ant-tasks.xml
    db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DataToDatabaseSink.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToDatabaseCommand.java

Modified: db/ddlutils/trunk/src/doc/src/documentation/content/xdocs/ant-tasks.xml
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/doc/src/documentation/content/xdocs/ant-tasks.xml?rev=405865&r1=405864&r2=405865&view=diff
==============================================================================
--- db/ddlutils/trunk/src/doc/src/documentation/content/xdocs/ant-tasks.xml (original)
+++ db/ddlutils/trunk/src/doc/src/documentation/content/xdocs/ant-tasks.xml Fri May 12 13:36:03
2006
@@ -498,7 +498,9 @@
         <p>
           DdlUtils will honor the order imposed by the foreign keys. Ie. first all required
entries are
           inserted, then the dependent ones. Obviously this requires that no circular references
exist
-          in the schema (DdlUtils currently does not check this).
+          in the schema (DdlUtils currently does not check this). Also, the referenced entries
must be
+          present in the data, otherwise the task will fail. This behavior can be turned
off via the
+          <code>ensureForeignKeyOrder</code> attribute.
         </p>
         <p>
           In order to define data for foreign key dependencies that use auto-incrementing
primary keys,
@@ -528,6 +530,14 @@
             <td></td>
             <td></td>
             <td>The name of the single XML file that contains the data to insert into
the database.</td>
+          </tr>
+          <tr>
+            <td>ensureForeignKeyOrder</td>
+            <td>no</td>
+            <td>true, false</td>
+            <td>true</td>
+            <td>Whether DdlUtils shall honor the foreign key order or simply assume
that the entry
+                order is ok.</td>
           </tr>
           <tr>
             <td>failOnError</td>

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DataToDatabaseSink.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DataToDatabaseSink.java?rev=405865&r1=405864&r2=405865&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DataToDatabaseSink.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DataToDatabaseSink.java Fri May 12 13:36:03
2006
@@ -123,7 +123,7 @@
      *
      * @param ensureFkOrder <code>true</code> if beans shall be inserted after
its foreignkey-references
      */
-    public void setEnsureFkOrder(boolean ensureFkOrder)
+    public void setEnsureForeignKeyOrder(boolean ensureFkOrder)
     {
         _ensureFkOrder = ensureFkOrder;
     }
@@ -198,17 +198,20 @@
         // lists of already-processed identities for these tables
         _processedIdentities.clear();
         _waitingObjects.clear();
-        for (int tableIdx = 0; tableIdx < _model.getTableCount(); tableIdx++)
+        if (_ensureFkOrder)
         {
-            Table table = _model.getTable(tableIdx);
-
-            for (int fkIdx = 0; fkIdx < table.getForeignKeyCount(); fkIdx++)
+            for (int tableIdx = 0; tableIdx < _model.getTableCount(); tableIdx++)
             {
-                ForeignKey curFk = table.getForeignKey(fkIdx);
-
-                if (!_processedIdentities.containsKey(curFk.getForeignTableName()))
+                Table table = _model.getTable(tableIdx);
+    
+                for (int fkIdx = 0; fkIdx < table.getForeignKeyCount(); fkIdx++)
                 {
-                    _processedIdentities.put(curFk.getForeignTableName(), new HashSet());
+                    ForeignKey curFk = table.getForeignKey(fkIdx);
+    
+                    if (!_processedIdentities.containsKey(curFk.getForeignTableName()))
+                    {
+                        _processedIdentities.put(curFk.getForeignTableName(), new HashSet());
+                    }
                 }
             }
         }
@@ -229,7 +232,7 @@
     {
         Table table = _model.getDynaClassFor(bean).getTable();
 
-        if (table.getForeignKeyCount() > 0)
+        if (_ensureFkOrder && (table.getForeignKeyCount() > 0))
         {
             WaitingObject waitingObj = new WaitingObject(bean);
 
@@ -268,7 +271,7 @@
             }
         }
         insertBeanIntoDatabase(table, bean);
-        if (_processedIdentities.containsKey(table.getName()))
+        if (_ensureFkOrder && _processedIdentities.containsKey(table.getName()))
         {
             Identity  identity           = buildIdentityFromPKs(table, bean);
             HashSet   identitiesForTable = (HashSet)_processedIdentities.get(table.getName());

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToDatabaseCommand.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToDatabaseCommand.java?rev=405865&r1=405864&r2=405865&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToDatabaseCommand.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToDatabaseCommand.java Fri
May 12 13:36:03 2006
@@ -42,6 +42,8 @@
     private File      _singleDataFile = null;
     /** The input files. */
     private ArrayList _fileSets = new ArrayList();
+    /** Whether foreign key order shall be followed when inserting data into the database.
*/
+    private boolean _ensureFKOrder = true;
     /** Whether we should use batch mode. */
     private Boolean _useBatchMode;
     /** The maximum number of objects to insert in one batch. */
@@ -78,9 +80,9 @@
     }
 
     /**
-     * Specifies whether we shall be using batch mode.
+     * Specifies whether batch mode shall be used.
      *
-     * @param useBatchMode <code>true</code> if we shall use batch mode
+     * @param useBatchMode <code>true</code> if batch mode shall be used
      */
     public void setUseBatchMode(boolean useBatchMode)
     {
@@ -88,6 +90,17 @@
     }
 
     /**
+     * Specifies whether the foreign key order shall be honored when inserted
+     * data into the database.
+     *
+     * @param ensureFKOrder <code>true</code> if the foreign key order shall
be followed
+     */
+    public void setEnsureForeignKeyOrder(boolean ensureFKOrder)
+    {
+        _ensureFKOrder = ensureFKOrder;
+    }
+
+    /**
      * {@inheritDoc}
      */
     public void execute(Task task, Database model) throws BuildException
@@ -98,6 +111,7 @@
             DataToDatabaseSink sink     = new DataToDatabaseSink(platform, model);
             DataReader         reader   = new DataReader();
 
+            sink.setEnsureForeignKeyOrder(_ensureFKOrder);
             if (_useBatchMode != null)
             {
                 sink.setUseBatchMode(_useBatchMode.booleanValue());



Mime
View raw message