org.apache.ddlutils.task
Class DdlToDatabaseTask

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by org.apache.ddlutils.task.DatabaseTaskBase
              extended by org.apache.ddlutils.task.DdlToDatabaseTask

public class DdlToDatabaseTask
extends DatabaseTaskBase

Task for performing operations on a live database. Sub tasks e.g. create the schema in the database, drop database schemas, insert data into the database, create DTDs for data files, or write the SQL for creating a schema to a file.
Example:

 <taskdef classname="org.apache.ddlutils.task.DdlToDatabaseTask"
          name="ddlToDatabase"
          classpathref="project-classpath"/>
 
 <ddlToDatabase usedelimitedsqlidentifiers="true">
   <database driverclassname="org.apache.derby.jdbc.ClientDriver"
             url="jdbc:derby://localhost/ddlutils"
             username="ddlutils"
             password="ddlutils"/> 
   <fileset dir=".">
     <include name="*schema.xml"/> 
   </fileset> 
 
   <createdatabase failonerror="false"/> 
   <writeschematodatabase alterdatabase="true"
                          failonerror="false"/> 
   <writedatatodatabase datafile="data.xml"
                        usebatchmode="true"
                        batchsize="1000"/>
 </ddlToDatabase> 
 
This Ant build file snippet essentially creates a database, creates tables, foreign keys etc. int it and then writes data into the newly created tables.

Version:
$Revision: 289996 $

Field Summary
 
Fields inherited from class org.apache.ddlutils.task.DatabaseTaskBase
_log
 
Fields inherited from class org.apache.tools.ant.Task
description, location, target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
project
 
Constructor Summary
DdlToDatabaseTask()
           
 
Method Summary
 void addConfiguredFileset(org.apache.tools.ant.types.FileSet fileset)
          Adds a fileset.
 void addCreateDatabase(CreateDatabaseCommand command)
          Adds the "create database"-command.
 void addDropDatabase(DropDatabaseCommand command)
          Adds the "drop database"-command.
 void addWriteDataToDatabase(WriteDataToDatabaseCommand command)
          Adds the "write data to database"-command.
 void addWriteDataToFile(WriteDataToFileCommand command)
          Adds the "write data to file"-command.
 void addWriteDtdToFile(WriteDtdToFileCommand command)
          Adds the "write dtd to file"-command.
 void addWriteSchemaSqlToFile(WriteSchemaSqlToFileCommand command)
          Adds the "write schema sql to file"-command.
 void addWriteSchemaToDatabase(WriteSchemaToDatabaseCommand command)
          Adds the "write schema to database"-command.
protected  Database readModel()
          Reads the database model on which the commands will work.
 void setSchemaFile(File schemaFile)
          Defines the single file that contains the database file.
 void setUseInternalDtd(boolean useInternalDtd)
          Specifies whether DdlUtils shall use the embedded DTD for validating the schema XML (if it matches http://db.apache.org/torque/dtd/database.dtd).
 void setValidateXml(boolean validateXml)
          Specifies whether XML input files should be validated against the DTD at all.
 
Methods inherited from class org.apache.ddlutils.task.DatabaseTaskBase
addCommand, addConfiguredDatabase, execute, executeCommands, getCommands, getDatabaseType, getDataSource, getPlatform, getPlatformConfiguration, hasCommands, isShutdownDatabase, isSortForeignKeys, isUseDelimitedSqlIdentifiers, setCatalogPattern, setDatabaseType, setSchemaPattern, setShutdownDatabase, setSimpleLogging, setSortForeignKeys, setUseDelimitedSqlIdentifiers, setVerbosity
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject, setProject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DdlToDatabaseTask

public DdlToDatabaseTask()
Method Detail

setUseInternalDtd

public void setUseInternalDtd(boolean useInternalDtd)
Specifies whether DdlUtils shall use the embedded DTD for validating the schema XML (if it matches http://db.apache.org/torque/dtd/database.dtd). This is especially useful in environments where no web access is possible or desired.

Parameters:
useInternalDtd - true if input files are to be validated against the internal DTD

setValidateXml

public void setValidateXml(boolean validateXml)
Specifies whether XML input files should be validated against the DTD at all.

Parameters:
validateXml - true if input files are to be validated

addConfiguredFileset

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

Parameters:
fileset - The additional input files

setSchemaFile

public void setSchemaFile(File schemaFile)
Defines the single file that contains the database file. You can use this instead of embedded fileset elements if you only have one schema file.

Parameters:
schemaFile - The schema

addCreateDatabase

public void addCreateDatabase(CreateDatabaseCommand command)
Adds the "create database"-command.

Parameters:
command - The command

addDropDatabase

public void addDropDatabase(DropDatabaseCommand command)
Adds the "drop database"-command.

Parameters:
command - The command

addWriteDtdToFile

public void addWriteDtdToFile(WriteDtdToFileCommand command)
Adds the "write dtd to file"-command.

Parameters:
command - The command

addWriteSchemaToDatabase

public void addWriteSchemaToDatabase(WriteSchemaToDatabaseCommand command)
Adds the "write schema to database"-command.

Parameters:
command - The command

addWriteSchemaSqlToFile

public void addWriteSchemaSqlToFile(WriteSchemaSqlToFileCommand command)
Adds the "write schema sql to file"-command.

Parameters:
command - The command

addWriteDataToDatabase

public void addWriteDataToDatabase(WriteDataToDatabaseCommand command)
Adds the "write data to database"-command.

Parameters:
command - The command

addWriteDataToFile

public void addWriteDataToFile(WriteDataToFileCommand command)
Adds the "write data to file"-command.

Parameters:
command - The command

readModel

protected Database readModel()
Reads the database model on which the commands will work.

Specified by:
readModel in class DatabaseTaskBase
Returns:
The database model


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