Package org.sqlproc.engine
Class SqlEngine
java.lang.Object
org.sqlproc.engine.SqlEngine
- Direct Known Subclasses:
SqlCrudEngine
,SqlProcedureEngine
,SqlQueryEngine
Common ancestor for
SqlQueryEngine
, SqlCrudEngine
and SqlProcedureEngine
.
For more info please see the Tutorials.
- Author:
- Vladimir Hudec
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate SqlEngineConfiguration
The overall configuration, which can be persisted.Configuration of the SQL Processor using map of features.protected final org.slf4j.Logger
The internal slf4j logger.protected SqlMappingRule
The pre-compiled mapping rule, which is an SQL execution result to Java output classes mapping prescription.protected SqlMonitor
Monitor for the runtime statistics gathering.protected String
Name of the META SQL query or statement, which uniquely identifies this instance.protected SqlPluginFactory
The factory for the SQL Processor plugins.protected ConcurrentHashMap
<String, SqlProcessResult> The processing cache used forSqlProcessResult
instances.protected ConcurrentHashMap
<String, AtomicLong> The processing cache statistics.protected SqlMetaStatement
The pre-compiled META SQL query or statement.protected SqlTypeFactory
The factory for the META types construction.protected SqlValidator
The injected validator. -
Constructor Summary
ConstructorsConstructorDescriptionSqlEngine
(String name, SqlMetaStatement statement, SqlMappingRule mapping, SqlMonitor monitor, Map<String, Object> features, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory, SqlEngineConfiguration configuration) Creates a new instance of the SqlEngine from one META SQL statement and one SQL Mapping rule instance. -
Method Summary
Modifier and TypeMethodDescription(package private) void
checkDynamicInputValues
(Object dynamicInputValues) Check the input parameters.(package private) void
checkStaticInputValues
(Object staticInputValues) Check the input parameters.static Object
getDynamicUpdateValues
(SqlControl sqlControl) The helper to prevent the NPEReturns the optional features, which can alter the SQL Processor runtime behavior.getFeatures
(SqlControl sqlControl) The helper to prevent the NPEstatic Integer
getFetchSize
(SqlControl sqlControl) The helper to prevent the NPEstatic Integer
getFirstResult
(SqlControl sqlControl) The helper to prevent the NPEstatic Integer
getMaxResults
(SqlControl sqlControl) The helper to prevent the NPEstatic Integer
getMaxTimeout
(SqlControl sqlControl) The helper to prevent the NPEgetMoreResultClasses
(SqlControl sqlControl) The helper to prevent the NPEstatic SqlOrder
getOrder
(SqlControl sqlControl) The helper to prevent the NPEReturns the factory for the SQL Processor plugins.Returns the processing cache used forSqlProcessResult
instances.Returns the processing cache statistics.static Object
getStaticInputValues
(SqlControl sqlControl) The helper to prevent the NPEReturns the factory for the META types construction.static boolean
isSkipEmptyStatement
(SqlControl sqlControl) Returns the indicator, that an empty INSERT or UPDATE statement execution should be ignored (for example update statement without any bounded input values).protected SqlProcessResult
process
(SqlMetaStatement.Type sqlStatementType, Object dynamicInputValues, SqlControl sqlControl) The main contract for a dynamic ANSI SQL Query generation.void
setFeature
(String name, Object value) Sets the optional feature in the stament's or global scope.void
setProcessingCache
(ConcurrentHashMap<String, SqlProcessResult> processingCache) Sets the processing cache used forSqlProcessResult
instances.void
setProcessingCacheStatistics
(ConcurrentHashMap<String, AtomicLong> processingCacheStatistics) Sets the processing cache statistics.void
setValidator
(SqlValidator validator) Injects a validator.void
unsetFeatures
(Set<String> names) Clears the optional features in the stament's or global scope.
-
Field Details
-
logger
protected final org.slf4j.Logger loggerThe internal slf4j logger. -
name
Name of the META SQL query or statement, which uniquely identifies this instance. -
statement
The pre-compiled META SQL query or statement. The META SQL is an ANSI SQL extension using the ANTLR defined grammar. -
mapping
The pre-compiled mapping rule, which is an SQL execution result to Java output classes mapping prescription. -
features
Configuration of the SQL Processor using map of features. Optional features can alter the SQL Processor runtime behavior. -
monitor
Monitor for the runtime statistics gathering. -
validator
The injected validator. It validates dynamic input values. -
typeFactory
The factory for the META types construction. The META type defines the mapping between a Java class type and a JDBC datatype. For the default META type factory, please seeJdbcTypeFactory
. -
pluginFactory
The factory for the SQL Processor plugins. This is the basic facility to alter the SQL Processor processing. -
processingCache
The processing cache used forSqlProcessResult
instances. -
processingCacheStatistics
The processing cache statistics. -
configuration
The overall configuration, which can be persisted.
-
-
Constructor Details
-
SqlEngine
public SqlEngine(String name, SqlMetaStatement statement, SqlMappingRule mapping, SqlMonitor monitor, Map<String, Object> features, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory, SqlEngineConfiguration configuration) Creates a new instance of the SqlEngine from one META SQL statement and one SQL Mapping rule instance. Both parameters are already pre-compiled instances using the ANTLR parsers. This is the recommended usage for the runtime performance optimization. This constructor is devoted to be used from theSqlProcessorLoader
, which is able to read all statements definitions from an external meta statements file and create the named SqlEngine instances. Also an external SQL Monitor for the runtime statistics gathering can be engaged.- Parameters:
name
- the name of this SQL Engine instancestatement
- the pre-compiled META SQL statementmapping
- the pre-compiled SQL mapping rulemonitor
- the SQL Monitor for the runtime statistics gatheringfeatures
- the optional SQL Processor featurestypeFactory
- the factory for the META types constructionpluginFactory
- the factory for the SQL Processor pluginsconfiguration
- the overall configuration, which can be persisted
-
-
Method Details
-
setValidator
Injects a validator. It validates dynamic input values.- Parameters:
validator
- a generir validator instance
-
setFeature
Sets the optional feature in the stament's or global scope.- Parameters:
name
- the name of the optional featurevalue
- the value of the optional feature
-
unsetFeatures
Clears the optional features in the stament's or global scope.- Parameters:
names
- the names of the optional features
-
getStaticInputValues
The helper to prevent the NPE- Parameters:
sqlControl
- the compound parameters controlling the META SQL execution- Returns:
- the object used for the SQL statement static input values
-
getDynamicUpdateValues
The helper to prevent the NPE- Parameters:
sqlControl
- the compound parameters controlling the META SQL execution- Returns:
- the object used for the SQL update statement dynamic input values
-
getMaxTimeout
The helper to prevent the NPE- Parameters:
sqlControl
- the compound parameters controlling the META SQL execution- Returns:
- the max SQL execution time
-
getFirstResult
The helper to prevent the NPE- Parameters:
sqlControl
- the compound parameters controlling the META SQL execution- Returns:
- the first SQL execution output row
-
getMaxResults
The helper to prevent the NPE- Parameters:
sqlControl
- the compound parameters controlling the META SQL execution- Returns:
- the max number of SQL execution output rows
-
getOrder
The helper to prevent the NPE- Parameters:
sqlControl
- the compound parameters controlling the META SQL execution- Returns:
- the ordering directive list
-
getMoreResultClasses
The helper to prevent the NPE- Parameters:
sqlControl
- the compound parameters controlling the META SQL execution- Returns:
- more result classes used for the return values
-
getFeatures
The helper to prevent the NPE- Parameters:
sqlControl
- the compound parameters controlling the META SQL execution- Returns:
- the optiona features
-
getFetchSize
The helper to prevent the NPE- Parameters:
sqlControl
- the compound parameters controlling the META SQL execution- Returns:
- the fetch size of SQL statement
-
isSkipEmptyStatement
Returns the indicator, that an empty INSERT or UPDATE statement execution should be ignored (for example update statement without any bounded input values).- Returns:
- the indicator, that an empty INSERT or UPDATE statement execution should be ignored
-
checkDynamicInputValues
Check the input parameters.- Parameters:
dynamicInputValues
- The object used for the SQL statement dynamic input values. The class of this object is also named as the input class or the dynamic parameters class. The exact class type isn't important, all the parameters settled into the SQL prepared statement are picked up using the reflection API.- Throws:
InvalidParameterException
- in the case the incorrect classes used for dynamic input values
-
checkStaticInputValues
Check the input parameters.- Parameters:
staticInputValues
- The object used for the SQL statement static input values. The class of this object is also named as the input class or the static parameters class. The exact class type isn't important, all the parameters injected into the SQL query command are picked up using the reflection API. Compared to dynamicInputValues input parameters, parameters in this class should't be produced by an end user to prevent SQL injection threat!- Throws:
InvalidParameterException
- in the case the incorrect classes used for static input values
-
getFeatures
Returns the optional features, which can alter the SQL Processor runtime behavior.- Returns:
- the optional features, which can alter the SQL Processor runtime behavior
-
getTypeFactory
Returns the factory for the META types construction. The META type defines the mapping between a Java class type and a JDBC datatype. For the default META type factory, please seeJdbcTypeFactory
- Returns:
- the factory for the META types construction
-
getPluginFactory
Returns the factory for the SQL Processor plugins. This is the basic facility to alter the SQL Processor processing.- Returns:
- the factory for the SQL Processor plugins
-
getProcessingCache
Returns the processing cache used forSqlProcessResult
instances.- Returns:
- the processing cache used for
SqlProcessResult
instances.
-
setProcessingCache
Sets the processing cache used forSqlProcessResult
instances.- Parameters:
processingCache
- the processing cache used forSqlProcessResult
instances.
-
getProcessingCacheStatistics
Returns the processing cache statistics.- Returns:
- the processing cache statistics
-
setProcessingCacheStatistics
public void setProcessingCacheStatistics(ConcurrentHashMap<String, AtomicLong> processingCacheStatistics) Sets the processing cache statistics.- Parameters:
processingCacheStatistics
- the processing cache statistics
-
process
protected SqlProcessResult process(SqlMetaStatement.Type sqlStatementType, Object dynamicInputValues, SqlControl sqlControl) The main contract for a dynamic ANSI SQL Query generation. The ANSI SQL Query creation is based on- META SQL
- dynamic input values
- static input values
- ordering list directive
- optional features
- Parameters:
sqlStatementType
- the SQL command typedynamicInputValues
- the SQL statement dynamic parameters (input values)sqlControl
- The compound parameters controlling the META SQL execution- Returns:
- the crate for ANSI SQL and other attributes, which control the SQL statement itself
-