|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.core.AbstractQuery
abstract class AbstractQuery
An abstract implementation of the Query
interface. This class
implements all methods and also adds protected methods for generating the
main and count queries. Implementors extending this class only needs
to add methods for executing the query.
Field Summary | |
---|---|
private Map<Class<?>,AutoJoiner<?,?>> |
autoJoiners
|
private static boolean |
debugEnabled
So we don't always have to call logSql.debug() |
private boolean |
distinct
If the query should only return the same item once or not. |
private int |
firstResult
The index of the first result that should be returned by the query. |
private List<Expression> |
groups
List of group expressions added to the query. |
private boolean |
hasAutoJoined
|
private List<Restriction> |
havings
List of having restrictions added to the query. |
private static Object |
HOLDER
|
private boolean |
isCounting
If the Query.count(DbControl) method is executing or not. |
private List<Join> |
joins
List of joins added to the query. |
private static Logger |
logSql
Log all SQL statements. |
private int |
maxResults
The maximum number of items that should be returned by the query. |
private List<Order> |
orders
List of orders added to the query. |
private Map<String,QueryParameter> |
parameters
Parameters values added to the query. |
private List<Expression> |
permanentGroups
List of permanent group expressions added to the query. |
private List<Restriction> |
permanentHavings
List of permanent having restrictions added to the query. |
private List<Join> |
permanentJoins
List of permanent joins added to the query. |
private List<Order> |
permanentOrders
List of permanent orders added to the query. |
private List<Restriction> |
permanentRestrictions
List of permanent restrictions added to the query. |
private List<Select> |
permanentSelects
List of permanent selections added to the query. |
private QuerySection |
querySection
The section of the query that is currently beeing built. |
private List<Restriction> |
restrictions
List of restrictions added to the query. |
private boolean |
returnTotalCount
If the query should calculate the total number of matching items in the case that limits have been set with firstResult
or maxResults . |
private String |
rootEntity
The root enitity. |
private List<Select> |
selects
List of selections added to the query. |
private List<Join> |
temporaryJoins
Tempoarary joins, that are automatically cleared after each build. |
private List<Select> |
temporarySelects
Tempoarary selections, that are automatically cleared after each build. |
private List<String> |
thetaJoinConditions
Temporary list to hold theta join conditions if needed by the database. |
Constructor Summary | |
---|---|
AbstractQuery(String rootEntity)
Create a new query. |
Method Summary | |
---|---|
void |
addAutoJoiner(AutoJoiner<?,?> autoJoiner)
|
private void |
addChildElements(Map<QueryElement,Object> all,
QueryElement root)
|
private int |
appendGroups(StringBuilder ql,
DbControl dc,
List<Expression> groups,
int alreadyAppended)
|
private int |
appendHavings(StringBuilder ql,
DbControl dc,
List<Restriction> havings,
int alreadyAppended)
|
private int |
appendJoins(StringBuilder ql,
DbControl dc,
List<Join> joins,
boolean useThetaJoin,
int alreadyAppended)
|
private int |
appendOrders(StringBuilder ql,
DbControl dc,
List<Order> orders,
int alreadyAppended)
|
private int |
appendRestrictions(StringBuilder ql,
DbControl dc,
List<Restriction> restrictions,
int alreadyAppended)
|
private int |
appendSelects(StringBuilder ql,
DbControl dc,
List<Select> selects,
int alreadyAppended)
|
private void |
autoJoin()
|
(package private) String |
getCountQuery(DbControl dc,
boolean autoJoin)
Build the query string for returning the total count. |
int |
getFirstResult()
The number of the row the query should start returning. |
(package private) String |
getMainQuery(DbControl dc,
boolean autoJoin)
Build the main query string. |
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. |
(package private) Map<String,QueryParameter> |
getParameters()
Get all query parameters. |
(package private) Type |
getParameterType(String name)
Get the type of the parameter, or null if not known. |
(package private) Object |
getParameterValue(String name)
Get the value of the named parameter. |
(package private) List<Select> |
getPermanentSelects()
Get all permanent selects. |
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. |
(package private) List<Select> |
getSelects()
Get all non-permanent selects. |
void |
group(Expression expression)
Add an expression query element to the group list. |
void |
groupPermanent(Expression expression)
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 restriction)
Add a restriction query element to the having list. |
void |
havingPermanent(Restriction restriction)
Permanently add a restriction query element to the having list. |
boolean |
isCounting()
Check if the query is executing the Query.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 join)
Add a join query element to the join list. |
void |
joinPermanent(Join join)
Permanently add a join query element to the join list. |
void |
order(Order order)
Add an ordering query element to the orderby list. |
void |
orderPermanent(Order order)
Permanently add an ordering query element to the orderby list. |
protected String |
postProcessQuery(String query)
Allows a subclass to modify the query. |
void |
reset()
Resets the query, allowing you to add more restrictions, joins, order objects and parameters. |
(package private) void |
resetTemporary()
|
void |
restrict(Restriction restriction)
Add a restriction query element to the restriction list. |
void |
restrictPermanent(Restriction restriction)
Permanently add a restriction query element to the restriction list. |
void |
select(Select select)
Add a selection query element to the selection list. |
void |
selectPermanent(Select select)
Permanently add a selection query element to the selection list. |
(package private) void |
setCounting(boolean isCounting)
Set the counting status of the query. |
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. |
private void |
setParameter(String name,
boolean permanent,
Object value,
Type valueType)
|
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 Query.setFirstResult(int)
and Query.setMaxResults(int) had been disabled, or if the results are
loaded by an iterator where the number of rows not are known beforehand. |
(package private) void |
temporaryJoin(Join join)
|
(package private) void |
temporarySelect(Select select)
|
String |
toQl(DbControl dc)
Generate the query string that is going to be sent to the underlying query system (eg. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface net.sf.basedb.core.query.Query |
---|
count, getQueryType, getRootAlias |
Field Detail |
---|
private static final Logger logSql
private static final boolean debugEnabled
private boolean hasAutoJoined
private Map<Class<?>,AutoJoiner<?,?>> autoJoiners
private List<Select> selects
private List<Select> permanentSelects
private List<Select> temporarySelects
private final String rootEntity
private List<Join> joins
private List<Join> permanentJoins
private List<Join> temporaryJoins
private List<Restriction> restrictions
private List<Restriction> permanentRestrictions
private List<Expression> groups
private List<Expression> permanentGroups
private List<Restriction> havings
private List<Restriction> permanentHavings
private List<Order> orders
private List<Order> permanentOrders
private Map<String,QueryParameter> parameters
private int firstResult
private int maxResults
private boolean returnTotalCount
firstResult
or maxResults
.
private boolean distinct
private List<String> thetaJoinConditions
private boolean isCounting
Query.count(DbControl)
method is executing or not.
private QuerySection querySection
private static final Object HOLDER
Constructor Detail |
---|
AbstractQuery(String rootEntity)
rootEntity
- The root entity of the queryMethod Detail |
---|
public void addAutoJoiner(AutoJoiner<?,?> autoJoiner) throws InvalidDataException
addAutoJoiner
in interface Query
InvalidDataException
public void select(Select select) throws InvalidDataException, BaseException
Query
select
in interface Query
select
- The query element to add
InvalidDataException
BaseException
Query.selectPermanent(Select)
public void selectPermanent(Select select) throws InvalidDataException, BaseException
Query
Query.reset()
method.
selectPermanent
in interface Query
select
- The query element to add
InvalidDataException
BaseException
Query.select(Select)
public void join(Join join) throws InvalidDataException, BaseException
Query
join
in interface Query
join
- The query element to add
InvalidDataException
BaseException
Query.joinPermanent(Join)
public void joinPermanent(Join join) throws InvalidDataException, BaseException
Query
Query.reset()
method.
joinPermanent
in interface Query
join
- The query element to add
InvalidDataException
BaseException
Query.join(Join)
public void restrict(Restriction restriction) throws InvalidDataException, BaseException
Query
restrict
in interface Query
restriction
- The query element to add
InvalidDataException
BaseException
Query.restrictPermanent(Restriction)
public void restrictPermanent(Restriction restriction) throws InvalidDataException, BaseException
Query
Query.reset()
method.
restrictPermanent
in interface Query
restriction
- The query element to add
InvalidDataException
BaseException
Query.restrict(Restriction)
public void group(Expression expression) throws InvalidDataException, BaseException
Query
group
in interface Query
expression
- The query element to add
InvalidDataException
BaseException
Query.groupPermanent(Expression)
public void groupPermanent(Expression expression) throws InvalidDataException, BaseException
Query
Query.reset()
method.
groupPermanent
in interface Query
expression
- The query element to add
InvalidDataException
BaseException
Query.group(Expression)
public void having(Restriction restriction) throws InvalidDataException, BaseException
Query
having
in interface Query
restriction
- The query element to add
InvalidDataException
BaseException
Query.havingPermanent(Restriction)
public void havingPermanent(Restriction restriction) throws InvalidDataException, BaseException
Query
Query.reset()
method.
havingPermanent
in interface Query
restriction
- The query element to add
InvalidDataException
BaseException
Query.having(Restriction)
public void order(Order order) throws InvalidDataException, BaseException
Query
order
in interface Query
order
- The query element to add
InvalidDataException
BaseException
Query.orderPermanent(Order)
public void orderPermanent(Order order) throws InvalidDataException, BaseException
Query
Query.reset()
method.
orderPermanent
in interface Query
order
- The query element to add
InvalidDataException
BaseException
Query.order(Order)
private void setParameter(String name, boolean permanent, Object value, Type valueType)
public void setParameter(String name, Object value, Type valueType) throws InvalidDataException, BaseException
Query
Query.setPermanentParameter(String, Object, Type)
method, an InvalidDataException
is thrown.
setParameter
in interface Query
name
- The name of the parametervalue
- The value of the parametervalueType
- The type of the value, or null if not needed
InvalidDataException
- If the value of the parameter has already
been permanently set
BaseException
Query.setPermanentParameter(String, Object, Type)
public void setPermanentParameter(String name, Object value, Type valueType) throws InvalidDataException, BaseException
Query
InvalidDataException
is thrown.
setPermanentParameter
in interface Query
name
- The name of the parametervalue
- The value of the parametervalueType
- The type of the value, or null if not needed
InvalidDataException
- If the value of the parameter has already
been permanently set
BaseException
Query.setParameter(String, Object, Type)
public boolean hasParameterValue(String name)
Query
hasParameterValue
in interface Query
public Set<String> getParameterNames()
Query
getParameterNames
in interface Query
public QueryParameter getQueryParameter(String name)
Query
getQueryParameter
in interface Query
name
- The name of the parameter
public void setFirstResult(int firstResult)
Query
Query.setMaxResults(int)
option.
setFirstResult
in interface Query
firstResult
- The number of the first row starting at 0Query.setMaxResults(int)
public int getFirstResult()
Query
getFirstResult
in interface Query
Query.setFirstResult(int)
public void setMaxResults(int maxResults)
Query
Query.setFirstResult(int)
option.
setMaxResults
in interface Query
maxResults
- The maximum number of rows to returnQuery.setFirstResult(int)
public int getMaxResults()
Query
getMaxResults
in interface Query
Query.setMaxResults(int)
public void setReturnTotalCount(boolean flag)
Query
Query.setFirstResult(int)
and Query.setMaxResults(int)
had been disabled, or if the results are
loaded by an iterator where the number of rows not are known beforehand.
setReturnTotalCount
in interface Query
flag
- TRUE if the query should return the total count, FALSE otherwisepublic boolean isReturningTotalCount()
Query
isReturningTotalCount
in interface Query
Query.setReturnTotalCount(boolean)
public void setDistinct(boolean flag)
Query
setDistinct
in interface Query
flag
- TRUE if the query should return distinct results, FALSE otherwisepublic boolean isDistinct()
Query
isDistinct
in interface Query
Query.setDistinct(boolean)
public boolean isReadonly()
Query
Query.reset()
would unlock the query and allow it to be modified again.
isReadonly
in interface Query
public void reset()
reset
in interface Query
public boolean isCounting()
Query
Query.count(DbControl)
method or not
isCounting
in interface Query
count
method, FALSE otherwisepublic QuerySection getQuerySection()
Query
QueryElement
:s if they need
different syntax in different sections.
getQuerySection
in interface Query
public String toQl(DbControl dc)
Query
toQl
in interface Query
dc
- The DbControl that is going to be used for
executing the query
public String toString()
toString
in class Object
void setCounting(boolean isCounting)
void temporarySelect(Select select) throws InvalidDataException, BaseException
InvalidDataException
BaseException
void temporaryJoin(Join join) throws InvalidDataException, BaseException
InvalidDataException
BaseException
void resetTemporary()
List<Select> getSelects()
List<Select> getPermanentSelects()
Map<String,QueryParameter> getParameters()
Object getParameterValue(String name)
name
- The name of the parameter
Type getParameterType(String name)
String getMainQuery(DbControl dc, boolean autoJoin) throws BaseException
BaseException
String getCountQuery(DbControl dc, boolean autoJoin) throws BaseException
BaseException
protected String postProcessQuery(String query)
private int appendSelects(StringBuilder ql, DbControl dc, List<Select> selects, int alreadyAppended) throws BaseException
BaseException
private int appendJoins(StringBuilder ql, DbControl dc, List<Join> joins, boolean useThetaJoin, int alreadyAppended) throws BaseException
BaseException
private int appendRestrictions(StringBuilder ql, DbControl dc, List<Restriction> restrictions, int alreadyAppended) throws BaseException
BaseException
private int appendGroups(StringBuilder ql, DbControl dc, List<Expression> groups, int alreadyAppended) throws BaseException
BaseException
private int appendHavings(StringBuilder ql, DbControl dc, List<Restriction> havings, int alreadyAppended) throws BaseException
BaseException
private int appendOrders(StringBuilder ql, DbControl dc, List<Order> orders, int alreadyAppended) throws BaseException
BaseException
private void autoJoin()
private void addChildElements(Map<QueryElement,Object> all, QueryElement root)
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |