All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.expershop.esapi.DbObject

java.lang.Object
   |
   +----com.expershop.esapi.DbObject

public class DbObject
extends Object

Method Index

 o addColumn(String, int, String)
Add a new column to this DbObject.
 o clearValues()
Reset all column values: Numeric columns are set to 0, String columns are set to "" (empty string).
 o deleteQuery(String)
Generate a DELETE SQL request, and return it as a String.
The request is for later use, deleteQuery() DOES NOT AFFECT the database.
 o get(String)
Retrieve a column's value, as a String.
 o getDouble(String)
Retrieve a column's value, as a double.
 o insertQuery()
Generate an INSERT SQL request to create the current object in the database, and return it as a String.
The request is for later use, insertQuery() DOES NOT AFFECT the database.
 o present(String)
Check if a column exists (is present).
 o saveChanges(String)
Update the database so it reflects the changes in the current DbObject.
This method WILL ISSUE AN UPDATE REQUEST TO THE DATABASE, so it will certainly affect the database content.
This method uses the updateQuery() method to generate the UPDATE query.
 o set(String, double)
Set a column's value, for columns of type double.
 o set(String, int)
Set a column's value, for columns of type int.
 o set(String, long)
Set a column's value, for columns of type long.
 o set(String, String)
Set a column's value, for columns of type String.
 o setFromRequest(ServletRequest)
Set column's values according to parameters in a ServletRequest.
Column names and ServletRequest parameter names are matched: when a ServletRequest parameter's name matches a writable column's name, the column's value is set according to the ServletRequest parameter's value.
 o setSqlEncode(boolean)
Decide to implicitly SQL-encode column values when they are set, or not; By default, implicit SQL-encoding is enabled.
This method influences the behavoiur of the set() methods.
SQL encoding replaces special characters, like quotes, with characters accepted in database column values.
SQL encoding rules are specified in the application's configuration file (sqlencode.Substitutions property).
Rules syntax: c1=s1;c2=s2;...cn=sn (replace char1 with string1, etc...)
 o setWritable(String, boolean)
Tell if a column is writable or not: by default, columns are writable.
 o updateQuery(String)
Generate an UPDATE SQL request that reflects the current object's changes, and return it as a String.
The request is for later use, updateQuery() DOES NOT AFFECT the database.
If you need to update the database, you may want to use the saveChanges() method instead.

Methods

 o setSqlEncode
 public void setSqlEncode(boolean s)
Decide to implicitly SQL-encode column values when they are set, or not; By default, implicit SQL-encoding is enabled.
This method influences the behavoiur of the set() methods.
SQL encoding replaces special characters, like quotes, with characters accepted in database column values.
SQL encoding rules are specified in the application's configuration file (sqlencode.Substitutions property).
Rules syntax: c1=s1;c2=s2;...cn=sn (replace char1 with string1, etc...)

Parameters:
s - true to SQL-encode values, false otherwise
 o setWritable
 public void setWritable(String name,
                         boolean w)
Tell if a column is writable or not: by default, columns are writable.

Parameters:
name - The column name.
w - true if writable, false if not.
 o get
 public String get(String name) throws SQLException
Retrieve a column's value, as a String.

Parameters:
name - The column name.
Returns:
The column value.
 o getDouble
 public double getDouble(String name) throws SQLException
Retrieve a column's value, as a double.

Parameters:
name - The column name.
Returns:
The column value.
 o set
 public void set(String name,
                 String val)
Set a column's value, for columns of type String.

Parameters:
name - The column name.
val - The column value.
 o set
 public void set(String name,
                 int val)
Set a column's value, for columns of type int.

Parameters:
name - The column name.
val - The column value.
 o set
 public void set(String name,
                 long val)
Set a column's value, for columns of type long.

Parameters:
name - The column name.
val - The column value.
 o set
 public void set(String name,
                 double val)
Set a column's value, for columns of type double.

Parameters:
name - The column name.
val - The column value.
 o present
 public boolean present(String col)
Check if a column exists (is present).

Parameters:
col - The column name.
Returns:
true if present, false if not.
 o setFromRequest
 public void setFromRequest(ServletRequest req)
Set column's values according to parameters in a ServletRequest.
Column names and ServletRequest parameter names are matched: when a ServletRequest parameter's name matches a writable column's name, the column's value is set according to the ServletRequest parameter's value.

Parameters:
req - A ServletRequest
 o addColumn
 public void addColumn(String name,
                       int type,
                       String val)
Add a new column to this DbObject.

Parameters:
name - The column name.
type - The column type: any type defined in java.sql.Types (examples: Types.INTEGER, Types.DOUBLE, Types.VARCHAR).
val - The column value, as a String.
 o saveChanges
 public void saveChanges(String where) throws SQLException
Update the database so it reflects the changes in the current DbObject.
This method WILL ISSUE AN UPDATE REQUEST TO THE DATABASE, so it will certainly affect the database content.
This method uses the updateQuery() method to generate the UPDATE query.

Parameters:
where - An SQL "where" clause (for example, "id=1" will result in an "update ... where id=1" SQL request to be issued).
 o clearValues
 public void clearValues()
Reset all column values: Numeric columns are set to 0, String columns are set to "" (empty string).

 o deleteQuery
 public String deleteQuery(String where)
Generate a DELETE SQL request, and return it as a String.
The request is for later use, deleteQuery() DOES NOT AFFECT the database.

Parameters:
where - An SQL "where" clause (for example, "id=1" will result in a "delete ... where id=1" SQL request to be generated).
 o updateQuery
 public String updateQuery(String where)
Generate an UPDATE SQL request that reflects the current object's changes, and return it as a String.
The request is for later use, updateQuery() DOES NOT AFFECT the database.
If you need to update the database, you may want to use the saveChanges() method instead.

Parameters:
where - An SQL "where" clause (for example, "id=1" will result in an "update ... where id=1" SQL request).
 o insertQuery
 public String insertQuery()
Generate an INSERT SQL request to create the current object in the database, and return it as a String.
The request is for later use, insertQuery() DOES NOT AFFECT the database.

Parameters:
where - An SQL "where" clause (for example, "id=1" will result in an "insert ..." SQL request).

All Packages  Class Hierarchy  This Package  Previous  Next  Index