|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.arsdigita.persistence.DataQueryDecorator
com.arsdigita.persistence.DataQueryDataCollectionAdapter
Adapter to make a data query look like a data collection. If your data query looks something like the following in PDL:
query ItemsInFolder {
ContentItem item;
ContentType type;
do {
select i.item_id, i.name, i.version,
t.type_id, t.label
from cms_items i, content_types t
where i.type_id = t.type_id
} map {
item.id = i.item_id;
item.name = i.name;
...
type.id = t.type_id;
type.label = t.label;
}
and dq
is a DataQuery
constructed from that
PDL description, then you can get a dat collection of items through
new DataQueryDataCollectionAdapter(dq, "item");
and a new data collection of content types through
new DataQueryDataCollectionAdapter(dq, "type");
Warning: Note that all manipulations of the data collection also
change the underlying data query. The constructed object is not a
cursor, it just wraps the data query that was passed in.
Field Summary |
Fields inherited from interface com.arsdigita.persistence.DataCollection |
versionId |
Constructor Summary | |
DataQueryDataCollectionAdapter(DataQuery dq,
String dataObjectProperty)
Create a data collection that uses the objects with name dataObjectProperty from the data query as its data
objects. |
|
DataQueryDataCollectionAdapter(String queryName,
String dataObjectProperty)
Create a data collection that uses the objects with name dataObjectProperty from the data query as its data
objects. |
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)
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. |
void |
addOrder(String order)
Set the order in which the result of this query will be returned. |
boolean |
contains(DataObject dobj)
Tests whether the current collection contains an object. |
boolean |
contains(OID oid)
Tests whether the current collection contains an object. |
Object |
get(String propertyName)
Returns the value of the propertyName property associated with the current position in the sequence. |
DataObject |
getDataObject()
Returns a data object for the current position in the collection. |
Object |
getLinkAttribute(String propertyName)
Retrieve an attribute of the underlying query. |
ObjectType |
getObjectType()
Returns the object type of the data collection. |
Filter |
setFilter(String conditions)
Sets a filter for this query. |
void |
setOrder(String order)
Set the order in which the result of this query will be returned. |
String |
toString()
|
Methods inherited from class com.arsdigita.persistence.DataQueryDecorator |
addInSubqueryFilter, addNotInSubqueryFilter, addOrderWithNull, addPath, alias, clearFilter, clearOrder, close, first, getDataQuery, getFilterFactory, getParameter, getPosition, getPropertyValues, getType, hasProperty, isAfterLast, isBeforeFirst, isEmpty, isFirst, isLast, last, next, previous, removeFilter, reset, rewind, setParameter, setRange, setRange, setReturnsLowerBound, setReturnsUpperBound, size |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.arsdigita.persistence.DataCollection |
getParameter, setParameter |
Methods inherited from interface com.arsdigita.persistence.DataQuery |
addInSubqueryFilter, addNotInSubqueryFilter, addOrderWithNull, addPath, alias, clearFilter, clearOrder, close, first, getFilterFactory, getPosition, getPropertyValues, getType, hasProperty, isAfterLast, isBeforeFirst, isEmpty, isFirst, isLast, last, next, previous, removeFilter, reset, rewind, setRange, setRange, setReturnsLowerBound, setReturnsUpperBound, size |
Constructor Detail |
public DataQueryDataCollectionAdapter(DataQuery dq, String dataObjectProperty)
dataObjectProperty
from the data query as its data
objects.
dq
- the data query from which data objects are takendataObjectProperty
- the name of the data objects in the querypublic DataQueryDataCollectionAdapter(String queryName, String dataObjectProperty)
dataObjectProperty
from the data query as its data
objects. The data query with name queryName
is
retrieved and used as the source for data objects.
queryName
- the name of the data query from which data objects
are takendataObjectProperty
- the name of the data objects in the queryMethod Detail |
public DataObject getDataObject()
DataCollection
getDataObject
in interface DataCollection
public ObjectType getObjectType()
DataCollection
getObjectType
in interface DataCollection
public Object getLinkAttribute(String propertyName)
propertyName
- the name of the link attribute to retrieve
public Object get(String propertyName)
DataQuery
get
in interface DataQuery
get
in class DataQueryDecorator
public Filter setFilter(String conditions)
DataQuery
Filter f = query.setFilter("id < :maxId and id > :minId"); f.set("maxId", 10); f.set("minId", 1);
setFilter
in interface DataQuery
setFilter
in class DataQueryDecorator
public Filter addFilter(String conditions)
DataQuery
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 < :uperBound");
filter.set("upperBound", new Integer(8));
filter.set("lowerBound", new Integer(3));
addFilter
in interface DataQuery
addFilter
in class DataQueryDecorator
public Filter addFilter(Filter filter)
DataQuery
addFilter
in interface DataQuery
addFilter
in class DataQueryDecorator
public Filter addInSubqueryFilter(String propertyName, String subqueryName)
DataQuery
addInSubqueryFilter
in interface DataQuery
addInSubqueryFilter
in class DataQueryDecorator
public Filter addEqualsFilter(String attribute, Object value)
DataQuery
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 DataQuery
addEqualsFilter
in class DataQueryDecorator
public Filter addNotEqualsFilter(String attribute, Object value)
DataQuery
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 DataQuery
addNotEqualsFilter
in class DataQueryDecorator
public void setOrder(String order) throws PersistenceException
DataQuery
query.setOrder("creationDate desc, id");
setOrder
in interface DataQuery
setOrder
in class DataQueryDecorator
PersistenceException
public void addOrder(String order) throws PersistenceException
DataQuery
query.addOrder("creationDate desc, id");
addOrder
in interface DataQuery
addOrder
in class DataQueryDecorator
PersistenceException
public String toString()
toString
in class DataQueryDecorator
public boolean contains(OID oid)
DataCollection
contains
in interface DataCollection
oid
- The oid of the object.
public boolean contains(DataObject dobj)
DataCollection
contains
in interface DataCollection
dobj
- The dataobject.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |