FileDocCategorySizeDatePackage
EJBQLParseTree.javaAPI DocGlassfish v2 API7586Tue May 22 16:54:38 BST 2007oracle.toplink.essentials.internal.parsing

EJBQLParseTree

public class EJBQLParseTree extends ParseTree
INTERNAL

Purpose: This represents an EJBQL parse tre

Responsibilities:

  • Maintain the context for the expression generation
  • Build an initial expression
  • Return a reference class for the expression
  • Maintain the root node for the query
author
Jon Driscoll and Joel Lucuik
since
TopLink 4.0

Fields Summary
Constructors Summary
public EJBQLParseTree()
EJBQLParseTree constructor comment.

        super();
    
Methods Summary
public GenerationContextbuildContext(ReadQuery readQuery, oracle.toplink.essentials.internal.sessions.AbstractSession session)
INTERNAL Build the context to be used when generating the expression from the parse tree

        GenerationContext contextForGeneration = super.buildContext(readQuery, session);

        contextForGeneration.setBaseQueryClass(readQuery.getReferenceClass());
        return contextForGeneration;
    
private GenerationContextbuildSubqueryContext(ReadQuery readQuery, GenerationContext outer)
INTERNAL Build the context to be used when generating the expression from the subquery parse tree.

        GenerationContext context = new SelectGenerationContext(outer, this);
        context.setBaseQueryClass(readQuery.getReferenceClass());
        return context;
    
private voidpopulateModifyQueryInternal(ModifyAllQuery query, GenerationContext generationContext)

        if (query.getReferenceClass() == null) {
            // Adjust the reference class if necessary
            adjustReferenceClassForQuery(query, generationContext);
        }
        query.setSession(generationContext.getSession());            

        // Initialize the base expression in the generation context
        initBaseExpression(query, generationContext);

        // Validate parse tree
        validate(generationContext.getSession(), getClassLoader());

        // Apply the query node to the query
        applyQueryNodeToQuery(query, generationContext);
        
        setSelectionCriteriaForQuery(query, generationContext);
    
public voidpopulateQuery(DatabaseQuery query, oracle.toplink.essentials.internal.sessions.AbstractSession session)
Add all of the relevant query settings from an EJBQLParseTree to the given database query.

param
query The query to populate
param
session The sessionto use to information such as descriptors.

        if (query.isObjectLevelReadQuery()) {
            ObjectLevelReadQuery objectQuery = (ObjectLevelReadQuery)query;
            GenerationContext generationContext = buildContext(objectQuery, session);
            populateReadQueryInternal(objectQuery, generationContext);
        } else if (query.isUpdateAllQuery()) {
            UpdateAllQuery updateQuery = (UpdateAllQuery)query;
            GenerationContext generationContext = buildContext(updateQuery, session);
            populateModifyQueryInternal(updateQuery, generationContext);
            addUpdatesToQuery(updateQuery, generationContext);
        } else if (query.isDeleteAllQuery()) {
            DeleteAllQuery deleteQuery = (DeleteAllQuery)query;
            GenerationContext generationContext = buildContext(deleteQuery, session);
            populateModifyQueryInternal(deleteQuery, generationContext);
        }
    
private voidpopulateReadQueryInternal(ObjectLevelReadQuery objectQuery, GenerationContext generationContext)

        // Get the reference class if it does not exist.  This is done
        // for dynamic queries in EJBQL 3.0
        if (objectQuery.getReferenceClass() == null) {
            // Adjust the reference class if necessary
            adjustReferenceClassForQuery(objectQuery, generationContext);
        }

        // Initialize the base expression in the generation context
        initBaseExpression(objectQuery, generationContext);
        
        // Validate parse tree
        validate(generationContext.getSession(), getClassLoader());

        // Apply the query node to the query (this will be a SelectNode for a read query)
        applyQueryNodeToQuery(objectQuery, generationContext);
        
        // Verify the SELECT is valid (valid alias, etc)
        verifySelect(objectQuery, generationContext);
        
        // This is what it's all about...
        setSelectionCriteriaForQuery(objectQuery, generationContext);
        
        // Add any ordering
        addOrderingToQuery(objectQuery, generationContext);

        // Add any grouping
        addGroupingToQuery(objectQuery, generationContext);
        
        // Add having
        addHavingToQuery(objectQuery, generationContext);
        
        // Add non fetch joined variables
        addNonFetchJoinAttributes(objectQuery, generationContext);
    
public GenerationContextpopulateSubquery(ObjectLevelReadQuery readQuery, GenerationContext outer)
Add all of the relevant query settings from an EJBQLParseTree to the given database query.

param
query The query to populate
param
outer the GenerationContext of the outer EJBQL query.
return
the GenerationContext for the subquery

        GenerationContext innerContext = buildSubqueryContext(readQuery, outer);
        populateReadQueryInternal(readQuery, innerContext);
        return innerContext;