Class JRAbstractQueryExecuter
- java.lang.Object
-
- net.sf.jasperreports.engine.query.JRAbstractQueryExecuter
-
- All Implemented Interfaces:
JRQueryExecuter
- Direct Known Subclasses:
AbstractJsonQueryExecuter
,AbstractXlsQueryExecuter
,JaxenXPathQueryExecuter
,JRCsvQueryExecuter
,JRHibernateQueryExecuter
,JRHibernateQueryExecuter
,JRJdbcQueryExecuter
,JRJpaQueryExecuter
,JRJpaQueryExecuter
,JRMondrianQueryExecuter
,JRXmlaQueryExecuter
,JRXPathQueryExecuter
,Olap4jMondrianQueryExecuter
,Olap4jXmlaQueryExecuter
,XalanXPathQueryExecuter
public abstract class JRAbstractQueryExecuter extends Object implements JRQueryExecuter
Base abstract query executer.- Author:
- Lucian Chirita (lucianc@users.sourceforge.net)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
JRAbstractQueryExecuter.QueryParameter
A parameter present in the query.protected static interface
JRAbstractQueryExecuter.QueryParameterEntry
protected static interface
JRAbstractQueryExecuter.QueryParameterVisitor
protected static class
JRAbstractQueryExecuter.ValuedQueryParameter
protected class
JRAbstractQueryExecuter.VisitExceptionWrapper
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,JRClauseFunction>
clauseFunctions
Clause function registry.protected JRDataset
dataset
static String
EXCEPTION_MESSAGE_KEY_NUMERIC_TYPE_REQUIRED
static String
EXCEPTION_MESSAGE_KEY_PARAMETER_NOT_FOUND
static String
EXCEPTION_MESSAGE_KEY_QUERY_CLAUSE_CIRCULARLY_NESTED_PARAMETER
static String
EXCEPTION_MESSAGE_KEY_QUERY_CLAUSE_ID_FIRST_TOKEN_MISSING
static String
EXCEPTION_MESSAGE_KEY_QUERY_CLAUSE_NOT_FOUND
static String
EXCEPTION_MESSAGE_KEY_UNSUPPORTED_PARAMETER_TYPE
static String
GET_COLLECTED
-
Constructor Summary
Constructors Modifier Constructor Description protected
JRAbstractQueryExecuter(JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parametersMap)
protected
JRAbstractQueryExecuter(QueryExecutionContext context, JRDataset dataset, Map<String,? extends JRValueParameter> parametersMap)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addQueryMultiParameters(String parameterName, int count)
Records a multi-valued query parameter.protected void
addQueryMultiParameters(String parameterName, int count, boolean ignoreNulls)
Records a multi-valued query parameter which ignore null values.protected void
addQueryParameter(Class<?> type, Object value)
protected void
addQueryParameter(String parameterName)
Records a query parameter.protected void
appendClauseChunk(StringBuffer sbuffer, String[] clauseTokens)
Handles aclause query chunk
.protected void
appendParameterChunk(StringBuffer sbuffer, String chunkText)
protected void
appendParameterClauseChunk(StringBuffer sbuffer, String chunkText)
protected void
appendQueryChunk(StringBuffer sbuffer, JRQueryChunk chunk)
protected void
appendTextChunk(StringBuffer sbuffer, String text)
protected void
applyClause(JRClauseFunction function, JRClauseTokens tokens, StringBuffer sbuffer)
protected void
checkParameter(String parameterName)
protected JRClauseFunction
findExtensionQueryFunction(String id)
protected Boolean
getBooleanParameter(String parameter, String property)
protected boolean
getBooleanParameter(String parameter, String property, boolean defaultValue)
protected Boolean
getBooleanParameterOrProperty(String name)
protected boolean
getBooleanParameterOrProperty(String name, boolean defaultValue)
protected String
getCanonicalQueryLanguage()
Returns a canonical query language for this query executer implementation.protected List<String>
getCollectedParameterNames()
Returns the list of parameter names in the order in which they appear in the query.protected List<JRAbstractQueryExecuter.QueryParameter>
getCollectedParameters()
Returns the list ofquery parameters
in the order in which they appear in the query.protected Integer
getIntegerParameter(String parameter, String property)
protected int
getIntegerParameter(String parameter, String property, int defaultValue)
protected Integer
getIntegerParameterOrProperty(String name)
protected int
getIntegerParameterOrProperty(String name, int defaultValue)
protected JasperReportsContext
getJasperReportsContext()
protected abstract String
getParameterReplacement(String parameterName)
Returns the replacement text for a query parameter.protected Object
getParameterValue(String parameterName)
Returns the value of a fill parameter.protected Object
getParameterValue(String parameterName, boolean ignoreMissing)
Returns the value of a fill parameter.protected JRPropertiesUtil
getPropertiesUtil()
protected QueryExecutionContext
getQueryExecutionContext()
protected String
getQueryString()
Returns the parsed query string with the parameter clauses replaced by the parameter values and the parameters replaced bygetParameterReplacement
.protected RepositoryContext
getRepositoryContext()
protected String
getStringParameter(String parameter, String property)
protected String
getStringParameterOrProperty(String name)
protected JRValueParameter
getValueParameter(String parameterName)
Return a value parameter from the parameters map.protected JRValueParameter
getValueParameter(String parameterName, boolean ignoreMissing)
Return a value parameter from the parameters map.protected boolean
parameterHasValue(String parameter)
protected void
parseQuery()
Parses the query and replaces the parameter clauses by the parameter values and the parameters by the return value ofgetParameterReplacement
.protected void
registerClauseFunction(String id, JRClauseFunction function)
Registers a clause function.protected JRClauseFunction
resolveFunction(String id)
Resolves a clause function ID to a function instance.protected void
unregisterClauseFunction(String id)
Unregisters a clause function.protected void
visitQueryParameters(JRAbstractQueryExecuter.QueryParameterVisitor visitor)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.jasperreports.engine.query.JRQueryExecuter
cancelQuery, close, createDatasource
-
-
-
-
Field Detail
-
EXCEPTION_MESSAGE_KEY_NUMERIC_TYPE_REQUIRED
public static final String EXCEPTION_MESSAGE_KEY_NUMERIC_TYPE_REQUIRED
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_PARAMETER_NOT_FOUND
public static final String EXCEPTION_MESSAGE_KEY_PARAMETER_NOT_FOUND
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_QUERY_CLAUSE_CIRCULARLY_NESTED_PARAMETER
public static final String EXCEPTION_MESSAGE_KEY_QUERY_CLAUSE_CIRCULARLY_NESTED_PARAMETER
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_QUERY_CLAUSE_ID_FIRST_TOKEN_MISSING
public static final String EXCEPTION_MESSAGE_KEY_QUERY_CLAUSE_ID_FIRST_TOKEN_MISSING
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_QUERY_CLAUSE_NOT_FOUND
public static final String EXCEPTION_MESSAGE_KEY_QUERY_CLAUSE_NOT_FOUND
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_UNSUPPORTED_PARAMETER_TYPE
public static final String EXCEPTION_MESSAGE_KEY_UNSUPPORTED_PARAMETER_TYPE
- See Also:
- Constant Field Values
-
GET_COLLECTED
public static final String GET_COLLECTED
- See Also:
- Constant Field Values
-
clauseFunctions
protected final Map<String,JRClauseFunction> clauseFunctions
Clause function registry.
-
dataset
protected final JRDataset dataset
-
-
Constructor Detail
-
JRAbstractQueryExecuter
protected JRAbstractQueryExecuter(JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parametersMap)
-
JRAbstractQueryExecuter
protected JRAbstractQueryExecuter(QueryExecutionContext context, JRDataset dataset, Map<String,? extends JRValueParameter> parametersMap)
-
-
Method Detail
-
getJasperReportsContext
protected JasperReportsContext getJasperReportsContext()
-
getQueryExecutionContext
protected QueryExecutionContext getQueryExecutionContext()
-
getRepositoryContext
protected RepositoryContext getRepositoryContext()
-
getPropertiesUtil
protected JRPropertiesUtil getPropertiesUtil()
-
registerClauseFunction
protected void registerClauseFunction(String id, JRClauseFunction function)
Registers a clause function.- Parameters:
id
- the function IDfunction
- the function
-
unregisterClauseFunction
protected void unregisterClauseFunction(String id)
Unregisters a clause function.- Parameters:
id
- the function ID
-
resolveFunction
protected JRClauseFunction resolveFunction(String id)
Resolves a clause function ID to a function instance.- Parameters:
id
- the function ID- Returns:
- the clause function registered for the ID
- Throws:
JRRuntimeException
- if no function for the ID is found
-
findExtensionQueryFunction
protected JRClauseFunction findExtensionQueryFunction(String id)
-
getCanonicalQueryLanguage
protected String getCanonicalQueryLanguage()
Returns a canonical query language for this query executer implementation.The canonical language is used to retrieve extensions for the query executer.
The default implementation returns the runtime query language used in the dataset, but query executer implementations should override this method and return a fixed language.
- Returns:
- a canonical query language
-
parseQuery
protected void parseQuery()
Parses the query and replaces the parameter clauses by the parameter values and the parameters by the return value ofgetParameterReplacement
.
-
appendQueryChunk
protected void appendQueryChunk(StringBuffer sbuffer, JRQueryChunk chunk)
-
appendTextChunk
protected void appendTextChunk(StringBuffer sbuffer, String text)
-
appendParameterChunk
protected void appendParameterChunk(StringBuffer sbuffer, String chunkText)
-
addQueryParameter
protected void addQueryParameter(String parameterName)
Records a query parameter.- Parameters:
parameterName
- the parameter name- See Also:
getCollectedParameters()
-
addQueryMultiParameters
protected void addQueryMultiParameters(String parameterName, int count)
Records a multi-valued query parameter.- Parameters:
parameterName
- the parameter namecount
- the value count- See Also:
getCollectedParameters()
,JRAbstractQueryExecuter.QueryParameter.isMulti()
-
addQueryMultiParameters
protected void addQueryMultiParameters(String parameterName, int count, boolean ignoreNulls)
Records a multi-valued query parameter which ignore null values.- Parameters:
parameterName
- the parameter namecount
- the value count- See Also:
getCollectedParameters()
,JRAbstractQueryExecuter.QueryParameter.isMulti()
-
appendParameterClauseChunk
protected void appendParameterClauseChunk(StringBuffer sbuffer, String chunkText)
-
appendClauseChunk
protected void appendClauseChunk(StringBuffer sbuffer, String[] clauseTokens)
Handles aclause query chunk
.The default implementation considers the first token as a
clause function
ID and delegates the call to the function.Extending query executers can override this to implement custom query clause handling.
- Parameters:
sbuffer
- the query text bufferclauseTokens
- clause tokens- Throws:
JRRuntimeException
- if there is no first token or no clause function is found for the ID- See Also:
registerClauseFunction(String, JRClauseFunction)
-
applyClause
protected void applyClause(JRClauseFunction function, JRClauseTokens tokens, StringBuffer sbuffer)
-
getQueryString
protected String getQueryString()
Returns the parsed query string with the parameter clauses replaced by the parameter values and the parameters replaced bygetParameterReplacement
.- Returns:
- the parsed query string
-
getCollectedParameterNames
protected List<String> getCollectedParameterNames()
Returns the list of parameter names in the order in which they appear in the query.- Returns:
- the list of parameter names
-
getCollectedParameters
protected List<JRAbstractQueryExecuter.QueryParameter> getCollectedParameters()
Returns the list ofquery parameters
in the order in which they appear in the query.- Returns:
- the list of query parameters
-
visitQueryParameters
protected void visitQueryParameters(JRAbstractQueryExecuter.QueryParameterVisitor visitor) throws JRAbstractQueryExecuter.VisitExceptionWrapper
-
getParameterValue
protected Object getParameterValue(String parameterName, boolean ignoreMissing)
Returns the value of a fill parameter.- Parameters:
parameterName
- the parameter nameignoreMissing
- iftrue
, the method will return null for non existing parameters; otherwise, an exception will be thrown if the parameter does not exist- Returns:
- the parameter value
-
getParameterValue
protected Object getParameterValue(String parameterName)
Returns the value of a fill parameter.- Parameters:
parameterName
- the parameter name- Returns:
- the parameter value
-
parameterHasValue
protected boolean parameterHasValue(String parameter)
-
getBooleanParameter
protected boolean getBooleanParameter(String parameter, String property, boolean defaultValue)
-
getBooleanParameterOrProperty
protected boolean getBooleanParameterOrProperty(String name, boolean defaultValue)
-
getIntegerParameter
protected int getIntegerParameter(String parameter, String property, int defaultValue)
-
getIntegerParameterOrProperty
protected int getIntegerParameterOrProperty(String name, int defaultValue)
-
checkParameter
protected void checkParameter(String parameterName)
-
getValueParameter
protected JRValueParameter getValueParameter(String parameterName, boolean ignoreMissing)
Return a value parameter from the parameters map.- Parameters:
parameterName
- the parameter nameignoreMissing
- iftrue
, the method will return null for non existing parameters; otherwise, an exception will be thrown if the parameter does not exist- Returns:
- the parameter
-
getValueParameter
protected JRValueParameter getValueParameter(String parameterName)
Return a value parameter from the parameters map.- Parameters:
parameterName
- the parameter name- Returns:
- the parameter
-
getParameterReplacement
protected abstract String getParameterReplacement(String parameterName)
Returns the replacement text for a query parameter.- Parameters:
parameterName
- the parameter name- Returns:
- the replacement text
- See Also:
JRQueryChunk.TYPE_PARAMETER
-
-