db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r233467 - in /db/ddlutils/trunk/src/java/org/apache/ddlutils: io/ task/
Date Fri, 19 Aug 2005 11:58:10 GMT
Author: tomdz
Date: Fri Aug 19 04:58:04 2005
New Revision: 233467

URL: http://svn.apache.org/viewcvs?rev=233467&view=rev
Log:
Added failOnError attribute to the database-modifying commands
Fixed ConcurrentModificationException bug when inserting a incomplete data xml file

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DataToDatabaseSink.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/CreateDatabaseCommand.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseCommand.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DropDatabaseCommand.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToSpecifiedDatabaseCommand.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java

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=233467&r1=233466&r2=233467&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 Aug 19 04:58:04
2005
@@ -243,8 +243,9 @@
         }
         if (_processedIdentities.containsKey(table.getName()))
         {
-            Identity identity           = buildIdentityFromPKs(table, bean);
-            HashSet  identitiesForTable = (HashSet)_processedIdentities.get(table.getName());
+            Identity  identity           = buildIdentityFromPKs(table, bean);
+            HashSet   identitiesForTable = (HashSet)_processedIdentities.get(table.getName());
+            ArrayList finishedObjs       = new ArrayList();
 
             identitiesForTable.add(identity);
             for (Iterator waitingObjIt = _waitingObjects.iterator(); waitingObjIt.hasNext();)
@@ -259,13 +260,20 @@
                     // prior to that we also update the fk fields in case one of the pk
                     // columns of the target object is auto-incremented by the database
                     updateFKColumns(waitingObj.getObject(), bean, fkIdentity.getForeignKeyName());
-                    addBean(waitingObj.getObject());
-                    if (_log.isDebugEnabled())
-                    {
-                        Table waitingObjTable = ((SqlDynaClass)waitingObj.getObject().getDynaClass()).getTable();
+                    // we defer handling of the finished objects to avoid concurrent modification
exceptions
+                    finishedObjs.add(waitingObj.getObject());
+                }
+            }
+            for (Iterator finishedObjIt = finishedObjs.iterator(); finishedObjIt.hasNext();)
+            {
+                DynaBean finishedObj = (DynaBean)finishedObjIt.next();
+
+                addBean(finishedObj);
+                if (_log.isDebugEnabled())
+                {
+                    Table waitingObjTable = ((SqlDynaClass)finishedObj.getDynaClass()).getTable();
 
-                        _log.debug("Inserted deferred bean "+buildIdentityFromPKs(waitingObjTable,
waitingObj.getObject()));
-                    }
+                    _log.debug("Inserted deferred bean "+buildIdentityFromPKs(waitingObjTable,
finishedObj));
                 }
             }
         }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/CreateDatabaseCommand.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/CreateDatabaseCommand.java?rev=233467&r1=233466&r2=233467&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/CreateDatabaseCommand.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/CreateDatabaseCommand.java Fri Aug
19 04:58:04 2005
@@ -57,7 +57,14 @@
         }
         catch (Exception ex)
         {
-            throw new BuildException(ex);
+            if (isFailOnError())
+            {
+                throw new BuildException(ex);
+            }
+            else
+            {
+                task.log(ex.getLocalizedMessage(), Project.MSG_ERR);
+            }
         }
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseCommand.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseCommand.java?rev=233467&r1=233466&r2=233467&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseCommand.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseCommand.java Fri Aug 19 04:58:04
2005
@@ -15,8 +15,8 @@
     private String _databaseType;
     /** The data source to use for accessing the database */
     private BasicDataSource _dataSource;
-    /** Whether to alter or re-set the database if it already exists */
-    private boolean _alterDb = true;
+    /** Whether to stop execution upon an error */
+    private boolean _failOnError = true;
 
     /**
      * Returns the database type.
@@ -59,23 +59,24 @@
     }
 
     /**
-     * Determines whether to alter the database if it already exists, or re-set it.
-     * 
-     * @return <code>true</code> if to alter the database
+     * Determines whether the command execution will be stopped upon an error.
+     * Default value is <code>true</code>.
+     *
+     * @return <code>true</code> if the execution stops in case of an error
      */
-    protected boolean isAlterDatabase()
+    public boolean isFailOnError()
     {
-        return _alterDb;
+        return _failOnError;
     }
 
     /**
-     * Specifies whether to alter the database if it already exists, or re-set it.
-     * 
-     * @param alterTheDb <code>true</code> if to alter the database
+     * Specifies whether the command execution will be stopped upon an error.
+     *
+     * @param failOnError <code>true</code> if the execution stops in case of
an error
      */
-    public void setAlterDatabase(boolean alterTheDb)
+    public void setFailOnError(boolean failOnError)
     {
-        _alterDb = alterTheDb;
+        _failOnError = failOnError;
     }
 
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DropDatabaseCommand.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DropDatabaseCommand.java?rev=233467&r1=233466&r2=233467&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DropDatabaseCommand.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DropDatabaseCommand.java Fri Aug 19
04:58:04 2005
@@ -57,7 +57,14 @@
         }
         catch (Exception ex)
         {
-            throw new BuildException(ex);
+            if (isFailOnError())
+            {
+                throw new BuildException(ex);
+            }
+            else
+            {
+                task.log(ex.getLocalizedMessage(), Project.MSG_ERR);
+            }
         }
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToSpecifiedDatabaseCommand.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToSpecifiedDatabaseCommand.java?rev=233467&r1=233466&r2=233467&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToSpecifiedDatabaseCommand.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToSpecifiedDatabaseCommand.java
Fri Aug 19 04:58:04 2005
@@ -19,9 +19,7 @@
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Iterator;
-
 import org.apache.ddlutils.Platform;
-import org.apache.ddlutils.PlatformFactory;
 import org.apache.ddlutils.io.DataReader;
 import org.apache.ddlutils.io.DataToDatabaseSink;
 import org.apache.ddlutils.model.Database;
@@ -73,7 +71,7 @@
 
         try
         {
-            Platform           platform = PlatformFactory.createNewPlatformInstance(getDatabaseType());
+            Platform           platform = getPlatform();
             DataToDatabaseSink sink     = new DataToDatabaseSink(platform, model);
             DataReader         reader   = new DataReader();
 

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java?rev=233467&r1=233466&r2=233467&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java Fri
Aug 19 04:58:04 2005
@@ -35,6 +35,8 @@
 {
     /** The file to output the DTD to */
     private File _outputFile;
+    /** Whether to alter or re-set the database if it already exists */
+    private boolean _alterDb = true;
 
     /**
      * Sets the file to output the sql to.
@@ -46,6 +48,26 @@
         _outputFile = outputFile;
     }
 
+    /**
+     * Determines whether to alter the database if it already exists, or re-set it.
+     * 
+     * @return <code>true</code> if to alter the database
+     */
+    protected boolean isAlterDatabase()
+    {
+        return _alterDb;
+    }
+
+    /**
+     * Specifies whether to alter the database if it already exists, or re-set it.
+     * 
+     * @param alterTheDb <code>true</code> if to alter the database
+     */
+    public void setAlterDatabase(boolean alterTheDb)
+    {
+        _alterDb = alterTheDb;
+    }
+
     /* (non-Javadoc)
      * @see org.apache.ddlutils.task.Command#execute(org.apache.tools.ant.Task, org.apache.ddlutils.model.Database)
      */
@@ -89,7 +111,14 @@
         }
         catch (Exception ex)
         {
-            throw new BuildException(ex);
+            if (isFailOnError())
+            {
+                throw new BuildException(ex);
+            }
+            else
+            {
+                task.log(ex.getLocalizedMessage(), Project.MSG_ERR);
+            }
         }
         finally
         {
@@ -104,5 +133,4 @@
             }
         }
     }
-
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java?rev=233467&r1=233466&r2=233467&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java
Fri Aug 19 04:58:04 2005
@@ -27,6 +27,29 @@
  */
 public class WriteSchemaToDatabaseCommand extends DatabaseCommand
 {
+    /** Whether to alter or re-set the database if it already exists */
+    private boolean _alterDb = true;
+
+    /**
+     * Determines whether to alter the database if it already exists, or re-set it.
+     * 
+     * @return <code>true</code> if to alter the database
+     */
+    protected boolean isAlterDatabase()
+    {
+        return _alterDb;
+    }
+
+    /**
+     * Specifies whether to alter the database if it already exists, or re-set it.
+     * 
+     * @param alterTheDb <code>true</code> if to alter the database
+     */
+    public void setAlterDatabase(boolean alterTheDb)
+    {
+        _alterDb = alterTheDb;
+    }
+
     /* (non-Javadoc)
      * @see org.apache.ddlutils.task.Command#execute(org.apache.tools.ant.Task, org.apache.ddlutils.model.Database)
      */
@@ -54,7 +77,14 @@
         }
         catch (Exception ex)
         {
-            throw new BuildException(ex);
+            if (isFailOnError())
+            {
+                throw new BuildException(ex);
+            }
+            else
+            {
+                task.log(ex.getLocalizedMessage(), Project.MSG_ERR);
+            }
         }
     }
 }



Mime
View raw message