|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.xoetrope.optional.data.sql.DatabaseTable
public class DatabaseTable
A holder for information about a database table and the result set obtained from a database query. This class provides some basic help to build queries to JDBC database tables and managing the interaction with the DataConnection object
Copyright (c) Xoetrope Ltd. 2001-2005
$Revision: 2.10 $ License: see license.txt
| Field Summary | |
|---|---|
protected static boolean |
caseSensitive
|
protected DataConnection |
connection
|
protected java.lang.String |
connName
|
protected int |
currentRow
|
protected java.lang.String |
defaultWhereClause
|
protected boolean |
dirty
|
protected boolean |
distinct
|
static int |
NORMAL_UPDATE
The database will attempt to synchronize periodically |
protected int |
numFields
|
protected int |
numRows
|
static int |
OPTIMISTIC_UPDATE
The database will only attempt to synchronize when absolutely necessary |
protected java.lang.String |
orderField
|
protected java.lang.String[] |
params
|
static int |
PARANOID_UPDATE
The database will always attemp to synchronize |
protected java.lang.String |
queryFields
|
protected java.lang.String |
queryTable
|
protected java.sql.ResultSet |
RS
|
protected java.lang.String |
sqlStatement
|
protected boolean |
writable
|
| Constructor Summary | |
|---|---|
DatabaseTable(java.lang.String tableName)
Create a new database table wrapper |
|
DatabaseTable(java.lang.String sql,
java.lang.String conn,
boolean allowWrites)
Create a new database table wrapper |
|
DatabaseTable(java.lang.String tableName,
java.lang.String fields,
java.lang.String where,
java.lang.String conn,
boolean allowWrites)
Create a new database table wrapper |
|
| Method Summary | |
|---|---|
protected void |
cacheData()
|
int |
executeUpdate(java.lang.String sql)
Execute an update statement |
protected void |
finalize()
|
void |
first()
Move to the first record in the result set. |
java.lang.String |
getConnName()
Get the connection name |
int |
getCurrentRow()
Gets the current row. |
int |
getFieldIndex(java.lang.String fieldName)
Get the index (zero based) of a named field |
java.lang.String |
getFieldName(int fieldIdx)
Get the name of a field |
java.lang.String |
getFields()
Gets the fields used for the query |
int |
getNumFields()
get the number of fields in the table |
int |
getNumRows()
Get the number of rows/records in the resultset/table |
java.sql.PreparedStatement |
getPreparedStatement(java.lang.String sql)
Get a prepared statement. |
java.lang.String |
getSQL(java.lang.String where)
Get the SQL for the SELECT statement or return the SQL that was specified |
java.lang.String |
getTableName()
Gets the table name |
void |
getTableName(java.lang.String name)
Get the table name |
java.lang.String |
getValue(int fieldIdx)
Get a field value |
java.lang.String |
getValue(int rowIdx,
int fieldIdx)
Get a field value |
java.lang.String |
getWhereClause()
Gets the value of any where clause |
boolean |
hasMoreRows()
Are there more records/rows? |
boolean |
isDistinct()
Check if the table is set to retrieve distinct rows. |
void |
last()
Move to the last record in the result set |
boolean |
next()
Move to the next record in the result set |
boolean |
previous()
Move to the previous record in the result set |
void |
releasePreparedStatement(java.sql.PreparedStatement preparedStatement)
Frees the prepared statement |
void |
retrieve()
Retrieve values using the default where clause or the params array if a PreparedStatement is to be used. |
void |
retrieve(java.lang.String where)
Retrieve values using the specified where clause. |
void |
retrieve(java.lang.String[] params)
Retrieve values using a Prepared statement. |
static void |
setCaseSensitive(boolean state)
Set the case sensitivity for database comparisons. |
void |
setCurrentRow(int idx)
Sets the current row. |
void |
setDistinct(boolean isDistinct)
Set the table to retrieve distinct rows |
void |
setOrderField(java.lang.String fld)
Set the field name(s) for the ORDER clause |
void |
setParams(java.lang.String[] prms)
If params are set then a PreparedStatement will be used in the query |
void |
setSql(java.lang.String sql)
Set the SQL Statement for the query |
void |
setValue(int rowIdx,
int fieldIdx,
java.lang.String value)
Set a field value |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int PARANOID_UPDATE
public static final int NORMAL_UPDATE
public static final int OPTIMISTIC_UPDATE
protected DataConnection connection
protected int numFields
protected int numRows
protected int currentRow
protected boolean dirty
protected java.lang.String queryFields
protected java.lang.String queryTable
protected java.sql.ResultSet RS
protected boolean distinct
protected java.lang.String orderField
protected java.lang.String sqlStatement
protected java.lang.String defaultWhereClause
protected java.lang.String connName
protected boolean writable
protected static boolean caseSensitive
protected java.lang.String[] params
| Constructor Detail |
|---|
public DatabaseTable(java.lang.String tableName)
tableName - the table name
public DatabaseTable(java.lang.String sql,
java.lang.String conn,
boolean allowWrites)
sql - the SQL query for the tableconn - the connection nameallowWrites - true if the result set is to be updatable
public DatabaseTable(java.lang.String tableName,
java.lang.String fields,
java.lang.String where,
java.lang.String conn,
boolean allowWrites)
tableName - the table namefields - the fields to retrievewhere - the where clause to use in the queryconn - the connection nameallowWrites - true if the result set is to be updatable| Method Detail |
|---|
public void setSql(java.lang.String sql)
sql - the new SQL statementpublic void setParams(java.lang.String[] prms)
prms - the array of params to populate the query.public void setDistinct(boolean isDistinct)
isDistinct - true to use the DISTINCT keyword in the SQL querypublic boolean isDistinct()
public void setOrderField(java.lang.String fld)
fld - the field name or names that will be used as the ORDER BY clause such that
the text ORDER BY public java.lang.String getValue(int fieldIdx)
fieldIdx - the (zero based) field index
public java.lang.String getValue(int rowIdx,
int fieldIdx)
rowIdx - the (zero based) row indexfieldIdx - the (zero based) field/column index
public void setValue(int rowIdx,
int fieldIdx,
java.lang.String value)
value - the new field valuerowIdx - the (zero based) row indexfieldIdx - the (zero based) field/column indexpublic int getFieldIndex(java.lang.String fieldName)
fieldName - the field name
public java.lang.String getFieldName(int fieldIdx)
fieldIdx - the field index (zero based)
public void retrieve()
public void retrieve(java.lang.String where)
where - the SQL where statement (without the WHERE)public void retrieve(java.lang.String[] params)
params - the params which will populate the PreparedStatement
public java.sql.PreparedStatement getPreparedStatement(java.lang.String sql)
throws java.sql.SQLException
sql - the sql query string or null to have the table build one
java.sql.SQLException
public void releasePreparedStatement(java.sql.PreparedStatement preparedStatement)
throws java.sql.SQLException
preparedStatement - the statement to free/release
java.sql.SQLException
public int executeUpdate(java.lang.String sql)
throws java.lang.Exception
sql - the UPDATE SQL statement
java.lang.Exceptionprotected void cacheData()
public int getNumRows()
public void setCurrentRow(int idx)
idx - the new row index - 0 basedpublic int getCurrentRow()
public void first()
public void last()
public boolean next()
public boolean previous()
public boolean hasMoreRows()
protected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwablepublic int getNumFields()
public java.lang.String getTableName()
public void getTableName(java.lang.String name)
name - the table namepublic java.lang.String getConnName()
public java.lang.String getWhereClause()
public java.lang.String getFields()
public static void setCaseSensitive(boolean state)
state - true for case-sensitive comparisons of field namespublic java.lang.String getSQL(java.lang.String where)
where - the where clause if any
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||