Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.cayenne.query
Class ProcedureQuery

    java.lang.Object
      org.apache.cayenne.query.AbstractQuery
          org.apache.cayenne.query.ProcedureQuery

All Implemented Interfaces:
  Serializable, ParameterizedQuery, Query, XMLSerializable

    public class ProcedureQuery

extends AbstractQuery
implements ParameterizedQuery, XMLSerializable

A query based on Procedure. Can be used as a select query, or as a query of an arbitrary complexity, performing data modification, selecting data (possibly with multiple result sets per call), returning values via OUT parameters.

### Execution with DataContext

#### Reading OUT parameters

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.

#### Using ProcedureQuery as a GenericSelectQuery

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)`.

Author:
  Andrus Adamchik
See Also:
  Serialized Form

Field Summary
`protected Map` | `parameters`
`protected Class` | `resultClass`
`protected List` | `resultDescriptors`
`protected String` | `resultEntityName`

Fields inherited from class org.apache.cayenne.query.AbstractQuery
`name, root`

Constructor Summary
`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)` Performance Note: with current EntityResolver implementation it is preferrable to use Procedure object instead of String as a query root.

Method Summary
`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 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 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()`
`String` | `getCachePolicy()`
`int` | `getFetchLimit()`
`QueryMetadata` | `getMetaData(EntityResolver resolver)` Returns default select parameters.
`int` | `getPageSize()`
`Map` | `getParameters()` Returns a map of procedure parameters.
`PrefetchTreeNode` | `getPrefetchTree()`
`List` | `getResultDescriptors()` Returns a List of #`RowDescriptor` objects describing query ResultSets in the order they are returned by the stored procedure.
`String` | `getResultEntityName()`
`void` | `initWithProperties(Map properties)` Initializes query parameters using a set of properties.
`boolean` | `isFetchingDataRows()`
`boolean` | `isRefreshingObjects()`
`boolean` | `isResolvingInherited()`
`void` | `removeParameter(String name)`
`void` | `removePrefetch(String prefetch)`
`void` | `removeResultDescriptor(ColumnDescriptor[] descriptor)` Removes result descriptor from the list of descriptors.
`void` | `setCacheGroups(String[] cachGroups)`
`void` | `setCachePolicy(String policy)`
`void` | `setFetchingDataRows(boolean flag)`
`void` | `setFetchLimit(int fetchLimit)`
`void` | `setPageSize(int pageSize)`
`void` | `setParameters(Map parameters)` Sets a map of parameters.
`void` | `setRefreshingObjects(boolean flag)`
`void` | `setResolvingInherited(boolean b)`
`void` | `setResultEntityName(String resultEntityName)`

Methods inherited from class org.apache.cayenne.query.AbstractQuery
`getName, getRoot, route, 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, route`

Field Detail

### resultEntityName

    protected String resultEntityName

Since:
  1.2

### resultClass

    protected Class resultClass

Since:
  1.2

### parameters

    protected Map parameters

### resultDescriptors

    protected List resultDescriptors

Since:
  1.2

Constructor Detail

### ProcedureQuery

    public ProcedureQuery()

  Creates an empty procedure query.

### ProcedureQuery

    public ProcedureQuery(Procedure procedure)

  Creates a ProcedureQuery based on a Procedure object.

### ProcedureQuery

    public ProcedureQuery(String procedureName)

  Creates a ProcedureQuery based on a stored procedure.

  Performance Note: with current EntityResolver implementation it is preferrable to use Procedure object instead of String as a query root. String root can cause unneeded EntityResolver reindexing on every call. See this mailing list thread: http://objectstyle.org/cayenne/lists/cayenne-user/2005/01/0109.html

  Parameters:
    `procedureName` - A name of the stored procedure. For this query to work, a procedure with this name must be mapped in Cayenne.

### ProcedureQuery

    public ProcedureQuery(Procedure procedure,
                          Class resultType)

Since:
  1.1

### ProcedureQuery

    public ProcedureQuery(String procedureName,
                          Class resultType)

  Performance Note: with current EntityResolver implementation it is preferrable to use Procedure object instead of String as a query root. String root can cause unneeded EntityResolver reindexing on every call. See this mailing list thread: http://objectstyle.org/cayenne/lists/cayenne-user/2005/01/0109.html

  Since:
    1.1

Method Detail

### getMetaData

    public QueryMetadata getMetaData(EntityResolver resolver)

  Description copied from class: `AbstractQuery`
  Returns default select parameters.

  Specified by:
    `getMetaData` in interface `Query`
  Overrides:
    `getMetaData` in class `AbstractQuery`
  Since:
    1.2

### getResultDescriptors

    public List getResultDescriptors()

  Returns a List of #`RowDescriptor` objects describing query ResultSets in the order they are returned by the stored procedure.

  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.

  Since:
    1.2

### addResultDescriptor

    public void addResultDescriptor(ColumnDescriptor[] descriptor)

  Adds a descriptor for a single ResultSet. More than one descriptor can be added by calling this method multiple times in the order of described ResultSet appearance in the procedure results.

  Since:
    1.2

### removeResultDescriptor

    public void removeResultDescriptor(ColumnDescriptor[] descriptor)

  Removes result descriptor from the list of descriptors.

  Since:
    1.2

### createSQLAction

    public SQLAction createSQLAction(SQLActionVisitor visitor)

  Calls "makeProcedure" on the visitor.

  Specified by:
    `createSQLAction` in interface `Query`
  Specified by:
    `createSQLAction` in class `AbstractQuery`
  Since:
    1.2

### initWithProperties

    public void initWithProperties(Map properties)

  Initializes query parameters using a set of properties.

  Since:
    1.1

### encodeAsXML

    public void encodeAsXML(XMLEncoder encoder)

  Prints itself as XML to the provided PrintWriter.

  Specified by:
    `encodeAsXML` in interface `XMLSerializable`
  Since:
    1.1

### createQuery

    public Query createQuery(Map parameters)

  Creates and returns a new ProcedureQuery built using this query as a prototype and substituting template parameters with the values from the map.

  Specified by:
    `createQuery` in interface `ParameterizedQuery`
  Since:
    1.1

### getCachePolicy

    public String getCachePolicy()

### setCachePolicy

    public void setCachePolicy(String policy)

### getCacheGroups

    public String[] getCacheGroups()

  Since:
    3.0

### setCacheGroups

    public void setCacheGroups(String[] cachGroups)

  Since:
    3.0

### getFetchLimit

    public int getFetchLimit()

### setFetchLimit

    public void setFetchLimit(int fetchLimit)

### getPageSize

    public int getPageSize()

### setPageSize

    public void setPageSize(int pageSize)

### setFetchingDataRows

    public void setFetchingDataRows(boolean flag)

### isFetchingDataRows

    public boolean isFetchingDataRows()

### isRefreshingObjects

    public boolean isRefreshingObjects()

### setRefreshingObjects

    public void setRefreshingObjects(boolean flag)

### isResolvingInherited

    public boolean isResolvingInherited()

### setResolvingInherited

    public void setResolvingInherited(boolean b)

### addParameter

    public void addParameter(String name,
                             Object value)

  Adds a named parameter to the internal map of parameters.

  Since:
    1.1

### removeParameter

    public void removeParameter(String name)

  Since:
    1.1

### getParameters

    public Map getParameters()

  Returns a map of procedure parameters.

  Since:
    1.1

### setParameters

    public void setParameters(Map parameters)

  Sets a map of parameters.

  Since:
    1.1

### clearParameters

    public void clearParameters()

  Cleans up all configured parameters.

  Since:
    1.1

### getPrefetchTree

    public PrefetchTreeNode getPrefetchTree()

  Since:
    1.2

### addPrefetch

    public PrefetchTreeNode addPrefetch(String prefetchPath)

  Adds a prefetch.

  Since:
    1.2

### removePrefetch

    public void removePrefetch(String prefetch)

  Since:
    1.2

### addPrefetches

    public void addPrefetches(Collection prefetches)

  Adds all prefetches from a provided collection.

  Since:
    1.2

### clearPrefetches

    public void clearPrefetches()

  Clears all prefetches.

  Since:
    1.2

### getResultEntityName

    public String getResultEntityName()

  Since:
    1.2

### setResultEntityName

    public void setResultEntityName(String resultEntityName)

  Since:
    1.2

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2007 Apache Cayenne. All Rights Reserved.