Top Description Inners Fields Constructors Methods
org.eclipse.persistence.queries

public Class ReportQuery

extends ReadAllQuery
Class Inheritance
Imports
java.util.*, org.eclipse.persistence.descriptors.VersionLockingPolicy, org.eclipse.persistence.expressions.*, org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy, org.eclipse.persistence.internal.expressions.*, org.eclipse.persistence.internal.queries.*, org.eclipse.persistence.exceptions.*, org.eclipse.persistence.internal.helper.*, org.eclipse.persistence.internal.sessions.remote.*, org.eclipse.persistence.internal.sessions.AbstractRecord, .AbstractSession, .UnitOfWorkImpl

Purpose: Query for information about a set of objects instead of the objects themselves. This supports select single attributes, nested attributes, aggregation functions and group bys.

Attribute Types:

  1. addAttribute("directQueryKey") is a short cut method to add an attribute with the same name as its corresponding direct query key.
  2. addAttribute("attributeName", expBuilder.get("oneToOneMapping").get("directQueryKey")) is the full approach for get values through joined 1:1 relationships.
  3. addAttribute("attributeName", expBuilder.getField("TABLE.FIELD")) allows the addition of raw values or values which were not mapped in the object model directly (i.e. FK attributes).
  4. addAttribute("attributeName", null) Leave a place holder (NULL) value in the result (used for included values from other systems or calculated values).
Retrieving Primary Keys: It is possible to retrieve the primary key raw values within each result, but stored in a separate (internal) vector. This primary key vector can later be used to retrieve the real object.
Author
Doug Clarke
Since
TOPLink/Java 2.0
See Also
If the values are wanted in the result array then they must be added as attributes. For primary keys which are not mapped directly you can add them as DatabaseFields (see above).

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum

Field Summary

Modifier and TypeField and Description
protected boolean
addToConstructorItem

flag to allow items to be added to the last ConstructorReportItem

public static final int
public static final int
FULL_PRIMARY_KEY

Specifies whether to retrieve primary keys, first primary key, or no primary key.

protected List<Expression>
groupByExpressions

Expressions representing fields to be used in the GROUP BY clause.

protected Expression
havingExpression

Expression representing the HAVING clause.

protected List<ReportItem>
items

Items to be selected, these could be attributes or aggregate functions.

protected List<String>
names

Collection of names for use by results.

public static final int
protected int
returnChoice

Can be one of (ShouldReturnSingleResult, ShouldReturnSingleValue, ShouldReturnSingleAttribute) Simplifies the result by only returning the first result, first value, or all attribute values

protected Set<Object>
protected int
shouldRetrievePrimaryKeys

Flag indicating whether the primary key values should also be retrieved for the reference class.

public static final int
ShouldReturnArray

For EJB 3 support returns results as an Object array.

public static final int
ShouldReturnReportResult

Default, returns ReportQueryResult objects.

public static final int
ShouldReturnSingleAttribute

Simplifies the result by only returning the single attribute(as opposed to wrapping in a ReportQueryResult).

public static final int
ShouldReturnSingleResult

Simplifies the result by only returning the first result.

public static final int
ShouldReturnSingleValue

Simplifies the result by only returning one value.

public static final int
ShouldReturnWithoutReportQueryResult

For EJB 3 support returns results without using the ReportQueryResult

public static final int
ShouldSelectValue1

For example, ...

Inherited from org.eclipse.persistence.queries.ReadAllQuery:
connectByExpressioncontainerPolicydirectionorderSiblingsByExpressionsstartWithExpression

Constructor Summary

AccessConstructor and Description
public
ReportQuery()

INTERNAL: The builder should be provided.

public
ReportQuery(Class<?> javaClass, Expression expression)

public
ReportQuery(Class<?> javaClass, ExpressionBuilder builder)

PUBLIC: The report query is require to be constructor with an expression builder.

public
ReportQuery(ExpressionBuilder builder)

PUBLIC: The report query is require to be constructor with an expression builder.

Method Summary

Modifier and TypeMethod and Description
public void
addAttribute(String itemName)

PUBLIC: Add the attribute from the reference class to be included in the result.

public void
addAttribute(String itemName, Expression attributeExpression)

PUBLIC: Add the attribute to be included in the result.

public void
addAttribute(String itemName, Expression attributeExpression, Class<?> type)

PUBLIC: Add the attribute to be included in the result.

public void
addAverage(String itemName)

PUBLIC: Add the average value of the attribute to be included in the result.

public void
addAverage(String itemName, Class<?> resultType)

PUBLIC: Add the average value of the attribute to be included in the result and return it as the specified resultType.

public void
addAverage(String itemName, Expression attributeExpression)

PUBLIC: Add the average value of the attribute to be included in the result.

public void
addAverage(String itemName, Expression attributeExpression, Class<?> resultType)

PUBLIC: Add the average value of the attribute to be included in the result and return it as the specified resultType.

public void
addConstructorReportItem(ConstructorReportItem
used to specify a class constructor and values to pass in from this query
item
)

PUBLIC: Add a ConstructorReportItem to this query's set of return values.

public void
addCount()

PUBLIC: Include the number of rows returned by the query in the result.

public void
addCount(String
the number of rows where attributeName is not null will be returned.
attributeName
)

PUBLIC: Include the number of rows returned by the query in the result, where attributeExpression is not null.

public void
addCount(String
the number of rows where attributeName is not null will be returned.
attributeName
,
Class<?> resultType)

PUBLIC: Include the number of rows returned by the query in the result, where attributeExpression is not null.

public void
addCount(String itemName, Expression attributeExpression)

PUBLIC: Include the number of rows returned by the query in the result, where attributeExpression is not null.

public void
addCount(String itemName, Expression attributeExpression, Class<?> resultType)

PUBLIC: Include the number of rows returned by the query in the result, where attributeExpression is not null.

public void
addFunctionItem(String itemName, Expression attributeExpression, String functionName)

ADVANCED: Add the function against the attribute expression to be included in the result.

public void
addGrouping(String attributeName)

PUBLIC: Add the attribute to the group by expressions.

public void
addGrouping(Expression expression)

PUBLIC: Add the attribute expression to the group by expressions.

private void
addItem(ReportItem item)

INTERNAL: Method used to abstract addToConstructorItem behavour from the public addItem methods

public void
addItem(String itemName, Expression attributeExpression)

ADVANCED: Add the expression value to be included in the result.

public void
addItem(String itemName, Expression attributeExpression, List<E> joinedExpressions)

ADVANCED: Add the expression value to be included in the result.

protected void
addItem(String itemName, Expression attributeExpression, Class<?> resultType)

INTERNAL: Add the expression value to be included in the result.

public void
addMaximum(String itemName)

PUBLIC: Add the maximum value of the attribute to be included in the result.

public void
addMaximum(String itemName, Class<?> resultType)

PUBLIC: Add the maximum value of the attribute to be included in the result.

public void
addMaximum(String itemName, Expression attributeExpression)

PUBLIC: Add the maximum value of the attribute to be included in the result.

public void
addMaximum(String itemName, Expression attributeExpression, Class<?> resultType)

PUBLIC: Add the maximum value of the attribute to be included in the result.

public void
addMinimum(String itemName)

PUBLIC: Add the minimum value of the attribute to be included in the result.

public void
addMinimum(String itemName, Class<?> resultType)

PUBLIC: Add the minimum value of the attribute to be included in the result.

public void
addMinimum(String itemName, Expression attributeExpression)

PUBLIC: Add the minimum value of the attribute to be included in the result.

public void
addMinimum(String itemName, Expression attributeExpression, Class<?> resultType)

PUBLIC: Add the minimum value of the attribute to be included in the result.

public void
addStandardDeviation(String itemName)

PUBLIC: Add the standard deviation value of the attribute to be included in the result.

public void
addStandardDeviation(String itemName, Expression attributeExpression)

PUBLIC: Add the standard deviation value of the attribute to be included in the result.

public void
addSum(String itemName)

PUBLIC: Add the sum value of the attribute to be included in the result.

public void
addSum(String itemName, Class<?> resultType)

PUBLIC: Add the sum value of the attribute to be included in the result and return it as the specified resultType.

public void
addSum(String itemName, Expression attributeExpression)

PUBLIC: Add the sum value of the attribute to be included in the result.

public void
addSum(String itemName, Expression attributeExpression, Class<?> resultType)

PUBLIC: Add the sum value of the attribute to be included in the result and return it as the specified resultType.

public void
addVariance(String itemName)

PUBLIC: Add the variance value of the attribute to be included in the result.

public void
addVariance(String itemName, Expression attributeExpression)

PUBLIC: Add the variance value of the attribute to be included in the result.

public ConstructorReportItem
beginAddingConstructorArguments(Class<?> constructorClass)

PUBLIC: Call a constructor for the given class with the results of this query.

public ConstructorReportItem
beginAddingConstructorArguments(Class<?> constructorClass, Class<?>[]
- sets the argument types to be passed to the constructor.
constructorArgTypes
)

PUBLIC: Call a constructor for the given class with the results of this query.

public Object
public Object
buildObject(AbstractRecord row, Vector<E>
All rows fetched by query. It is required to be not null.
toManyJoinData
)

INTERNAL: Construct a result from a row.

public Object
buildObjects(Vector<E> rows)

INTERNAL: Construct a container of ReportQueryResult from the rows.

protected Object
checkEarlyReturnLocal(AbstractSession session, AbstractRecord translationRow)

Overrides org.eclipse.persistence.queries.ReadAllQuery.checkEarlyReturnLocal.

INTERNAL: The cache check is done before the prepare as a hit will not require the work to be done.
protected DatabaseQuery
checkForCustomQuery(AbstractSession
Current session.
session
,
AbstractRecord
Database record.
translationRow
)

Overrides org.eclipse.persistence.queries.ObjectLevelReadQuery.checkForCustomQuery.

INTERNAL: Check to see if a custom query should be used for this query.
public void
clearItems()

INTERNAL: Clear the ReportQueryItems

public Object
clone()

Overrides org.eclipse.persistence.queries.ReadAllQuery.clone.

INTERNAL: Clone the query.
public void
copyReportItems(Map<K, V> alreadyDone)

INTERNAL: Required for a very special case of bug 2612185: ReportItems from parallelExpressions, on a ReportQuery which is a subQuery, which is being batch read.

public void
dontRetrievePrimaryKeys()

PUBLIC: Set if the query results should contain the primary keys or each associated object.

public void
dontReturnSingleAttribute()

PUBLIC: Don't simplify the result by returning the single attribute.

public void
dontReturnSingleResult()

PUBLIC: Simplifies the result by only returning the first result.

public void
dontReturnSingleValue()

PUBLIC: Simplifies the result by only returning a single value.

public void
dontReturnWithoutReportQueryResult()

PUBLIC: Simplifies the result by only returning a single value.

public void
endAddingToConstructorItem()

PUBLIC: Used in conjunction with beginAddingConstructorArguments to signal that expressions should no longer be be added to the collection used in the constructor.

public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides org.eclipse.persistence.queries.ReadAllQuery.equals.

INTERNAL: Return if the query is equal to the other.
public Object

Returns:

either collection of objects, or report data resulting from execution of query.
executeDatabaseQuery
()

Overrides org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery.

INTERNAL: Execute the query.
public Object
extractRemoteResult(Transporter transporter)

Overrides org.eclipse.persistence.queries.ReadAllQuery.extractRemoteResult.

INTERNAL: Extract the correct query result from the transporter.
protected QueryRedirector
getDefaultRedirector()

Overrides org.eclipse.persistence.queries.ReadAllQuery.getDefaultRedirector.

INTERNAL: Returns the specific default redirector for this query type.
public List<Expression>
getGroupByExpressions()

INTERNAL: Return the group bys.

public Expression
getHavingExpression()

INTERNAL: Return the Having expression.

public ReportItem

Returns:

ReportItems with the name
getItem
(String name)

INTERNAL:

public List<ReportItem>

Returns:

ReportItems defining the attributes to be read.
getItems
()

INTERNAL:

public List<String>
getNames()

INTERNAL: Lazily initialize and return the names of the items requested for use in each result object.

public Vector<E>
getQueryExpressions()

INTERNAL: return a collection of expressions if PK's are used.

public int
getReturnType()

PUBLIC: Return the return type.

public boolean
hasGroupByExpressions()

INTERNAL: Return if any group bys exist, allow lazy initialization.

public boolean
isReportQuery()

Overrides org.eclipse.persistence.queries.DatabaseQuery.isReportQuery.

PUBLIC: Return if this is a report query.
protected void
prepare()

Overrides org.eclipse.persistence.queries.ReadAllQuery.prepare.

INTERNAL: Prepare the receiver for execution in a session.
public void
prepareFetchGroup()

Overrides org.eclipse.persistence.queries.ObjectLevelReadQuery.prepareFetchGroup.

INTERNAL: ReportQuery doesn't support fetch groups.
public void
prepareFromQuery(DatabaseQuery query)

Overrides org.eclipse.persistence.queries.ReadAllQuery.prepareFromQuery.

INTERNAL: Prepare the query from the prepared query.
protected void
prepareObjectAttributeCount(Map<K, V> clonedExpressions)

INTERNAL: Prepare a report query with a count defined on an object attribute.

private void
prepareObjectAttributeCount(List<ReportItem> items, Map<K, V> clonedExpressions)

JPQL allows count([distinct] e), where e can be an object, not just a single field, however the database only allows a single field, so object needs to be translated to a single field.

protected void
public synchronized void
prepareSubSelect(AbstractSession session, AbstractRecord translationRow, Map<K, V> clonedExpressions)

INTERNAL: Prepare the receiver for being printed inside a subselect.

public Map<K, V>
replaceValueHoldersIn(Object object, RemoteSessionController controller)

Overrides org.eclipse.persistence.queries.ReadAllQuery.replaceValueHoldersIn.

INTERNAL: replace the value holders in the specified result object(s)
public void
retrievePrimaryKeys()

PUBLIC: Set if the query results should contain the primary keys or each associated object.

public void
returnSingleAttribute()

PUBLIC: Simplify the result by returning a single attribute.

public void
returnSingleResult()

PUBLIC: Simplifies the result by only returning the first result.

public void
returnSingleValue()

PUBLIC: Simplifies the result by only returning a single value.

public void
returnWithoutReportQueryResult()

PUBLIC: Simplifies the result by only returning a single value.

public void
selectValue1()

PUBLIC: Simplifies the result by only returning a single value.

public void
setGroupByExpressions(List<Expression> groupByExpressions)

INTERNAL: Set the group bys.

public void
setHavingExpression(Expression expression)

PUBLIC: Add the expression to the query to be used in the HAVING clause.

public void
setItems(List<ReportItem> items)

INTERNAL: Set the ReportQueryItems defining the attributes to be read.

public boolean

Returns:

returns a failure flag indicating that we were UNABLE to set the lock mode because of validation. Callers to this method should check the return value and throw the necessary exception.
setLockModeType
(String lockModeType, AbstractSession session)

Overrides org.eclipse.persistence.queries.ObjectLevelReadQuery.setLockModeType.

INTERNAL: Sets a jakarta.persistence.LockModeType to used with this queries execution.
protected void
setNames(List<String> names)

INTERNAL: Set the item names.

public void
setReturnType(int returnChoice)

PUBLIC: Set the return type.

public void
setShouldRetrieveFirstPrimaryKey(boolean shouldRetrieveFirstPrimaryKey)

ADVANCED: Sets if the query results should contain the first primary key of each associated object.

public void
setShouldRetrievePrimaryKeys(boolean shouldRetrievePrimaryKeys)

PUBLIC: Set if the query results should contain the primary keys or each associated object.

public void
setShouldReturnSingleAttribute(boolean newChoice)

PUBLIC: Simplifies the result by only returning the attribute (as opposed to wrapping in a ReportQueryResult).

public void
setShouldReturnSingleResult(boolean newChoice)

PUBLIC: Simplifies the result by only returning the first result.

public void
setShouldReturnSingleValue(boolean newChoice)

PUBLIC: Simplifies the result by only returning a single value.

public void
setShouldReturnWithoutReportQueryResult(boolean newChoice)

PUBLIC: Simplifies the result by returning a nested list instead of the ReportQueryResult.

public boolean
shouldRetrieveFirstPrimaryKey()

PUBLIC: Return if the query results should contain the first primary key of each associated object.

public boolean
shouldRetrievePrimaryKeys()

PUBLIC: Return if the query results should contain the primary keys or each associated object.

public boolean
shouldReturnArray()

PUBLIC: Returns true if results should be returned as an Object array.

public boolean
shouldReturnSingleAttribute()

PUBLIC: Answer if we are only returning the attribute (as opposed to wrapping in a ReportQueryResult).

public boolean
shouldReturnSingleResult()

PUBLIC: Simplifies the result by only returning the first result.

public boolean
shouldReturnSingleValue()

PUBLIC: Simplifies the result by only returning a single value.

public boolean
shouldReturnWithoutReportQueryResult()

PUBLIC: Simplifies the result by returning a nested list instead of the ReportQueryResult.

public boolean
shouldSelectValue1()

PUBLIC: Returns true if results should be returned as an Object array.

Inherited from org.eclipse.persistence.queries.ReadAllQuery:
addAscendingOrderingcacheResultcheckCustomQueryFlagconformResultexecuteexecuteObjectLevelReadQueryexecuteObjectLevelReadQueryFromResultSetgetConnectByExpressiongetContainerPolicygetDirectiongetOrderSiblingsByExpressionsgetReadQuerygetStartWithExpressionhasHierarchicalExpressionsisDefaultPropertiesQueryisReadAllQueryprepareCustomQueryprepareForExecutionregisterResultInUnitOfWorkregisterResultSetInUnitOfWorkremoteExecutesetContainerPolicysetHierarchicalQueryClausesetHierarchicalQueryClausesupportsResultSetAccessOptimizationOnExecutesupportsResultSetAccessOptimizationOnPrepareuseCollectionClassuseCursoredStreamuseCursoredStreamuseCursoredStreamuseMapClassuseScrollableCursoruseScrollableCursoruseScrollableCursor