org.apache.openjpa.persistence.criteria
Class SubqueryImpl<T>

java.lang.Object
  extended by org.apache.openjpa.persistence.criteria.SelectionImpl<X>
      extended by org.apache.openjpa.persistence.criteria.ExpressionImpl<T>
          extended by org.apache.openjpa.persistence.criteria.SubqueryImpl<T>
Type Parameters:
T - the type selected by this subquery.
All Implemented Interfaces:
AbstractQuery<T>, Expression<T>, Selection<T>, Subquery<T>, TupleElement<T>, CriteriaExpression

 class SubqueryImpl<T>
extends ExpressionImpl<T>
implements Subquery<T>

Subquery is an expression which itself is a query and always appears in the context of a parent query. A subquery delegates to a captive query for most of the operations but also maintains its own joins and correlated joins.

Since:
2.0.0
Author:
Pinaki Poddar, Fay Wang

Constructor Summary
SubqueryImpl(Class<T> cls, AbstractQuery<?> parent)
          Construct a subquery always in the context of a parent query.
 
Method Summary
 StringBuilder asValue(AliasContext q)
          Get a string representation of this node as a value in the context of the given query.
 StringBuilder asVariable(AliasContext q)
          Get a string representation of this node as a variable in the context of the given query.
<X,Y> CollectionJoin<X,Y>
correlate(CollectionJoin<X,Y> parentJoin)
           
<X,Y> Join<X,Y>
correlate(Join<X,Y> parentJoin)
          Correlate this subquery with the given join.
<X,Y> ListJoin<X,Y>
correlate(ListJoin<X,Y> parentJoin)
           
<X,K,V> MapJoin<X,K,V>
correlate(MapJoin<X,K,V> parentJoin)
           
<Y> Root<Y>
correlate(Root<Y> root)
          Correlate this subquery with the given root.
<X,Y> SetJoin<X,Y>
correlate(SetJoin<X,Y> parentJoin)
           
 Subquery<T> distinct(boolean distinct)
           
<X> Root<X>
from(Class<X> entityClass)
           
<X> Root<X>
from(EntityType<X> entity)
           
(package private)  Stack<Context> getContexts()
           
 Set<Join<?,?>> getCorrelatedJoins()
           
(package private)  CriteriaQueryImpl<T> getDelegate()
          Gets the captive query to which this subquery delegates.
 List<Expression<?>> getGroupList()
           
 Predicate getGroupRestriction()
           
 CriteriaQueryImpl<?> getInnermostParent()
          Gets the 'root' query for this subquery.
 MetamodelImpl getMetamodel()
           
 AbstractQuery<?> getParent()
          Gets the parent query of this subquery.
 Predicate getRestriction()
           
 Class<T> getResultType()
           
 Root<?> getRoot()
           
 Set<Root<?>> getRoots()
           
 Expression<T> getSelection()
           
(package private)  Subquery getSubQ()
           
 Subquery<T> groupBy(Expression<?>... grouping)
           
 Subquery<T> groupBy(List<Expression<?>> grouping)
           
 Subquery<T> having(Expression<Boolean> restriction)
           
 Subquery<T> having(Predicate... restrictions)
           
 boolean isCorrelated()
          Affirms if this is a correlated subquery.
 boolean isDistinct()
           
 Subquery<T> select(Expression<T> expression)
           
<U> Subquery<U>
subquery(Class<U> type)
           
 Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q)
          Convert this path to a kernel path value.
 Subquery<T> where(Expression<Boolean> restriction)
           
 Subquery<T> where(Predicate... restrictions)
           
 
Methods inherited from class org.apache.openjpa.persistence.criteria.ExpressionImpl
as, in, in, in, in, isNotNull, isNull, toKernelExpression
 
Methods inherited from class org.apache.openjpa.persistence.criteria.SelectionImpl
acceptVisit, alias, asProjection, assertValidName, getAlias, getCompoundSelectionItems, getJavaType, isAliased, isAutoAliased, isCompoundSelection, setAutoAlias
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.persistence.criteria.Expression
as, in, in, in, in, isNotNull, isNull
 
Methods inherited from interface javax.persistence.criteria.Selection
alias, getCompoundSelectionItems, isCompoundSelection
 
Methods inherited from interface javax.persistence.TupleElement
getAlias, getJavaType
 

Constructor Detail

SubqueryImpl

SubqueryImpl(Class<T> cls,
             AbstractQuery<?> parent)
Construct a subquery always in the context of a parent query.

Parameters:
cls - the result type of this subquery
parent - the non-null parent query which itself can be a subquery.
Method Detail

getParent

public AbstractQuery<?> getParent()
Gets the parent query of this subquery. Can be a query or another subquery.

Specified by:
getParent in interface Subquery<T>

getDelegate

CriteriaQueryImpl<T> getDelegate()
Gets the captive query to which this subquery delegates.


getMetamodel

public MetamodelImpl getMetamodel()

getContexts

Stack<Context> getContexts()

getInnermostParent

public CriteriaQueryImpl<?> getInnermostParent()
Gets the 'root' query for this subquery.


select

public Subquery<T> select(Expression<T> expression)
Specified by:
select in interface Subquery<T>

getSelection

public Expression<T> getSelection()
Specified by:
getSelection in interface AbstractQuery<T>
Specified by:
getSelection in interface Subquery<T>

from

public <X> Root<X> from(EntityType<X> entity)
Specified by:
from in interface AbstractQuery<T>

from

public <X> Root<X> from(Class<X> entityClass)
Specified by:
from in interface AbstractQuery<T>

getRoots

public Set<Root<?>> getRoots()
Specified by:
getRoots in interface AbstractQuery<T>

getRoot

public Root<?> getRoot()

where

public Subquery<T> where(Expression<Boolean> restriction)
Specified by:
where in interface AbstractQuery<T>
Specified by:
where in interface Subquery<T>

where

public Subquery<T> where(Predicate... restrictions)
Specified by:
where in interface AbstractQuery<T>
Specified by:
where in interface Subquery<T>

groupBy

public Subquery<T> groupBy(Expression<?>... grouping)
Specified by:
groupBy in interface AbstractQuery<T>
Specified by:
groupBy in interface Subquery<T>

groupBy

public Subquery<T> groupBy(List<Expression<?>> grouping)
Specified by:
groupBy in interface AbstractQuery<T>
Specified by:
groupBy in interface Subquery<T>

having

public Subquery<T> having(Expression<Boolean> restriction)
Specified by:
having in interface AbstractQuery<T>
Specified by:
having in interface Subquery<T>

having

public Subquery<T> having(Predicate... restrictions)
Specified by:
having in interface AbstractQuery<T>
Specified by:
having in interface Subquery<T>

distinct

public Subquery<T> distinct(boolean distinct)
Specified by:
distinct in interface AbstractQuery<T>
Specified by:
distinct in interface Subquery<T>

getGroupList

public List<Expression<?>> getGroupList()
Specified by:
getGroupList in interface AbstractQuery<T>

getRestriction

public Predicate getRestriction()
Specified by:
getRestriction in interface AbstractQuery<T>

getGroupRestriction

public Predicate getGroupRestriction()
Specified by:
getGroupRestriction in interface AbstractQuery<T>

isDistinct

public boolean isDistinct()
Specified by:
isDistinct in interface AbstractQuery<T>

subquery

public <U> Subquery<U> subquery(Class<U> type)
Specified by:
subquery in interface AbstractQuery<T>

correlate

public <Y> Root<Y> correlate(Root<Y> root)
Correlate this subquery with the given root.

Specified by:
correlate in interface Subquery<T>

getCorrelatedJoins

public Set<Join<?,?>> getCorrelatedJoins()
Specified by:
getCorrelatedJoins in interface Subquery<T>

correlate

public <X,Y> Join<X,Y> correlate(Join<X,Y> parentJoin)
Correlate this subquery with the given join.

Specified by:
correlate in interface Subquery<T>

isCorrelated

public boolean isCorrelated()
Affirms if this is a correlated subquery.


correlate

public <X,Y> CollectionJoin<X,Y> correlate(CollectionJoin<X,Y> parentJoin)
Specified by:
correlate in interface Subquery<T>

correlate

public <X,Y> SetJoin<X,Y> correlate(SetJoin<X,Y> parentJoin)
Specified by:
correlate in interface Subquery<T>

correlate

public <X,Y> ListJoin<X,Y> correlate(ListJoin<X,Y> parentJoin)
Specified by:
correlate in interface Subquery<T>

correlate

public <X,K,V> MapJoin<X,K,V> correlate(MapJoin<X,K,V> parentJoin)
Specified by:
correlate in interface Subquery<T>

getSubQ

Subquery getSubQ()

toValue

public Value toValue(ExpressionFactory factory,
                     CriteriaQueryImpl<?> q)
Convert this path to a kernel path value.

Specified by:
toValue in class ExpressionImpl<T>
Parameters:
factory - creates the kernel expression
q - the query definition context of this expression
Returns:
an equivalent kernel value

getResultType

public Class<T> getResultType()
Specified by:
getResultType in interface AbstractQuery<T>

asValue

public StringBuilder asValue(AliasContext q)
Description copied from interface: CriteriaExpression
Get a string representation of this node as a value in the context of the given query.

Specified by:
asValue in interface CriteriaExpression
Overrides:
asValue in class SelectionImpl<T>

asVariable

public StringBuilder asVariable(AliasContext q)
Description copied from interface: CriteriaExpression
Get a string representation of this node as a variable in the context of the given query.

Specified by:
asVariable in interface CriteriaExpression
Overrides:
asVariable in class SelectionImpl<T>


Copyright © 2006-2012 Apache Software Foundation. All Rights Reserved.