/** * {@inheritDoc} */ @Override public void visit(SimpleSelectStatement expression) { resolver = new DeclarationResolver(queryContext, resolver); collectDescriptors(expression, resolver); resolver = resolver.getParent(); }
/** * Adds a virtual range variable declaration that will be used when a JPQL fragment is parsed. * * @param entityName The name of the entity to be accessible with the given variable name * @param variableName The identification variable used to navigate to the entity */ void addRangeVariableDeclaration(String entityName, String variableName) { // This method should only be used by HermesParser.buildSelectionCriteria() declarationResolver = new DeclarationResolver(this, null); declarationResolver.addRangeVariableDeclaration( entityName, variableName ); }
/** * Retrieves the {@link Declaration} for which the given variable name is used to navigate to the * "root" object. This does not go up the hierarchy when looking for the {@link Declaration}. * * @param variableName The name of the identification variable that is used to navigate a "root" object * @return The {@link Declaration} containing the information about the identification variable declaration * @see #findDeclaration(String) */ Declaration getDeclaration(String variableName) { return getDeclarationResolver().getDeclaration(variableName); }
/** * Returns the {@link DeclarationResolver} of the current query's declaration. * * @return The {@link DeclarationResolver} for the current query being visited */ DeclarationResolver getDeclarationResolverImp() { if (declarationResolver == null) { DeclarationResolver parentResolver = (parent == null) ? null : parent.getDeclarationResolverImp(); declarationResolver = new DeclarationResolver(this, parentResolver); } declarationResolver.populate(currentQuery); return declarationResolver; }
private void collectDescriptors(Expression expression, DeclarationResolver resolver) { resolver.populate(expression); for (Declaration declaration : resolver.getDeclarations()) { ClassDescriptor descriptor = declaration.getDescriptor(); if (descriptor != null) { descriptors.add(descriptor); } } }
private void collectLocalDeclarationIdentificationVariables(JPQLQueryContext queryContext, Map<String, List<IdentificationVariable>> identificationVariables) { DeclarationResolver declarationResolver = queryContext.getDeclarationResolverImp(); // Collect the identification variables from the declarations for (Declaration declaration : declarationResolver.getDeclarations()) { IdentificationVariable identificationVariable = declaration.identificationVariable; addIdentificationVariable(identificationVariable, identificationVariables); } // Collect the result variables for (IdentificationVariable identificationVariable : declarationResolver.getResultVariables()) { addIdentificationVariable(identificationVariable, identificationVariables); } }
/** * Determines whether the given variable is a result variable or not. * * @param variableName The variable to check if it used to identify a select expression * @return <code>true</code> if the given variable is defined as a result variable; * <code>false</code> otherwise */ boolean isResultVariable(String variableName) { // Only the top-level SELECT query has result variables if (parent != null) { return parent.isResultVariable(variableName); } for (IdentificationVariable resultVariable : getResultVariables()) { if (resultVariable.getText().equalsIgnoreCase(variableName)) { return true; } } return false; }
/** * {@inheritDoc} */ @Override public void visit(DeleteClause expression) { resolver = new DeclarationResolver(queryContext, null); collectDescriptors(expression, resolver); }
/** * Returns the ordered list of {@link Declaration Declarations}. * * @return The {@link Declaration Declarations} of the current query that was parsed */ List<Declaration> getDeclarations() { return getDeclarationResolver().getDeclarations(); }
/** * Returns the first {@link Declaration}, from this context, that was created after visiting the * declaration clause. * * @return The first {@link Declaration} object */ Declaration getFirstDeclarationImp() { return getDeclarationResolverImp().getFirstDeclaration(); }
/** * Creates a new <code>DeclarationResolver</code>. * * @param queryContext The context used to query information about the application metadata and * cached information * @param parent The parent {@link DeclarationResolver} which represents the superquery's declaration */ DeclarationResolver(JPQLQueryContext queryContext, DeclarationResolver parent) { super(); initialize(queryContext, parent); }
/** * Returns the parsed representation of a <b>JOIN FETCH</b> that were defined in the same * declaration than the given range identification variable name. * * @param variableName The name of the identification variable that should be used to define an * abstract schema name * @return The <b>JOIN FETCH</b> expressions used in the same declaration or an empty collection * if none was defined */ Collection<Join> getJoinFetches(String variableName) { return getDeclarationResolver().getJoinFetches(variableName); }
/** * Converts the given {@link Declaration} from being set as a range variable declaration to * a path expression declaration. * <p> * In this query "<code>UPDATE Employee SET firstName = 'MODIFIED' WHERE (SELECT COUNT(m) FROM * managedEmployees m) > 0</code>" <em>managedEmployees</em> is an unqualified collection-valued * path expression (<code>employee.managedEmployees</code>). */ private void convertUnqualifiedDeclaration() { // Retrieve the range identification variable from the parent declaration Declaration parentDeclaration = queryContext.getParent().getFirstDeclarationImp(); String outerVariableName = parentDeclaration.getVariableName(); // Qualify the range expression to be fully qualified queryContext.getDeclarationResolver().convertUnqualifiedDeclaration(this, outerVariableName); }
/** * Returns the variables that got defined in the select expression. This only applies to JPQL * queries built for JPA 2.0 or later. * * @return The variables identifying the select expressions, if any was defined or an empty set * if none were defined */ Collection<IdentificationVariable> getResultVariables() { if (parent != null) { return parent.getResultVariables(); } if (resultVariables == null) { ResultVariableVisitor visitor = new ResultVariableVisitor(); queryContext.getJPQLExpression().accept(visitor); resultVariables = visitor.resultVariables; } return resultVariables; }
private void collectDescriptors(Expression expression, DeclarationResolver resolver) { resolver.populate(expression); for (Declaration declaration : resolver.getDeclarations()) { ClassDescriptor descriptor = declaration.getDescriptor(); if (descriptor != null) { descriptors.add(descriptor); } } }
/** * Returns the {@link DeclarationResolver} of the current query's declaration. * * @return The {@link DeclarationResolver} for the current query being visited */ DeclarationResolver getDeclarationResolverImp() { if (declarationResolver == null) { DeclarationResolver parentResolver = (parent == null) ? null : parent.getDeclarationResolverImp(); declarationResolver = new DeclarationResolver(this, parentResolver); } declarationResolver.populate(currentQuery); return declarationResolver; }
private void collectLocalDeclarationIdentificationVariables(JPQLQueryContext queryContext, Map<String, List<IdentificationVariable>> identificationVariables) { DeclarationResolver declarationResolver = queryContext.getDeclarationResolverImp(); // Collect the identification variables from the declarations for (Declaration declaration : declarationResolver.getDeclarations()) { IdentificationVariable identificationVariable = declaration.identificationVariable; addIdentificationVariable(identificationVariable, identificationVariables); } // Collect the result variables for (IdentificationVariable identificationVariable : declarationResolver.getResultVariables()) { addIdentificationVariable(identificationVariable, identificationVariables); } }
/** * Determines whether the given variable is a result variable or not. * * @param variableName The variable to check if it used to identify a select expression * @return <code>true</code> if the given variable is defined as a result variable; * <code>false</code> otherwise */ boolean isResultVariable(String variableName) { // Only the top-level SELECT query has result variables if (parent != null) { return parent.isResultVariable(variableName); } for (IdentificationVariable resultVariable : getResultVariables()) { if (resultVariable.getText().equalsIgnoreCase(variableName)) { return true; } } return false; }
/** * {@inheritDoc} */ @Override public void visit(UpdateClause expression) { resolver = new DeclarationResolver(queryContext, null); collectDescriptors(expression, resolver); } }
/** * Returns the ordered list of {@link Declaration Declarations}. * * @return The {@link Declaration Declarations} of the current query that was parsed */ List<Declaration> getDeclarations() { return getDeclarationResolver().getDeclarations(); }