|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.cayenne.query.AbstractQuery
org.apache.cayenne.query.QualifiedQuery
org.apache.cayenne.query.SelectQuery
public class SelectQuery
A query that selects persistent objects of a certain type or "raw data" (aka DataRows). Supports expression qualifier, multiple orderings and a number of other parameters that serve as runtime hints to Cayenne on how to optimize the fetch and result processing.
Field Summary | |
---|---|
protected List<String> |
customDbAttributes
|
protected boolean |
distinct
|
static boolean |
DISTINCT_DEFAULT
|
static String |
DISTINCT_PROPERTY
|
protected List<Ordering> |
orderings
|
Fields inherited from class org.apache.cayenne.query.QualifiedQuery |
---|
qualifier |
Fields inherited from class org.apache.cayenne.query.AbstractQuery |
---|
name, root |
Constructor Summary | |
---|---|
SelectQuery()
Creates an empty SelectQuery. |
|
SelectQuery(Class<?> rootClass)
Creates a SelectQuery that selects all objects of a given persistent class. |
|
SelectQuery(Class<?> rootClass,
Expression qualifier)
Creates a SelectQuery that selects objects of a given persistent class that match supplied qualifier. |
|
SelectQuery(DbEntity root)
Creates a SelectQuery for the specified DbEntity. |
|
SelectQuery(DbEntity root,
Expression qualifier)
Creates a SelectQuery for the specified DbEntity with the given qualifier. |
|
SelectQuery(ObjEntity root)
Creates a SelectQuery with null qualifier, for the specifed ObjEntity |
|
SelectQuery(ObjEntity root,
Expression qualifier)
Creates a SelectQuery for the specified ObjEntity with the given qualifier |
|
SelectQuery(String objEntityName)
Creates SelectQuery with objEntityName parameter. |
|
SelectQuery(String objEntityName,
Expression qualifier)
Creates SelectQuery with objEntityName and qualifier
parameters. |
Method Summary | |
---|---|
void |
addCustomDbAttribute(String attributePath)
Deprecated. since 3.0. Will likely be removed after 3.0M6. Can be replaced with EJBQL. |
void |
addCustomDbAttributes(List<String> attrPaths)
Deprecated. since 3.0. Will likely be removed after 3.0M6. Can be replaced with EJBQL. |
void |
addOrdering(Ordering ordering)
Adds ordering specification to this query orderings. |
void |
addOrdering(String sortPathSpec,
boolean isAscending)
Adds ordering specification to this query orderings. |
void |
addOrdering(String sortPathSpec,
boolean isAscending,
boolean ignoreCase)
Adds ordering specification to this query orderings. |
void |
addOrderings(List<Ordering> orderings)
Adds a list of orderings. |
PrefetchTreeNode |
addPrefetch(String prefetchPath)
Adds a prefetch with specified relationship path to the query. |
void |
aliasPathSplits(String path,
String... aliases)
Adds one or more aliases for the qualifier expression path. |
void |
clearOrderings()
Clears all configured orderings. |
void |
clearPrefetches()
Clears all stored prefetch paths. |
Query |
createQuery(Map<String,?> parameters)
Creates and returns a new SelectQuery built using this query as a prototype and substituting qualifier parameters with the values from the map. |
SQLAction |
createSQLAction(SQLActionVisitor visitor)
Calls "makeSelect" on the visitor. |
void |
encodeAsXML(XMLEncoder encoder)
Prints itself as XML to the provided PrintWriter. |
String[] |
getCacheGroups()
|
String |
getCachePolicy()
Deprecated. since 3.0 getCacheStrategy() replaces this method. |
QueryCacheStrategy |
getCacheStrategy()
|
List<String> |
getCustomDbAttributes()
Deprecated. since 3.0. Will likely be removed after 3.0M6. Can be replaced with EJBQL. |
int |
getFetchLimit()
Returns the fetchLimit. |
int |
getFetchOffset()
Returns the fetchOffset. |
QueryMetadata |
getMetaData(EntityResolver resolver)
Returns default select parameters. |
List<Ordering> |
getOrderings()
Returns a list of orderings used by this query. |
int |
getPageSize()
Returns pageSize property. |
PrefetchTreeNode |
getPrefetchTree()
|
void |
initWithProperties(Map<String,?> properties)
Initializes query parameters using a set of properties. |
boolean |
isDistinct()
Returns true if this query returns distinct rows. |
boolean |
isFetchingCustomAttributes()
Returns true if there is at least one custom query attribute
specified, otherwise returns false for the case when the query results
will contain only the root entity attributes. |
boolean |
isFetchingDataRows()
Returns true if this query should produce a list of data rows as
opposed to DataObjects, false for DataObjects. |
boolean |
isRefreshingObjects()
Deprecated. since 3.0. With introduction of the cache strategies this setting is redundant, although it is still being taken into account. It will be removed in the later versions of Cayenne. |
boolean |
isResolvingInherited()
Deprecated. since 3.0. Inheritance resolving is not optional anymore. |
SelectQuery |
queryWithParameters(Map<String,?> parameters)
A shortcut for queryWithParameters(Map, boolean) that prunes parts of
qualifier that have no parameter value set. |
SelectQuery |
queryWithParameters(Map<String,?> parameters,
boolean pruneMissing)
Returns a query built using this query as a prototype, using a set of parameters to build the qualifier. |
void |
removeOrdering(Ordering ordering)
Removes ordering. |
void |
removePrefetch(String prefetchPath)
Removes prefetch. |
void |
route(QueryRouter router,
EntityResolver resolver,
Query substitutedQuery)
Routes itself and if there are any prefetches configured, creates prefetch queries and routes them as well. |
void |
setCacheGroups(String... cacheGroups)
|
void |
setCachePolicy(String policy)
Deprecated. since 3.0 setCacheStrategy(QueryCacheStrategy) replaces this
method. |
void |
setCacheStrategy(QueryCacheStrategy strategy)
|
void |
setDistinct(boolean distinct)
Sets distinct property that determines whether this query returns
distinct row. |
void |
setFetchingDataRows(boolean flag)
Sets query result type. |
void |
setFetchLimit(int fetchLimit)
Sets the fetchLimit. |
void |
setFetchOffset(int fetchOffset)
|
void |
setPageSize(int pageSize)
Sets pageSize property. |
void |
setPrefetchTree(PrefetchTreeNode prefetchTree)
|
void |
setRefreshingObjects(boolean flag)
Deprecated. since 3.0. With introduction of the cache strategies this setting is redundant, although it is still being taken into account. It will be removed in the later versions of Cayenne. |
void |
setResolvingInherited(boolean b)
Deprecated. since 3.0. Inheritance resolving is not optional anymore. |
Methods inherited from class org.apache.cayenne.query.QualifiedQuery |
---|
andQualifier, getQualifier, orQualifier, setQualifier |
Methods inherited from class org.apache.cayenne.query.AbstractQuery |
---|
getName, getRoot, setName, setRoot, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.apache.cayenne.query.Query |
---|
getName |
Field Detail |
---|
public static final String DISTINCT_PROPERTY
public static final boolean DISTINCT_DEFAULT
protected List<String> customDbAttributes
protected List<Ordering> orderings
protected boolean distinct
Constructor Detail |
---|
public SelectQuery()
public SelectQuery(ObjEntity root)
root
- the ObjEntity this SelectQuery is for.public SelectQuery(ObjEntity root, Expression qualifier)
root
- the ObjEntity this SelectQuery is for.qualifier
- an Expression indicating which objects should be fetchedpublic SelectQuery(Class<?> rootClass)
rootClass
- the Class of objects fetched by this query.public SelectQuery(Class<?> rootClass, Expression qualifier)
rootClass
- the Class of objects fetched by this query.public SelectQuery(DbEntity root)
root
- the DbEntity this SelectQuery is for.public SelectQuery(DbEntity root, Expression qualifier)
root
- the DbEntity this SelectQuery is for.qualifier
- an Expression indicating which objects should be fetchedpublic SelectQuery(String objEntityName)
objEntityName
parameter.
public SelectQuery(String objEntityName, Expression qualifier)
objEntityName
and qualifier
parameters.
Method Detail |
---|
public QueryMetadata getMetaData(EntityResolver resolver)
AbstractQuery
getMetaData
in interface Query
getMetaData
in class AbstractQuery
public void route(QueryRouter router, EntityResolver resolver, Query substitutedQuery)
route
in interface Query
route
in class AbstractQuery
public SQLAction createSQLAction(SQLActionVisitor visitor)
createSQLAction
in interface Query
createSQLAction
in class AbstractQuery
public void initWithProperties(Map<String,?> properties)
public void encodeAsXML(XMLEncoder encoder)
encodeAsXML
in interface XMLSerializable
public SelectQuery queryWithParameters(Map<String,?> parameters)
queryWithParameters(Map, boolean)
that prunes parts of
qualifier that have no parameter value set.
public SelectQuery queryWithParameters(Map<String,?> parameters, boolean pruneMissing)
parameter substitution.
public Query createQuery(Map<String,?> parameters)
createQuery
in interface ParameterizedQuery
public void addOrdering(Ordering ordering)
public void addOrderings(List<Ordering> orderings)
public void addOrdering(String sortPathSpec, boolean isAscending)
public void addOrdering(String sortPathSpec, boolean isAscending, boolean ignoreCase)
public void removeOrdering(Ordering ordering)
public List<Ordering> getOrderings()
public void clearOrderings()
public boolean isDistinct()
public void setDistinct(boolean distinct)
distinct
property that determines whether this query returns
distinct row.
public void aliasPathSplits(String path, String... aliases)
ExpressionFactory.matchAllExp(String, Object...)
.
public List<String> getCustomDbAttributes()
public void addCustomDbAttribute(String attributePath)
ARTIST_NAME
,
PAINTING_ARRAY.PAINTING_ID
, etc.
public void addCustomDbAttributes(List<String> attrPaths)
public boolean isFetchingCustomAttributes()
true
if there is at least one custom query attribute
specified, otherwise returns false
for the case when the query results
will contain only the root entity attributes.
Note that queries that are fetching custom attributes always return data rows instead of DataObjects.
public PrefetchTreeNode getPrefetchTree()
public void setPrefetchTree(PrefetchTreeNode prefetchTree)
public PrefetchTreeNode addPrefetch(String prefetchPath)
public void clearPrefetches()
public void removePrefetch(String prefetchPath)
public boolean isFetchingDataRows()
true
if this query should produce a list of data rows as
opposed to DataObjects, false
for DataObjects. This is a hint to
QueryEngine executing this query.
public void setFetchingDataRows(boolean flag)
flag
parameter is true
, then
results will be in the form of data rows.
Note that if isFetchingCustAttributes()
returns true
,
this setting has no effect, and data rows are always fetched.
public boolean isRefreshingObjects()
true
.
public void setRefreshingObjects(boolean flag)
public String getCachePolicy()
getCacheStrategy()
replaces this method.
public void setCachePolicy(String policy)
setCacheStrategy(QueryCacheStrategy)
replaces this
method.
public QueryCacheStrategy getCacheStrategy()
public void setCacheStrategy(QueryCacheStrategy strategy)
public String[] getCacheGroups()
public void setCacheGroups(String... cacheGroups)
public int getFetchOffset()
public int getFetchLimit()
public void setFetchLimit(int fetchLimit)
public void setFetchOffset(int fetchOffset)
public int getPageSize()
pageSize
property. Page size is a hint telling Cayenne
QueryEngine that query result should use paging instead of reading the whole result
in the memory.
public void setPageSize(int pageSize)
pageSize
property.
pageSize
- The pageSize to setpublic boolean isResolvingInherited()
public void setResolvingInherited(boolean b)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |