|
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.zentense.step2.model.ResultSetModel
public class ResultSetModel
A model represent a table, that is, a collection of rows, where
each row is a collection of columns, where one or more of the columns
are used to identify each row from the other ones.
A ResultSetModel is a model that represents a relational database
table and allows to execute SQL queries. The resulting JDBC
Resultsets are encapsulated into ResultSetViews.
A ResultSetModel supports forward only, scrollable and updatable
resultsets as well as prepared statements. The type of resultset
is selected using rowMode, loopMode and updateMode.
Some methods have two versions: one including a RequestRuntime instance as an
argument and other without it. It is safer use always the first ones,
while is slightly faster using the second ones. The RequestRuntime object
contains request information and it is the same during the entire
request. Each request locks on a database connection and releases it
when it finishes to ensure the code to be thread safe. If
ResultSetModel queries a database with a database connection of an older
request results may be unexpected. It is safer to use always the method
that passes a RequestRuntime instance as an argument.
| Field Summary | |
|---|---|
protected java.lang.String |
idName
Name of identifier column |
static int |
logLevel
|
protected java.util.Hashtable |
prepared
Hashtable of prepared stataments |
protected java.lang.String |
preparedTableId
Prepared table id |
protected int |
RSConcur
Concurrency of newxt resultset |
protected int |
RSType
Type of next resultset |
protected DBTableData.Table |
table
Table metadata |
| Constructor Summary | |
|---|---|
ResultSetModel()
|
|
ResultSetModel(java.lang.String tableName,
java.lang.String idName)
|
|
| Method Summary | |
|---|---|
void |
addPrepared(java.lang.String name,
java.lang.String sql)
Creates a prepared statement and leaves it ready to be executed with doPrepared. |
void |
clearPrepared()
Clears prepared statements table |
void |
delete(java.lang.Object id)
Executes a delete query (delete from table where id= ...) |
void |
deleteAll()
Deletes all rows in this table |
void |
deleteBy(java.lang.String by)
Deletes a group of rows (delete from table where ...) |
View |
doPrepared(java.lang.String name,
java.lang.Object[] obj)
Executes a prepared statement. |
View |
doQuery(java.lang.String sql)
Executes a SQL query using JDBC. |
void |
doUpdate(java.lang.String sql)
Executes a SQL statement using JDBC. |
boolean |
exists(java.lang.Object id)
Exists a given row? |
View |
find(java.lang.String cols,
java.lang.String where)
Select a group of rows. |
View |
find(java.lang.String cols,
java.lang.String where,
java.lang.String order)
Selects a group of rows with order. |
View |
findById(java.lang.Object id)
Selects a row. |
java.lang.String |
genSQL(java.lang.String cols)
Generates an SQL statement (select ... from table) |
java.lang.String |
genSQL(java.lang.String cols,
java.lang.String where)
Generates an SQL statement (select ... from table where ...) |
protected java.lang.String |
genSQL(java.lang.String cols,
java.lang.String where,
java.lang.String order)
Generates an SQL statement (select ... from table where ... order by ...) |
View |
getAll()
Selects all rows in table. |
View |
getAllOrderedBy(java.lang.String orderBy)
Selects all rows in table ordered. |
static java.sql.Connection |
getConnection()
|
int |
getCount()
Gets number of rows in table (select count(*) from table) |
int |
getMaxId()
Gets maximum identifier in table. |
java.lang.String |
getPK()
Returns identifier column name |
java.sql.PreparedStatement |
getPrepared(java.lang.String name)
Returns a prepared statement |
java.lang.String |
getTableName()
Returns table name |
ResultSetView |
insertMode()
Returns an updatable view with one row that can be updated and then inserted into table with insertRow |
ResultSetView |
insertMode(java.lang.Object id)
Returns an updatable view with one row that can be updated and then inserted into table with insertRow |
ResultSetModel |
loopMode()
Prepares this model for generating a scrollable, read only resultset the next time a query will be executed. |
ResultSetModel |
prepare(int type,
int concur)
Sets the features for the next resultset generated by this model |
void |
prepareStatements()
Creates prepared statements if any. |
ResultSetModel |
rowMode()
Prepares this model for generating a forward only, read only resultset the next time a query will be executed. |
void |
update(java.lang.String set,
java.lang.Object id)
Executes a update query (update table set ... where id = ...) |
ResultSetModel |
updateMode()
Prepares this model for generating a scrollable, updatale resultset the next time a query will be executed. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static int logLevel
protected int RSType
ResultSetModel#rowMode(RequestRuntime),
ResultSetModel#loopMode(RequestRuntime)protected int RSConcur
ResultSetModel#updateMode(RequestRuntime)protected java.lang.String idName
protected DBTableData.Table table
protected java.util.Hashtable prepared
protected java.lang.String preparedTableId
| Constructor Detail |
|---|
public ResultSetModel()
public ResultSetModel(java.lang.String tableName,
java.lang.String idName)
tableName - Name of the tableidName - Name of identifier column| Method Detail |
|---|
public final java.lang.String getPK()
public final java.lang.String getTableName()
public static final java.sql.Connection getConnection()
public final ResultSetModel rowMode()
public final ResultSetModel loopMode()
public final ResultSetModel updateMode()
ResultSetView.updateRow()
public ResultSetModel prepare(int type,
int concur)
vm - Runtimetype - JDBC Resultset scroll typeconcur - JDBC Resultset concurrency
public final ResultSetView insertMode()
throws java.sql.SQLException
java.sql.SQLExceptionResultSetView.insertRow()
public final ResultSetView insertMode(java.lang.Object id)
throws java.lang.Exception
id - Identifier for the new row
java.lang.ExceptionResultSetView.insertRow()public View doQuery(java.lang.String sql)
sql - SQL statement to execute
public void doUpdate(java.lang.String sql)
sql - SQL statement to execute
public final void update(java.lang.String set,
java.lang.Object id)
set - update list of sets (column1=val1, columns2=val2 ...)id - Identifier value of row to be updatedpublic final java.lang.String genSQL(java.lang.String cols)
cols - Colums to be selected
public final java.lang.String genSQL(java.lang.String cols,
java.lang.String where)
cols - Colums to be selectedwhere - Where clauses
protected final java.lang.String genSQL(java.lang.String cols,
java.lang.String where,
java.lang.String order)
cols - Colums to be selectedwhere - Where clausesorder - Order by part of SQL statement
public void delete(java.lang.Object id)
id - Identifier value of row to be deletedpublic final void deleteBy(java.lang.String by)
by - Where clause that selects rows to be deletedpublic final void deleteAll()
public View findById(java.lang.Object id)
id - Identifier of row to be selected
public final View find(java.lang.String cols,
java.lang.String where)
cols - Cols to be selectedwhere - Where clause that defines rows to be selected
public final View find(java.lang.String cols,
java.lang.String where,
java.lang.String order)
cols - Cols to be selectedwhere - Where clause that defines rows to be selectedorder - Order part of SQL statement
public final View getAll()
public final View getAllOrderedBy(java.lang.String orderBy)
public final int getCount()
throws java.lang.Exception
vm - A RequestRuntime instance
java.lang.Exception
public final int getMaxId()
throws java.lang.Exception
vm - A RequestRuntime instance
java.lang.Exception
public final boolean exists(java.lang.Object id)
throws java.lang.Exception
id - Value of identifier column
java.lang.Exceptionpublic void prepareStatements()
public final void addPrepared(java.lang.String name,
java.lang.String sql)
name - Name for this prepared statementsql - SQL Statement to preparepublic final java.sql.PreparedStatement getPrepared(java.lang.String name)
name - Name of prepared statement
public final void clearPrepared()
public View doPrepared(java.lang.String name,
java.lang.Object[] obj)
name - Name of prepared statement previosly crated with addPreparedobj - Array of objects to be set in statement. Use ResultSetView.NULL
for setting a null value into the statement.
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||