public class ProcedureQuery extends AbstractQuery implements ParameterizedQuery, XMLSerializable
If a ProcedureQuery has OUT parameters, they are wrapped in a separate List in the query result. Such list will contain a single Map with OUT parameter values.
Executing ProcedureQuery via
DataContext.performQuery(Query)
makes sense only if
the stored procedure returns a single result set (or alternatively returns a result via
OUT parameters and no other result sets). It is still OK if data modification occurs as
a side effect. However if the query returns more then one result set, a more generic
form should be used:
DataContext.performGenericQuery(Query)
.
Modifier and Type | Field and Description |
---|---|
protected CapsStrategy |
columnNamesCapitalization |
protected Map<String,Object> |
parameters |
protected Class<?> |
resultClass |
protected List<ColumnDescriptor[]> |
resultDescriptors |
protected String |
resultEntityName |
dataMap, name, root
Constructor and Description |
---|
ProcedureQuery()
Creates an empty procedure query.
|
ProcedureQuery(Procedure procedure)
Creates a ProcedureQuery based on a Procedure object.
|
ProcedureQuery(Procedure procedure,
Class<?> resultType) |
ProcedureQuery(String procedureName)
Creates a ProcedureQuery based on a stored procedure.
|
ProcedureQuery(String procedureName,
Class<?> resultType) |
Modifier and Type | Method and Description |
---|---|
void |
addParameter(String name,
Object value)
Adds a named parameter to the internal map of parameters.
|
PrefetchTreeNode |
addPrefetch(String prefetchPath)
Adds a prefetch.
|
void |
addPrefetches(Collection<String> prefetches)
Adds all prefetches from a provided collection.
|
void |
addResultDescriptor(ColumnDescriptor[] descriptor)
Adds a descriptor for a single ResultSet.
|
void |
clearParameters()
Cleans up all configured parameters.
|
void |
clearPrefetches()
Clears all prefetches.
|
Query |
createQuery(Map<String,?> parameters)
Creates and returns a new ProcedureQuery built using this query as a prototype and
substituting template parameters with the values from the map.
|
SQLAction |
createSQLAction(SQLActionVisitor visitor)
Calls "makeProcedure" on the visitor.
|
void |
encodeAsXML(XMLEncoder encoder)
Prints itself as XML to the provided PrintWriter.
|
String[] |
getCacheGroups() |
QueryCacheStrategy |
getCacheStrategy() |
CapsStrategy |
getColumnNamesCapitalization() |
int |
getFetchLimit() |
int |
getFetchOffset() |
QueryMetadata |
getMetaData(EntityResolver resolver)
Returns default select parameters.
|
int |
getPageSize() |
Map<String,?> |
getParameters()
Returns a map of procedure parameters.
|
PrefetchTreeNode |
getPrefetchTree() |
List<ColumnDescriptor[]> |
getResultDescriptors()
Returns a List of descriptors for query ResultSets in the order they are returned
by the stored procedure.
|
String |
getResultEntityName() |
int |
getStatementFetchSize() |
void |
initWithProperties(Map<String,?> properties)
Initializes query parameters using a set of properties.
|
boolean |
isFetchingDataRows() |
void |
removeParameter(String name) |
void |
removePrefetch(String prefetch) |
void |
removeResultDescriptor(ColumnDescriptor[] descriptor)
Removes result descriptor from the list of descriptors.
|
void |
setCacheGroups(String... cacheGroups) |
void |
setCacheStrategy(QueryCacheStrategy strategy) |
void |
setColumnNamesCapitalization(CapsStrategy columnNameCapitalization) |
void |
setFetchingDataRows(boolean flag) |
void |
setFetchLimit(int fetchLimit) |
void |
setFetchOffset(int fetchOffset) |
void |
setPageSize(int pageSize) |
void |
setParameters(Map<String,?> parameters)
Sets a map of parameters.
|
void |
setResultEntityName(String resultEntityName) |
void |
setStatementFetchSize(int size)
Sets statement's fetch size (0 for no default size)
|
void |
useLocalCache(String... cacheGroups)
Instructs Cayenne to look for query results in the "local" cache when
running the query.
|
void |
useSharedCache(String... cacheGroups)
Instructs Cayenne to look for query results in the "shared" cache when
running the query.
|
acceptVisitor, getDataMap, getName, getRoot, route, setDataMap, setName, setRoot, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getDataMap, getName, route
acceptVisitor
protected String resultEntityName
protected Class<?> resultClass
protected CapsStrategy columnNamesCapitalization
protected List<ColumnDescriptor[]> resultDescriptors
public ProcedureQuery()
ProcedureQuery(String, Class)
constructor or by calling
setFetchingDataRows(boolean)
and setResultEntityName(String)
methods.public ProcedureQuery(Procedure procedure)
ProcedureQuery(String, Class)
constructor or by calling
setFetchingDataRows(boolean)
and setResultEntityName(String)
methods.public ProcedureQuery(String procedureName)
ProcedureQuery(String, Class)
constructor or by calling
setFetchingDataRows(boolean)
and setResultEntityName(String)
methods.procedureName
- A name of the stored procedure. For this query to work, a
procedure with this name must be mapped in Cayenne.public QueryMetadata getMetaData(EntityResolver resolver)
AbstractQuery
getMetaData
in interface Query
getMetaData
in class AbstractQuery
public List<ColumnDescriptor[]> getResultDescriptors()
Note that if a procedure returns ResultSet in an OUT parameter, it is returned prior to any other result sets (though in practice database engines usually support only one mechanism for returning result sets.
public void addResultDescriptor(ColumnDescriptor[] descriptor)
public void removeResultDescriptor(ColumnDescriptor[] descriptor)
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 Query createQuery(Map<String,?> parameters)
createQuery
in interface ParameterizedQuery
public QueryCacheStrategy getCacheStrategy()
public void setCacheStrategy(QueryCacheStrategy strategy)
public String[] getCacheGroups()
public void setCacheGroups(String... cacheGroups)
public void useLocalCache(String... cacheGroups)
query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE); query.setCacheGroups("group1", "group2");
public void useSharedCache(String... cacheGroups)
query.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE); query.setCacheGroups("group1", "group2");
public int getFetchLimit()
public void setFetchLimit(int fetchLimit)
public int getFetchOffset()
public void setFetchOffset(int fetchOffset)
public int getPageSize()
public void setPageSize(int pageSize)
public void setFetchingDataRows(boolean flag)
public boolean isFetchingDataRows()
public void addParameter(String name, Object value)
public void removeParameter(String name)
public Map<String,?> getParameters()
public void setParameters(Map<String,?> parameters)
public void clearParameters()
public PrefetchTreeNode getPrefetchTree()
public PrefetchTreeNode addPrefetch(String prefetchPath)
public void removePrefetch(String prefetch)
public void addPrefetches(Collection<String> prefetches)
public void clearPrefetches()
public String getResultEntityName()
public void setResultEntityName(String resultEntityName)
public CapsStrategy getColumnNamesCapitalization()
public void setColumnNamesCapitalization(CapsStrategy columnNameCapitalization)
public void setStatementFetchSize(int size)
public int getStatementFetchSize()
Copyright © 2001–2015 Apache Cayenne. All rights reserved.