DAO generator

The general focus of this generator is to automatic create EJB classes which can be used as data access objects (DAO / DAO-pattern). The input of the DAO generator is an existing interface or class. For each method of the input file will the generator creates an EJB which contains methods.

The next simple example shows the mechanism:

Input file:

public interface DAOTestFile
{
...
    public void create();
    public void update();
    public void delete();
    public void run();
...
}

The generator will create the following files (depending on the configuration):

The xxxDAOHome class defines the EJB home interface and the xxxDAO class the EJB remote interface. The class xxxDAOBean implements the concrete statless session EJB. The selected method like update in the example is the public method in the DAO. Additional throws each DAO method the RemoteException to be compatible with EJB. The DAO generator creates or updates also the ejb deployment descriptor (META-INF/ejb-jar.xml)! In the example above the create method has a special configuration. This is the reason why it is placed in the subdirectory testdata (see).

The junit testcases will also generated by the DAO generator. The testcase files of each package are placed in the subdirectory tests as default. The testcase file test.conf will also be created which can used by the TestFramework.


Using DAO generator

To use te DAO generator you can use the script file daogenerator.bat or daogenerator.sh. You have probably some hands on the files to work with your environment.

The usage is the following:

Usage:  jptools.pattern.dao.generator.DAOFileGenerator [OPTIONS]
OPTIONS:
  -o [path]                       Sets the output path
  -i [path or file]               Sets the input file (directory or a file)
  
OPTIONAL OPTIONS:
  -c [configuration.properties]   Reads the generator and formatter base configuration. This file defines the global settings.
  -pc [configuration.properties]  Reads the additional or project specific generator and formatter configuration.
  -verbose                        Sets on the verbose mode
  -t [testcase configuration]     Sets the testcase file
  -dd [deployment-descriptor]     Sets the EJB deployment descriptor
  -ejb                            Create the DAO as EJB (with Home and Remote interface and deployment descriptor)
  -processor                      Enables SQL processor generation
  -sqlInputPath [path]            Sets the sql base path
  -d [configuration.properties]   Defines the database configuration file

The input definition defines either one or multiple files or a directory followed by the names of the files in the directory to consider.


Configuration

The generator can be configured over a properties file. Additional the javadoc will be used to define some special behavior. The description of the configuration is here available.