|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.youyounet.db.Table
Table is the class that encapsulate the common database operations in its methods calls. Each data bean class is designed to map to a database table and will have a class-wide(statically declared) table object. This Table object is responsible for the database operations initiated by the actual data bean instances. In the most cases, users will not directly call this Table class' methods except for a few static ones. Rather, users will normally code their data bean class according to a preset pattern and the data bean class will then inherite the database functionalities from its abstract ancestor class.
DataBean
Field Summary | |
protected java.lang.Class |
cls
|
protected java.util.Vector |
columns
|
protected java.lang.String |
deleteSql
|
protected java.util.Hashtable |
fieldMap
|
protected java.lang.String |
insertSql
|
protected java.lang.String |
key
|
protected static java.util.logging.Logger |
log
|
protected int |
nColumns
|
protected java.lang.String |
selectSql
|
protected java.lang.String |
tableName
|
protected java.lang.String |
updateSql
|
Constructor Summary | |
Table(java.lang.String tableName,
java.lang.String className,
java.util.Hashtable fieldMap)
public constructor |
|
Table(java.lang.String tableName,
java.lang.String className,
java.util.Hashtable fieldMap,
java.lang.String key)
public constructor. |
Method Summary | |
protected java.util.Vector |
buildColumns()
|
boolean |
create(java.lang.Object obj)
Insert the data bean obj as a new row to the corresponding database table. |
boolean |
create(java.lang.Object obj,
boolean ignorAutoIncrement)
Insert the data bean obj as a new row to the corresponding database table. |
boolean |
create(java.lang.Object obj,
java.sql.Connection con)
Insert the data bean obj as a new row to the corresponding database table. |
boolean |
create(java.lang.Object obj,
java.sql.Connection con,
boolean ignorAutoIncrement)
Insert the data bean obj as a new row to the corresponding database table. |
int |
delete(java.lang.String condition)
Delete data beans from this table using the condition specified. |
int |
delete(java.lang.String condition,
java.sql.Connection con)
Delete data beans from this table using the condition specified. |
static int |
delete(java.lang.String table,
java.lang.String condition)
Delete data beans from the table using the condition specified. |
static int |
delete(java.lang.String table,
java.lang.String condition,
java.sql.Connection con)
Delete from the database table, using the condition specified. |
boolean |
exists(java.lang.Object obj)
check if the data bean obj exists in the table. |
boolean |
find(java.lang.Object obj,
java.lang.String condition)
Check whether the data bean obj exists in the corresponding table satisfied by the additional SQL condition if present. |
java.lang.String |
getColumnNamesAsString(java.lang.String prefix)
Get a string of all the column names of this table. |
java.lang.String |
getKey(java.util.Hashtable fieldMap)
Get the name of the primary key column. |
java.lang.String |
getKeyColumnName()
Get the name of the primary key column. |
protected java.lang.String |
getKeyCondition(java.lang.Object obj)
if there is a primary key, a string representing a SQL condition "primaryKey=value" will be returned. |
java.lang.Object |
getMaxID(java.lang.String indexColumnName,
java.sql.Connection con)
Get the max value of the indexColumnName column. |
java.lang.Object |
getMaxPrimaryKey(java.sql.Connection con)
Get the max value of the primary key column, if there is a primary key for this table. |
java.lang.String |
getName()
Get the name of the table. |
java.util.Iterator |
iterator()
returns a bean Iterator. |
java.util.Iterator |
iterator(java.lang.String condition)
returns a bean Iterator. |
java.util.Iterator |
iterator(java.lang.String tables,
java.lang.String condition)
returns a bean Iterator. |
boolean |
load(java.lang.Object obj)
load the databean obj's property from the database table, using the SQL condition specified by getKeyCondition method |
boolean |
load(java.lang.Object obj,
java.sql.Connection con)
load the databean obj's property from the database table, using the SQL condition specified by getKeyCondition method |
boolean |
load(java.lang.Object obj,
java.lang.String condition)
load the databean obj's property from the database table, using the condition specified |
boolean |
load(java.lang.Object obj,
java.lang.String condition,
java.sql.Connection con)
load the databean obj's property from the database table, using the condition specified |
boolean |
remove(java.lang.Object obj)
Remove the databean obj from the database table, using the condition specified by getKeyCondition method . |
boolean |
remove(java.lang.Object obj,
java.sql.Connection con)
Remove the databean obj from the database table, using the condition specified by getKeyCondition method . |
boolean |
remove(java.lang.Object obj,
java.lang.String condition)
Remove the data bean obj from the database table, using the condition specified. |
boolean |
remove(java.lang.Object obj,
java.lang.String condition,
java.sql.Connection con)
Remove the databean obj from the database table, using the condition specified. |
java.util.Vector |
select(java.lang.String condition,
java.lang.String orderBy)
Select a Vector of data beans satisfied by the passed in SQL condition. |
java.util.Vector |
select(java.lang.String condition,
java.lang.String orderBy,
java.sql.Connection con)
Select a Vector of data beans satisfied by the passed in SQL condition. |
java.util.Vector |
select(java.lang.String tableList,
java.lang.String condition,
java.lang.String orderBy)
Select a Vector of data beans from this table that is satisfied by the passed in SQL condition. |
java.util.Vector |
select(java.lang.String tableList,
java.lang.String condition,
java.lang.String orderBy,
java.sql.Connection con)
Select a Vector of data beans from this table that is satisfied by the passed in SQL condition. |
static java.util.Vector |
select(java.lang.String tableList,
java.lang.String columnList,
java.lang.String condition,
java.lang.String orderBy)
A static method to select a vector of SimpleBean objects. |
static java.util.Vector |
select(java.lang.String tableList,
java.lang.String columnList,
java.lang.String condition,
java.lang.String orderBy,
java.sql.Connection con)
A static method to select a vector of SimpleBean objects. |
protected void |
setSQL()
|
boolean |
store(java.lang.Object obj)
Store the data bean obj's property value to the database table, using the condition get from getKeyCondition method . |
boolean |
store(java.lang.Object obj,
java.sql.Connection con)
store the databean obj's property value to the database table, using the condition specified by getKeyCondition method . |
boolean |
store(java.lang.Object obj,
java.lang.String condition)
store the databean obj's property value to the associated table, using the condition specified. |
boolean |
store(java.lang.Object obj,
java.lang.String condition,
java.sql.Connection con)
store the databean obj's property value to the database table, using the condition specified. |
int |
update(java.lang.Object obj,
java.util.Vector columnNames,
java.lang.String condition)
Update one or more data beans' value in the table with value drawn from the passed in data bean obj. |
int |
update(java.lang.Object obj,
java.util.Vector columnNames,
java.lang.String condition,
java.sql.Connection con)
Update one or more data beans' value in the table with value drawn from the passed in data bean obj. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static java.util.logging.Logger log
protected java.lang.String tableName
protected java.lang.Class cls
protected java.util.Vector columns
protected java.util.Hashtable fieldMap
protected int nColumns
protected java.lang.String key
protected java.lang.String selectSql
protected java.lang.String updateSql
protected java.lang.String deleteSql
protected java.lang.String insertSql
Constructor Detail |
public Table(java.lang.String tableName, java.lang.String className, java.util.Hashtable fieldMap)
public Table(java.lang.String tableName, java.lang.String className, java.util.Hashtable fieldMap, java.lang.String key)
Method Detail |
public java.lang.String getKeyColumnName()
public java.lang.String getKey(java.util.Hashtable fieldMap)
public java.lang.String getName()
protected void setSQL()
protected java.util.Vector buildColumns()
public java.lang.String getColumnNamesAsString(java.lang.String prefix)
prefix
- the prefix to be added to all the column names.protected java.lang.String getKeyCondition(java.lang.Object obj)
obj
- whose corresponding value will be used to set the SQL condition
for the primary keypublic boolean load(java.lang.Object obj, java.lang.String condition) throws java.sql.SQLException, DataTransferException
obj
- the databean object whose property value will be set from the values
get from the databasecondition
- the SQL condition used to load the data from the database
java.sql.SQLException
DataTransferException
public boolean load(java.lang.Object obj, java.lang.String condition, java.sql.Connection con) throws java.sql.SQLException, DataTransferException
obj
- the databean object whose property value will be set from the values
get from the databasecondition
- the SQL condition used to load the data from the databasecon
- the load operation is part of the database transaction associated
with this connection object
java.sql.SQLException
DataTransferException
public boolean load(java.lang.Object obj) throws java.sql.SQLException, DataTransferException
getKeyCondition method
obj
- the databean object whose property value will be set from the values
get from the database
java.sql.SQLException
DataTransferException
public boolean load(java.lang.Object obj, java.sql.Connection con) throws DataTransferException, java.sql.SQLException
getKeyCondition method
obj
- the databean object whose property value will be set from the values
get from the databasecon
- the load operation is part of the database transaction associated
with this connection object
java.sql.SQLException
DataTransferException
public boolean store(java.lang.Object obj, java.lang.String condition) throws DataTransferException, java.sql.SQLException
obj
- the databean object whose property value will be stored to the
corresponding tablecondition
- the SQL condition used to store the obj's property value
to the database
java.sql.SQLException
DataTransferException
public boolean store(java.lang.Object obj, java.lang.String condition, java.sql.Connection con) throws DataTransferException, java.sql.SQLException
obj
- the databean object whose property value will be stored to the
corresponding tablecondition
- the SQL condition used to store the obj's property value
to the databasecon
- the store operation is part of the database transaction associated
with this connection object
java.sql.SQLException
DataTransferException
public boolean store(java.lang.Object obj) throws DataTransferException, java.sql.SQLException
getKeyCondition method
.
obj
- the databean object whose property value will be stored to the
corresponding table
java.sql.SQLException
DataTransferException
public boolean store(java.lang.Object obj, java.sql.Connection con) throws DataTransferException, java.sql.SQLException
getKeyCondition method
.
obj
- the databean object whose property value will be stored to the
corresponding tablecon
- the store operation is part of the database transaction associated
with this connection object
java.sql.SQLException
DataTransferException
public static int delete(java.lang.String table, java.lang.String condition) throws java.sql.SQLException
table
- the table namecondition
- the SQL condition used in the delete operation
java.sql.SQLException
public static int delete(java.lang.String table, java.lang.String condition, java.sql.Connection con) throws java.sql.SQLException
table
- the table namecondition
- the SQL condition used in the delete operation
java.sql.SQLException
public int delete(java.lang.String condition) throws java.sql.SQLException
condition
- the SQL condition used in the delete operation
java.sql.SQLException
public int delete(java.lang.String condition, java.sql.Connection con) throws java.sql.SQLException
condition
- the SQL condition used in the delete operationcon
- the delete operation is part of the transaction associated with
the Connection object
java.sql.SQLException
public boolean remove(java.lang.Object obj, java.lang.String condition) throws DataTransferException, java.sql.SQLException
The difference of a remove method and a delete method is that a remove method can only remove the passed in data bean itself from this table, while a delete method may delete multiple data beans from this table. The data beans that will be deleted from the call to the delete method will be determined by the SQL condition passed in.
obj
- the databean object will be removed from the databasecondition
- the SQL condition used to remove the data from the database
java.sql.SQLException
DataTransferException
- if more than one object would be removed based
on the specified SQL condition.public boolean remove(java.lang.Object obj, java.lang.String condition, java.sql.Connection con) throws DataTransferException, java.sql.SQLException
The difference of a remove method and a delete method is that a remove method can only remove the calling data bean itself from the table, while a delete method will not necesalary delete the calling data bean from the table and doesn't even require that the calling data bean exists in the table. The data beans that will be deleted from the call to the delete method will be determined by the SQL condition passed in.
obj
- the databean object will be removed from the databasecondition
- the SQL condition used to remove the data from the databasecon
- the remove operation is part of the transaction associated with
the Connection Object
java.sql.SQLException
DataTransferException
java.sql.SQLException
DataTransferException
- if more than one bean would be removed from the table
under the specified condition.public boolean remove(java.lang.Object obj) throws DataTransferException, java.sql.SQLException
getKeyCondition method
.
The difference of a remove method and a delete method is that a remove method can only remove the calling data bean itself from the table, while a delete method will not necesalary delete the calling data bean from the table and doesn't even require that the calling data bean exists in the table. The data beans that will be deleted from the call to the delete method will be determined by the SQL condition passed in.
obj
- the databean object will be removed from the database
java.sql.SQLException
DataTransferException
java.sql.SQLException
DataTransferException
public boolean remove(java.lang.Object obj, java.sql.Connection con) throws DataTransferException, java.sql.SQLException
getKeyCondition method
.
The difference of a remove method and a delete method is that a remove method can only remove the calling data bean itself from the table, while a delete method will not necesalary delete the calling data bean from the table and doesn't even require that the calling data bean exists in the table. The data beans that will be deleted from the call to the delete method will be determined by the SQL condition passed in.
obj
- the databean object will be removed from the databasecon
- the remove operation is part of the transaction associated with
the Connection object
java.sql.SQLException
DataTransferException
java.sql.SQLException
DataTransferException
public boolean create(java.lang.Object obj) throws DataTransferException, java.sql.SQLException
obj
- the data bean to be inserted
java.sql.SQLException
DataTransferException
public boolean create(java.lang.Object obj, boolean ignorAutoIncrement) throws DataTransferException, java.sql.SQLException
obj
- the data bean to be insertedignorAutoIncrement
- if there is a auto increment column in the table then the
value inserted to that column will depend on the value of this parameter.
In this case, if the parameter is true, the value inserted into the auto increment
column will be drawn from the corresponding property value of the data bean obj;
If this parameter is false, then a null value will be inserted into that column
and the actual value of that column will be determined by the system.
java.sql.SQLException
DataTransferException
public boolean create(java.lang.Object obj, java.sql.Connection con, boolean ignorAutoIncrement) throws DataTransferException, java.sql.SQLException
create(Object obj, boolean ignorAutoIncrement)
except that the operation of this method is part of the transaction associated
with the Connection object con passed in.
obj
- the data bean to be insertedcon
- the operation of this method is part of the transaction associated
with the this Connection object.ignorAutoIncrement
- if there is a auto increment column in the table then the
value inserted to that column will depend on the value of this parameter.
In this case, if the parameter is true, the value inserted into the auto increment
column will be drawn from the corresponding property value of the data bean obj;
If this parameter is false, then a null value will be inserted into that column
and the actual value of that column will be determined by the system.
java.sql.SQLException
DataTransferException
public boolean create(java.lang.Object obj, java.sql.Connection con) throws DataTransferException, java.sql.SQLException
obj
- the data bean to be insertedcon
- the operation of this method is part of the transaction associated by
this Connection object
java.sql.SQLException
DataTransferException
public boolean find(java.lang.Object obj, java.lang.String condition) throws java.sql.SQLException, DataTransferException
obj
- the data bean to be checkedcondition
- the SQL condition that must also be met if present when checking
the existence of the data bean in the table
java.sql.SQLException
{@link
- DataTransferException}
DataTransferException
public java.util.Vector select(java.lang.String condition, java.lang.String orderBy) throws java.sql.SQLException, DataTransferException
condition
- the SQL condition of the selectorderBy
- the SQL order by clause used in the selection (exclude the "order
by" key words and only include the column(s) part of the clause in this
parameter)
java.sql.SQLException
{@link
- DataTransferException}
DataTransferException
public java.util.Vector select(java.lang.String condition, java.lang.String orderBy, java.sql.Connection con) throws java.sql.SQLException, DataTransferException
select(String condition, String orderBy)
except that the operation of this method is part of the transaction associated
with the Connection object con passed in.
condition
- the SQL condition of the selectorderBy
- the SQL order by clause used in the selection (exclude the "order
by" key words and only include the column(s) part of the clause in this
parameter)con
- the Connection object
java.sql.SQLException
{@link
- DataTransferException}
DataTransferException
public java.util.Vector select(java.lang.String tableList, java.lang.String condition, java.lang.String orderBy) throws java.sql.SQLException, DataTransferException
tableList
- a string of table names separated by a comma. The tables
in the list will only be referenced from the SQL condition and should not
contain this table's name. No column from tables in this list will actually
be selected.condition
- the SQL condition of the selectorderBy
- the SQL order by clause used in the selection (exclude the "order
by" key words and only include the column(s) part of the clause in this
parameter)
java.sql.SQLException
{@link
- DataTransferException}
DataTransferException
public java.util.Vector select(java.lang.String tableList, java.lang.String condition, java.lang.String orderBy, java.sql.Connection con) throws java.sql.SQLException, DataTransferException
tableList
- a string of table names separated by a comma. The tables
in the list will only be referenced from the SQL condition and should not
contain this table's name. No column from tables in this list will actually
be selected.condition
- the SQL condition of the selectorderBy
- the SQL order by clause used in the selection (exclude the "order
by" key words and only include the column(s) part of the clause in this
parameter)con
- the operation of this method is part of the transaction associated
with this Connection object
java.sql.SQLException
{@link
- DataTransferException}
DataTransferException
public static java.util.Vector select(java.lang.String tableList, java.lang.String columnList, java.lang.String condition, java.lang.String orderBy) throws java.sql.SQLException, DataTransferException
SimpleBean
objects.
tableList
- a string of table names list to be selected fromcolumnList
- a string of column names list to be selectedcondition
- the SQL condition of the selectorderBy
- the SQL order by clause used in the selection (exclude the "order
by" key words and only include the column(s) part of the clause in this
parameter)
SimpleBean
objects selected
java.sql.SQLException
{@link
- DataTransferException}
DataTransferException
public static java.util.Vector select(java.lang.String tableList, java.lang.String columnList, java.lang.String condition, java.lang.String orderBy, java.sql.Connection con) throws java.sql.SQLException, DataTransferException
SimpleBean
objects.
tableList
- a string of table names list to be selected fromcolumnList
- a string of column names list to be selectedcondition
- the SQL condition of the selectorderBy
- the SQL order by clause used in the selection (exclude the "order
by" key words and only include the column(s) part of the clause in this
parameter)con
- the operation of this method is part of the transaction associated
with this Connection object
SimpleBean
objects selected
java.sql.SQLException
{@link
- DataTransferException}
DataTransferException
public int update(java.lang.Object obj, java.util.Vector columnNames, java.lang.String condition) throws DataTransferException, java.sql.SQLException
obj
- the data bean whose properties value will be used to set the values
of other beans. This bean must have this table as its associated table.columnNames
- a vector representation of the columns to be updatedcondition
- the SQL condition used in the update
java.sql.SQLException
DataTransferException
- if update columns are mismatched with declared
fields in obj.public int update(java.lang.Object obj, java.util.Vector columnNames, java.lang.String condition, java.sql.Connection con) throws DataTransferException, java.sql.SQLException
obj
- the data bean whose properties value will be used to set the values
of other beans. This bean must have the same type as the calling bean of this
method does.columnNames
- a vector representation of the columns to be updatedcondition
- the SQL condition used in the updatecon
- the operation of this method is part of the transaction associated
with this Connection object
java.sql.SQLException
DataTransferException
- if the update columns are mismatched.public java.lang.Object getMaxID(java.lang.String indexColumnName, java.sql.Connection con) throws java.sql.SQLException
indexColumnName
- column name whose max value is fetched. This column must
have a type so that the SQL operation "select max(thiscolumn) from ...." is legal.con
- The operation of this method is part of the transaction associated
with this Connection object.
java.sql.SQLException
public java.lang.Object getMaxPrimaryKey(java.sql.Connection con) throws java.sql.SQLException
con
- The operation of this method is part of the transaction associated
with this Connection object.
java.sql.SQLException
java.lang.RuntimeException
- if the table doesn't have a primary key.public boolean exists(java.lang.Object obj) throws DataTransferException, java.sql.SQLException
obj
- the data bean whose existence in the table that will be checked
java.sql.SQLException
DataTransferException
public java.util.Iterator iterator(java.lang.String tables, java.lang.String condition)
condition
- the SQL condition for the selectpublic java.util.Iterator iterator(java.lang.String condition)
condition
- the SQL condition for the selectpublic java.util.Iterator iterator()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |