org.sqlproc.engine
Class SqlEngine

java.lang.Object
  extended by 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 Summary
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  Map<String,SqlProcessResult> processingCache
          The processing cache used for SqlProcessResult instances.
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
SqlEngine(String name, SqlMetaStatement statement, SqlMappingRule mapping, SqlMonitor monitor, Map<String,Object> features, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory)
          Creates a new instance of the SqlEngine from one META SQL statement and one SQL Mapping rule instance.
 
Method Summary
(package private)  void checkDynamicInputValues(Object dynamicInputValues)
          Check the input parameters.
(package private)  void checkStaticInputValues(Object staticInputValues)
          Check the input parameters.
 Map<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 NPE
static int getFetchSize(SqlControl sqlControl)
          The helper to prevent the NPE
static int getFirstResult(SqlControl sqlControl)
          The helper to prevent the NPE
static int getMaxResults(SqlControl sqlControl)
          The helper to prevent the NPE
static int getMaxTimeout(SqlControl sqlControl)
          The helper to prevent the NPE
static Map<String,Class<?>> getMoreResultClasses(SqlControl sqlControl)
          The helper to prevent the NPE
static SqlOrder getOrder(SqlControl sqlControl)
          The helper to prevent the NPE
 SqlPluginFactory getPluginFactory()
          Returns the factory for the SQL Processor plugins.
 Map<String,SqlProcessResult> getProcessingCache()
          Returns the processing cache used for SqlProcessResult instances.
static String getProcessingId(SqlControl sqlControl)
          The helper to prevent the NPE
static Object getStaticInputValues(SqlControl sqlControl)
          The helper to prevent the NPE
 SqlTypeFactory getTypeFactory()
          Returns the factory for the META types construction.
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(Map<String,SqlProcessResult> processingCache)
          Sets the processing cache used for SqlProcessResult instances.
 void setValidator(SqlValidator validator)
          Injects a validator.
 void unsetFeatures(Set<String> names)
          Clears the optional features in the stament's or global scope.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 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 Map<String,SqlProcessResult> processingCache
The processing cache used for SqlProcessResult instances.

Constructor Detail

SqlEngine

public SqlEngine(String name,
                 SqlMetaStatement statement,
                 SqlMappingRule mapping,
                 SqlMonitor monitor,
                 Map<String,Object> features,
                 SqlTypeFactory typeFactory,
                 SqlPluginFactory pluginFactory)
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
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 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

getMaxTimeout

public static int 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 int 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 int 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

getProcessingId

public static String getProcessingId(SqlControl sqlControl)
The helper to prevent the NPE

Parameters:
sqlControl - the compound parameters controlling the META SQL execution
Returns:
the unique ID of the executed statement based on the input values combination

getFetchSize

public static int 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

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 Map<String,SqlProcessResult> getProcessingCache()
Returns the processing cache used for SqlProcessResult instances.

Returns:
the processing cache used for SqlProcessResult instances.

setProcessingCache

public void setProcessingCache(Map<String,SqlProcessResult> processingCache)
Sets the processing cache used for SqlProcessResult instances.

Parameters:
processingCache - the processing cache used for SqlProcessResult instances.

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


Copyright © 2015. All rights reserved.