.::=Generator reference=::.

Butler has a generator that generates java source files or xml descriptor files, based on the database metadata.

Java source files

The two main reason to generate java source files is to avoid typing table and column names as strings in the source code. Intellisense and code completion can be used for more efficient and safer programming. Another advantage is performance. Butler does not have to retrive database metadata during runtime. Metadata is retrived during generation and defined in the generated source files.

The generator can generate subclasses of Schema, Table and Record. For each table a Table- and Record-subclass will be generated.

In the Schema subclasses get-methods are generated for every Table in the schema.

In the Table subclass get-methods for every column, foreign key and index is generated. These methods can be used when queries are constructed etc.

In the Record subclass get- and set-methods are generated for every column. These methods can be used for getting and setting column values in this record.

Schema xml descriptor

If generated source files is not needed, but runtime retrival of database metadata is needed, a schema xml descriptor should be generated. The generator will extract metadata information from the database and store it in a xml files. This file will later be used by the butler runtime instead of retrive metadata from the database.

Instructions

Before starting the generator, edit the file conf/databases.xml, in the butler folder. Be sure that your database is defined in this file.

To start the generator, start a command shell and go to the directory where butler is installed and type following.

ant generate

The generator will now list all databases defined in databases.xml. Type the alias of the database you want to generate from.

Now the generator will list all catalogs in the selected database. Type the name of the catalog you want to use.

The generator will now list all schemas in the selected catalog. Type the name of the schema you want to generate from.

Next the generator will ask if you want to generator schema xml or java class definitions.

If you select schema xml, the generator will ask for the filename of the xml files and then generate table definitions for the entire schema.

If you select java classes, the generator will ask where to put the java source files, and the package name. Finally the generator will ask for the table name to generate. If "%" is typed as table name, classes for all tables in the selected schema will be generated.