/** * Retrieves all the {@link InputParameter InputParameters} with the given parameter name. * * @param parameterName The parameter used to find the {@link InputParameter InputParameters} * with the same value * @return Either the {@link InputParameter InputParameters} that has the given parameter or an * empty collection */ public Collection<InputParameter> findInputParameters(String parameterName) { InputParameterVisitor visitor = getInputParameterVisitor(); try { visitor.parameterName = parameterName; visitor.inputParameters = new ArrayList<InputParameter>(); jpqlExpression.accept(visitor); return visitor.inputParameters; } finally { visitor.parameterName = null; visitor.inputParameters = null; } }
/** * Renames a given entity name. * * @param oldEntityName The current name of the entity to rename * @param newEntityName The new name of the entity */ public void renameEntityName(String oldEntityName, String newEntityName) { AbstractRenamer renamer = buildEntityNameRenamer(oldEntityName, newEntityName); getExpression().accept(renamer); delta.addTextEdits(renamer.textEdits); }
/** * Renames a variable name. * * @param oldVariableName The current identification variable name * @param newVariableName The new name of the identification variable */ public void renameVariable(String oldVariableName, String newVariableName) { AbstractRenamer renamer = buildVariableNameRenamer(oldVariableName, newVariableName); getExpression().accept(renamer); delta.addTextEdits(renamer.textEdits); }
/** * Renames a fully qualified class name. * * @param oldClassName The current fully qualified class name of the class to rename * @param newClassName The new fully qualified class name */ public void renameClassName(String oldClassName, String newClassName) { ClassNameRenamer renamer = buildClassNameRenamer(oldClassName, newClassName); getExpression().accept(renamer); delta.addTextEdits(renamer.textEdits); }
/** * Renames a result variable name. * * @param oldVariableName The current identification variable name * @param newVariableName The new name of the identification variable */ public void renameResultVariable(String oldVariableName, String newVariableName) { AbstractRenamer renamer = buildResultVariableNameRenamer(oldVariableName, newVariableName); getExpression().accept(renamer); delta.addTextEdits(renamer.textEdits); }
/** * Populates this object by scanning the JPQL query using the given JPQL grammar. * * @param jpqlGrammar The {@link JPQLGrammar} how the JPQL query is parsed */ void populate(JPQLGrammar jpqlGrammar) { JPQLQueryContext queryContext = new JPQLQueryContext(query, jpqlGrammar); ConstructorVisitor visitor = new ConstructorVisitor(queryContext); queryContext.getJPQLExpression().accept(visitor); }
/** * Renames the attribute (persistent field or persistent property) from the given type. * * @param typeName The fully qualified name of the type that got one of its attributes renamed * @param oldAttributeName The current name of the attribute to rename * @param newAttributeName The new name of the attribute */ public void renameAttribute(String typeName, String oldAttributeName, String newAttributeName) { AbstractRenamer renamer = buildAttributeNameRenamer(typeName, oldAttributeName, newAttributeName); getExpression().accept(renamer); delta.addTextEdits(renamer.textEdits); }
/** * Renames an enum constant, which has to be fully qualified. * * @param oldEnumConstant The current fully qualified name of the enum constant to rename * @param newEnumConstant The new fully qualified name of the enum constant */ public void renameEnumConstant(String oldEnumConstant, String newEnumConstant) { AbstractRenamer renamer = buildEnumConstantRenamer(oldEnumConstant, newEnumConstant); getExpression().accept(renamer); delta.addTextEdits(renamer.textEdits); }
/** * Populates this object by scanning the JPQL query using the given JPQL grammar. * * @param jpqlGrammar The {@link JPQLGrammar} how the JPQL query is parsed */ void populate(JPQLGrammar jpqlGrammar) { JPQLQueryContext queryContext = new JPQLQueryContext(query, jpqlGrammar); ConstructorVisitor visitor = new ConstructorVisitor(queryContext); queryContext.getJPQLExpression().accept(visitor); }
/** * 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; }
/** * 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; }
/** * Retrieves the list of {@link ClassDescriptor descriptors} corresponding to the entities used * throughout the given JPQL query. * * @param jpqlQuery The JPQL query used to gather the descriptors defined in the declaration clause * @param session The {@link AbstractSession} is used to retrieve the descriptors * @return The list of {@link ClassDescriptors descriptors} used in the JPQL query or an empty * list if the JPQL query is invalid or incomplete */ public List<ClassDescriptor> getClassDescriptors(CharSequence jpqlQuery, AbstractSession session) { // Parse the JPQL query JPQLExpression jpqlExpression = new JPQLExpression(jpqlQuery, jpqlGrammar, true); // Create the context and cache the information JPQLQueryContext queryContext = new JPQLQueryContext(jpqlGrammar); queryContext.cache(session, null, jpqlExpression, jpqlQuery); // Visit the JPQL query and collect the descriptors defined in the declaration clauses DescriptorCollector collector = new DescriptorCollector(queryContext); jpqlExpression.accept(collector); return new ArrayList<ClassDescriptor>(collector.descriptors); }
/** * Retrieves the list of {@link ClassDescriptor descriptors} corresponding to the entities used * throughout the given JPQL query. * * @param jpqlQuery The JPQL query used to gather the descriptors defined in the declaration clause * @param session The {@link AbstractSession} is used to retrieve the descriptors * @return The list of {@link ClassDescriptors descriptors} used in the JPQL query or an empty * list if the JPQL query is invalid or incomplete */ public List<ClassDescriptor> getClassDescriptors(CharSequence jpqlQuery, AbstractSession session) { // Parse the JPQL query JPQLExpression jpqlExpression = new JPQLExpression(jpqlQuery, jpqlGrammar, true); // Create the context and cache the information JPQLQueryContext queryContext = new JPQLQueryContext(jpqlGrammar); queryContext.cache(session, null, jpqlExpression, jpqlQuery); // Visit the JPQL query and collect the descriptors defined in the declaration clauses DescriptorCollector collector = new DescriptorCollector(queryContext); jpqlExpression.accept(collector); return new ArrayList<ClassDescriptor>(collector.descriptors); }
/** * {@inheritDoc} */ public JPQLQueryStateObject buildStateObject(IManagedTypeProvider provider, CharSequence jpqlQuery, String queryBNFId, boolean tolerant) { // First parse the JPQL query JPQLExpression jpqlExpression = parse(jpqlQuery, getGrammar(), tolerant); // Now visit the parsed expression and create the state object hierarchy BasicStateObjectBuilder builder = getStateObjectBuilder(); try { builder.jpqlQueryBuilder = this; builder.managedTypeProvider = provider; jpqlExpression.accept(wrap(builder)); return builder.parent; } finally { builder.jpqlQueryBuilder = null; builder.managedTypeProvider = null; builder.parent = null; builder.stateObject = null; } }
jpqlExpression.accept(visitor);
jpqlExpression.accept(visitor);