|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.tentackle.db.Query
public class Query
A database query.
Combines the generation of an sql-string and parameter set for
the ResultSetWrapper. Useful for one-time queries entered by the user.
Notice that by default the underlying prepared statement is closed
when the resultset (or cursor) is closed by the application.
You can change that behaviour, however.
| Constructor Summary | |
|---|---|
Query()
Creates a query. |
|
| Method Summary | |
|---|---|
void |
add(String sql,
Object... data)
Appends an sql-part and corresponding parameters to this query. |
void |
apply(Db db,
PreparedStatementWrapper st)
Applies the query parameters to the statement. Optionally applies limit, offset as well. |
ResultSetWrapper |
execute(Db db)
Executes the query with ResultSet.TYPE_FORWARD_ONLY and ResultSet.CONCUR_READ_ONLY. |
ResultSetWrapper |
execute(Db db,
int resultSetType)
Executes the query with ResultSet.CONCUR_READ_ONLY. |
ResultSetWrapper |
execute(Db db,
int resultSetType,
int resultSetConcurrency)
Executes the query. |
int |
getEstimatedRowCount(Db db)
Gets the number of objects returned by this query. |
int |
getFetchSize()
Gets the fetchsize. |
int |
getLimit()
Gets the maximum number of rows for this query. |
int |
getMaxRows()
Gets the maximum row count for this cursor |
int |
getOffset()
Gets the offset of this query. |
String |
getSql(Db db)
Gets the SQL-String of this query. Optionally modifies the sql query according to limit and offset. |
boolean |
isCloseStatementOnClose()
Returns whether statement is closed when result set is closed. |
void |
setCloseStatementOnClose(boolean closeStatementOnClose)
Sets whether to close the statement when resultset is closed. |
void |
setFetchSize(int fetchSize)
Sets the optional fetchsize. |
void |
setLimit(int limit)
Sets the maximum number of rows to retrieve for this query. |
void |
setMaxRows(int maxRows)
Sets the optional maximum row count for this cursor. |
void |
setOffset(int offset)
Sets an offset, i.e. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Query()
| Method Detail |
|---|
public void setOffset(int offset)
offset - the offset, 0 to disablepublic int getOffset()
public void setLimit(int limit)
limit - the maximum number of rows, 0 if ulimited (default)public int getLimit()
public void add(String sql,
Object... data)
Example: add(" AND FIELD_ID=?", object.getId());
add(" AND FIELD_MONEY=?", object.getAmount());
sql - is the SQL-stringdata - is an array of parameterspublic void setCloseStatementOnClose(boolean closeStatementOnClose)
closeStatementOnClose - true if statement is closed, false = left openpublic boolean isCloseStatementOnClose()
public void setFetchSize(int fetchSize)
fetchSize - the fetchsizeResultSetWrapper.setFetchSize(int)public int getFetchSize()
ResultSetWrapper.getFetchSize()public void setMaxRows(int maxRows)
maxRows - the max rows, 0 = no limitpublic int getMaxRows()
public ResultSetWrapper execute(Db db,
int resultSetType,
int resultSetConcurrency)
db - is the database connectionresultSetType - is one of ResultSet.TYPE_...resultSetConcurrency - is one of ResultSet.CONCUR_..
public ResultSetWrapper execute(Db db,
int resultSetType)
db - is the database connectionresultSetType - is one of ResultSet.TYPE_...
public ResultSetWrapper execute(Db db)
db - is the database connection
public int getEstimatedRowCount(Db db)
This is not done by retrieving all rows but by a "SELECT COUNT(*)".
Applications may use this in conjunction with limit and offset for pagination
(in web pages, for example).
db - the db connection
public String getSql(Db db)
db - the db connection
public void apply(Db db,
PreparedStatementWrapper st)
db - the database connectionst - the prepared statement
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||