Ant task

Salto-db generator provides an Ant Task so you can use it in your build files.

In order to generate something, you have to choose which plugin you want to use. Here are the built-in plugins :

  • Salto-db
  • EJB3
  • EJB3AndHibernateDao
  • EJB3HibernateDaoAndTestCases
  • Hibernate
  • PojoHibernateDao

You need to set one of these plugins in the "plugin" parameter of the salto-db-generate task.

Parameters of the salto-db-generate task

driverClassName required Class name of the jdbc driver to use (i.e. com.mysql.jdbc.Driver for MySQL, oracle.jdbc.OracleDriver for Oracle, etc.)
followForeignKeys optional (default is false) If set to true, Salto-db Generator will follow foreign keys on table to retrieve dependants tables to execute plugin on them as well. It is recursive (see maxDepth).
generateView optional (default is true) If set to false, views will be ignored by Salto-db Generator. Default is true.
jdbcUrl required JDBC url to access to the database.
login required Login to access to the database.
maxDepth optional (default is 0) When you set followForeignKeys to true, you need to set a max depth to retrieve dependants table, otherwise you will retrieve the whole database.
nameOffset optional (default is 0) You can set an offset to ignore first characters of table names. As an example if you run the Hibernate plugin on a table named "TB_PERSON", a pojo mapping this table will be generated. By default its name would be "TbPerson" but if you set nameOffset to 3, the generated name will be "Person" because the first characters "TB_" have been ignored.
plugin optional (default is Salto-db) Name of the plugin you want to use in Salto-db Generator.
prefix optional (default is empty string) You can choose a prefix that will be added to every classes that the plugin considers as a table. As an example if you run the Hibernate plugin on a table named "PERSON", a pojo mapping this table will be generated. By default its name would be "Person" but if you set a prefix the generated name will be prefix+"Person".
outputDir required Output directory where generated files will be saved.
packageName required Name of the java package in which generated files will be saved.
password required Password of the user to access to the database.
schema required Name of the schema in which target tables can be found
tablesNames required Comma-separated patterns to search for tables that you want to use. You can use the joker character '%' in patterns.
Parameters

Sample build file for Ant that will generate ejb3s

<project name="salto-db-ant-test" basedir="." default="generate">

        
        <!-- set the name of your database schema -->
        <property name="schema" value=""/>
                
        <!-- set a pattern to search for tables. You can use the joker character '%'. 
        If you want to generate DataObjects for every tables, just set '%' -->
        <property name="tablesNames" value=""/>
                
        <!-- set your database username-->
        <property name="login" value=""/>
                
        <!-- set your database password-->
        <property name="password" value=""/>
                
        <!-- set your jdbc url to access the database-->
        <property name="jdbcUrl" value=""/>
                
        <!-- set the jdbc driver class name to access to your database. 
        This class should be in the classpath of the taskdef. You can copy the jar file in the current directory.-->
        <property name="driverClassName" value=""/>
                
        <!-- set the path where to generate DataObjects source code-->
        <property name="outputDir" value="generated-src"/>
                
        <!-- set the package name in which to generate DataObjects-->
        <property name="packageName" value="com.salto.db.test"/>
                
        <path id="lib.path">
                <fileset dir="." includes="*.jar"/>
        </path>
                
        <taskdef name="salto-db-generate" classname="com.salto.db.ant.DOGeneratorTask" 
                classpathref="lib.path"/>
        
        <target name="generate">
                <salto-db-generate plugin="EJB3" schema="${schema}" tablesNames="${tablesNames}" 
                login="${login}" password="${password}" jdbcUrl="${jdbcUrl}" 
                driverClassName="${driverClassName}" outputDir="${outputDir}" packageName="${packageName}"/>
        </target>


</project>

All you need to do is to put this build file in the same directory as salto-db-generator.jar, or you can change the "lib.path" path accordingly to your configuration.

Then you need to set values for tableName, login, password, jdbcUrl and driverClassName properties.