AutomotiveJava

(Yet another) Java Database Persistence API

Generic DBEntity experiment.

update: 10/2/09 -- In retrospect, this thing kinda sucks. Just use Spring-Hibernate
 
update: 9/02/09 -- I wasn't aware that Spring-Hibernate exists when i wrote this.. now that I've worked with it as a software engineer at http://www.mywayinteractive.com, i must say i'm quite impressed with it. Nowever, this package is far more light-weight, and in my opinion far more flexible, since you don't need to make VO bean and add Hibernate annotations to it. When I get more free time, i will make better documenation of this thing and post some existing examples using this package.

 My name is Yisheng Jiang and I'm trying to make a java library that injects Database features into 
 regular java classes. Let's say you have a java class with several instance
 variables, and might be a good candidate for DB storage. Theoretically you 
can just download this library and "extend GenericDBEntity" on the class declaration.
And you would get access to the following features:

INTERFACES:

public interface DBEntity {

    public String createTableStatement();
    public String getColumnNamesString();
    public void addColumn(String name, String type, String constraint);
    public String getColumnValuesString();
    public String getColumnValuesString(int parentKey);
    public String selectStatement(int ID);
    public String FKSelectStatement(int FK);
    public String getFKCol();
    public void setValue(String name, String value);
    public void setPK(int pk);
    public String insertStatement();
    public void addChildTable(String tableName, String FKColumn);
    public String getChildTable();
    public String getChildFKColumn();
    public void setLeafLevel(boolean b);
    public boolean isLeafLevel();
    public ArrayList<DBEntity> getChildEntity();
    public void addChildEntity(DBEntity c);
    public int getPK();
    public String getTableName();
    public void enterDBValues(ArrayList<ArrayList> DBResult)
            throws TooManyRowsInTheResultSetException, DBException;
    public void updateObject(String columnName, String val)
            throws DBException;

    public Object getValue(String columnName);

    public String displayString();

    public String displayHTMLString();

    public void castDBValues();

    public void castDBValues(DBEntity dbe);
}



PACKAGE Database: classes and some of their methods

- DBConn.java
    + DBConn()
    + getConnection(): Connection

- DBProcs.java
    +DBProcs()
    - getDBProperties()
   + executeQuery(String query), returns ArrayList<ArrayList> (a table of strings)
   + executeUpdate(String update) -- inserts a row into a table
   + executeCreateTable(String update) -- creates a table in the DB

- DBInit.java
    +DBInit()
    +CreateAutoTables() -- creates tables for Auto, OptionSet, Options in the DB using DBProcs.executeCreateTable()

- DBInput.java
    +DBInput()
    + InsertDBEntity(DBEntity d, boolean cascade)  <-- if cascade = true, inserts associated child tables as well
    + ....

- DBOutput.java
    + DBOutput()
    + readDBEntity(String tableName, int primaryKey, boolean cascade) <-- if cascade = true, reads the row + it's child rows (and their child rows recursively)
    + readPrimaryKeys(String tableName, String constraints) <-- reads a list of primary keys from a tableName, and given some constraints, which can be null
    + ....
 
email me at my first name + last name no space all in one word at yahoo dot com to talk about this some more

Attachments (4)