Class SQuery<T extends SRecordInstance>
For example:-
This API is a little unusual in that there is only one SQuery instance
created, and each of the methods update its state and then return
this
.
The normal expansion of the query into SQL is performed by SQueryExecute in the SSessionJdbc package. The raw* methods can be used to poke any string into the SQL Where or Order By clauses in the order they appear.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
static class
-
Constructor Summary
ConstructorsConstructorDescriptionSQuery
(SRecordMeta<T> record) SQuery
(SRecordMeta<T> record, SQueryMode queryMode) SQuery
(SRecordMeta<T> record, SQueryMode queryMode, SFieldScalar[] selectList) A new query object that can be .exeuted to produce an SResultSet.SQuery
(SRecordMeta<T> record, SQueryMode queryMode, SSelectMode selectMode) SQuery
(SRecordMeta<T> record, SSelectMode selectMode) -
Method Summary
Modifier and TypeMethodDescriptionascending
(SFieldMeta field) rawOrderBy(field.columnName)
descending
(SFieldMeta field) rawOrderBy(field.columnName) DESC
eq
(SFieldMeta field, Object value) Normally just addsfieldRelopParameter(field, "=", value)
.eq
(SFieldScalar field1, SFieldMeta field2) equivalent
(SFieldBoolean field, boolean value) True if boolean field == writeFieldValue(value).fieldQuery
(SFieldScalar field, String clause) Generatesfield clause
, ie the clause string is poked literally into the query.fieldRelopParameter
(SFieldScalar field, String relop, Object value) Generatesfield relop ?
and then subsequently sets the parameter value.fieldRelopParameter
(SFieldScalar field1, String relop, SFieldScalar field2) Generatesfield1 relop field2
ge
(SFieldScalar field, double value) ge
(SFieldScalar field, int value) ge
(SFieldScalar field, long value) ge
(SFieldScalar field, Object value) Just addsfieldRelopParameter(field, ">=", value)
ge
(SFieldScalar field1, SFieldMeta field2) getJoins()
long
getLimit()
long
getWhere()
gt
(SFieldScalar field, double value) gt
(SFieldScalar field, int value) gt
(SFieldScalar field, long value) gt
(SFieldScalar field, Object value) Just addsfieldRelopParameter(field, ">", value)
gt
(SFieldScalar field1, SFieldMeta field2) in
(SFieldScalar field, Object... values) Use or clause to simulate the in clauseisFalse
(SFieldBoolean field) isNotNull
(SFieldMeta field) Just addsfieldQuery(field, "IS NULL")
isNull
(SFieldMeta field) Just addsfieldQuery(field, "IS NULL")
isTrue
(SFieldBoolean field) shortcut for equivalent(field, true);join
(SFieldReference<?> reference) Join to another table, based on the specified reference that is in the query table.join
(SFieldReference<?> reference, SSelectMode selectMode) le
(SFieldScalar field, double value) le
(SFieldScalar field, int value) le
(SFieldScalar field, long value) le
(SFieldScalar field, Object value) Just addsfieldRelopParameter(field, "<=", value)
le
(SFieldScalar field1, SFieldMeta field2) like
(SFieldScalar field, Object value) Just addsfieldRelopParameter(field, "like", value)
lt
(SFieldScalar field, double value) lt
(SFieldScalar field, int value) lt
(SFieldScalar field, long value) lt
(SFieldScalar field, Object value) Just addsfieldRelopParameter(field, "<", value)
lt
(SFieldScalar field1, SFieldMeta field2) ne
(SFieldMeta field, Object value) Just addsfieldRelopParameter(field, "<>", value)
.ne
(SFieldScalar field1, SFieldMeta field2) Add a join to the join statement.rawOrderBy
(String raw) Add a clause to the OrderBy statement, eg.rawOrderBy
(SFieldMeta field, boolean ascending) rawPredicate
(String predicate, Object... parameters) Add predicate to the where class, eg.Just specifies the entire SQL statement, including the Select.setLimit
(long lim) Set limitsetOffset
(long off) Set offsettoString()
See SSession.queryToString for a fuller print out.
-
Constructor Details
-
SQuery
A new query object that can be .exeuted to produce an SResultSet. -
SQuery
-
SQuery
-
SQuery
-
SQuery
-
-
Method Details
-
getRecordMeta
-
setLimit
Set limit -
getLimit
public long getLimit() -
getOffset
public long getOffset() -
setOffset
Set offset -
rawJoin
Add a join to the join statement. Spaces before and after statement are added systematically. -
rawPredicate
Add predicate to the where class, eg. "BUDGET > ?". Not normally called directly. -
rawOrderBy
Add a clause to the OrderBy statement, eg. "NAME DESC". Commas are added automatically. -
rawOrderBy
-
rawSql
Just specifies the entire SQL statement, including the Select. -
fieldRelopParameter
Generatesfield relop ?
and then subsequently sets the parameter value. Eg.fieldRelopParameter(Employee.Name, "=", myName)
-
fieldRelopParameter
Generatesfield1 relop field2
E.g.
fieldRelopParameter(Order.QuantityRequired, "=", Order.QuantityReceived)
Mainly useful for Joins.
-
fieldQuery
Generatesfield clause
, ie the clause string is poked literally into the query. Eg.fieldQuery(Employee.Name, "= 'Fred'")
Use fieldRelopParameter instead for parameters determined at run time as blindly concatenating strings is dangerous.
-
join
Join to another table, based on the specified reference that is in the query table. This peforms an eager lookup on the referenced tables, so avoiding the N+1 problem.Joins only work from the query table to tables directly liked by the reference. It is not currently possible to join a table to itself (eg. Employee.Manager).
Normally the looked up records are also retrieved, although it is possible to specify selectMode = NONE if the join is only for the WHERE clause.
Currently implemented as Inner joins, but will be fixed to be left outer joins.
Note that this is only useful if the number of joined in records is substantial. For example, if there are 1,000 employees in 10 departments, then it is probably faster (and certainly simpler) to retrieve the departments lazily rather than retrieve the fields for the 10 departments 1000 times and throw them away each time.
Note also that Subselects can be used to reference fields in the where clause without introduing outer join issues.
-
join
-
getJoinTables
-
getJoinFields
-
getSelectList
-
eq
Normally just addsfieldRelopParameter(field, "=", value)
.If field is a reference it recursively expands the foreign keys, and value must be an instance of the same record type.
value must not be null, you need the special case IS NULL test. (It would be possible to optimize this here, but what about field == field where one of them is null -- that would be inconsistent.)
-
eq
-
equivalent
True if boolean field == writeFieldValue(value). Ie. value is converted from bool to "Y"/"N" etc. -
isTrue
shortcut for equivalent(field, true); -
isFalse
-
ne
Just addsfieldRelopParameter(field, "<>", value)
.Note that there are few methods
ne(SfieldMeta, int)
etc. This is because 5 relops * 5 data types would require 25 methods! Java 1.5 boxing will (finally) make this unnecessary anyway. -
ne
-
isNull
Just addsfieldQuery(field, "IS NULL")
-
isNotNull
Just addsfieldQuery(field, "IS NULL")
-
gt
Just addsfieldRelopParameter(field, ">", value)
-
gt
-
gt
-
gt
-
gt
-
lt
Just addsfieldRelopParameter(field, "<", value)
-
lt
-
lt
-
lt
-
lt
-
le
Just addsfieldRelopParameter(field, "<=", value)
-
le
-
le
-
le
-
le
-
ge
Just addsfieldRelopParameter(field, ">=", value)
-
ge
-
ge
-
ge
-
ge
-
in
Use or clause to simulate the in clause -
like
Just addsfieldRelopParameter(field, "like", value)
-
ascending
rawOrderBy(field.columnName)
-
descending
rawOrderBy(field.columnName) DESC
-
toString
See SSession.queryToString for a fuller print out. -
getQueryParameters
-
getJoins
-
getOrderBy
-
getWhere
-
getQueryMode
-
getRawSql
-