org.apache.ddlutils.task
Class DatabaseToDdlTask

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.DatabaseToDdlTask

public class DatabaseToDdlTask
extends DatabaseTaskBase

Task for getting structural info and data from a live database. Eg. it has sub tasks for writing the schema of the live database or the data currently in it to an XML file, for creating the DTDs for these data files, and for generating SQL to creating a schema in the database to a file.
Example:

 <taskdef classname="org.apache.ddlutils.task.DatabaseToDdlTask"
          name="databaseToDdl"
          classpathref="project-classpath" />
 
 <databaseToDdl usedelimitedsqlidentifiers="true"
                modelname="example">
   <database driverclassname="org.apache.derby.jdbc.ClientDriver"
             url="jdbc:derby://localhost/ddlutils"
             username="ddlutils"
             password="ddlutils"/> 
 
   <writeschematofile outputfile="schema.xml"/> 
   <writedatatofile outputfile="data.xml"
                    encoding="ISO-8859-1"/> 
 </databaseToDdl> 
 
This reads the schema and data from the database and writes them to XML files.

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
DatabaseToDdlTask()
           
 
Method Summary
 void addWriteDataToDatabase(WriteDataToDatabaseCommand command)
          Adds the "write data into database"-command.
 void addWriteDataToFile(WriteDataToFileCommand command)
          Adds the "write data into file"-command.
 void addWriteDtdToFile(WriteDtdToFileCommand command)
          Adds the "create dtd"-command.
 void addWriteSchemaSqlToFile(WriteSchemaSqlToFileCommand command)
          Adds the "write schema sql to file"-command.
 void addWriteSchemaToFile(WriteSchemaToFileCommand command)
          Adds the "write schema to file"-command.
protected  Database readModel()
          Reads the database model on which the commands will work.
 void setModelName(String modelName)
          Specifies the name of the model that is read from the database.
 void setTableTypes(String tableTypes)
          Specifies the table types to be processed.
 
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

DatabaseToDdlTask

public DatabaseToDdlTask()
Method Detail

setTableTypes

public void setTableTypes(String tableTypes)
Specifies the table types to be processed. More precisely, all tables that are of a type not in this list, will be ignored by the task and its sub tasks. For details and typical table types see java.sql.DatabaseMetaData#getTables.

Parameters:
tableTypes - The table types as a comma-separated list

setModelName

public void setModelName(String modelName)
Specifies the name of the model that is read from the database. This is mostly useful for the the writeSchemaToFile sub-task as it ensures that the generated XML defines a valid model.

Parameters:
modelName - The model name. Use null or an empty string for the default name

addWriteDtdToFile

public void addWriteDtdToFile(WriteDtdToFileCommand command)
Adds the "create dtd"-command.

Parameters:
command - The command

addWriteSchemaToFile

public void addWriteSchemaToFile(WriteSchemaToFileCommand command)
Adds the "write schema to file"-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 into database"-command.

Parameters:
command - The command

addWriteDataToFile

public void addWriteDataToFile(WriteDataToFileCommand command)
Adds the "write data into 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.