| java.lang.Object simpleorm.core.SPreparedStatement
SPreparedStatement | public class SPreparedStatement (Code) | | This class represents a SimpleORM prepared query statement. It is
analagous to the JDBC prepared statement.
The general flow of a query goes as follows:-
SPreparedStatement stmt = Employee.meta.select("SALARY > ?", "NAME");
// SELECT FROM XX_EMPLOYEE
// WHERE SALARY > ? ORDER BY NAME
stmt.setInt(1, 50000);
SResultSet res = stmt.execute();
while (res.hasNext()) {
Employee emp = res.getRecord();
emp.getString(Employee.NAME);
}
To avoid a brittle structure with an ever growing number of parameters
to SPreparedStatement, the objects now created in two steps one to
create the object and set parameters. To utilize this use the following style instead:-
SPreparedStatement limitps = new SPreparedStatement();
limitps.setOffset(1);
limitps.setLimit(1);
SResultSet limitR = Employee.meta.newQuery()
.ascending(Employee.EMPEE_ID)
.execute(limitps);
// Employee.meta.Select(limitps,...)
## This uses of the SPreparedStatement seems a little odd. Maybe newQuery(limitps) would
be better, and also use newSPreparedStatement(Employee.meta...) instead of Select. Mabye.
But definitely do not want to create a Properties object one per query.
|
Method Summary | |
public void | close() | public SResultSet | execute() Execute the query having set "?" paramenters. | public boolean | getDistinct() | public PreparedStatement | getJDBCPreparedStatement() Retrieves the underlying JDBC PreparedStatement object.
Dangerous. | public SRecordMeta[] | getJoinTables() | public long | getLimit() | public long | getOffset() Offset and Limit reduce the number of rows retrieved. | public String | getSQL() | protected void | prepareStatement(SRecordMeta meta, String where, String orderBy, long sqy_bitSet, SFieldMeta[] selectList) | public void | setBigDecimal(int parameterIndex, BigDecimal value) | public void | setDate(int parameterIndex, java.util.Date value) See
SRecordInstance.setTimestamp for discussion of Date parameter. | public void | setDistinct(boolean jts) | public void | setDouble(int parameterIndex, double value) | public void | setInt(int parameterIndex, int value) | public void | setJoinTables(SRecordMeta[] jts) | public void | setLimit(long lim) | public void | setLong(int parameterIndex, long value) | public void | setObject(int parameterIndex, Object value) | public void | setOffset(long off) | public void | setString(int parameterIndex, String value) value replaces the parameterIndexth
"?" in the query. | public void | setTime(int parameterIndex, java.util.Date value) See
SRecordInstance.setTimestamp for discussion of Date parameter. | public void | setTimestamp(int parameterIndex, java.util.Date value) See
SRecordInstance.setTimestamp for discussion of Date parameter. | public String | toString() |
distinct | boolean distinct(Code) | | |
optimistic | boolean optimistic(Code) | | |
readOnly | boolean readOnly(Code) | | |
unrepeatableRead | boolean unrepeatableRead(Code) | | |
SPreparedStatement | public SPreparedStatement()(Code) | | |
execute | public SResultSet execute()(Code) | | Execute the query having set "?" paramenters.
|
getDistinct | public boolean getDistinct()(Code) | | Select DISTINCT
|
getJDBCPreparedStatement | public PreparedStatement getJDBCPreparedStatement()(Code) | | Retrieves the underlying JDBC PreparedStatement object.
Dangerous. The authors can see no reason why this would ever
need to be used but it is provided for completeness.
|
getLimit | public long getLimit()(Code) | | see limit
|
getOffset | public long getOffset()(Code) | | Offset and Limit reduce the number of rows retrieved. My be
implemented efficiently by the database, or just by skipping
ahead during execute. Semantics are not that well defined
between transactions, rows may be missed. Useful for paging out
query results.
Note that if offset = 2 and limit = 5, the rows 0 and 1 are
skipped, and rows 2..6 are returned.
|
setBigDecimal | public void setBigDecimal(int parameterIndex, BigDecimal value)(Code) | | |
setDistinct | public void setDistinct(boolean jts)(Code) | | |
setDouble | public void setDouble(int parameterIndex, double value)(Code) | | |
setInt | public void setInt(int parameterIndex, int value)(Code) | | |
setLimit | public void setLimit(long lim)(Code) | | |
setLong | public void setLong(int parameterIndex, long value)(Code) | | |
setObject | public void setObject(int parameterIndex, Object value)(Code) | | |
setOffset | public void setOffset(long off)(Code) | | |
setString | public void setString(int parameterIndex, String value)(Code) | | value replaces the parameterIndexth
"?" in the query. The first "?" is 1, not 0.
Analagous to jdbc PreparedStatement.setString.
|
|
|