org.apache.ddlutils.task
Class WriteDataToDatabaseCommand

java.lang.Object
  extended by org.apache.ddlutils.task.Command
      extended by org.apache.ddlutils.task.DatabaseCommand
          extended by org.apache.ddlutils.task.ConvertingDatabaseCommand
              extended by org.apache.ddlutils.task.WriteDataToDatabaseCommand

public class WriteDataToDatabaseCommand
extends ConvertingDatabaseCommand

Inserts the data defined by the data XML file(s) into the database. This requires the schema in the database to match the schema defined by the XML files specified at the enclosing task.
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). Also, the referenced entries must be present in the data, otherwise the task will fail. This behavior can be turned off via the ensureForeignKeyOrder attribute.
In order to define data for foreign key dependencies that use auto-incrementing primary keys, simply use some unique values for their columns. DdlUtils then will automatically use the real primary key values when inserting the data. Note though that not every database supports the retrieval of auto-increment values which is necessary for this to work.

Version:
$Revision: 289996 $

Field Summary
 
Fields inherited from class org.apache.ddlutils.task.Command
_log
 
Constructor Summary
WriteDataToDatabaseCommand()
           
 
Method Summary
 void addConfiguredFileset(org.apache.tools.ant.types.FileSet fileset)
          Adds a fileset.
 void execute(DatabaseTaskBase task, Database model)
          Executes this command.
 void setBatchSize(int batchSize)
          The maximum number of insert statements to combine in one batch.
 void setDataFile(File dataFile)
          Specifies the name of the single XML file that contains the data to insert into the database.
 void setEnsureForeignKeyOrder(boolean ensureFKOrder)
          Specifies whether the foreign key order shall be honored when inserting data into the database.
 void setUseBatchMode(boolean useBatchMode)
          Specifies whether batch mode shall be used for inserting the data.
 void setUseExplicitIdentityValues(boolean useExplicitIdentityValues)
          Defines whether values for identity columns in the data XML shall be used instead of letting the database define the value.
 
Methods inherited from class org.apache.ddlutils.task.ConvertingDatabaseCommand
addConfiguredConverter, getDataIO
 
Methods inherited from class org.apache.ddlutils.task.DatabaseCommand
getCatalogPattern, getDatabaseType, getDataSource, getPlatform, getSchemaPattern, isRequiringModel, setPlatformConfiguration
 
Methods inherited from class org.apache.ddlutils.task.Command
handleException, isFailOnError, setFailOnError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WriteDataToDatabaseCommand

public WriteDataToDatabaseCommand()
Method Detail

setUseExplicitIdentityValues

public void setUseExplicitIdentityValues(boolean useExplicitIdentityValues)
Defines whether values for identity columns in the data XML shall be used instead of letting the database define the value. Unless ensureForeignKeyOrder is set to false, setting this to false (the default) does not affect foreign keys as DdlUtils will automatically update the values of the columns of foreign keys pointing to the inserted row with the database-created values.

Parameters:
useExplicitIdentityValues - true if explicitly specified identity column values should be inserted instead of letting the database define the values for these columns

addConfiguredFileset

public void addConfiguredFileset(org.apache.tools.ant.types.FileSet fileset)
Adds a fileset.

Parameters:
fileset - The additional input files

setDataFile

public void setDataFile(File dataFile)
Specifies the name of the single XML file that contains the data to insert into the database.

Parameters:
dataFile - The data file

setBatchSize

public void setBatchSize(int batchSize)
The maximum number of insert statements to combine in one batch. The number typically depends on the JDBC driver and the amount of available memory.
This value is only used if useBatchMode is true.

Parameters:
batchSize - The number of objects

setUseBatchMode

public void setUseBatchMode(boolean useBatchMode)
Specifies whether batch mode shall be used for inserting the data. In batch mode, insert statements for the same table are bundled together and executed as one statement. This can be a lot faster than single insert statements but is not supported by all JDBC drivers/databases. To achieve the highest performance, you should group the data in the XML file according to the tables. This is because a batch insert only works for one table at a time. Thus when the table changes in an entry in the XML file, the batch is committed and then a new one is started.

Parameters:
useBatchMode - true if batch mode shall be used

setEnsureForeignKeyOrder

public void setEnsureForeignKeyOrder(boolean ensureFKOrder)
Specifies whether the foreign key order shall be honored when inserting data into the database. If not, DdlUtils will simply assume that the entry order is correct, i.e. that referenced rows come before referencing rows in the data XML. Note that execution will be slower when DdlUtils has to ensure the foreign-key order of the data. Thus if you know that the data is specified in foreign key order turn this off.

Parameters:
ensureFKOrder - true if the foreign key order shall be followed

execute

public void execute(DatabaseTaskBase task,
                    Database model)
             throws org.apache.tools.ant.BuildException
Executes this command.

Specified by:
execute in class Command
Parameters:
task - The executing task
model - The database model
Throws:
org.apache.tools.ant.BuildException


Copyright © 2005-2007 Apache Software Foundation. All Rights Reserved.