Class SqlProcessorLoader
The purpose of this class is to load and analyze (=parse) the SQL Processor artifacts:
- the META SQL statements
- the mapping rules
- the optional features
This is rather a low level helper class. For more simple approach please see SqlDefaultFactory
All the statements with the name name(QRY)
are parsed as the META SQL queries using the ANTLR based
grammar.
All the statements with the name name(CRUD)
are parsed as the META SQL CRUD statements using the ANTLR
based grammar.
All the statements with the name name(CALL)
are parsed as the META SQL CALL statements using the ANTLR
based grammar. These are used to call the stored procedures.
All the statements with the name name(OUT)
are parsed as the mapping rules using the ANTLR based
grammar.
A pair of the META SQL statement and the (optional) mapping rule forms one named SQL Engine instance.
All the statements with the name name(OPT)
are taken as the optional features used in the process of the
SQL query/statement generation and execution.
In the process of ANTLR based parsing different kinds of incorrect stuff can cause the SqlEngineException
to
be raised.
In the process of the META SQL statements and mapping rules parsing the input/output values META types have to be
established. For this purpose a factory class responsible for these META types construction has to be supplied.
To initialize the SqlProcessorLoader, Spring DI configuration can be utilized, like the next one:
<beans ...> ... <bean id="sqlFactory" class="org.sqlproc.engine.jdbc.JdbcEngineFactory" init-method="init"> <property name="metaFilesNames"> <list> <value>statements.qry</value> </list> </property> </bean> </beans>and use the next code to obtain an instance of the SQL Query engine
SqlEngineFactory sqlFactory = context.getBean("sqlFactory", SqlEngineFactory.class); SqlQueryEngine sqlEngine = sqlFactory.getQueryEngine("ALL");or the next code to obtain an instance of the SQL CRUD engine
SqlEngineFactory sqlFactory = context.getBean("sqlFactory", SqlEngineFactory.class); SqlCrudEngine sqlEngine = sqlFactory.getCrudEngine("ALL");
Another possibility is to utilize SqlFilesLoader
.
SqlFilesLoader loader = new SqlFilesLoader("statements.qry", this.getClass()); SqlProcessorLoader sqlLoader = new SqlProcessorLoader(loader.getStatements(), JdbcTypeFactory.getInstance()); SqlQueryEngine sqlEngine = sqlLoader.getQueryEngine("ALL");
For more info please see the Tutorials.
- Author:
- Vladimir Hudec
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
(package private) static class
The SQL Processor processing cache(package private) static class
The SQL Processor initialized enginesstatic enum
The SQL Engine types -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map
<String, SqlMetaStatement> The collection of named META SQL CALLABLE statements.private SqlTypeFactory
The combined factory for the META types construction.private SqlEngineConfiguration
The overall configuration, which can be persisted.private Map
<String, SqlMetaStatement> The collection of named META SQL CRUD statements.private SqlProcessorLoader.Engine
The collection of named dynamic SQL Engines (the primary SQL Processor class) instances.private SqlProcessorLoader.Engine
The collection of named SQL Engines (the primary SQL Processor class) instances.private ConcurrentHashMap
<String, String> The result of initialization.The collection of the SQL Processor optional features.protected final org.slf4j.Logger
The internal slf4j logger.private SqlMonitorFactory
The monitor factory used in the process of the SQL Monitor instances creationprivate Map
<String, SqlMappingRule> The collection of named explicitly defined mapping rules.private SqlPluginFactory
The factory for the SQL Processor plugins.private SqlProcessorLoader.Cache
The processing cache used forSqlProcessResult
instances.private Map
<String, SqlMetaStatement> The collection of named META SQL queries.The collection of the SQL Processor optional features in the statement context.The collection of the SQL Processor optional features to be cleared in the statement context.private SqlValidatorFactory
The validator factory used in the process of the SQL Monitor instances creation -
Constructor Summary
ConstructorsConstructorDescriptionSqlProcessorLoader
(StringBuilder sbStatements, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory) Creates a new instance of the SqlProcessorLoader from the String content repository (which is in fact a collection of the META SQL statements, mapping rules and optional features.SqlProcessorLoader
(StringBuilder sbStatements, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory, String filter) Creates a new instance of the SqlProcessorLoader from the String content repository (which is in fact a collection of the META SQL statements, mapping rules and optional features.SqlProcessorLoader
(StringBuilder sbStatements, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory, String filter, SqlMonitorFactory monitorFactory) Creates a new instance of the SqlProcessorLoader from the String content repository (which is in fact a collection of the META SQL statements, mapping rules and optional features.SqlProcessorLoader
(StringBuilder sbStatements, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory, String filter, SqlMonitorFactory monitorFactory, String... onlyStatements) Creates a new instance of the SqlProcessorLoader from the String content repository (which is in fact a collection of the META SQL statements, mapping rules and optional features.SqlProcessorLoader
(StringBuilder sbStatements, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory, String filter, SqlMonitorFactory monitorFactory, List<SqlMetaType> customTypes, String... onlyStatements) Creates a new instance of the SqlProcessorLoader from the String content repository (which is in fact a collection of the META SQL statements, mapping rules and optional features.SqlProcessorLoader
(StringBuilder sbStatements, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory, String filter, SqlMonitorFactory monitorFactory, SqlValidatorFactory validatorFactory, List<SqlMetaType> customTypes, String... onlyStatements) Creates a new instance of the SqlProcessorLoader from the String content repository (which is in fact a collection of the META SQL statements, mapping rules and optional features.SqlProcessorLoader
(StringBuilder sbStatements, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory, String filter, SqlMonitorFactory monitorFactory, SqlValidatorFactory validatorFactory, List<SqlMetaType> customTypes, SqlEngineConfiguration configuration, String... onlyStatements) Creates a new instance of the SqlProcessorLoader from the String content repository (which is in fact a collection of the META SQL statements, mapping rules and optional features. -
Method Summary
Modifier and TypeMethodDescriptionprivate SqlEngine
createEngine
(String name, SqlProcessorLoader.EngineType engineType, SqlMetaStatement stmt, String sqlStatement) Creates a new instance of the SQL Engine instance (the primary SQL Processor class).getDynamicEngine
(String name, SqlProcessorLoader.EngineType engineType, String sqlStatement) Returns the named dynamic SQL Engine instance (the primary SQL Processor class).getDynamicEngines
(SqlProcessorLoader.EngineType engineType) Returns all dynamic engines of the required typegetEngine
(String name, SqlProcessorLoader.EngineType engineType) Returns the named static or dynamic SQL Engine instance (the primary SQL Processor class).getEngines
(SqlProcessorLoader.EngineType engineType) Returns all static engines of the required typeReturns the result of engines initialization process.Returns the result of engines initialization process.private Map
<String, SqlMetaStatement> getStatements
(SqlProcessorLoader.EngineType engineType) Returns the static statements container based on required SQL Engine typegetStaticEngine
(String name, SqlProcessorLoader.EngineType engineType) Returns the named static SQL Engine instance (the primary SQL Processor class).void
Initializes all SQL Processor engines.boolean
Returns a flag which indicates the lazy initialization mode.private void
loadStatementFeatures
(String name, SqlEngine sqlEngine) Some filters can be the optional features in the statement context.void
setConfiguration
(SqlEngineConfiguration configuration) Sets the overall dynamic configuration
-
Field Details
-
logger
protected final org.slf4j.Logger loggerThe internal slf4j logger. -
composedTypeFactory
The combined factory for the META types construction. -
pluginFactory
The factory for the SQL Processor plugins. This is the basic facility to alter the SQL Processor processing. -
monitorFactory
The monitor factory used in the process of the SQL Monitor instances creation -
validatorFactory
The validator factory used in the process of the SQL Monitor instances creation -
engines
The collection of named SQL Engines (the primary SQL Processor class) instances. -
dynamicEngines
The collection of named dynamic SQL Engines (the primary SQL Processor class) instances. -
sqls
The collection of named META SQL queries. -
cruds
The collection of named META SQL CRUD statements. -
calls
The collection of named META SQL CALLABLE statements. -
outs
The collection of named explicitly defined mapping rules. -
features
The collection of the SQL Processor optional features. -
statementsFeatures
The collection of the SQL Processor optional features in the statement context. -
statementsFeaturesUnset
The collection of the SQL Processor optional features to be cleared in the statement context. -
configuration
The overall configuration, which can be persisted. -
processingCache
The processing cache used forSqlProcessResult
instances. -
enginesInitErrors
The result of initialization. For every engine, for which there's error in the initialization process there a error message.
-
-
Constructor Details
-
SqlProcessorLoader
public SqlProcessorLoader(StringBuilder sbStatements, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory) throws SqlEngineException Creates a new instance of the SqlProcessorLoader from the String content repository (which is in fact a collection of the META SQL statements, mapping rules and optional features. During the instance construction all the statements are parsed and the collection of named SQL Engine instances is established. Later these instances are used for the SQL queries/statements execution. For the purpose of the META types construction (located inside the META SQL statements and mapping rules) a factory instance has to be supplied.- Parameters:
sbStatements
- the String representation of the META SQL queries/statements/output mappingstypeFactory
- the factory for the META types constructionpluginFactory
- the factory for the SQL Processor plugins- Throws:
SqlEngineException
- mainly in the case the provided statements or rules are not compliant with the ANTLR based grammar
-
SqlProcessorLoader
public SqlProcessorLoader(StringBuilder sbStatements, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory, String filter) throws SqlEngineException Creates a new instance of the SqlProcessorLoader from the String content repository (which is in fact a collection of the META SQL statements, mapping rules and optional features. During the instance construction all the statements are parsed and the collection of named SQL Engine instances is established. Later these instances are used for the SQL queries/statements execution. For the purpose of the META types construction (located inside the META SQL statements and mapping rules) a factory instance has to be supplied.- Parameters:
sbStatements
- the String representation of the META SQL queries/statements/output mappingstypeFactory
- the factory for the META types constructionpluginFactory
- the factory for the SQL Processor pluginsfilter
- the properties name prefix to filter the META SQL statements, mapping rules and optional features- Throws:
SqlEngineException
- mainly in the case the provided statements or rules are not compliant with the ANTLR based grammar
-
SqlProcessorLoader
public SqlProcessorLoader(StringBuilder sbStatements, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory, String filter, SqlMonitorFactory monitorFactory) throws SqlEngineException Creates a new instance of the SqlProcessorLoader from the String content repository (which is in fact a collection of the META SQL statements, mapping rules and optional features. During the instance construction all the statements are parsed and the collection of named SQL Engine instances is established. Later these instances are used for the SQL queries/statements execution. For the purpose of the META types construction (located inside the META SQL statements and mapping rules) a factory instance has to be supplied. Every instance of the SQL Engine is accompanied with the SQL Monitor for the runtime statistics gathering. For the creation of these monitors the SQL Monitor Factory can be used.- Parameters:
sbStatements
- the String representation of the META SQL queries/statements/output mappingstypeFactory
- the factory for the META types constructionpluginFactory
- the factory for the SQL Processor pluginsfilter
- the properties name prefix to filter the META SQL statements, mapping rules and optional featuresmonitorFactory
- the monitor factory used in the process of the SQL Monitor instances creation- Throws:
SqlEngineException
- mainly in the case the provided statements or rules are not compliant with the ANTLR based grammar
-
SqlProcessorLoader
public SqlProcessorLoader(StringBuilder sbStatements, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory, String filter, SqlMonitorFactory monitorFactory, String... onlyStatements) Creates a new instance of the SqlProcessorLoader from the String content repository (which is in fact a collection of the META SQL statements, mapping rules and optional features. During the instance construction all the statements are parsed and the collection of named SQL Engine instances is established. Later these instances are used for the SQL queries/statements execution. For the purpose of the META types construction (located inside the META SQL statements and mapping rules) a factory instance has to be supplied. Every instance of the SQL Engine is accompanied with the SQL Monitor for the runtime statistics gathering. For the creation of these monitors the SQL Monitor Factory can be used.- Parameters:
sbStatements
- the String representation of the META SQL queries/statements/output mappingstypeFactory
- the factory for the META types constructionpluginFactory
- the factory for the SQL Processor pluginsfilter
- the properties name prefix to filter the META SQL statements, mapping rules and optional featuresmonitorFactory
- the monitor factory used in the process of the SQL Monitor instances creationonlyStatements
- only statements and rules with the names in this container are picked up from the properties repository- Throws:
SqlEngineException
- mainly in the case the provided statements or rules are not compliant with the ANTLR based grammar
-
SqlProcessorLoader
public SqlProcessorLoader(StringBuilder sbStatements, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory, String filter, SqlMonitorFactory monitorFactory, List<SqlMetaType> customTypes, String... onlyStatements) throws SqlEngineException Creates a new instance of the SqlProcessorLoader from the String content repository (which is in fact a collection of the META SQL statements, mapping rules and optional features. During the instance construction all the statements are parsed and the collection of named SQL Engine instances is established. Later these instances are used for the SQL queries/statements execution. For the purpose of the META types construction (located inside the META SQL statements and mapping rules) a factory instance has to be supplied. Every instance of the SQL Engine is accompanied with the SQL Monitor for the runtime statistics gathering. For the creation of these monitors the SQL Monitor Factory can be used.- Parameters:
sbStatements
- the String representation of the META SQL queries/statements/output mappingstypeFactory
- the factory for the META types constructionpluginFactory
- the factory for the SQL Processor pluginsfilter
- the properties name prefix to filter the META SQL statements, mapping rules and optional featuresmonitorFactory
- the monitor factory used in the process of the SQL Monitor instances creationcustomTypes
- the custom META typesonlyStatements
- only statements and rules with the names in this container are picked up from the properties repository- Throws:
SqlEngineException
- mainly in the case the provided statements or rules are not compliant with the ANTLR based grammar
-
SqlProcessorLoader
public SqlProcessorLoader(StringBuilder sbStatements, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory, String filter, SqlMonitorFactory monitorFactory, SqlValidatorFactory validatorFactory, List<SqlMetaType> customTypes, String... onlyStatements) throws SqlEngineException Creates a new instance of the SqlProcessorLoader from the String content repository (which is in fact a collection of the META SQL statements, mapping rules and optional features. During the instance construction all the statements are parsed and the collection of named SQL Engine instances is established. Later these instances are used for the SQL queries/statements execution. For the purpose of the META types construction (located inside the META SQL statements and mapping rules) a factory instance has to be supplied. Every instance of the SQL Engine is accompanied with the SQL Monitor for the runtime statistics gathering. For the creation of these monitors the SQL Monitor Factory can be used.- Parameters:
sbStatements
- the String representation of the META SQL queries/statements/output mappingstypeFactory
- the factory for the META types constructionpluginFactory
- the factory for the SQL Processor pluginsfilter
- the properties name prefix to filter the META SQL statements, mapping rules and optional featuresmonitorFactory
- the monitor factory used in the process of the SQL Monitor instances creationvalidatorFactory
- the validator factory used in the process of the SQL Monitor instances creationcustomTypes
- the custom META typesonlyStatements
- only statements and rules with the names in this container are picked up from the properties repository- Throws:
SqlEngineException
- mainly in the case the provided statements or rules are not compliant with the ANTLR based grammar
-
SqlProcessorLoader
public SqlProcessorLoader(StringBuilder sbStatements, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory, String filter, SqlMonitorFactory monitorFactory, SqlValidatorFactory validatorFactory, List<SqlMetaType> customTypes, SqlEngineConfiguration configuration, String... onlyStatements) throws SqlEngineException Creates a new instance of the SqlProcessorLoader from the String content repository (which is in fact a collection of the META SQL statements, mapping rules and optional features. During the instance construction all the statements are parsed and the collection of named SQL Engine instances is established. Later these instances are used for the SQL queries/statements execution. For the purpose of the META types construction (located inside the META SQL statements and mapping rules) a factory instance has to be supplied. Every instance of the SQL Engine is accompanied with the SQL Monitor for the runtime statistics gathering. For the creation of these monitors the SQL Monitor Factory can be used.- Parameters:
sbStatements
- the String representation of the META SQL queries/statements/output mappingstypeFactory
- the factory for the META types constructionpluginFactory
- the factory for the SQL Processor pluginsfilter
- the properties name prefix to filter the META SQL statements, mapping rules and optional featuresmonitorFactory
- the monitor factory used in the process of the SQL Monitor instances creationvalidatorFactory
- the validator factory used in the process of the SQL Monitor instances creationcustomTypes
- the custom META typesconfiguration
- the overall configuration, which can be persistedonlyStatements
- only statements and rules with the names in this container are picked up from the properties repository- Throws:
SqlEngineException
- mainly in the case the provided statements or rules are not compliant with the ANTLR based grammar
-
-
Method Details
-
init
public void init(Executor executor, Set<String> sqlsToInit, Set<String> crudsToInit, Set<String> callsToInit) Initializes all SQL Processor engines. It can be done synchronously or asynchronously. For every engine, for which there's error in the initialization process there a error message.- Parameters:
executor
- The asynchronous executor. In the case it is null, the initialization is provided in synchronous mode.sqlsToInit
- The SQL engine names to initialize.crudsToInit
- The CRUD engine names to initialize.callsToInit
- The Procedure engine names to initialize.
-
getEnginesInitErrors
Returns the result of engines initialization process. For every engine, for which there's error in the initialization process there a error message. In the case there's no error, the result message is null.- Returns:
- the result of engines initialization process
-
getEnginesInitErrorsMsg
Returns the result of engines initialization process. For every engine, for which there's error in the initialization process there a error message. In the case there's no error, the result message is null.- Returns:
- the result of engines initialization process
-
loadStatementFeatures
Some filters can be the optional features in the statement context.- Parameters:
name
- the name of the META SQL statement
-
getEngines
Returns all static engines of the required type- Parameters:
engineType
- the required SQL Engine type- Returns:
- a container of initialized engines
-
getDynamicEngines
Returns all dynamic engines of the required type- Parameters:
engineType
- the required SQL Engine type- Returns:
- a container of initialized engines
-
createEngine
private SqlEngine createEngine(String name, SqlProcessorLoader.EngineType engineType, SqlMetaStatement stmt, String sqlStatement) Creates a new instance of the SQL Engine instance (the primary SQL Processor class).- Parameters:
name
- the name of the required SQL Procedure Engine instanceengineType
- the required SQL Engine typestmt
- the new SQL META statement instance for the case of static SQL Engine instancesqlStatement
- the new SQL statement for the case of dynamic SQL Engine instance- Returns:
- the new SQL Engine instance
- Throws:
SqlEngineException
- in the case the instance can't be created
-
getStaticEngine
Returns the named static SQL Engine instance (the primary SQL Processor class).- Parameters:
name
- the name of the required SQL Procedure Engine instanceengineType
- the required SQL Engine type- Returns:
- the SQL Engine instance
- Throws:
SqlEngineException
- in the case the instance can't be created
-
getDynamicEngine
public SqlEngine getDynamicEngine(String name, SqlProcessorLoader.EngineType engineType, String sqlStatement) Returns the named dynamic SQL Engine instance (the primary SQL Processor class).- Parameters:
name
- the name of the required SQL Procedure Engine instanceengineType
- the required SQL Engine typesqlStatement
- the new SQL statement- Returns:
- the SQL Engine instance
- Throws:
SqlEngineException
- in the case the instance can't be created
-
getEngine
Returns the named static or dynamic SQL Engine instance (the primary SQL Processor class).- Parameters:
name
- the name of the required SQL Procedure Engine instanceengineType
- the required SQL Engine type- Returns:
- the SQL Engine instance
- Throws:
SqlEngineException
- in the case the instance can't be created
-
getStatements
Returns the static statements container based on required SQL Engine type- Parameters:
engineType
- the required SQL Engine type- Returns:
- the static statements container
-
setConfiguration
Sets the overall dynamic configuration- Parameters:
configuration
- the overall dynamic configuration
-
isLazyInit
public boolean isLazyInit()Returns a flag which indicates the lazy initialization mode.- Returns:
- a flag which indicates the lazy initialization mode.
-