|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.arsdigita.domain.DomainQuery
This is the base class that all other domain query classes
would extend. It provides a facade on to a contained DataQuery.
DataQuery| Field Summary | |
protected DataQuery |
m_dataQuery
|
static String |
versionId
|
| Constructor Summary | |
DomainQuery(DataQuery dataQuery)
Constructor. |
|
DomainQuery(String queryName)
Creates a new domain query based on the named data query. |
|
| Method Summary | |
Filter |
addEqualsFilter(String attribute,
Object value)
This creates the appropriate SQL for the given attribute and passed in value. |
Filter |
addFilter(Filter filter)
This adds the passed in filter to this query and ANDs it with an existing filters. |
Filter |
addFilter(String conditions)
Adds the conditions to the filter that will be used on this query. |
Filter |
addInSubqueryFilter(String propertyName,
String subqueryName)
Highly experimental, for use by permissions service only. |
Filter |
addInSubqueryFilter(String propertyName,
String subQueryProperty,
String queryName)
Add an 'in' subquery to a query. |
Filter |
addNotEqualsFilter(String attribute,
Object value)
This creates the appropriate SQL for the given attribute and passed in value. |
Filter |
addNotInSubqueryFilter(String propertyName,
String subqueryName)
|
void |
addOrder(String order)
Set the order in which the result of this query will be returned. |
void |
addOrderWithNull(String orderOne,
Object orderTwo,
boolean isAscending)
This adds order on the first value if it is not null or the second value if the first value is null. |
void |
addPath(String path)
Adds to the set of paths fetched by this DataQuery. |
void |
alias(String fromPrefix,
String toPrefix)
Alias a compound property name to a different value. |
void |
clearFilter()
Clears the current filter for the data query. |
void |
clearOrder()
Clears the current order clause for the data query. |
void |
close()
Explicitly closes this domain collection. |
boolean |
first()
Moves the cursor to the first object in the collection. |
Object |
get(String propertyName)
Returns the value of the propertyName property associated with the current position in the sequence. |
FilterFactory |
getFilterFactory()
This retrieves the factory that is used to create the filters for this DataQuery |
Object |
getParameter(String parameterName)
Allows a caller to get a parameter value for a parameter that has already been set |
int |
getPosition()
Returns the currect position with the collection. |
Map |
getPropertyValues()
This method returns a map of all property/value pairs. |
CompoundType |
getType()
Returns the type of this data query. |
boolean |
hasProperty(String propertyName)
Returns true if this query fetches the given property. |
boolean |
isAfterLast()
Indicates whether the cursor is after the last row of the query. |
boolean |
isBeforeFirst()
Indicates whether the cursor is before the first row of the query. |
boolean |
isEmpty()
Returns true if the collection has no rows. |
boolean |
isFirst()
Inidicates whether the cursor is on the first object of the collection. |
boolean |
isLast()
Indicates whether the cursor is on the last object of the collection. |
boolean |
last()
Moves the cursor to the last object in the collection. |
boolean |
next()
Moves to the next object in the collection. |
boolean |
previous()
Moves to the previous object in the collection. |
boolean |
removeFilter(Filter filter)
Removes the passed in filter from this query if it was directly added to the query. |
void |
reset()
Returns this collection to its initial state by rewinding it and clearing any filters or ordering. |
void |
rewind()
Rewinds this collection to the beginning, i.e. |
Filter |
setFilter(String conditions)
Deprecated. see addFilter(java.lang.String) |
void |
setOrder(String order)
Deprecated. see addOrder(java.lang.String) |
void |
setParameter(String parameterName,
Object value)
Allows a user to bind a parameter within a named query. |
void |
setRange(Integer beginIndex)
This method allows the developer to set the range of rows desired. |
void |
setRange(Integer beginIndex,
Integer endIndex)
This method allows the developer to set the range of rows desired. |
void |
setReturnsLowerBound(int lowerBound)
This sets the lower bound on the number of rows that can be returned by this query |
void |
setReturnsUpperBound(int upperBound)
This sets the upper bound on the number of rows that can be returned by this query |
long |
size()
Returns the number of rows in this collection. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final String versionId
protected final DataQuery m_dataQuery
| Constructor Detail |
public DomainQuery(DataQuery dataQuery)
DataQuerypublic DomainQuery(String queryName)
queryName - the fully qualified query name| Method Detail |
public boolean hasProperty(String propertyName)
hasProperty in interface DataQuerypropertyName - A property name.
public boolean first()
first in interface DataQueryDataQuery.first()public boolean next()
next in interface DataQueryDataQuery.next()public boolean previous()
previous in interface DataQueryDataQuery.previous()public boolean last()
last in interface DataQueryDataQuery.last()public boolean isFirst()
isFirst in interface DataQueryDataQuery.isFirst()public boolean isLast()
isLast in interface DataQueryDataQuery.isLast()public int getPosition()
getPosition in interface DataQueryDataQuery.getPosition()public boolean isEmpty()
isEmpty in interface DataQueryDataQuery.isEmpty()
public boolean isBeforeFirst()
throws PersistenceException
isBeforeFirst in interface DataQueryPersistenceException
public boolean isAfterLast()
throws PersistenceException
isAfterLast in interface DataQueryPersistenceExceptionpublic void addPath(String path)
DataQuery query = ssn.retrieve("exampleQuery");
query.addPath("foo.bar.name");
query.addPath("foo.bar.desc");
while (query.next()) {
BigInteger id = query.get("foo.bar.id");
String name = query.get("foo.bar.name");
String desc = query.get("foo.bar.desc");
}
addPath in interface DataQuerypath - the additional path to fetchpublic Filter setFilter(String conditions)
addFilter(java.lang.String)
Filter f = query.setFilter("id < :maxId and id > :minId");
f.set("maxId", 10);
f.set("minId", 1);
setFilter in interface DataQueryconditions - the conditions for the filter
public Filter addFilter(String conditions)
select * from (<data query here>) results
where <conditions here>
When adding filters, the user should not use the same parameter name in multiple filters. That is, the following will not work
Filter filter = query.addFilter("priority > :bound");
filter.set("bound", new Integer(3));
filter = query.addFilter("priority < :bound");
filter.set("bound", new Integer(8));
The above actually evaluates to
"priority < 8 and priority > 8"
which is clearly not what the developer wants.
The following will work.
Filter filter = query.addFilter("priority > :lowerBound");
filter.set("lowerBound", new Integer(3));
filter = query.addFilter("priority < :upperBound");
filter.set("upperBound", new Integer(8));
It is actually the same as
Filter filter = query.addFilter("priority > :lowerBound
and priority < :upperBound");
filter.set("upperBound", new Integer(8));
filter.set("lowerBound", new Integer(3));
addFilter in interface DataQueryconditions - The conditions for the filter. This is a string
that should be used to filter the DataQuery. Specifically,
if this is the first filter added, it appends the information
on to a view-on-the-fly. e.g.
select * from (<data query here>) results
where <conditions here>
unless the WRAP_QUERIES option for the DataQuery is set to
"false".
If this is the case, the Filter is simply appended to the end of
the query as follows:
<data query here>)
[where | or] <conditions here>
It should normally take the form of
<attribute_name> <condition> <attribute bind
variable>
where the "condition" is something like "=", "<", ">", or
"!=". The "bind variable" should be a colon followed by
some attribute name that will later be set with a call to
Filter.set(java.lang.String,
java.lang.Object)
It is possible to set multiple conditions with a single addFilter statement by combining the conditions with an "and" or an "or". Conditions may be grouped by using parentheses. Consecutive calls to addFilter append the filters using "and".
If there is already a filter that exists for this query
then the passed in conditions are added to the current
conditions with an AND like (<current conditions>)
and (< passed in conditions>)
public boolean removeFilter(Filter filter)
removeFilter in interface DataQuerypublic Filter addFilter(Filter filter)
addFilter in interface DataQuery
public Filter addInSubqueryFilter(String propertyName,
String subqueryName)
addInSubqueryFilter in interface DataQuerypropertyName - The column to be filtered on.subqueryName - The full name of a query defined in a PDL file.
public Filter addInSubqueryFilter(String propertyName,
String subQueryProperty,
String queryName)
subQueryProperty is the column pulled out of the subquery.
addInSubqueryFilter in interface DataQuerypropertyName - The column to be filtered on.subQueryProperty - The column in the subquery to be used.queryName - The fully name of a query defined in a PDL file.
public Filter addNotInSubqueryFilter(String propertyName,
String subqueryName)
addNotInSubqueryFilter in interface DataQuery
public Filter addEqualsFilter(String attribute,
Object value)
attribute
= 'value.toString()'" unless the value is an integer
(in which case it creates "attribute =
value.toString()") or the developer is using oracle and
the value is null. In this case, it would create
"attribute is null".
This is simply a convenience method for
addFilter(getFilterFactory().equals(attribute, value));
addEqualsFilter in interface DataQueryattribute - The name of the attribute to bind with the valuevalue - The value for the specified attribute
public Filter addNotEqualsFilter(String attribute,
Object value)
attribute
= 'value.toString()'" unless the value is an integer
(in which case it creates "attribute !=
value.toString()") or the developer is using oracle and
the value is null. In this case, it would create
"attribute is not null".
This is simply a convenience method for
addFilter(getFilterFactory().notEquals(attribute, value));
addNotEqualsFilter in interface DataQueryattribute - The name of the attribute to bind with the valuevalue - The value for the specified attributepublic void clearFilter()
clearFilter in interface DataQuerypublic FilterFactory getFilterFactory()
getFilterFactory in interface DataQuery
public void setOrder(String order)
throws PersistenceException
addOrder(java.lang.String)
query.setOrder("creationDate desc, id");
setOrder in interface DataQueryPersistenceException
public void addOrderWithNull(String orderOne,
Object orderTwo,
boolean isAscending)
addOrderWithNull in interface DataQueryorderOne - This is typically the column that will
be used for the ordering. If this column
is null then the value of orderTwo is used for
the orderingorderTwo - This is typically an actual value (such as -1)
but can also be a column name the value used
for the orderingisAscending - If this is true then the items are ordered
in ascending order. Otherwise, they are
ordering in descending order
PersistenceException - is thrown if the query has
already been executed.
public void addOrder(String order)
throws PersistenceException
query.addOrder("creationDate desc, id");
addOrder in interface DataQueryorder - This String parameter specifies the ordering of the
output. This should be a comma seperated list
of Attribute names (not the database column names)
in the order of precedence.
Separating attributes by commas is the same as
calling addOrder multiple times, each with the
next attribute. For instance, this
addOrder("creationDate");
addOrder("creationUser");
is the same as
addOrder("creationDate, creationUser");
If the items should be ordered in ascending order, the attribute name should be followed by the word "asc" If the items should be ordered in descending order, the attribute should be followed by the word "desc" For instance, or order by ascending date and descending user (for users created with the same date), you would use the following:
addOrder("creationDate asc, creationUser desc");
PersistenceExceptionpublic void clearOrder()
clearOrder in interface DataQuery
public void setParameter(String parameterName,
Object value)
setParameter in interface DataQueryparameterName - The name of the parameter to bindvalue - The value to assign to the parameterpublic Object getParameter(String parameterName)
getParameter in interface DataQueryparameterName - The name of the parameter to retrieve
public void setRange(Integer beginIndex)
setRange in interface DataQuerybeginIndex - This is the number of the first row that
should be returned by this query. Setting
beginIndex to 1 returns all rows. This is
inclusive.
public void setRange(Integer beginIndex,
Integer endIndex)
setRange in interface DataQuerybeginIndex - This is the number of the first row that
should be returned by this query. Setting
beginIndex to 1 returns the rows from the
beginning. This is inclusive.endIndex - This is the number of the row after the last
row that should be returned. That is, this
is exclusive (specifying beginIndex = 1 and
endIndex = 10 returns 9 rows);
A - PersistenceException is thrown if
endIndex <= beginIndexpublic Map getPropertyValues()
getPropertyValues in interface DataQuerypublic void setReturnsUpperBound(int upperBound)
setReturnsUpperBound in interface DataQuerypublic void setReturnsLowerBound(int lowerBound)
setReturnsLowerBound in interface DataQuerypublic long size()
size in interface DataQueryDataQueryImpl.size()public void rewind()
rewind in interface DataQueryDataQueryImpl.rewind()public void reset()
reset in interface DataQueryDataQueryImpl.reset()public void close()
close in interface DataQuerypublic Object get(String propertyName)
get in interface DataQuerypropertyName - the name of the property
public CompoundType getType()
getType in interface DataQuery
public void alias(String fromPrefix,
String toPrefix)
alias in interface DataQueryfromPrefix - the prefix that you're mapping from i.e.,
the prefix in the PDL file.toPrefix - the prefix that you're mapping to i.e.,
the prefix that the programmer is going to use.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||