Class SqlEngine

java.lang.Object
org.sqlproc.engine.SqlEngine
Direct Known Subclasses:
SqlCrudEngine, SqlProcedureEngine, SqlQueryEngine

public abstract class SqlEngine extends Object
Common ancestor for SqlQueryEngine, SqlCrudEngine and SqlProcedureEngine.

For more info please see the Tutorials.

Author:
Vladimir Hudec
  • Field Details

    • 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 see JdbcTypeFactory .
    • 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 for SqlProcessResult instances.
    • processingCacheStatistics

      protected ConcurrentHashMap<String,AtomicLong> processingCacheStatistics
      The processing cache statistics.
    • configuration

      private SqlEngineConfiguration 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 the SqlProcessorLoader, 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 instance
      statement - the pre-compiled META SQL statement
      mapping - the pre-compiled SQL mapping rule
      monitor - the SQL Monitor for the runtime statistics gathering
      features - the optional SQL Processor features
      typeFactory - the factory for the META types construction
      pluginFactory - the factory for the SQL Processor plugins
      configuration - the overall configuration, which can be persisted
  • Method Details

    • 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 feature
      value - 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 see JdbcTypeFactory
      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 for SqlProcessResult instances.
      Returns:
      the processing cache used for SqlProcessResult instances.
    • setProcessingCache

      public void setProcessingCache(ConcurrentHashMap<String,SqlProcessResult> processingCache)
      Sets the processing cache used for SqlProcessResult instances.
      Parameters:
      processingCache - the processing cache used for SqlProcessResult 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 type
      dynamicInputValues - 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