RelationshipQuery (cayenne-doc: Cayenne Documentation 5.0-M2 API)
Description: declaration: package: org.apache.cayenne.query, class: RelationshipQuery

# Class RelationshipQuery

java.lang.Object
org.apache.cayenne.query.IndirectQuery
org.apache.cayenne.query.RelationshipQuery

All Implemented Interfaces:
  `Serializable, Query`

public class RelationshipQuery extends IndirectQuery
A query that selects objects related to a given object via a mapped relationship. RelationshipQuery is used by Cayenne internally to resolve relationships, and is rarely executed by the application directly, although this of course is possible too.

Since:
  1.2
See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected ArcProperty`
  `arc`
  `protected QueryMetadata`
  `metadata`
  `protected EntityResolver`
  `metadataResolver`
  `protected ObjectId`
  `objectId`
  `protected boolean`
  `refreshing`
  `protected String`
  `relationshipName`
  `protected int`
  `statementFetchSize`

  ### Fields inherited from class IndirectQuery

  `dataMap, lastResolver, name, replacementQuery`
  Modifier and Type
  Field
  Description
  `protected DataMap`
  `dataMap`
  `protected EntityResolver`
  `lastResolver`
  `protected String`
  `name`
  `protected Query`
  `replacementQuery`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RelationshipQuery(ObjectId objectID, String relationshipName)`
  Creates a RelationshipQuery.
  `RelationshipQuery(ObjectId objectID, String relationshipName, boolean refreshing)`
  Creates a RelationshipQuery.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected Query`
  `createReplacementQuery(EntityResolver resolver)`
  Creates a substitute query.
  `QueryMetadata`
  `getMetaData(EntityResolver resolver)`
  Returns query metadata object.
  `ObjectId`
  `getObjectId()`
  `ObjRelationship`
  `getRelationship(EntityResolver resolver)`
  Returns a non-null relationship object for this query.
  `String`
  `getRelationshipName()`
  `int`
  `getStatementFetchSize()`
  `boolean`
  `isRefreshing()`
  `void`
  `setStatementFetchSize(int size)`
  Sets statement's fetch size (0 for no default size)
  `String`
  `toString()`
  Overrides toString() outputting a short string with query class and relationship name.

  ### Methods inherited from class IndirectQuery

  `createSQLAction, getReplacementQuery, route`
  Modifier and Type
  Method
  Description
  `SQLAction`
  `createSQLAction(SQLActionVisitor visitor)`
  Throws an exception as indirect query should not be executed directly.
  `protected Query`
  `getReplacementQuery(EntityResolver resolver)`
  Returns a replacement query, creating it on demand and caching it for reuse.
  `void`
  `route(QueryRouter router, EntityResolver resolver, Query substitutedQuery)`
  Delegates routing to a replacement query.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### objectId

    protected ObjectId objectId

  - ### relationshipName

    protected String relationshipName

  - ### refreshing

    protected boolean refreshing

  - ### statementFetchSize

    protected int statementFetchSize

  - ### metadataResolver

    protected transient EntityResolver metadataResolver

  - ### metadata

    protected transient QueryMetadata metadata

  - ### arc

    protected transient ArcProperty arc

- ## Constructor Details

  - ### RelationshipQuery

    public RelationshipQuery(ObjectId objectID, String relationshipName)
    Creates a RelationshipQuery. Same as new RelationshipQuery(objectID, relationshipName, true).
    Parameters:
      `objectID` - ObjectId of a root object of the relationship.
      `relationshipName` - The name of the relationship.

  - ### RelationshipQuery

    public RelationshipQuery(ObjectId objectID, String relationshipName, boolean refreshing)
    Creates a RelationshipQuery.
    Parameters:
      `objectID` - ObjectId of a root object of the relationship.
      `relationshipName` - The name of the relationship.
      `refreshing` - whether objects should be refreshed

- ## Method Details

  - ### getMetaData

    public QueryMetadata getMetaData(EntityResolver resolver)
    Returns query metadata object.
    Specified by:
      `getMetaData` in interface `Query`
    Overrides:
      `getMetaData` in class `IndirectQuery`

  - ### getObjectId

    public ObjectId getObjectId()

  - ### isRefreshing

    public boolean isRefreshing()

  - ### getRelationshipName

    public String getRelationshipName()

  - ### createReplacementQuery

    protected Query createReplacementQuery(EntityResolver resolver)
    Description copied from class: `IndirectQuery`
    Creates a substitute query. An implementor is free to provide an arbitrary replacement query.
    Specified by:
      `createReplacementQuery` in class `IndirectQuery`

  - ### getRelationship

    public ObjRelationship getRelationship(EntityResolver resolver)
    Returns a non-null relationship object for this query.

  - ### setStatementFetchSize

    public void setStatementFetchSize(int size)
    Sets statement's fetch size (0 for no default size)
    Since:
      3.0

  - ### getStatementFetchSize

    public int getStatementFetchSize()
    Returns:
      statement's fetch size
    Since:
      3.0

  - ### toString

    public String toString()
    Overrides toString() outputting a short string with query class and relationship name.
    Overrides:
      `toString` in class `Object`