com.youyounet.db
Class DataBean

java.lang.Object
  |
  +--com.youyounet.db.DataBean

public abstract class DataBean
extends java.lang.Object

DataBean is the abstract class that should be subclassed to define the actual data bean classes. The actual data bean instances will then have all the database functionalities defined in this class. The definition of an actual data bean class should follow certain pattern, and is explained in the following:

It's probably easier to illustrate this fact through an example. Let's say you have a database table called User which has the following schema

  create table User(
      UserID bigint not null auto_increment, primary key(UserID),
      Username varchar(20) not null, unique index(Username),
      Password varchar(20) not null,
      LastLogin datetime,
      Tmstamp timestamp
  ) 
 
The data bean class mapping to this database table will have the following code
 import com.youyounet.db.*;

 public class User extends DataBean{
 //the following few lines of code defines the mapping of the class properties to the 
 //the table columns.  
 public static Hashtable fieldMap = new Hashtable();
 static{
      fieldMap.put("userID", new ColumnAttribute("UserID", 6));
      fieldMap.put("username", new ColumnAttribute("Username"));
      fieldMap.put("password", new ColumnAttribute("Password", 8));
      fieldMap.put("lastLogin", new ColumnAttribute("LastLogin"));
      fieldMap.put("tmstamp", new ColumnAttribute("Tmstamp", 16));
 }
 public static Table table = new Table("User", //table name
     "com.jdb.data.User", //class name
      fieldMap); 
   
 public Table getTable(){ return table; }
 
 //after the above mapping code, the following is just the standard Java bean definition  
 public int userID = -1;
 public String username = "";
 public String password = "";
 public Timestamp lastLogin = null;
 public Timestamp tmstamp = null;

 public int getUserID(){ return UserID; }
 public void setUserID(int var){
     userID = var;
 }
   
 public String getUsername(){ return username; }
 public void setUsername(String var){
     username = var;
 }
   
 public String getPassword(){ return password; }
 public void setPassword(String var){
     password = var;
 }

 public Timestamp getLastLogin(){ return lastLogin; }
 public void setLastLogin(Timestamp var){
     lastLogin = var; 
 }
   
 public Timestamp getTmstamp(){ return tmstamp; }
 public void setTmstamp(Timestamp var){
     tmstamp = var; 
 }
   
 public int getID(){ return getUserID(); }
 }
 
The first part of the class code is dedicated to the mapping of the class properties to the database table columns. No magic of this, simply put the class property names as keys and table column attributes as values in the statically declared fieldMap. All the names are case sensitive. After that, declare a class-wide table object and pass the table name, the class name, the fieldMap as the arguments. This table object is responsible for doing the database operations for the instances of the class. Finally, give a get method for the table object. This completes the mapping. The remaining code of the class is simply standard Java Bean styled code and will not be explained here. Please note, the code pattern of the data bean class could be automatically generated by a tool given the database table schema. This is in the todo list.

Once having all these defined, we can do something like this, for example:

 User user = new User();
 String username = request.getParameter("username");
 String password = request.getParameter("password");
 if(!user.load("Username='" + username + "'"))
      //username not in database, do something;
 if(!user.getPassword().equals(password))
      //password not correct, do some thing;
 user.setLastLogin(new Timestamp());
 user.store(); //the user record will be updated.
 
The type of data bean properties that could map to a database table column is not limited to the known Java SQL types. Composite property can also map to a table column of type BLOB provided that the composite property can be serialized to a binary stream.


Field Summary
protected  java.util.logging.Logger log
           
 
Constructor Summary
DataBean()
          Default constructor.
 
Method Summary
 boolean create()
          This method is the same as create(boolean ignorAutoIncrement), with the ignorAutoIncrement parameter set to false.
 boolean create(boolean ignorAutoIncrement)
          Insert this calling data bean as a new row to its associated table.
 boolean create(java.sql.Connection con)
          This method is the same as create(Connection con, boolean ignorAutoIncrement), with the ignorAutoIncrement parameter set to false.
 boolean create(java.sql.Connection con, boolean ignorAutoIncrement)
          Insert this calling data bean as a new row to its associated table.
 boolean create(DBContext c)
          This method is the same as create(DBContext c, boolean ignorAutoIncrement), with the ignorAutoIncrement parameter set to false.
 boolean create(DBContext c, boolean ignorAutoIncrement)
          Insert this calling data bean as a new row to its associated table.
 int delete(java.lang.String condition)
          Delete data beans from this calling bean's associated table using the condition specified.
 int delete(java.lang.String condition, java.sql.Connection con)
          Delete data beans from this calling bean's associated table using the condition specified.
 int delete(java.lang.String condition, DBContext c)
          Delete data beans from this calling bean's associated table using the condition specified.
 boolean exists()
          check if the calling data bean exists in its associated table.
 boolean exists(java.lang.String condition)
          check if the calling data bean exists in its associated table and is also satisfied by the SQL condition passed in.
 boolean exists(java.lang.String tables, java.lang.String condition)
          Check if the calling data bean exists in its associated table and is also satisfied by the SQL condition passed in.
 boolean find(java.lang.String condition)
          Check whether the calling data bean exists in its associated table satisfied by the additional SQL condition if present.
 java.lang.String getColumnList(java.lang.String prefix)
          Get a string of all the column names of the calling data bean's associated table.
abstract  int getID()
          Get the id of the calling data bean.
 java.lang.String getKeyColumnName()
          Get the primary key of the calling data bean's associated database table.
 java.lang.Object getMaxID(java.lang.String column, java.sql.Connection con)
          Get the max value of the specified column.
 java.lang.Object getMaxID(java.lang.String column, DBContext c)
          Get the max value of the specified 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 bean.
 java.lang.Object getMaxPrimaryKey(DBContext c)
          Get the max value of the primary key column, if there is a primary key for this bean.
abstract  Table getTable()
          Returns the table object associated with this data bean.
 java.lang.String getTableName()
          Get the calling data bean's associated database table name.
 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 tableList, java.lang.String condition)
          returns a bean Iterator.
 boolean load()
          Load this calling bean's properties value with values from the associated table, using the SQL condition specified by getKeyCondition method.
 boolean load(java.sql.Connection con)
          Load this calling bean's properties value with values from the associated table, using the SQL condition specified by getKeyCondition method.
 boolean load(DBContext c)
          Load this calling bean's properties value with values from the associated table, using the SQL condition specified by getKeyCondition method.
 boolean load(java.lang.String condition)
          Load this calling bean's properties value with values from the associated table, using the SQL condition specified.
 boolean load(java.lang.String condition, java.sql.Connection con)
          Load this calling bean's properties value with values from the associated table, using the SQL condition specified.
 boolean load(java.lang.String condition, DBContext c)
          Load this calling bean's properties value with values from the associated table, using the SQL condition specified.
 boolean remove()
          Remove this data bean from the associated table, using the condition specified by getKeyCondition method.
 boolean remove(java.sql.Connection con)
          Remove this data bean from the associated table, using the condition specified by getKeyCondition method.
 boolean remove(DBContext c)
          Remove this data bean from the associated table, using the condition specified by getKeyCondition method.
 boolean remove(java.lang.String condition)
          Remove this data bean from the associated table, using the condition specified.
 boolean remove(java.lang.String condition, java.sql.Connection con)
          Remove this data bean from the associated table, using the condition specified.
 boolean remove(java.lang.String condition, DBContext c)
          Remove this data bean from the associated table, using the condition specified.
 java.util.Vector select(java.lang.String condition, java.lang.String orderBy)
          Select a Vector of data beans from this calling bean's associated table and 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 from this calling bean's associated table and satisfied by the passed in SQL condition.
 java.util.Vector select(java.lang.String condition, java.lang.String orderBy, DBContext c)
          Select a Vector of data beans from this calling bean's associated table and 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 calling bean's associated table and 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 calling bean's associated table and satisfied by the passed in SQL condition.
 java.util.Vector select(java.lang.String tableList, java.lang.String condition, java.lang.String orderBy, DBContext c)
          Select a Vector of data beans from this calling bean's associated table and satisfied by the passed in SQL condition.
 boolean store()
          store this calling data bean to the associated table, using the SQL condition specified by getKeyCondition method.
 boolean store(java.sql.Connection con)
          store this calling data bean to the associated table, using the SQL condition specified by getKeyCondition method.
 boolean store(DBContext c)
          store this calling data bean to the associated table, using the SQL condition specified by getKeyCondition method.
 boolean store(java.lang.String condition)
          Store this calling data bean to the associated table, using the condition specified.
 boolean store(java.lang.String condition, java.sql.Connection con)
          Store this calling data bean to the associated table, using the condition specified.
 boolean store(java.lang.String condition, DBContext c)
          store this calling data bean to the associated table, using the condition specified.
 int update(java.util.Vector columnNames, java.lang.String condition)
          Update one or more data beans' value in the associated table with value drawn from this calling data bean.
 int update(java.util.Vector columnNames, java.lang.String condition, java.sql.Connection con)
          Update one or more data beans' value in the associated table with value drawn from this calling data bean.
 int update(java.util.Vector columnNames, java.lang.String condition, DBContext c)
          Update one or more data beans' value in the associated table with value drawn from this calling data bean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected java.util.logging.Logger log
Constructor Detail

DataBean

public DataBean()
Default constructor.

Method Detail

getTable

public abstract Table getTable()
Returns the table object associated with this data bean.


update

public int update(java.util.Vector columnNames,
                  java.lang.String condition)
           throws DataTransferException,
                  java.sql.SQLException
Update one or more data beans' value in the associated table with value drawn from this calling data bean. This method will not necessarily update the calling data bean instance. In fact the method doesn't require the calling bean to exist in the table. The data beans that will be affected by this method call are determined by the passed in SQL condition.

Parameters:
columnNames - a vector representation of the columns to be updated
condition - the SQL condition used in the update
Returns:
the number of data beans affected by the call of this method
Throws:
java.sql.SQLException
DataTransferException - if update columns are mismatched with declared fields in the calling bean.

update

public int update(java.util.Vector columnNames,
                  java.lang.String condition,
                  DBContext c)
           throws DataTransferException,
                  java.sql.SQLException
Update one or more data beans' value in the associated table with value drawn from this calling data bean. This method will not necessarily update the calling data bean instance. In fact the method doesn't require the calling bean to exist in the table. The data beans that will be affected by this method call are determined by the passed in SQL condition.

Parameters:
columnNames - a vector representation of the columns to be updated
condition - the SQL condition used in the update
c - this operation of update is part of the transaction associated with with this DBContext object
Returns:
the number of data beans affected by the call of this method
Throws:
java.sql.SQLException
DataTransferException - if update columns are mismatched with declared fields in the calling bean.

update

public int update(java.util.Vector columnNames,
                  java.lang.String condition,
                  java.sql.Connection con)
           throws DataTransferException,
                  java.sql.SQLException
Update one or more data beans' value in the associated table with value drawn from this calling data bean. This method will not necessarily update the calling data bean instance. In fact the method doesn't require the calling bean to exist in the table. The data beans that will be affected by this method call are determined by the passed in SQL condition.

Parameters:
columnNames - a vector representation of the columns to be updated
condition - the SQL condition used in the update
con - this operation of update is part of the transaction associated with with this Connection object
Returns:
the number of data beans affected by the call of this method
Throws:
java.sql.SQLException
DataTransferException - if update columns are mismatched with declared fields in the calling bean.

select

public java.util.Vector select(java.lang.String tableList,
                               java.lang.String condition,
                               java.lang.String orderBy)
                        throws java.sql.SQLException,
                               DataTransferException
Select a Vector of data beans from this calling bean's associated table and satisfied by the passed in SQL condition. The tableList String that is passed in is only for constructing the SQL condition, and should not contain this calling bean's associated table name. No column from tables in this list will actually be selected.

Parameters:
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 the calling bean's associated table. No column from tables in this list will actually be selected.
condition - the SQL condition of the select
orderBy - 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)
Throws:
java.sql.SQLException
{@link - DataTransferException}
DataTransferException

select

public java.util.Vector select(java.lang.String tableList,
                               java.lang.String condition,
                               java.lang.String orderBy,
                               DBContext c)
                        throws java.sql.SQLException,
                               DataTransferException
Select a Vector of data beans from this calling bean's associated table and satisfied by the passed in SQL condition. The tableList String that is passed in is only for constructing the SQL condition, and should not contain this calling bean's associated table name. No column from tables in this list will actually be selected.

Parameters:
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 the calling bean's associated table. No column from tables in this list will actually be selected.
condition - the SQL condition of the select
orderBy - 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).
c - the operation of this select is part of the transaction associated with this DBContext object.
Throws:
java.sql.SQLException
{@link - DataTransferException}
DataTransferException

select

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
Select a Vector of data beans from this calling bean's associated table and satisfied by the passed in SQL condition. The tableList String that is passed in is only for constructing the SQL condition, and should not contain this calling bean's associated table name. No column from tables in this list will actually be selected.

Parameters:
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 the calling bean's associated table. No column from tables in this list will actually be selected.
condition - the SQL condition of the select
orderBy - 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 select is part of the transaction associated with this Connection object.
Throws:
java.sql.SQLException
{@link - DataTransferException}
DataTransferException

select

public java.util.Vector select(java.lang.String condition,
                               java.lang.String orderBy)
                        throws java.sql.SQLException,
                               DataTransferException
Select a Vector of data beans from this calling bean's associated table and satisfied by the passed in SQL condition.

Parameters:
condition - the SQL condition of the select
orderBy - 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).
Throws:
java.sql.SQLException
{@link - DataTransferException}
DataTransferException

select

public java.util.Vector select(java.lang.String condition,
                               java.lang.String orderBy,
                               DBContext c)
                        throws java.sql.SQLException,
                               DataTransferException
Select a Vector of data beans from this calling bean's associated table and satisfied by the passed in SQL condition.

Parameters:
condition - the SQL condition of the select
orderBy - 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).
c - the operation of this select is part of the transaction associated with this DBContext object.
Throws:
java.sql.SQLException
{@link - DataTransferException}
DataTransferException

select

public java.util.Vector select(java.lang.String condition,
                               java.lang.String orderBy,
                               java.sql.Connection con)
                        throws java.sql.SQLException,
                               DataTransferException
Select a Vector of data beans from this calling bean's associated table and satisfied by the passed in SQL condition.

Parameters:
condition - the SQL condition of the select
orderBy - 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 select is part of the transaction associated with this Connection object.
Throws:
java.sql.SQLException
{@link - DataTransferException}
DataTransferException

delete

public int delete(java.lang.String condition)
           throws java.sql.SQLException
Delete data beans from this calling bean's associated table using the condition specified.

Parameters:
condition - the SQL condition used in the delete operation
Returns:
an int indicating the number of records were deleted
Throws:
java.sql.SQLException

delete

public int delete(java.lang.String condition,
                  java.sql.Connection con)
           throws java.sql.SQLException
Delete data beans from this calling bean's associated table using the condition specified.

Parameters:
con - this delete operation is part of the transaction associated with this Connection object.
condition - the SQL condition used in the delete operation
Returns:
an int indicating the number of records were deleted
Throws:
java.sql.SQLException

delete

public int delete(java.lang.String condition,
                  DBContext c)
           throws java.sql.SQLException
Delete data beans from this calling bean's associated table using the condition specified.

Parameters:
c - this delete operation is part of the transaction associated with this DBContext object.
condition - the SQL condition used in the delete operation
Returns:
an int indicating the number of records were deleted
Throws:
java.sql.SQLException

load

public boolean load(java.lang.String condition)
             throws DataTransferException,
                    java.sql.SQLException
Load this calling bean's properties value with values from the associated table, using the SQL condition specified.

Parameters:
condition - the SQL condition to load the data from database.
Returns:
a boolean value indicating the load is successful or not, true means the load is completed
Throws:
java.sql.SQLException
DataTransferException

load

public boolean load(java.lang.String condition,
                    java.sql.Connection con)
             throws DataTransferException,
                    java.sql.SQLException
Load this calling bean's properties value with values from the associated table, using the SQL condition specified.

Parameters:
condition - the SQL condition to load the data from database.
con - this load operation is part of the transaction associated with this Connection object.
Returns:
a boolean value indicating the load is successful or not, true means the load is completed
Throws:
java.sql.SQLException
DataTransferException

load

public boolean load(java.lang.String condition,
                    DBContext c)
             throws DataTransferException,
                    java.sql.SQLException
Load this calling bean's properties value with values from the associated table, using the SQL condition specified.

Parameters:
condition - the SQL condition to load the data from database.
c - this load operation is part of the transaction associated with this DBContext object.
Returns:
a boolean value indicating the load is successful or not, true means the load is completed
Throws:
java.sql.SQLException
DataTransferException

load

public boolean load()
             throws DataTransferException,
                    java.sql.SQLException
Load this calling bean's properties value with values from the associated table, using the SQL condition specified by getKeyCondition method.

Returns:
a boolean value indicating the load is successful or not, true means the load is completed
Throws:
java.sql.SQLException
DataTransferException

load

public boolean load(java.sql.Connection con)
             throws DataTransferException,
                    java.sql.SQLException
Load this calling bean's properties value with values from the associated table, using the SQL condition specified by getKeyCondition method.

Parameters:
con - this load operation is part of the transaction associated with this Connection object.
Returns:
a boolean value indicating the load is successful or not, true means the load is completed
Throws:
java.sql.SQLException
DataTransferException

load

public boolean load(DBContext c)
             throws DataTransferException,
                    java.sql.SQLException
Load this calling bean's properties value with values from the associated table, using the SQL condition specified by getKeyCondition method.

Returns:
a boolean value indicating the load is successful or not, true means the load is completed
Throws:
java.sql.SQLException
DataTransferException

store

public boolean store(java.lang.String condition)
              throws DataTransferException,
                     java.sql.SQLException
Store this calling data bean to the associated table, using the condition specified.

Parameters:
condition - the SQL condition used to store this bean to the associated table.
Returns:
a boolean value indicating the store is successful or not, true means the store is completed successfully
Throws:
java.sql.SQLException
DataTransferException

store

public boolean store(java.lang.String condition,
                     java.sql.Connection con)
              throws DataTransferException,
                     java.sql.SQLException
Store this calling data bean to the associated table, using the condition specified.

Parameters:
condition - the SQL condition used to store this bean to the associated table.
con - this store operation is part of the transaction associated with this Connection object.
Returns:
a boolean value indicating the store is successful or not, true means the store is completed successfully
Throws:
java.sql.SQLException
DataTransferException

store

public boolean store(java.lang.String condition,
                     DBContext c)
              throws DataTransferException,
                     java.sql.SQLException
store this calling data bean to the associated table, using the condition specified.

Parameters:
condition - the SQL condition used to store this bean to the associated table.
c - this store operation is part of the transaction associated with this DBContext object.
Returns:
a boolean value indicating the store is successful or not, true means the store is completed successfully
Throws:
java.sql.SQLException
DataTransferException

store

public boolean store()
              throws DataTransferException,
                     java.sql.SQLException
store this calling data bean to the associated table, using the SQL condition specified by getKeyCondition method.

Returns:
a boolean value indicating the store is successful or not, true means the store is completed successfully
Throws:
java.sql.SQLException
DataTransferException

store

public boolean store(java.sql.Connection con)
              throws DataTransferException,
                     java.sql.SQLException
store this calling data bean to the associated table, using the SQL condition specified by getKeyCondition method.

Parameters:
con - the store operation is part of the transaction associated with this Connection object.
Returns:
a boolean value indicating the store is successful or not, true means the store is completed successfully
Throws:
java.sql.SQLException
DataTransferException

store

public boolean store(DBContext c)
              throws DataTransferException,
                     java.sql.SQLException
store this calling data bean to the associated table, using the SQL condition specified by getKeyCondition method.

Returns:
a boolean value indicating the store is successful or not, true means the store is completed successfully
Throws:
java.sql.SQLException
DataTransferException

remove

public boolean remove(java.lang.String condition)
               throws DataTransferException,
                      java.sql.SQLException
Remove this data bean from the associated table, using the condition specified.

The difference of a remove method and a delete method is that a remove method can only remove the calling data bean itself from its associated table, while a delete method will not necessarily 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.

Parameters:
condition - the SQL condition used to remove the calling bean from the database
Returns:
a boolean value indicating the remove is successful or not, true means the remove is completed successfully
Throws:
java.sql.SQLException
DataTransferException - if more than one object would be removed based on the specified SQL condition.

remove

public boolean remove(java.lang.String condition,
                      DBContext c)
               throws DataTransferException,
                      java.sql.SQLException
Remove this data bean from the associated table, using the condition specified.

The difference of a remove method and a delete method is that a remove method can only remove the calling data bean itself from its associated table, while a delete method will not necessarily 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.

Parameters:
condition - the SQL condition used to remove the calling bean from the database.
c - the operation of remove is part of the transaction associated with this DBContext object.
Returns:
a boolean value indicating the remove is successful or not, true means the remove is completed successfully
Throws:
java.sql.SQLException
DataTransferException - if more than one object would be removed based on the specified SQL condition.

remove

public boolean remove(java.lang.String condition,
                      java.sql.Connection con)
               throws DataTransferException,
                      java.sql.SQLException
Remove this data bean from the associated table, using the condition specified.

The difference of a remove method and a delete method is that a remove method can only remove the calling data bean itself from its associated table, while a delete method will not necessarily 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.

Parameters:
condition - the SQL condition used to remove the calling bean from the database.
con - the operation of remove is part of the transaction associated with this Connection object.
Returns:
a boolean value indicating the remove is successful or not, true means the remove is completed successfully
Throws:
java.sql.SQLException
DataTransferException - if more than one object would be removed based on the specified SQL condition.

remove

public boolean remove()
               throws DataTransferException,
                      java.sql.SQLException
Remove this data bean from the associated table, using the condition specified by 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 its associated table, while a delete method will not necessarily 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.

Returns:
a boolean value indicating the remove is successful or not, true means the remove is completed successfully
Throws:
java.sql.SQLException
DataTransferException - if more than one object would be removed based on the specified SQL condition.

remove

public boolean remove(java.sql.Connection con)
               throws DataTransferException,
                      java.sql.SQLException
Remove this data bean from the associated table, using the condition specified by 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 its associated table, while a delete method will not necessarily 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.

Parameters:
con - the operation of this remove is part of the transaction associated with this Connection object.
Returns:
a boolean value indicating the remove is successful or not, true means the remove is completed successfully
Throws:
java.sql.SQLException
DataTransferException - if more than one object would be removed based on the specified SQL condition.

remove

public boolean remove(DBContext c)
               throws DataTransferException,
                      java.sql.SQLException
Remove this data bean from the associated table, using the condition specified by 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 its associated table, while a delete method will not necessarily 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.

Parameters:
c - the operation of this remove is part of the transaction associated with this DBContext object.
Returns:
a boolean value indicating the remove is successful or not, true means the remove is completed successfully
Throws:
java.sql.SQLException
DataTransferException - if more than one object would be removed based on the specified SQL condition.

create

public boolean create(boolean ignorAutoIncrement)
               throws DataTransferException,
                      java.sql.SQLException
Insert this calling data bean as a new row to its associated table.

Parameters:
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(there is a auto_increment column), if the parameter is true, the value inserted into the auto increment column will be drawn from the corresponding property value of the calling data bean; 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.
Returns:
a boolean value indicating whether the insert operation is successful or not. Returning true means successful insertion.
Throws:
java.sql.SQLException
DataTransferException

create

public boolean create()
               throws DataTransferException,
                      java.sql.SQLException
This method is the same as create(boolean ignorAutoIncrement), with the ignorAutoIncrement parameter set to false. This is the default behavior.

DataTransferException
java.sql.SQLException

create

public boolean create(java.sql.Connection con)
               throws DataTransferException,
                      java.sql.SQLException
This method is the same as create(Connection con, boolean ignorAutoIncrement), with the ignorAutoIncrement parameter set to false.

DataTransferException
java.sql.SQLException

create

public boolean create(DBContext c)
               throws DataTransferException,
                      java.sql.SQLException
This method is the same as create(DBContext c, boolean ignorAutoIncrement), with the ignorAutoIncrement parameter set to false.

DataTransferException
java.sql.SQLException

create

public boolean create(java.sql.Connection con,
                      boolean ignorAutoIncrement)
               throws DataTransferException,
                      java.sql.SQLException
Insert this calling data bean as a new row to its associated table.

Parameters:
con - the create operation is part of the transaction associated with 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(there is a auto_increment column), if the parameter is true, the value inserted into the auto increment column will be drawn from the corresponding property value of the calling data bean; 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.
Returns:
a boolean value indicating whether the insert operation is successful or not. Returning true means successful insertion.
Throws:
java.sql.SQLException
DataTransferException

create

public boolean create(DBContext c,
                      boolean ignorAutoIncrement)
               throws DataTransferException,
                      java.sql.SQLException
Insert this calling data bean as a new row to its associated table.

Parameters:
c - the create operation is part of the transaction associated with this DBContext 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(there is a auto_increment column), if the parameter is true, the value inserted into the auto increment column will be drawn from the corresponding property value of the calling data bean; 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.
Returns:
a boolean value indicating whether the insert operation is successful or not. Returning true means successful insertion.
Throws:
java.sql.SQLException
DataTransferException

find

public boolean find(java.lang.String condition)
             throws DataTransferException,
                    java.sql.SQLException
Check whether the calling data bean exists in its associated table satisfied by the additional SQL condition if present.

Parameters:
condition - the SQL condition that must also be met if present when checking the existence of the data bean in the table
Returns:
the result checked
Throws:
java.sql.SQLException
{@link - DataTransferException}
DataTransferException

getColumnList

public java.lang.String getColumnList(java.lang.String prefix)
Get a string of all the column names of the calling data bean's associated table. If parameter prefix is not null, all the column names will be prepended with the prefix followed by a dot(.).

Parameters:
prefix - the prefix to be added to all the column names.

getMaxID

public java.lang.Object getMaxID(java.lang.String column,
                                 java.sql.Connection con)
                          throws java.sql.SQLException
Get the max value of the specified column. This method is usually called within a transaction.

Parameters:
column - this is the 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.
Returns:
the result of the select
Throws:
java.sql.SQLException

getMaxID

public java.lang.Object getMaxID(java.lang.String column,
                                 DBContext c)
                          throws java.sql.SQLException
Get the max value of the specified column. This method is usually called within a transaction.

Parameters:
column - this is the column name whose max value is fetched. This column must have a type so that the SQL operation "select max(thiscolumn) from ...." is legal.
c - The operation of this method is part of the transaction associated with this DBContext object.
Returns:
the result of the select
Throws:
java.sql.SQLException

getMaxPrimaryKey

public java.lang.Object getMaxPrimaryKey(java.sql.Connection con)
                                  throws java.sql.SQLException
Get the max value of the primary key column, if there is a primary key for this bean. If there is no primary key exists, a RuntimeException will then be thrown. This method is usually called within a transaction.

Parameters:
con - The operation of this method is part of the transaction associated with this Connection object.
Returns:
the result of the select
Throws:
java.sql.SQLException
java.lang.RuntimeException - if the table doesn't have a primary key.

getMaxPrimaryKey

public java.lang.Object getMaxPrimaryKey(DBContext c)
                                  throws java.sql.SQLException
Get the max value of the primary key column, if there is a primary key for this bean. If there is no primary key exists, a RuntimeException will then be thrown. This method is usually called within a transaction.

Parameters:
c - The operation of this method is part of the transaction associated with this DBContext object.
Returns:
the result of the select
Throws:
java.sql.SQLException
java.lang.RuntimeException - if the table doesn't have a primary key.

iterator

public java.util.Iterator iterator()
returns a bean Iterator. This method can be used to iterate through all the data beans in the calling bean's associated table.


iterator

public java.util.Iterator iterator(java.lang.String condition)
returns a bean Iterator. This method can be used to iterate through all the data beans in the calling bean's associated table that satisfies the passed in SQL condition.

Parameters:
condition - the SQL condition for the select

iterator

public java.util.Iterator iterator(java.lang.String tableList,
                                   java.lang.String condition)
returns a bean Iterator. This method can be used to iterate through all the data beans in the calling bean's associated table that satisfies the passed in SQL condition. The table names in the passed in tableList parameter will only be referenced from the SQL condition and should not contain the calling bean's associated table name.

Parameters:
tableList - a string of table names seprated by a comma. The tables in the list will only be referenced from the SQL condition and should not contain the calling bean's associated table name.
condition - the SQL condition for the select

getID

public abstract int getID()
Get the id of the calling data bean.


getTableName

public java.lang.String getTableName()
Get the calling data bean's associated database table name.


getKeyColumnName

public java.lang.String getKeyColumnName()
Get the primary key of the calling data bean's associated database table. If there is no primary key defined in the table, null will be returned.


exists

public boolean exists()
               throws DataTransferException,
                      java.sql.SQLException
check if the calling data bean exists in its associated table.

Returns:
the result of the check
Throws:
java.sql.SQLException
DataTransferException

exists

public boolean exists(java.lang.String condition)
               throws DataTransferException,
                      java.sql.SQLException
check if the calling data bean exists in its associated table and is also satisfied by the SQL condition passed in.

Parameters:
condition - the SQL condition that must be met when checking the existence of the calling data bean in its associated database table.
Returns:
the result of the check
Throws:
java.sql.SQLException
DataTransferException

exists

public boolean exists(java.lang.String tables,
                      java.lang.String condition)
               throws DataTransferException,
                      java.sql.SQLException
Check if the calling data bean exists in its associated table and is also satisfied by the SQL condition passed in. The tables parameter will only be referened from the SQL condition that will also be passed in.

Parameters:
tables - 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 the calling bean's associated table name.
condition - the SQL condition that must be met when checking the existence of the calling data bean in its associated database table.
Returns:
the result of the check
Throws:
java.sql.SQLException
DataTransferException