use of org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration in project eclipselink by eclipse-ee4j.
the class EclipseLinkContentAssistVisitor method getTableName.
protected String getTableName(String variableName) {
Declaration declaration = queryContext.getDeclaration(variableName);
Expression baseExpression = (declaration != null) ? declaration.getBaseExpression() : null;
if ((baseExpression != null) && isTableExpression(baseExpression)) {
return queryContext.literal(baseExpression, LiteralType.STRING_LITERAL);
}
return null;
}
use of org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration in project eclipselink by eclipse-ee4j.
the class GenericSemanticValidatorHelper method collectLocalDeclarationIdentificationVariables.
protected void collectLocalDeclarationIdentificationVariables(JPQLQueryContext queryContext, Map<String, List<IdentificationVariable>> identificationVariables) {
DeclarationResolver declarationResolver = queryContext.getDeclarationResolverImp();
for (Declaration declaration : declarationResolver.getDeclarations()) {
// Register the identification variable from the base expression
IdentificationVariable identificationVariable = declaration.getIdentificationVariable();
addIdentificationVariable(identificationVariable, identificationVariables);
// Register the identification variable from the JOIN expressions
for (Join join : declaration.getJoins()) {
IdentificationVariable joinIdentificationVariable = getIdentificationVariable(join.getIdentificationVariable());
addIdentificationVariable(joinIdentificationVariable, identificationVariables);
}
}
if (queryContext.getParent() == null) {
for (IdentificationVariable identificationVariable : declarationResolver.getResultVariablesMap().keySet()) {
addIdentificationVariable(identificationVariable, identificationVariables);
}
}
}
use of org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration in project eclipselink by eclipse-ee4j.
the class JPQLQueryContext method convertUnqualifiedDeclaration.
/**
* 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) {@literal >} 0</code>" <em>managedEmployees</em> is an unqualified
* collection-valued path expression (<code>employee.managedEmployees</code>).
*
* @param declaration The {@link Declaration} that was parsed to range over an abstract schema
* name but is actually ranging over a path expression
*/
public void convertUnqualifiedDeclaration(Declaration declaration) {
if (parent != null) {
// Retrieve the range identification variable from the parent declaration
Declaration parentDeclaration = parent.getDeclarationResolverImp().getDeclarations().get(0);
String outerVariableName = parentDeclaration.getVariableName();
// Qualify the range expression to be fully qualified
getDeclarationResolverImp().convertUnqualifiedDeclaration(declaration, outerVariableName);
}
}
use of org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration in project eclipselink by eclipse-ee4j.
the class DeclarationTest method testDeclarations.
protected final void testDeclarations(JPQLQueryContext queryContext, Map<Expression, DeclarationTester[]> declarationTesters) {
for (Map.Entry<Expression, DeclarationTester[]> entry : declarationTesters.entrySet()) {
Expression expression = entry.getKey();
DeclarationTester[] testers = entry.getValue();
if (expression.getRoot() != expression) {
queryContext.newSubqueryContext(expression);
}
// Retrieve the list of Declarations
List<Declaration> declarations = queryContext.getDeclarations();
assertNotNull(declarations);
assertEquals(testers.length, declarations.size());
// Test each one of them
for (int index = testers.length; --index >= 0; ) {
Declaration declaration = declarations.get(index);
DeclarationTester tester = testers[index];
tester.test(declaration);
}
if (expression.getRoot() != expression) {
queryContext.disposeSubqueryContext();
}
}
}
use of org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration in project eclipselink by eclipse-ee4j.
the class DeclarationTest method testDeclarations.
protected final void testDeclarations(String jpqlQuery, boolean tolerant, DeclarationTester... declarationTesters) {
// Build the JPQLQueryContext, which will parse the JPQL query and create the list of Declarations
JPQLQueryContext queryContext = buildQueryContext();
queryContext.setTolerant(tolerant);
queryContext.setQuery(buildQuery(jpqlQuery));
// Retrieve the list of Declarations
List<Declaration> declarations = queryContext.getDeclarations();
assertNotNull(declarations);
assertEquals(declarationTesters.length, declarations.size());
// Test each one of them
for (int index = declarationTesters.length; --index >= 0; ) {
Declaration declaration = declarations.get(index);
DeclarationTester tester = declarationTesters[index];
tester.test(declaration);
}
}
Aggregations