org.apache.torque.task
Class TorqueDataModelTask

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by org.apache.texen.ant.TexenTask
              extended by org.apache.torque.task.TorqueDataModelTask
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
TorqueDataDumpTask, TorqueDataSQLTask, TorqueDocumentationTask, TorqueSQLTask

public class TorqueDataModelTask
extends org.apache.texen.ant.TexenTask

A base torque task that uses either a single XML schema representing a data model, or a <fileset> of XML schemas. We are making the assumption that an XML schema representing a data model contains tables for a single database.

Author:
Jason van Zyl, Daniel Rall

Nested Class Summary
static class TorqueDataModelTask.TorqueClasspathResourceLoader
          A custom classpath resource loader which filters tabs and removes spaces from lines with velocity commands.
static class TorqueDataModelTask.TorqueFileResourceLoader
          A custom file resource loader which filters tabs and removes spaces from lines with velocity commands.
 
Field Summary
protected  org.apache.velocity.context.Context context
          Velocity context which exposes our objects in the templates.
protected  java.util.Hashtable databaseNames
          Hashtable containing the names of all the databases in our collection of schemas.
protected  java.util.Hashtable dataModelDbMap
          Map of data model name to database name.
protected  java.util.List dataModels
          Data models that we collect.
protected  java.util.List filesets
          Fileset of XML schemas which represent our data models.
protected  java.lang.String sqldbmap
          Name of the properties file that maps an SQL file to a particular database.
protected  java.lang.String xmlFile
          XML that describes the database model, this is transformed into the application model object.
 
Fields inherited from class org.apache.texen.ant.TexenTask
contextProperties, controlTemplate, inputEncoding, logFile, outputDirectory, outputEncoding, outputFile, resourceLoaderModificationCheckInterval, templatePath, useClasspath, useResourceLoaderCache
 
Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
 
Constructor Summary
TorqueDataModelTask()
           
 
Method Summary
 void addFileset(org.apache.tools.ant.types.FileSet set)
          Adds a set of xml schema files (nested fileset attribute).
 void execute()
          This method creates an VelocityEngine instance, parses every template and creates the corresponding output.
protected  java.io.InputStream filter(java.io.InputStream resource)
          This method filters the template and replaces some unwanted characters.
 java.util.Hashtable getDataModelDbMap()
          Return the data model to database name map.
 java.util.List getDataModels()
          Return the data models that have been processed.
 java.lang.String getSqlDbMap()
          Get the sqldbmap.
 java.lang.String getTargetDatabase()
          Get the current target database.
 java.lang.String getTargetPackage()
          Get the current target package.
 java.lang.String getXmlFile()
          Get the xml schema describing the application model.
 org.apache.velocity.context.Context initControlContext()
          Set up the initial context for generating the SQL from the XML schema.
protected  void populateInitialContext(org.apache.velocity.context.Context context)
          Change type of "now" to java.util.Date
 void setContextProperties(java.lang.String file)
          Override Texen's context properties to map the torque.xxx properties (including defaults set by the org/apache/torque/defaults.properties) to just xxx.
 void setSqlDbMap(java.lang.String sqldbmap)
          Set the sqldbmap.
 void setTargetDatabase(java.lang.String v)
          Set the current target database.
 void setTargetPackage(java.lang.String v)
          Set the current target package.
 void setXmlFile(java.lang.String xmlFile)
          Set the xml schema describing the application model.
 
Methods inherited from class org.apache.texen.ant.TexenTask
cleanup, getContextProperties, getControlTemplate, getLogFile, getOutputDirectory, getOutputFile, getTemplatePath, setControlTemplate, setInputEncoding, setLogFile, setOutputDirectory, setOutputEncoding, setOutputFile, setResourceLoaderModificationCheckInterval, setTemplatePath, setUseClasspath, setUseResourceLoaderCache
 
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xmlFile

protected java.lang.String xmlFile
XML that describes the database model, this is transformed into the application model object.


filesets

protected java.util.List filesets
Fileset of XML schemas which represent our data models.


dataModels

protected java.util.List dataModels
Data models that we collect. One from each XML schema file.


context

protected org.apache.velocity.context.Context context
Velocity context which exposes our objects in the templates.


dataModelDbMap

protected java.util.Hashtable dataModelDbMap
Map of data model name to database name. Should probably stick to the convention of them being the same but I know right now in a lot of cases they won't be.


databaseNames

protected java.util.Hashtable databaseNames
Hashtable containing the names of all the databases in our collection of schemas.


sqldbmap

protected java.lang.String sqldbmap
Name of the properties file that maps an SQL file to a particular database.

Constructor Detail

TorqueDataModelTask

public TorqueDataModelTask()
Method Detail

setSqlDbMap

public void setSqlDbMap(java.lang.String sqldbmap)
Set the sqldbmap.

Parameters:
sqldbmap - th db map

getSqlDbMap

public java.lang.String getSqlDbMap()
Get the sqldbmap.

Returns:
String sqldbmap.

getDataModels

public java.util.List getDataModels()
Return the data models that have been processed.

Returns:
List data models

getDataModelDbMap

public java.util.Hashtable getDataModelDbMap()
Return the data model to database name map.

Returns:
Hashtable data model name to database name map.

getXmlFile

public java.lang.String getXmlFile()
Get the xml schema describing the application model.

Returns:
String xml schema file.

setXmlFile

public void setXmlFile(java.lang.String xmlFile)
Set the xml schema describing the application model.

Parameters:
xmlFile - The new XmlFile value

addFileset

public void addFileset(org.apache.tools.ant.types.FileSet set)
Adds a set of xml schema files (nested fileset attribute).

Parameters:
set - a Set of xml schema files

getTargetDatabase

public java.lang.String getTargetDatabase()
Get the current target database.

Returns:
String target database(s)

setTargetDatabase

public void setTargetDatabase(java.lang.String v)
Set the current target database. (e.g. mysql, oracle, ..)

Parameters:
v - target database(s)

getTargetPackage

public java.lang.String getTargetPackage()
Get the current target package.

Returns:
return target java package.

setTargetPackage

public void setTargetPackage(java.lang.String v)
Set the current target package. This is where generated java classes will live.

Parameters:
v - target java package.

initControlContext

public org.apache.velocity.context.Context initControlContext()
                                                       throws java.lang.Exception
Set up the initial context for generating the SQL from the XML schema.

Overrides:
initControlContext in class org.apache.texen.ant.TexenTask
Returns:
the context
Throws:
java.lang.Exception

populateInitialContext

protected void populateInitialContext(org.apache.velocity.context.Context context)
                               throws java.lang.Exception
Change type of "now" to java.util.Date

Overrides:
populateInitialContext in class org.apache.texen.ant.TexenTask
Throws:
java.lang.Exception
See Also:
TexenTask.populateInitialContext(org.apache.velocity.context.Context)

setContextProperties

public void setContextProperties(java.lang.String file)
Override Texen's context properties to map the torque.xxx properties (including defaults set by the org/apache/torque/defaults.properties) to just xxx.

Also, move xxx.yyy properties to xxxYyy as Velocity doesn't like the xxx.yyy syntax.

Overrides:
setContextProperties in class org.apache.texen.ant.TexenTask
Parameters:
file - the file to read the properties from

execute

public void execute()
             throws org.apache.tools.ant.BuildException
This method creates an VelocityEngine instance, parses every template and creates the corresponding output. Unfortunately the TextenTask.execute() method makes everything for us but we just want to set our own VelocityTemplateLoader. TODO: change once TEXEN-14 is resolved and out.

Overrides:
execute in class org.apache.texen.ant.TexenTask
Throws:
org.apache.tools.ant.BuildException
See Also:
TexenTask.execute()

filter

protected java.io.InputStream filter(java.io.InputStream resource)
                              throws java.io.IOException
This method filters the template and replaces some unwanted characters. For example it removes leading spaces in front of velocity commands and replaces tabs with spaces to prevent bounces in different code editors with different tab-width-setting.

Parameters:
resource - the input stream to filter
Returns:
the filtered input stream.
Throws:
java.io.IOException - if creating, reading or writing to a stream fails.


Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.