|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Query
This defines the simplest form of a relational query. A relational query can be written in the form:
SELECT [DISTINCT] <selection-list> FROM <root-entity> [JOIN <joined-entity>] [WHERE <restrictions>] [GROUP BY <groupby-list] [HAVING <restrictions>] [ORDER BY <orderby-list>]Only the
SELECT
and FROM
query elements are needed,
everything else is optional. The methods in this interface are used to build
the query by adding QueryElement
:s to the query.
All query elements can be either permanent or non-permanent. The difference
is that permanent options are not cleared by the reset()
method.
Query implementations are not required to support all options. If that
is the case a UnsupportedOperationException
should be thrown.
This interface doesn't define any execution methods, because the type of
return object depends on the data that is returned. It is up to the
implementors to define appropriate execution methods. For
example: ItemQuery.list(DbControl)
.
AbstractQuery
Method Summary | |
---|---|
void |
addAutoJoiner(AutoJoiner<?,?> joiner)
|
long |
count(DbControl dc)
Count the number of items/rows that are returned by the query. |
int |
getFirstResult()
The number of the row the query should start returning. |
int |
getMaxResults()
The maximum number of rows returned by the query. |
Set<String> |
getParameterNames()
Get a set with the names for all parameters in this query. |
QueryParameter |
getQueryParameter(String name)
Get parameter information for the parameter with given name. |
QuerySection |
getQuerySection()
Get the current section of the query that is beeing built. |
QueryType |
getQueryType()
Get the type of query. |
String |
getRootAlias()
The alias of the root-entity in the FROM part. |
void |
group(Expression e)
Add an expression query element to the group list. |
void |
groupPermanent(Expression e)
Permanently add an expression query element to the group list. |
boolean |
hasParameterValue(String name)
Check if a value for the specified parameter has been set or not. |
void |
having(Restriction r)
Add a restriction query element to the having list. |
void |
havingPermanent(Restriction r)
Permanently add a restriction query element to the having list. |
boolean |
isCounting()
Check if the query is executing the count(DbControl) method or not |
boolean |
isDistinct()
If this query returns distinct results of not. |
boolean |
isReadonly()
If this query is readonly and cannot be structurally modified. |
boolean |
isReturningTotalCount()
If this query returns the total count or not. |
void |
join(Join j)
Add a join query element to the join list. |
void |
joinPermanent(Join j)
Permanently add a join query element to the join list. |
void |
order(Order o)
Add an ordering query element to the orderby list. |
void |
orderPermanent(Order o)
Permanently add an ordering query element to the orderby list. |
void |
reset()
Reset the query, removing all non-permanent query elements and parameter values. |
void |
restrict(Restriction r)
Add a restriction query element to the restriction list. |
void |
restrictPermanent(Restriction r)
Permanently add a restriction query element to the restriction list. |
void |
select(Select s)
Add a selection query element to the selection list. |
void |
selectPermanent(Select s)
Permanently add a selection query element to the selection list. |
void |
setDistinct(boolean flag)
Specify if the query should only return distinct rows. |
void |
setFirstResult(int firstResult)
Specify that the query should start returning rows from the specified row number. 0 = start returning from the first row. |
void |
setMaxResults(int maxResults)
Specify that the query should at most return the specified number of rows. |
void |
setParameter(String name,
Object value,
Type valueType)
Set the value of a query parameter. |
void |
setPermanentParameter(String name,
Object value,
Type valueType)
Permanently set the value of a query parameter. |
void |
setReturnTotalCount(boolean flag)
Specify if the query should return a count for the total number of items that would have been returned if the setFirstResult(int)
and setMaxResults(int) had been disabled, or if the results are
loaded by an iterator where the number of rows not are known beforehand. |
String |
toQl(DbControl dc)
Generate the query string that is going to be sent to the underlying query system (eg. |
Method Detail |
---|
QueryType getQueryType()
QueryType
enumerationvoid addAutoJoiner(AutoJoiner<?,?> joiner)
void select(Select s)
s
- The query element to add
UnsupportedOperationException
- If this operation isn't supported by
the implementationselectPermanent(Select)
void selectPermanent(Select s)
reset()
method.
s
- The query element to add
UnsupportedOperationException
- If this operation isn't supported by
the implementationselect(Select)
void join(Join j)
j
- The query element to add
UnsupportedOperationException
- If this operation isn't supported by
the implementationjoinPermanent(Join)
void joinPermanent(Join j)
reset()
method.
j
- The query element to add
UnsupportedOperationException
- If this operation isn't supported by
the implementationjoin(Join)
void restrict(Restriction r)
r
- The query element to add
UnsupportedOperationException
- If this operation isn't supported by
the implementationrestrictPermanent(Restriction)
void restrictPermanent(Restriction r)
reset()
method.
r
- The query element to add
UnsupportedOperationException
- If this operation isn't supported by
the implementationrestrict(Restriction)
void group(Expression e)
e
- The query element to add
UnsupportedOperationException
- If this operation isn't supported by
the implementationgroupPermanent(Expression)
void groupPermanent(Expression e)
reset()
method.
e
- The query element to add
UnsupportedOperationException
- If this operation isn't supported by
the implementationgroup(Expression)
void having(Restriction r)
r
- The query element to add
UnsupportedOperationException
- If this operation isn't supported by
the implementationhavingPermanent(Restriction)
void havingPermanent(Restriction r)
reset()
method.
r
- The query element to add
UnsupportedOperationException
- If this operation isn't supported by
the implementationhaving(Restriction)
void order(Order o)
o
- The query element to add
UnsupportedOperationException
- If this operation isn't supported by
the implementationorderPermanent(Order)
void orderPermanent(Order o)
reset()
method.
o
- The query element to add
UnsupportedOperationException
- If this operation isn't supported by
the implementationorder(Order)
void setParameter(String name, Object value, Type valueType)
setPermanentParameter(String, Object, Type)
method, an InvalidDataException
is thrown.
name
- The name of the parametervalue
- The value of the parametervalueType
- The type of the value, or null if not needed
UnsupportedOperationException
- If this operation isn't supported by
the implementation
InvalidDataException
- If the value of the parameter has already
been permanently setsetPermanentParameter(String, Object, Type)
void setPermanentParameter(String name, Object value, Type valueType)
InvalidDataException
is thrown.
name
- The name of the parametervalue
- The value of the parametervalueType
- The type of the value, or null if not needed
UnsupportedOperationException
- If this operation isn't supported by
the implementation
InvalidDataException
- If the value of the parameter has already
been permanently setsetParameter(String, Object, Type)
boolean hasParameterValue(String name)
Set<String> getParameterNames()
QueryParameter getQueryParameter(String name)
name
- The name of the parameter
void setFirstResult(int firstResult)
setMaxResults(int)
option.
firstResult
- The number of the first row starting at 0
UnsupportedOperationException
- If this operation isn't supported by
the implementationsetMaxResults(int)
int getFirstResult()
setFirstResult(int)
void setMaxResults(int maxResults)
setFirstResult(int)
option.
maxResults
- The maximum number of rows to return
UnsupportedOperationException
- If this operation isn't supported by
the implementationsetFirstResult(int)
int getMaxResults()
setMaxResults(int)
void setReturnTotalCount(boolean flag)
setFirstResult(int)
and setMaxResults(int)
had been disabled, or if the results are
loaded by an iterator where the number of rows not are known beforehand.
flag
- TRUE if the query should return the total count, FALSE otherwise
UnsupportedOperationException
- If this operation isn't supported by
the implementationboolean isReturningTotalCount()
setReturnTotalCount(boolean)
void setDistinct(boolean flag)
flag
- TRUE if the query should return distinct results, FALSE otherwiseboolean isDistinct()
setDistinct(boolean)
boolean isReadonly()
reset()
would unlock the query and allow it to be modified again.
void reset()
String getRootAlias()
root-entity
in the FROM
part.
This value is used by the query elements to let a client application
skip specifying the root alias all the time.
Hql.property(String, String)
long count(DbControl dc) throws BaseException
getFirstResult()
and getMaxResults()
settings.
BaseException
- If there is an errorboolean isCounting()
count(DbControl)
method or not
count
method, FALSE otherwiseQuerySection getQuerySection()
QueryElement
:s if they need
different syntax in different sections.
String toQl(DbControl dc)
dc
- The DbControl that is going to be used for
executing the query
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |