org.javaWebGen.data
Class DAO

java.lang.Object
  extended by org.javaWebGen.data.DAO
Direct Known Subclasses:
CodeGenerator, GenerateCachedTable, GenericSequence, LoginDAO, OracleSequence, ReportDAO, TestDAO

public abstract class DAO
extends java.lang.Object

Base DAO(Data Access Object) object that handles running sql against the database.

Version:
$Revision: 1.2 $
Author:
Kevin Scott

Field Summary
static int TOO_MANY_ROWS
           
static java.lang.String TOO_MANY_ROWS_WARNING
           
 
Constructor Summary
protected DAO()
          will get a data manager specified in the config file if it fails it will try to use the MySQL as a DataManager
protected DAO(DataManager dataManager)
           
 
Method Summary
protected  void close(java.sql.Connection con)
           
protected  java.lang.Object getColumnClass(int column, java.sql.ResultSet result)
          find the Object for a specified column
protected  java.sql.Connection getConnection()
          returns a open connection to the database
protected  DataManager getDataManager()
           
protected  int getNextValue(java.sql.Connection con, java.lang.String tablename)
          Calls the DataManager object for the next value for a primary key
protected  int getNextValue(java.lang.String tablename)
          Calls the DataManager object for the next value for a primary key
protected  java.sql.ResultSet getResultSet(java.sql.Connection con, java.lang.String sql)
          get the result set after running a sql statment generaly only used to get the metadata by one of the code generators.
protected  java.util.ArrayList<java.lang.Object[]> query(java.sql.Connection con, java.lang.String sql)
          returns the results of running a sql statement Calling object is responsible for handleing data base conection Calling object should use the runQuery method because it returns more information
protected  java.util.ArrayList<java.lang.Object[]> query(java.sql.Connection con, java.lang.String sql, java.lang.Object[] parms)
          returns the results of running a SQL statement Calling object is responsible for handling the data base connection
protected  java.util.ArrayList<java.lang.Object[]> query(java.lang.String sql)
          returns the results of running a SQL statement Calling objects should use the runQuery method instead it returns more information
protected  java.util.ArrayList<java.lang.Object[]> query(java.lang.String sql, java.lang.Object[] parms)
          returns the results of running a sql statement and handles the database connection
 DbResult runQuery(java.sql.Connection con, java.lang.String sql)
          runs a SQL statemnt returning the resultes in a DbResult object The calling object is responsible for handling the connection to the data base.
 DbResult runQuery(java.sql.Connection con, java.lang.String sql, java.lang.Object[] parms)
          runs an SQL statemnt returning the results in a DbResult object calling object should use this method.
 DbResult runQuery(java.lang.String sql)
          runs an SQL statement returning the results in a DbResult object data base.
 DbResult runQuery(java.lang.String sql, java.lang.Object[] parms)
          runs an SQL statement returning the results in a DbResult object calling objects should use this method
protected  void setColumn(int index, int type, java.lang.Object column, java.sql.PreparedStatement pstmt)
          set a column in a prepared statement based on the java.sql.Type for that column
protected  int update(java.sql.Connection con, java.lang.String sql)
          make a change to a database using sql calling objects should handle the database connection
protected  int update(java.sql.Connection con, java.lang.String sql, java.lang.Object[] parms)
          make a change to a database using sql
protected  int update(java.lang.String sql)
          make a change to a database using sql
protected  int update(java.lang.String sql, java.lang.Object[] parms)
          make a change to a database using sql
 int updateDataBean(java.sql.Connection con, java.lang.String sql, DataBean databean)
          runs an update to database based on a DataBean
 int updateDataBean(java.lang.String sql, DataBean databean)
          runs an update to database based on a DataBean
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOO_MANY_ROWS

public static final int TOO_MANY_ROWS
See Also:
Constant Field Values

TOO_MANY_ROWS_WARNING

public static final java.lang.String TOO_MANY_ROWS_WARNING
See Also:
Constant Field Values
Constructor Detail

DAO

protected DAO(DataManager dataManager)
Parameters:
dataManager - data manager to use to talk to the database

DAO

protected DAO()
will get a data manager specified in the config file if it fails it will try to use the MySQL as a DataManager

Method Detail

getDataManager

protected DataManager getDataManager()
Returns:
current DataManager

getConnection

protected java.sql.Connection getConnection()
                                     throws DBException
returns a open connection to the database

Returns:
db connection
Throws:
DBException

close

protected void close(java.sql.Connection con)
Parameters:
con - db connection to close

update

protected int update(java.lang.String sql)
              throws java.sql.SQLException
make a change to a database using sql

Parameters:
sql - statement to change database
Returns:
in number of rows affected
Throws:
java.sql.SQLException

update

protected int update(java.sql.Connection con,
                     java.lang.String sql)
              throws java.sql.SQLException
make a change to a database using sql calling objects should handle the database connection

Parameters:
con - db connection
sql - statement to change database
Returns:
number of rows affected
Throws:
java.sql.SQLException

update

protected int update(java.lang.String sql,
                     java.lang.Object[] parms)
              throws java.sql.SQLException
make a change to a database using sql

Parameters:
sql - statement to change database
parms - list of parms to pass the sql statement
Returns:
in number of rows affected
Throws:
java.sql.SQLException

update

protected int update(java.sql.Connection con,
                     java.lang.String sql,
                     java.lang.Object[] parms)
              throws java.sql.SQLException
make a change to a database using sql

Parameters:
con - db connection
sql - statement to change database
parms - to pass the sql
Returns:
in number of rows affected
Throws:
java.sql.SQLException

query

protected java.util.ArrayList<java.lang.Object[]> query(java.sql.Connection con,
                                                        java.lang.String sql,
                                                        java.lang.Object[] parms)
                                                 throws java.sql.SQLException
returns the results of running a SQL statement Calling object is responsible for handling the data base connection

Parameters:
con - db connection
sql - to run
parms - to pass to query
Returns:
array list of Object[] that represent the data object
Throws:
java.sql.SQLException

query

protected java.util.ArrayList<java.lang.Object[]> query(java.lang.String sql,
                                                        java.lang.Object[] parms)
                                                 throws java.sql.SQLException
returns the results of running a sql statement and handles the database connection

Parameters:
sql - statement to run against the db
parms - to pass to the prepared staement
Returns:
array list of Object[] that represent the data object
Throws:
java.sql.SQLException

query

protected java.util.ArrayList<java.lang.Object[]> query(java.lang.String sql)
                                                 throws java.sql.SQLException
returns the results of running a SQL statement Calling objects should use the runQuery method instead it returns more information

Parameters:
sql - statement
Returns:
array list of Object[] that represent the data
Throws:
java.sql.SQLException
See Also:
runQuery(java.sql.Connection, java.lang.String)

query

protected java.util.ArrayList<java.lang.Object[]> query(java.sql.Connection con,
                                                        java.lang.String sql)
                                                 throws java.sql.SQLException
returns the results of running a sql statement Calling object is responsible for handleing data base conection Calling object should use the runQuery method because it returns more information

Parameters:
con - db connection
sql - to run
Returns:
array list of Object[] that represent the data
Throws:
java.sql.SQLException
See Also:
runQuery(java.sql.Connection, java.lang.String)

runQuery

public DbResult runQuery(java.sql.Connection con,
                         java.lang.String sql)
                  throws java.sql.SQLException
runs a SQL statemnt returning the resultes in a DbResult object The calling object is responsible for handling the connection to the data base. Calling objects should use this method

Parameters:
con - connection to DB
sql - statement
Returns:
results of running a query including some meta data
Throws:
java.sql.SQLException

runQuery

public DbResult runQuery(java.lang.String sql)
                  throws java.sql.SQLException
runs an SQL statement returning the results in a DbResult object data base. Calling objects should use this method

Parameters:
sql - statement
Returns:
results of running a query including some meta data
Throws:
java.sql.SQLException

runQuery

public DbResult runQuery(java.sql.Connection con,
                         java.lang.String sql,
                         java.lang.Object[] parms)
                  throws java.sql.SQLException
runs an SQL statemnt returning the results in a DbResult object calling object should use this method. Please note this method uses db metadate in order to work. The normal JDBC PreparedStatement will be slightly faster. Also it will return the entire result into memory. Large results should use the normal JDBC resultset

Parameters:
con - connection to DB
sql - statement
parms - object[] of parameters to pass into the prepared statement
Returns:
results of running a query including some meta data
Throws:
java.sql.SQLException

runQuery

public DbResult runQuery(java.lang.String sql,
                         java.lang.Object[] parms)
                  throws java.sql.SQLException
runs an SQL statement returning the results in a DbResult object calling objects should use this method

Parameters:
sql - statement
parms - to pass into the prepared statement returns
Returns:
results of running a query including some meta data
Throws:
java.sql.SQLException

updateDataBean

public int updateDataBean(java.lang.String sql,
                          DataBean databean)
                   throws DBException
runs an update to database based on a DataBean

Parameters:
sql - with where clause
databean - with table data to update
Throws:
DBException
See Also:
DataBean

updateDataBean

public int updateDataBean(java.sql.Connection con,
                          java.lang.String sql,
                          DataBean databean)
                   throws DBException
runs an update to database based on a DataBean

Parameters:
con - db connection
sql - with where clause
databean - with table data to update
Throws:
DBException
See Also:
DataBean

getColumnClass

protected java.lang.Object getColumnClass(int column,
                                          java.sql.ResultSet result)
                                   throws java.sql.SQLException
find the Object for a specified column

Parameters:
column - number
result - resultset to work on (get matadata for)
Throws:
java.sql.SQLException

setColumn

protected void setColumn(int index,
                         int type,
                         java.lang.Object column,
                         java.sql.PreparedStatement pstmt)
                  throws java.sql.SQLException
set a column in a prepared statement based on the java.sql.Type for that column

Parameters:
index - of the row to start with
type - SQL data Type
column - data
pstmt - the actual preparedStatement to set paramanters for
Throws:
java.sql.SQLException

getResultSet

protected java.sql.ResultSet getResultSet(java.sql.Connection con,
                                          java.lang.String sql)
                                   throws java.sql.SQLException
get the result set after running a sql statment generaly only used to get the metadata by one of the code generators. Calling object should use a the runQuery method AND should CLOSE THE RESULTSET when done with IT!

Parameters:
con - db connection
sql - string
Returns:
the result set for a sql statement
Throws:
java.sql.SQLException
See Also:
runQuery(java.sql.Connection, java.lang.String)

getNextValue

protected int getNextValue(java.lang.String tablename)
                    throws DBException
Calls the DataManager object for the next value for a primary key

Parameters:
tablename -
Returns:
the next value for a primary key
Throws:
DBException
See Also:
DataManager

getNextValue

protected int getNextValue(java.sql.Connection con,
                           java.lang.String tablename)
                    throws java.sql.SQLException
Calls the DataManager object for the next value for a primary key

Parameters:
con - DB connection
tablename -
Returns:
the next value for a primary key
Throws:
java.sql.SQLException
See Also:
DataManager


Copyright(C) 2003-2006 Kevin Scott - All Rights Reserved.