Class AbstractJPQLQueryHelper
- java.lang.Object
-
- org.eclipse.persistence.jpa.jpql.tools.AbstractJPQLQueryHelper
-
- Direct Known Subclasses:
DefaultJPQLQueryHelper
,EclipseLinkJPQLQueryHelper
public abstract class AbstractJPQLQueryHelper extends java.lang.Object
This helper can perform the following operations over a JPQL query:- Calculates the result type of a query:
getResultType()
; - Calculates the type of an input parameter:
getParameterType(String)
. - Calculates the possible choices to complete the query from a given
position (used for content assist):
buildContentAssistProposals(int)
. - Validates the query by introspecting it grammatically and semantically:
- Refactoring support:
buildBasicRefactoringTool()
provides support for generating the delta of the refactoring operation through a collection ofTextEdit
objects.buildRefactoringTool()
provides support for refactoring the JPQL query through the editableStateObject
and once all refactoring operations have been executed, theIJPQLQueryFormatter
will generate a new string representation of the JPQL query.
Provisional API: This interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.
- Version:
- 2.5
- Author:
- Pascal Filion
- Since:
- 2.3
-
-
Constructor Summary
Constructors Modifier Constructor Description AbstractJPQLQueryHelper(JPQLGrammar jpqlGrammar)
Creates a newAbstractJPQLQueryHelper
.protected
AbstractJPQLQueryHelper(JPQLQueryContext queryContext)
Creates a newAbstractJPQLQueryHelper
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract BasicRefactoringTool
buildBasicRefactoringTool()
Creates the concrete instance of the tool that can refactor the content of a JPQL query.ContentAssistProposals
buildContentAssistProposals(int position)
Retrieves the possibles choices that can complete the query from the given position within the query.ContentAssistProposals
buildContentAssistProposals(int position, ContentAssistExtension extension)
Retrieves the possibles choices that can complete the query from the given position within the query.protected abstract AbstractContentAssistVisitor
buildContentAssistVisitor(JPQLQueryContext queryContext)
Creates the concrete instance of the content assist visitor that will give the possible choices based on the position of the cursor within the JPQL query.protected abstract AbstractGrammarValidator
buildGrammarValidator(JPQLGrammar jpqlGrammar)
Creates the concrete instance of the validator that will grammatically validate the JPQL query.protected abstract JPQLQueryContext
buildJPQLQueryContext(JPQLGrammar jpqlGrammar)
Creates a context that will be used to store and retrieve information about the JPQL query.protected java.util.Comparator<IType>
buildNumericTypeComparator()
Creates theComparator
that can sortITypes
based on the numerical priority.abstract RefactoringTool
buildRefactoringTool()
Creates the concrete instance of the tool that can refactor the content of a JPQL query.protected abstract AbstractSemanticValidator
buildSemanticValidator(JPQLQueryContext queryContext)
Creates the concrete instance of the validator that will semantically validate the JPQL query.void
dispose()
Disposes of the internal data.protected AbstractContentAssistVisitor
getContentAssistVisitor()
Returns the visitor that can visit a JPQL query and based on the position of the cursor within the JPQL query and determines the valid proposals.JPQLGrammar
getGrammar()
Returns the JPQL grammar that will be used to define how to parse a JPQL query.protected AbstractGrammarValidator
getGrammarValidator()
JPQLExpression
getJPQLExpression()
Returns the root of the parsed tree representation of the JPQL query.IType
getParameterType(java.lang.String parameterName)
Retrieves, if it can be determined, the type of the given input parameter with the given name.java.lang.String
getParsedJPQLQuery()
Returns the string representation of the parsed tree.IManagedTypeProvider
getProvider()
Returns the provider for managed types (entities, embeddables, mapped superclasses).IQuery
getQuery()
Returns the external form representing a named query.JPQLQueryContext
getQueryContext()
Returns theJPQLQueryContext
that contains information about the JPQL query.IType
getResultType()
Calculates the type of the query result of the JPQL query.protected AbstractSemanticValidator
getSemanticValidator()
IType
getType(java.lang.Class<?> type)
Returns theIType
representing the given Java type.TypeHelper
getTypeHelper()
Returns a helper that gives access to the most commontypes
.ITypeRepository
getTypeRepository()
Returns the repository that gives access to the application's types.void
setJPQLExpression(JPQLExpression jpqlExpression)
Sets the parsed tree representation of the JPQL query.void
setQuery(IQuery query)
Sets the external form of the JPQL query, which will be parsed and information will be extracted for later access.java.util.List<JPQLQueryProblem>
validate()
Validates the query by introspecting it grammatically and semantically.void
validate(Expression expression, java.util.List<JPQLQueryProblem> problems)
Validates the query by introspecting it grammatically and semantically.java.util.List<JPQLQueryProblem>
validateGrammar()
Validates the query by only introspecting it grammatically.void
validateGrammar(Expression expression, java.util.List<JPQLQueryProblem> problems)
Validates the query by only introspecting it grammatically.java.util.List<JPQLQueryProblem>
validateSemantic()
Validates the query by only introspecting it semantically.void
validateSemantic(Expression expression, java.util.List<JPQLQueryProblem> problems)
Validates the query by only introspecting it semantically.
-
-
-
Constructor Detail
-
AbstractJPQLQueryHelper
public AbstractJPQLQueryHelper(JPQLGrammar jpqlGrammar)
Creates a newAbstractJPQLQueryHelper
.- Parameters:
jpqlGrammar
- TheJPQLGrammar
that will determine how to parse JPQL queries
-
AbstractJPQLQueryHelper
protected AbstractJPQLQueryHelper(JPQLQueryContext queryContext)
Creates a newAbstractJPQLQueryHelper
.- Parameters:
queryContext
- The context used to query information about the JPQL query- Throws:
java.lang.NullPointerException
- The JPQLQueryContext cannot benull
-
-
Method Detail
-
buildBasicRefactoringTool
public abstract BasicRefactoringTool buildBasicRefactoringTool()
Creates the concrete instance of the tool that can refactor the content of a JPQL query. This version simply provides the delta of the refactoring operations.- Returns:
- The concrete instance of
RefactoringTool
- See Also:
buildRefactoringTool()
- Since:
- 2.5
-
buildContentAssistProposals
public ContentAssistProposals buildContentAssistProposals(int position)
Retrieves the possibles choices that can complete the query from the given position within the query.Note: Disposing of the internal data is not done automatically.
- Parameters:
position
- The position within the query for which a list of possible choices are created for completing the query- Returns:
- The list of valid proposals regrouped by categories
-
buildContentAssistProposals
public ContentAssistProposals buildContentAssistProposals(int position, ContentAssistExtension extension)
Retrieves the possibles choices that can complete the query from the given position within the query.Note: Disposing of the internal data is not done automatically.
- Parameters:
position
- The position within the query for which a list of possible choices are created for completing the queryextension
- This extension can be used to provide additional information that is outside the scope of simply providing JPA metadata information, such as table names, column names, class names- Returns:
- The list of valid proposals regrouped by categories
- Since:
- 2.5
-
buildContentAssistVisitor
protected abstract AbstractContentAssistVisitor buildContentAssistVisitor(JPQLQueryContext queryContext)
Creates the concrete instance of the content assist visitor that will give the possible choices based on the position of the cursor within the JPQL query.- Parameters:
queryContext
- The context used to query information about the JPQL query- Returns:
- A new concrete instance of
AbstractContentAssistVisitor
-
buildGrammarValidator
protected abstract AbstractGrammarValidator buildGrammarValidator(JPQLGrammar jpqlGrammar)
Creates the concrete instance of the validator that will grammatically validate the JPQL query.- Parameters:
jpqlGrammar
- The context used to query information about the JPQL query- Returns:
- A new concrete instance of
AbstractGrammarValidator
-
buildJPQLQueryContext
protected abstract JPQLQueryContext buildJPQLQueryContext(JPQLGrammar jpqlGrammar)
Creates a context that will be used to store and retrieve information about the JPQL query.- Parameters:
jpqlGrammar
- The JPQL grammar that is required for dictating how the JPQL query will be parsed. It is also used by validation and by the content assist- Returns:
- A new
JPQLQueryContext
-
buildNumericTypeComparator
protected java.util.Comparator<IType> buildNumericTypeComparator()
Creates theComparator
that can sortITypes
based on the numerical priority.- Returns:
NumericTypeComparator
-
buildRefactoringTool
public abstract RefactoringTool buildRefactoringTool()
Creates the concrete instance of the tool that can refactor the content of a JPQL query. This version provides a way to manipulate the editable version of the JPQL query (StateObject
and simply outputs the result of the refactoring operations, i.e. the updated JPQL query).- Returns:
- The concrete instance of
RefactoringTool
- See Also:
buildBasicRefactoringTool()
- Since:
- 2.4
-
buildSemanticValidator
protected abstract AbstractSemanticValidator buildSemanticValidator(JPQLQueryContext queryContext)
Creates the concrete instance of the validator that will semantically validate the JPQL query.- Parameters:
queryContext
- The context used to query information about the JPQL query- Returns:
- A new concrete instance of
AbstractSemanticValidator
-
dispose
public void dispose()
Disposes of the internal data.
-
getContentAssistVisitor
protected AbstractContentAssistVisitor getContentAssistVisitor()
Returns the visitor that can visit a JPQL query and based on the position of the cursor within the JPQL query and determines the valid proposals.- Returns:
- A concrete instance of
AbstractContentAssistVisitor
- See Also:
buildContentAssistVisitor(JPQLQueryContext)
-
getGrammar
public JPQLGrammar getGrammar()
Returns the JPQL grammar that will be used to define how to parse a JPQL query.- Returns:
- The grammar that was used to parse this
Expression
- Since:
- 2.4
-
getGrammarValidator
protected AbstractGrammarValidator getGrammarValidator()
-
getJPQLExpression
public JPQLExpression getJPQLExpression()
Returns the root of the parsed tree representation of the JPQL query.- Returns:
- The parsed JPQL query
-
getParameterType
public IType getParameterType(java.lang.String parameterName)
Retrieves, if it can be determined, the type of the given input parameter with the given name. The type will be guessed based on its location within expression.Note: Both named and positional input parameter can be used.
- Parameters:
parameterName
- The name of the input parameter to retrieve its type, which needs to be prepended by ':' or '?'- Returns:
- Either the closest type of the input parameter or
null
if the type couldn't be determined
-
getParsedJPQLQuery
public java.lang.String getParsedJPQLQuery()
Returns the string representation of the parsed tree.- Returns:
- The string created from the parsed tree representation of the original JPQL query
-
getProvider
public IManagedTypeProvider getProvider()
Returns the provider for managed types (entities, embeddables, mapped superclasses).- Returns:
- The container of managed types
-
getQuery
public IQuery getQuery()
Returns the external form representing a named query.- Returns:
- The external form representing a named query
-
getQueryContext
public JPQLQueryContext getQueryContext()
Returns theJPQLQueryContext
that contains information about the JPQL query.- Returns:
- The
JPQLQueryContext
that contains information contained in the JPQL query
-
getResultType
public IType getResultType()
Calculates the type of the query result of the JPQL query.See
Resolver
to understand how the type is calculated.- Returns:
- The result type of the JPQL query if it could accurately be calculated or the
IType
forObject
if it could not be calculated
-
getSemanticValidator
protected AbstractSemanticValidator getSemanticValidator()
-
getType
public IType getType(java.lang.Class<?> type)
Returns theIType
representing the given Java type.- Parameters:
type
- The Java type for which its external form is requested- Returns:
- The external form for the given Java type
-
getTypeHelper
public TypeHelper getTypeHelper()
Returns a helper that gives access to the most commontypes
.- Returns:
- A helper containing a collection of methods related to
IType
-
getTypeRepository
public ITypeRepository getTypeRepository()
Returns the repository that gives access to the application's types.- Returns:
- The repository for classes, interfaces, enum types and annotations
-
setJPQLExpression
public void setJPQLExpression(JPQLExpression jpqlExpression)
Sets the parsed tree representation of the JPQL query. If the expression was parsed outside of the scope of this context, then this method has to be invoked beforesetQuery(IQuery)
because the JPQL query is automatically parsed by that method.- Parameters:
jpqlExpression
- The parsed representation of the JPQL query to manipulate- See Also:
setQuery(IQuery)
-
setQuery
public void setQuery(IQuery query)
Sets the external form of the JPQL query, which will be parsed and information will be extracted for later access.- Parameters:
query
- The external form of the JPQL query
-
validate
public java.util.List<JPQLQueryProblem> validate()
Validates the query by introspecting it grammatically and semantically.- Returns:
- The non-
null
list that will be used to store theproblems
if any was found
-
validate
public void validate(Expression expression, java.util.List<JPQLQueryProblem> problems)
Validates the query by introspecting it grammatically and semantically.- Parameters:
expression
- The parsed tree representation of the JPQL fragment to validateproblems
- A non-null
list that will be used to store theproblems
if any was found
-
validateGrammar
public java.util.List<JPQLQueryProblem> validateGrammar()
Validates the query by only introspecting it grammatically.- Returns:
- The non-
null
list that will be used to store theproblems
if any was found
-
validateGrammar
public void validateGrammar(Expression expression, java.util.List<JPQLQueryProblem> problems)
Validates the query by only introspecting it grammatically.- Parameters:
expression
- The parsed tree representation of the queryproblems
- A non-null
list that will be used to store theproblems
if any was found
-
validateSemantic
public java.util.List<JPQLQueryProblem> validateSemantic()
Validates the query by only introspecting it semantically.- Returns:
- The non-
null
list that will be used to store theproblems
if any was found
-
validateSemantic
public void validateSemantic(Expression expression, java.util.List<JPQLQueryProblem> problems)
Validates the query by only introspecting it semantically.- Parameters:
expression
- The parsed tree representation of the queryproblems
- A non-null
list that will be used to store theproblems
if any was found
-
-