Package org.sqlproc.engine
Class SqlEngine
- java.lang.Object
-
- org.sqlproc.engine.SqlEngine
-
- Direct Known Subclasses:
SqlCrudEngine
,SqlProcedureEngine
,SqlQueryEngine
public abstract class SqlEngine extends Object
Common ancestor forSqlQueryEngine
,SqlCrudEngine
andSqlProcedureEngine
.For more info please see the Tutorials.
- Author:
- Vladimir Hudec
-
-
Field Summary
Fields Modifier and Type Field Description private SqlEngineConfiguration
configuration
The overall configuration, which can be persisted.protected Map<String,Object>
features
Configuration of the SQL Processor using map of features.protected org.slf4j.Logger
logger
The internal slf4j logger.protected SqlMappingRule
mapping
The pre-compiled mapping rule, which is an SQL execution result to Java output classes mapping prescription.protected SqlMonitor
monitor
Monitor for the runtime statistics gathering.protected String
name
Name of the META SQL query or statement, which uniquely identifies this instance.protected SqlPluginFactory
pluginFactory
The factory for the SQL Processor plugins.protected ConcurrentHashMap<String,SqlProcessResult>
processingCache
The processing cache used forSqlProcessResult
instances.protected ConcurrentHashMap<String,AtomicLong>
processingCacheStatistics
The processing cache statistics.protected SqlMetaStatement
statement
The pre-compiled META SQL query or statement.protected SqlTypeFactory
typeFactory
The factory for the META types construction.protected SqlValidator
validator
The injected validator.
-
Constructor Summary
Constructors Constructor Description 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (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 NPEMap<String,Object>
getFeatures()
Returns the optional features, which can alter the SQL Processor runtime behavior.static Map<String,Object>
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 NPEstatic Map<String,Class<?>>
getMoreResultClasses(SqlControl sqlControl)
The helper to prevent the NPEstatic SqlOrder
getOrder(SqlControl sqlControl)
The helper to prevent the NPESqlPluginFactory
getPluginFactory()
Returns the factory for the SQL Processor plugins.ConcurrentHashMap<String,SqlProcessResult>
getProcessingCache()
Returns the processing cache used forSqlProcessResult
instances.ConcurrentHashMap<String,AtomicLong>
getProcessingCacheStatistics()
Returns the processing cache statistics.static Object
getStaticInputValues(SqlControl sqlControl)
The helper to prevent the NPESqlTypeFactory
getTypeFactory()
Returns 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 Detail
-
logger
protected final org.slf4j.Logger logger
The internal slf4j logger.
-
name
protected String name
Name of the META SQL query or statement, which uniquely identifies this instance.
-
statement
protected SqlMetaStatement statement
The pre-compiled META SQL query or statement. The META SQL is an ANSI SQL extension using the ANTLR defined grammar.
-
mapping
protected SqlMappingRule mapping
The pre-compiled mapping rule, which is an SQL execution result to Java output classes mapping prescription.
-
features
protected Map<String,Object> features
Configuration of the SQL Processor using map of features. Optional features can alter the SQL Processor runtime behavior.
-
monitor
protected SqlMonitor monitor
Monitor for the runtime statistics gathering.
-
validator
protected SqlValidator validator
The injected validator. It validates dynamic input values.
-
typeFactory
protected SqlTypeFactory 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
protected SqlPluginFactory pluginFactory
The factory for the SQL Processor plugins. This is the basic facility to alter the SQL Processor processing.
-
processingCache
protected ConcurrentHashMap<String,SqlProcessResult> processingCache
The processing cache used forSqlProcessResult
instances.
-
processingCacheStatistics
protected ConcurrentHashMap<String,AtomicLong> processingCacheStatistics
The processing cache statistics.
-
configuration
private SqlEngineConfiguration configuration
The overall configuration, which can be persisted.
-
-
Constructor Detail
-
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 Detail
-
setValidator
public void setValidator(SqlValidator validator)
Injects a validator. It validates dynamic input values.- Parameters:
validator
- a generir validator instance
-
setFeature
public void setFeature(String name, Object value)
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
public void unsetFeatures(Set<String> names)
Clears the optional features in the stament's or global scope.- Parameters:
names
- the names of the optional features
-
getStaticInputValues
public static Object getStaticInputValues(SqlControl sqlControl)
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
public static Object getDynamicUpdateValues(SqlControl sqlControl)
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
public static Integer getMaxTimeout(SqlControl sqlControl)
The helper to prevent the NPE- Parameters:
sqlControl
- the compound parameters controlling the META SQL execution- Returns:
- the max SQL execution time
-
getFirstResult
public static Integer getFirstResult(SqlControl sqlControl)
The helper to prevent the NPE- Parameters:
sqlControl
- the compound parameters controlling the META SQL execution- Returns:
- the first SQL execution output row
-
getMaxResults
public static Integer getMaxResults(SqlControl sqlControl)
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
public static SqlOrder getOrder(SqlControl sqlControl)
The helper to prevent the NPE- Parameters:
sqlControl
- the compound parameters controlling the META SQL execution- Returns:
- the ordering directive list
-
getMoreResultClasses
public static Map<String,Class<?>> getMoreResultClasses(SqlControl sqlControl)
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
public static Map<String,Object> getFeatures(SqlControl sqlControl)
The helper to prevent the NPE- Parameters:
sqlControl
- the compound parameters controlling the META SQL execution- Returns:
- the optiona features
-
getFetchSize
public static Integer getFetchSize(SqlControl sqlControl)
The helper to prevent the NPE- Parameters:
sqlControl
- the compound parameters controlling the META SQL execution- Returns:
- the fetch size of SQL statement
-
isSkipEmptyStatement
public 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).- Returns:
- the indicator, that an empty INSERT or UPDATE statement execution should be ignored
-
checkDynamicInputValues
void checkDynamicInputValues(Object dynamicInputValues)
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
void checkStaticInputValues(Object staticInputValues)
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
public Map<String,Object> 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
public SqlTypeFactory 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
public SqlPluginFactory 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
public ConcurrentHashMap<String,SqlProcessResult> getProcessingCache()
Returns the processing cache used forSqlProcessResult
instances.- Returns:
- the processing cache used for
SqlProcessResult
instances.
-
setProcessingCache
public void setProcessingCache(ConcurrentHashMap<String,SqlProcessResult> processingCache)
Sets the processing cache used forSqlProcessResult
instances.- Parameters:
processingCache
- the processing cache used forSqlProcessResult
instances.
-
getProcessingCacheStatistics
public ConcurrentHashMap<String,AtomicLong> 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
-
-