|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectfc.jdbc.dbo.Generate
public final class Generate
Generates java objects that represent tables in a database. Each object represents 1 table in the database.
This framework is great for inserting and updating data in various tables and even fetching one or more rows form individual tables.
For each table foo in our database, the following classes are generated:
This framework is not intended to transparently allow arbitrary joins and data from multiple tables. A better way is to use prepared statements directly to run ad-hoc SQL queries including those containing arbitrary joins.
However, to somewhat facilitate arbitrary select queries/joins across multiple tables,
each generated "Mgr" class has a columns()
method that returns a list of columns for the corresponding table. For
example, in say a Molly Server Page where information from two tables
(table1, table2) is displayed from both tables on the same page.
String my_query = "select "
+ table1Mgr.columns() + ", " + table2.columns()
+ " from table1, table2 WHERE table1.x = table2.x";
PreparedStatement ps = connection.prepareStatement(my_query);
ResultSet rs = connection.executeQuery();
while (rs.next())
{
table1 t1 = table1Mgr.getFromRS(rs); //create a new table1 from the rs
table2 t2 = table2Mgr.getFromRS(rs); //ditto for table2
//..use t1 and t2...
//....
}
Cache utility
class(es).
Note 2: MySQL 3.x, 4.x or 5.x does not have true boolean types and silently converts bool types to TINYINT. This wreaks havoc with auto-generated code which creates methods with the wrong signature (TINYINT as opposed to bool).
There are 2 approaches to solving this mysql-specific problem:
a) Require all boolean columns to begin with some keyword (say bool_) and if a column begins with this word, then treat it as a boolean, regardless of the type returned by the database meta data.If the flag mysqlBooleanHack is set to false in the configuration file, then TINYINT's are not transformed to booleans. There should be no practical need to do this however.
b) Treat all TINYINT's as boolean types. This is the approach I have chosen since TINYINT's are NOT portable across databases (for example PostgresQL does not have TINYINT's). Therefore we should not use TINYINT's in physical database models; if booleans are turned into TINYINT's by MySQL then so be it..since that will not clash with any of our modelled types.
This program uses a user specified configuration file. The configuration file allows for many code generation options. To see the configuration help, invoke this program from the command line with no arguments, such as:
java fc.jdbc.dbo.Generate
| Constructor Summary | |
|---|---|
Generate(java.lang.String[] args)
|
|
| Method Summary | |
|---|---|
static void |
main(java.lang.String[] args)
Usage: java fc.jdbc.dbobjects.Generate -conf |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Generate(java.lang.String[] args)
throws java.lang.Exception
java.lang.Exception| Method Detail |
|---|
public static void main(java.lang.String[] args)
throws java.lang.Exception
java.lang.Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||