Class WriteDataToDatabaseCommand
java.lang.Object
edu.internet2.middleware.grouper.ext.org.apache.ddlutils.task.Command
edu.internet2.middleware.grouper.ext.org.apache.ddlutils.task.DatabaseCommand
edu.internet2.middleware.grouper.ext.org.apache.ddlutils.task.ConvertingDatabaseCommand
edu.internet2.middleware.grouper.ext.org.apache.ddlutils.task.WriteDataToDatabaseCommand
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
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.
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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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 edu.internet2.middleware.grouper.ext.org.apache.ddlutils.task.ConvertingDatabaseCommand
addConfiguredConverter, getDataIO
Methods inherited from class edu.internet2.middleware.grouper.ext.org.apache.ddlutils.task.DatabaseCommand
getCatalogPattern, getDatabaseType, getDataSource, getPlatform, getSchemaPattern, isRequiringModel, setPlatformConfiguration
Methods inherited from class edu.internet2.middleware.grouper.ext.org.apache.ddlutils.task.Command
handleException, isFailOnError, setFailOnError
-
Constructor Details
-
WriteDataToDatabaseCommand
public WriteDataToDatabaseCommand()
-
-
Method Details
-
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. UnlessensureForeignKeyOrder
is set to false, setting this tofalse
(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
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 ifuseBatchMode
istrue
.- 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.
-