R
- class type which contains members for columns of a row in a tablepublic class ScalarSelectOperation<R> extends SqlOperation<R> implements java.lang.Iterable<R>
Collection
objects.Constructor and Description |
---|
ScalarSelectOperation(Table<R> table)
Constructs standard sql select by primary key as:
SELECT c1, c2, c3, ... |
ScalarSelectOperation(Table<R> table,
java.lang.String whereConditionName)
Constructs standard sql select by primary key as:
SELECT c1, c2, c3, ... |
Modifier and Type | Method and Description |
---|---|
<F> void |
addFilter(java.lang.Class<F> rowClass,
java.util.function.BiPredicate<F,java.lang.Boolean> filterPredicate)
Adds a filter to use for a row type.
|
void |
close()
Cleans up after operation is no longer needed.
|
void |
execute()
Performs query.
|
java.util.Map<java.lang.Class<?>,java.util.function.BiPredicate<?,java.lang.Boolean>> |
getFilterPredicateMap()
Gets all filters defined for this operation.
|
int |
getMaximumRowsRead()
Gets the maximum number of rows to read from result set.
|
java.lang.String |
getOrderByName()
Gets order by name that was set with
setOrderBy(String) . |
protected OrderByTranslator<R> |
getOrderByTranslator()
Gets the
OrderByTranslator . |
protected java.sql.ResultSet |
getResultSet()
Gets the result set of the most recent select.
|
int |
getRowsReadCount()
Gets the count of rows that were read since the most recent
execute() . |
protected java.lang.String |
getSql()
Gets full sql statement to prepare.
|
protected void |
initBaseSql()
Sets the base sql with
SqlOperation.setBaseSql(String) . |
boolean |
isExecuted()
Indicates if
execute() has been invoked. |
boolean |
isLazySelectsCascades()
Reports that operation has at least one field with
SelectCascade.lazy() true. |
boolean |
isNotifyLazySelects()
Reports that
isLazySelectsCascades() is true and row is instance of LazySelectable . |
java.util.Iterator<R> |
iterator()
Creates iterator for results of this operation.
|
void |
positionAbsolute(int rowNumber)
Positions the result set cursor to a specific row.
|
void |
positionRelative(int rowOffset)
Positions the result set cursor to a row relative to the current row.
|
protected void |
postRead(R row)
Invoked after reading columns into row.
|
protected void |
postReadCascade(R row)
Invoked after reading row.
|
protected java.util.List<CascadeOperation<R,?>> |
prepareCascades(java.lang.reflect.Field field)
Creates and prepares cascade operations based upon cascade annotations for a field.
|
protected void |
preRead(R row)
Invoked prior to reading columns into row.
|
protected void |
preReadCascade(R row)
Invoked prior to reading row.
|
R |
readNext()
Reads next row from current result set.
|
<F> void |
removeFilter(java.lang.Class<F> rowClass)
Removes a filter that was previously added with
addFilter(Class, BiPredicate) . |
void |
resetRowsReadCount()
Sets the number of rows read to zero.
|
R |
select(java.lang.Object... parameters)
Set parameters, executes, reads one row, closes.
|
R |
select(R whereParameters)
Set parameters, executes, reads one row, closes.
|
void |
setFilterPredicateMap(java.util.Map<java.lang.Class<?>,java.util.function.BiPredicate<?,java.lang.Boolean>> filterPredicateMap)
Sets all filters defined for this operation and lower level cascades.
|
void |
setMaximumRowsRead(int maximumRowsRead)
Sets the maximum number of rows to read from result set.
|
void |
setOrderBy(java.lang.String orderByName)
Sets order of results in list.
|
protected void |
setOrderByTranslator(OrderByTranslator<R> orderByTranslator)
Sets the
OrderByTranslator that creates the sql "order by" phrase based upon
the OrderBy annotations. |
void |
setParameters(java.lang.Object... parameters)
Sets any parameters to be used by operation.
|
void |
setRowParameters(R rowParameters)
Set parameters using values from a row object.
|
protected boolean |
updateActiveFilterPredicate(java.lang.Class<?> rowClass,
java.util.function.BiPredicate<?,java.lang.Boolean> filterPredicate)
Tests if filterPredicate parameter is to be used for this operation.
|
cancel, cascade, closeCascades, closeStatement, createRowField, getBaseSql, getCascadeDepth, getConnection, getCustomSql, getNamedParameterMap, getNextParameter, getOperationTime, getParameter, getParameters, getPreparedSql, getPreparedStatement, getQueryTimeout, getRequiredCascades, getTable, getTargetTable, getTimingId, getWhereAnnotation, getWhereConditionName, getWhereTranslator, initOperationTime, isCached, isCascade, isCascading, isIncludeIdentityColumns, isPrimaryKey, isReadOnly, isRequiredCascade, isTimings, logTimings, prepare, prepareCascades, prepareCheck, prepareStatement, setBaseSql, setCached, setCascade, setCascadeDepth, setCustomSql, setIncludeIdentityColumns, setNamedParameterMap, setNextParameter, setParameter, setQueryTimeout, setReadOnly, setRequiredCascades, setTimingId, setTimings, setWhere, setWhereTranslator, writeColumns, writeParameter, writeParameters, writeWhere
public ScalarSelectOperation(Table<R> table) throws OperationException
table
- select from this tableOperationException
- if errorpublic ScalarSelectOperation(Table<R> table, java.lang.String whereConditionName) throws OperationException
table
- select from this tablewhereConditionName
- name of where condition to use ("primaryKey" to select
by primary key; empty string to select all rows in table)OperationException
- if errorpublic java.util.Iterator<R> iterator()
iterator
in interface java.lang.Iterable<R>
SelectIterator
public int getMaximumRowsRead()
Integer.MAX_VALUE
.Integer.MAX_VALUE
public void setMaximumRowsRead(int maximumRowsRead)
readNext()
and
SelectOperation.readAll()
. Limiting rows read is useful to avoid
reading too many rows and thus creating memory or display problems.maximumRowsRead
- 0..Integer.MAX_VALUE
public int getRowsReadCount()
execute()
.public void resetRowsReadCount()
setMaximumRowsRead(int)
has been
used to limit the number of rows, some rows have already been read, and you would like to reset
the counting of maximum number of rows. For example, after a page of rows is read.public void setRowParameters(R rowParameters)
setParameters(Object...)
.rowParameters
- where parameters are read from this object using fields defined by
Where
or the primary key defined by Column.primaryKey()
,
Column.identity()
, or Row.primaryKeyFields()
.public void setParameters(java.lang.Object... parameters)
Column.primaryKey()
or Where
annotation
or Row.primaryKeyFields()
.setParameters
in class SqlOperation<R>
parameters
- parameters as objects (not from row fields)public void execute() throws OperationException
readNext()
to get the next row selected.execute
in class SqlOperation<R>
OperationException
- if errorpublic boolean isExecuted()
execute()
has been invoked.public void close() throws OperationException
CascadeOperation
objects. This method should
be invoked when operation is no longer needed for proper JDBC clean up.close
in interface java.lang.AutoCloseable
close
in class SqlOperation<R>
OperationException
- if errorpublic void positionAbsolute(int rowNumber) throws OperationException
rowNumber
- the number of the row to which the cursor should move. A value of zero indicates that the cursor will be
positioned before the first row; a positive number indicates the row number counting from the beginning of the result set;
a negative number indicates the row number counting from the end of the result setOperationException
- if errorResultSet.absolute(int)
public void positionRelative(int rowOffset) throws OperationException
rowOffset
- - the number of rows to move from the current row; a positive number moves the cursor forward;
a negative number moves the cursor backwardOperationException
- if errorResultSet.relative(int)
public R readNext() throws OperationException
OperationException
- if errorpublic void setOrderBy(java.lang.String orderByName) throws OperationException
orderByName
- name of order phrase to use as defined in OrderBy.name()
in OrderBy
annotation on row R; use empty string for no orderingOperationException
- if errorpublic java.lang.String getOrderByName()
setOrderBy(String)
.public R select(java.lang.Object... parameters) throws OperationException
Since this class implements AutoCloseable
, you may see resource leak
warning when you use this method. You can ignore it, add a suppress annotation,
explicitly close, or close with a try-with-resources statement. Closing an operation
more than once will not cause problems since the close methods are idempotent.
parameters
- query parameters as objects (see setParameters(Object...)
)readNext()
OperationException
- if errorpublic R select(R whereParameters) throws OperationException
Since this class implements AutoCloseable
, you may see resource leak
warning when you use this method. You can ignore it, add a suppress annotation,
explicitly close, or close with a try-with-resources statement. Closing an operation
more than once will not cause problems since the close methods are idempotent.
whereParameters
- query parameters are read from an existing row object
(see setRowParameters(Object)
)readNext()
OperationException
- if errorpublic boolean isLazySelectsCascades()
SelectCascade.lazy()
true. This
status is set during SqlOperation.prepare()
.public boolean isNotifyLazySelects()
isLazySelectsCascades()
is true and row is instance of LazySelectable
. This is
set as an optimization so the readNext()
only tests a boolean to know when to invoke
LazySelectable.pendingLazySelects(org.sormula.Database)
.LazySelectable.pendingLazySelects(org.sormula.Database)
will be inovked for each row selectedpublic <F> void addFilter(java.lang.Class<F> rowClass, java.util.function.BiPredicate<F,java.lang.Boolean> filterPredicate)
It is tested up to two times. It is always tested immediately after it is read. It is tested a second time if the row has cascades after all cascades have been performed on the row.
An example use:
All filters that here are automatically added to lower level cascades when the operation is prepared. The purpose of this is so that a top-level select operation can define filters for any/all lower level cascaded row types.SelectOperation<Order.class> op = ... op.addFilter(Order.class, (order, cascadesCompleted) -> { if (!cascadesCompleted) { // tests prior to cascades return ... } else { // tests after cascades return ... } });
F
- row type to filterrowClass
- type of row to testfilterPredicate
- predicate to perform the testpublic <F> void removeFilter(java.lang.Class<F> rowClass)
addFilter(Class, BiPredicate)
.F
- row type to filterrowClass
- remove filter defined for this row classpublic java.util.Map<java.lang.Class<?>,java.util.function.BiPredicate<?,java.lang.Boolean>> getFilterPredicateMap()
public void setFilterPredicateMap(java.util.Map<java.lang.Class<?>,java.util.function.BiPredicate<?,java.lang.Boolean>> filterPredicateMap)
filterPredicateMap
- map of row class to filterprotected boolean updateActiveFilterPredicate(java.lang.Class<?> rowClass, java.util.function.BiPredicate<?,java.lang.Boolean> filterPredicate)
rowClass
- row class that is to use filterPredicatefilterPredicate
- filterrowTranslator
)
or if rowClass is Object.class (indicates that filter is to be used for all row types)protected OrderByTranslator<R> getOrderByTranslator()
OrderByTranslator
. See setOrderByTranslator(OrderByTranslator)
for details.protected void setOrderByTranslator(OrderByTranslator<R> orderByTranslator)
OrderByTranslator
that creates the sql "order by" phrase based upon
the OrderBy
annotations. Default is null. Set by setOrderBy(String)
.orderByTranslator
- order translator or null if no ordering desiredprotected java.lang.String getSql()
getSql()
.getSql
in class SqlOperation<R>
SqlOperation.prepare()
protected java.sql.ResultSet getResultSet()
protected void initBaseSql()
SqlOperation.setBaseSql(String)
.protected void preRead(R row)
row
- row that will get column values from tableprotected void postRead(R row)
row
- row that got column values from tableprotected void preReadCascade(R row) throws OperationException
SelectCascade.post()
is false.row
- row that will get column values from tableOperationException
- if errorprotected void postReadCascade(R row) throws OperationException
SelectCascade.post()
is true.row
- row that got column values from tableOperationException
- if errorprotected java.util.List<CascadeOperation<R,?>> prepareCascades(java.lang.reflect.Field field) throws OperationException
prepareCascades
in class SqlOperation<R>
field
- annotation is for this field of row class ROperationException
- if error