Package com.tangosol.coherence.dslquery
Class CoherenceQueryLanguage
- java.lang.Object
-
- com.tangosol.coherence.dslquery.CoherenceQueryLanguage
-
public class CoherenceQueryLanguage extends Object
CoherenceQueryLanguage is a simple language for building Filters and doing simple queries that are similar in style to SQL. This class configures CohQL and contains various attributes that control CohQL execution.- Author:
- djl 2009.08.31, jk 2013.12.02
-
-
Field Summary
Fields Modifier and Type Field Description protected ExtractorBuilder
m_bldrExtractor
TheExtractorBuilder
that will be used to realizeValueExtractor
s to be used by CohQL.protected Map<String,ParameterizedBuilder<?>>
m_mapFunctions
The map of CohQL functions.protected Map<CharSequence,BaseOperator>
m_mapOperators
The map of CohQL operators.protected Map<String,StatementBuilder<?>>
m_mapStatementBuilders
The map of CohQL query builders.protected TokenTable
m_tokenTableExtendedSQL
The extended TokenTable for the full language that resembles SQL.protected TokenTable
m_tokenTableForFilter
The TokenTable for Filters.protected TokenTable
m_tokenTableSQL
The TokenTable for the full language that resembles SQL.
-
Constructor Summary
Constructors Constructor Description CoherenceQueryLanguage()
Construct a CoherenceQueryLanguage instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFunction(String sName, ParameterizedBuilder bldrFunction)
Map the specified CohQLParameterizedBuilder
to the specified function name.void
addOperator(BaseOperator operator)
Add the custom operator to the CohQL language.void
addStatement(String sFunctor, StatementBuilder<?> builder)
Register the givenStatementBuilder
to the specified functor name.void
clearCustomFunctions()
Remove all custom function mappings that have been registered.void
clearCustomOperators()
Remove all customisations that have been added to the CohQL language.protected Map<String,StatementBuilder<?>>
createStatements()
Create the CohQLStatementBuilder
map and initialise it with the standard CohQL statements.TokenTable
extendedSqlTokenTable()
Return an initialized TokenTable for the full CoherenceQueryLanguage.TokenTable
filtersTokenTable()
Return an initialized standardTokenTable
known by this CoherenceQueryLanguage.ExtractorBuilder
getExtractorBuilder()
Return theExtractorBuilder
to use to buildValueExtractor
s.ParameterizedBuilder
getFunction(String sName)
Return the function mapped to the given function name or null if no function mapping exists.protected String
getFunctionKey(String sFunctionName)
Returns a key value based on case-insensitivity of the token table.BaseOperator
getOperator(String sSymbol)
Return theBaseOperator
mapped to the given symbol.Set<CharSequence>
getOperators()
Return the set of CohQL Operators characters.protected TokenTable
getSqlTokenTable(boolean fExtended)
Return an initialized TokenTable for the full CoherenceQueryLanguage.StatementBuilder<?>
getStatementBuilder(String sFunctor)
Return theStatementBuilder
for a given CohQL AST functor.Map<String,StatementBuilder<?>>
getStatementBuilders()
Return the map ofStatementBuilder
instances.protected Map<String,ParameterizedBuilder<?>>
initializeFunctionMap()
Creates the Map holding CohQL functions and populates it with the default functions available in CohQL.protected Map<CharSequence,BaseOperator>
initializeOperatorMap()
Initialize the CohQL operators Map with all of the built-in CohQL operators and return the Map.Statement
prepareStatement(NodeTerm term, ExecutionContext context, List listBindVars, ParameterResolver namedBindVars)
Realize an instance of theStatement
that will execute the CohQL statement represented by the AST node.ParameterizedBuilder<?>
removeFunction(String sName)
Remove the CohQL function mapping for the specified function name.StatementBuilder<?>
removeStatementBuilder(String sFunctor)
Remove theStatementBuilder
associated with the given functor.void
setExtractorBuilder(ExtractorBuilder builder)
Set theExtractorBuilder
that will be used by CohQL queries to buildValueExtractor
s.TokenTable
sqlTokenTable()
Return an initialized extendedTokenTable
known by this CoherenceQueryLanguage.
-
-
-
Field Detail
-
m_tokenTableForFilter
protected TokenTable m_tokenTableForFilter
The TokenTable for Filters.
-
m_tokenTableSQL
protected TokenTable m_tokenTableSQL
The TokenTable for the full language that resembles SQL.
-
m_tokenTableExtendedSQL
protected TokenTable m_tokenTableExtendedSQL
The extended TokenTable for the full language that resembles SQL.
-
m_mapFunctions
protected Map<String,ParameterizedBuilder<?>> m_mapFunctions
The map of CohQL functions. The key is the function name and the value is the function implementation.
-
m_mapOperators
protected Map<CharSequence,BaseOperator> m_mapOperators
The map of CohQL operators. The key is the operator name and the value is theBaseOperator
implementation.
-
m_mapStatementBuilders
protected Map<String,StatementBuilder<?>> m_mapStatementBuilders
The map of CohQL query builders. The key is the CohQL token name that the parser produces to represent a particular query.
-
m_bldrExtractor
protected ExtractorBuilder m_bldrExtractor
TheExtractorBuilder
that will be used to realizeValueExtractor
s to be used by CohQL.
-
-
Method Detail
-
filtersTokenTable
public TokenTable filtersTokenTable()
Return an initialized standardTokenTable
known by this CoherenceQueryLanguage.- Returns:
- an initialized standard TokenTable known by this CoherenceQueryLanguage
-
sqlTokenTable
public TokenTable sqlTokenTable()
Return an initialized extendedTokenTable
known by this CoherenceQueryLanguage.- Returns:
- an initialized extended TokenTable known by this CoherenceQueryLanguage
-
extendedSqlTokenTable
public TokenTable extendedSqlTokenTable()
Return an initialized TokenTable for the full CoherenceQueryLanguage.- Returns:
- a TokenTable for the CoherenceQueryLanguage
-
getSqlTokenTable
protected TokenTable getSqlTokenTable(boolean fExtended)
Return an initialized TokenTable for the full CoherenceQueryLanguage.- Parameters:
fExtended
- flag that enables extended and experimental features- Returns:
- a TokenTable for the CoherenceQueryLanguage
-
initializeFunctionMap
protected Map<String,ParameterizedBuilder<?>> initializeFunctionMap()
Creates the Map holding CohQL functions and populates it with the default functions available in CohQL. CohQL functions are elements such as sum(), avg(), max() etc.- Returns:
- the function Map populated with the default functions
-
getFunction
public ParameterizedBuilder getFunction(String sName)
Return the function mapped to the given function name or null if no function mapping exists.- Parameters:
sName
- the name of the function to return- Returns:
- the function mapped to the given function name or null if no function mapping exists
-
addFunction
public void addFunction(String sName, ParameterizedBuilder bldrFunction)
Map the specified CohQLParameterizedBuilder
to the specified function name. If either the name of the implementation is null then no mapping will occur.- Parameters:
sName
- the name of the functionbldrFunction
- the implementation of the function
-
removeFunction
public ParameterizedBuilder<?> removeFunction(String sName)
Remove the CohQL function mapping for the specified function name. The removedParameterizedBuilder
will be returned, or null if there was no mapping for the specified name.- Parameters:
sName
- the name of the function to remove- Returns:
- the removed ParameterizedBuilder will be returned, or null if there was no mapping for the specified name.
-
clearCustomFunctions
public void clearCustomFunctions()
Remove all custom function mappings that have been registered.
-
initializeOperatorMap
protected Map<CharSequence,BaseOperator> initializeOperatorMap()
Initialize the CohQL operators Map with all of the built-in CohQL operators and return the Map.- Returns:
- the Map of CohQL operators
-
addOperator
public void addOperator(BaseOperator operator)
Add the custom operator to the CohQL language.- Parameters:
operator
- the operator to add
-
getOperators
public Set<CharSequence> getOperators()
Return the set of CohQL Operators characters.- Returns:
- the set of CohQL operators characters
-
getOperator
public BaseOperator getOperator(String sSymbol)
Return theBaseOperator
mapped to the given symbol.- Parameters:
sSymbol
- the symbol of the BaseOperator to get- Returns:
- the BaseOperator mapped to the specified symbol or null if there i sno mapping for that symbol
-
getStatementBuilders
public Map<String,StatementBuilder<?>> getStatementBuilders()
Return the map ofStatementBuilder
instances. The map is keyed on the functor used to represent a particular query type in a CohQL AST.- Returns:
- the map of StatementBuilder instances
-
createStatements
protected Map<String,StatementBuilder<?>> createStatements()
Create the CohQLStatementBuilder
map and initialise it with the standard CohQL statements.- Returns:
- the standard CohQL statement map
-
getStatementBuilder
public StatementBuilder<?> getStatementBuilder(String sFunctor)
Return theStatementBuilder
for a given CohQL AST functor. The returned value may be null if no builder has been registered for a given functor.- Parameters:
sFunctor
- the functor representing the statement who's builder should be returned- Returns:
- the StatementBuilder for a given CohQL AST functor
-
prepareStatement
public Statement prepareStatement(NodeTerm term, ExecutionContext context, List listBindVars, ParameterResolver namedBindVars)
Realize an instance of theStatement
that will execute the CohQL statement represented by the AST node.- Parameters:
term
- the parsed AST node representing the CohQL statementcontext
- theExecutionContext
to use to realize the commandlistBindVars
- the indexed bind variables to use for the querynamedBindVars
- the named bind variables to use for the query- Returns:
- the Statement to execute the CohQL statement
- Throws:
CohQLException
- if there is an error building the statement or there are no registered builders for the statement
-
addStatement
public void addStatement(String sFunctor, StatementBuilder<?> builder)
Register the givenStatementBuilder
to the specified functor name. The specified StatementBuilder will then be used to build anyStatement
instances when the given functor is present in a query AST.- Parameters:
sFunctor
- the functor to map the StatementBuilder tobuilder
- the StatementBuilder to be mapped
-
removeStatementBuilder
public StatementBuilder<?> removeStatementBuilder(String sFunctor)
Remove theStatementBuilder
associated with the given functor.Note: removal of a functor may cause errors if subsequent queries refer to the functor.
- Parameters:
sFunctor
- the functor mapping to remove- Returns:
- the removed StatementBuilder or null
-
clearCustomOperators
public void clearCustomOperators()
Remove all customisations that have been added to the CohQL language.
-
setExtractorBuilder
public void setExtractorBuilder(ExtractorBuilder builder)
Set theExtractorBuilder
that will be used by CohQL queries to buildValueExtractor
s.- Parameters:
builder
- the ExtractorBuilder to use
-
getExtractorBuilder
public ExtractorBuilder getExtractorBuilder()
Return theExtractorBuilder
to use to buildValueExtractor
s.- Returns:
- the ExtractorBuilder to use to build ValueExtractors
-
-