Class SqlDefaultFactory

  • All Implemented Interfaces:
    SqlEngineFactory
    Direct Known Subclasses:
    JdbcEngineFactory

    public class SqlDefaultFactory
    extends Object
    implements SqlEngineFactory
    The simple implementation of the SqlEngineFactory.

    It's suitable mainly for the Spring DI based configuration, like the next one for the loader SqlProcessorLoader:

     <beans ...>
       ...
       <bean id="typeFactory" class="org.sqlproc.engine.jdbc.type.JdbcTypeFactory" factory-method="getInstance" />
     
       <bean id="sqlFactory" class="org.sqlproc.engine.SqlDefaultFactory" init-method="init">
         <property name="metaFilesNames">
           <list>
             <value>statements.qry</value>
           </list>
         </property>
         <property name="typeFactory" ref="typeFactory" />
       </bean>
     </beans>
     
    and use the next code to obtain an instance of the SQL Query engine
     SqlQueryEngine sqlEngine = sqlFactory.getQueryEngine("ALL");
     
    or the next code to obtain an instance of the SQL CRUD engine
     SqlCrudEngine sqlEngine = sqlFactory.getCrudEngine("ALL");
     

    In the case the SQL Processor runs on the top of the JDBC stack, there's more suitable JdbcEngineFactory.

    For more info please see the Tutorials.

    Author:
    Vladimir Hudec
    • Field Detail

      • logger

        protected final org.slf4j.Logger logger
        The internal slf4j logger.
      • LINESEP

        private static final String LINESEP
        The platform based line separator.
      • metaFilesNames

        private List<String> metaFilesNames
        The names of files, which hold a collection of the SQL Processor artifacts (META SQL statements, mapping rules and optional features).
      • metaStatements

        private StringBuilder metaStatements
        The String representation of all SQL Processor artifacts (META SQL statements, mapping rules and optional features).
      • typeFactory

        private SqlTypeFactory typeFactory
        The factory for the META types construction.
      • pluginFactory

        protected SqlPluginFactory pluginFactory
        The factory for the SQL Processor plugins.
      • filter

        private String filter
        The name of the filter to filter the META SQL statements, mapping rules and optional features.
      • monitorFactory

        private SqlMonitorFactory monitorFactory
        The monitor factory used in the process of the SQL Monitor instances creation.
      • customTypes

        private List<SqlMetaType> customTypes
        The custom META types.
      • onlyStatements

        private String[] onlyStatements
        Only statements and rules with the names in this set are picked up from the properties repository.
      • jdbc

        private boolean jdbc
        The indicator the JDBC stack is used.
      • processorLoader

        private volatile SqlProcessorLoader processorLoader
        The helper class for the META SQL statements and mapping rules parsing. All artifacts are loaded from new grammar based files.
      • validatorFactory

        private SqlValidatorFactory validatorFactory
        The validator factory used in the process of the SQL Monitor instances creation.
      • lazyInit

        private Boolean lazyInit
        This flag indicates to speed up the initialization process.
      • asyncInitThreads

        private Integer asyncInitThreads
        The number of threads used for asynchronous initialization.
      • configuration

        private SqlEngineConfiguration configuration
        The overall configuration, which can be persisted.
      • executor

        private Executor executor
        The asynchronous SQL Processor engines initialization executor. It can be a Spring TaskExecutor.
      • executorTerminated

        private Boolean executorTerminated
        The flag indicating the asynchronous SQL Processor engines initialization has been finished.
      • collectionsAreStandardTypes

        private boolean collectionsAreStandardTypes
        The indicator that Collections should be handled as standard types. This is standard behaviour for Cassandra DB..
      • skipAliasesInQqlCommand

        private boolean skipAliasesInQqlCommand
        The indicator that column aliases are not included in generated SQL command. This is standard behaviour for Cassandra DB.
    • Constructor Detail

      • SqlDefaultFactory

        public SqlDefaultFactory()
        Creates a new instance with no default values.
      • SqlDefaultFactory

        public SqlDefaultFactory​(boolean lazyInit)
        Creates a new instance with no default values.
        Parameters:
        lazyInit - this flag indicates to speed up the initialization process.
      • SqlDefaultFactory

        public SqlDefaultFactory​(int asyncInitThreads)
        Creates a new instance with no default values.
        Parameters:
        asyncInitThreads - number of threads used for asynchronous initialization
      • SqlDefaultFactory

        public SqlDefaultFactory​(boolean lazyInit,
                                 int asyncInitThreads)
        Creates a new instance with no default values.
        Parameters:
        lazyInit - this flag indicates to speed up the initialization process.
        asyncInitThreads - number of threads used for asynchronous initialization
    • Method Detail

      • init

        public void init()
        Dynamic initialization, called mainly from the Spring configuration initialization.
      • init0

        public void init0()
        Conditional dynamic initialization, called mainly from the Spring configuration initialization.
      • getQueryEngine

        public SqlQueryEngine getQueryEngine​(String name)
        Returns the named static or dynamic SQL Query Engine instance (the primary SQL Processor class). In fact it returns the cached instance in the case it exists (it can be a static or dynamic one). Otherwise it instantiates a new static instance.
        Specified by:
        getQueryEngine in interface SqlEngineFactory
        Parameters:
        name - the name of the required SQL Query Engine instance
        Returns:
        the SQL Engine instance or null value in the case the related statement is missing
      • getCrudEngine

        public SqlCrudEngine getCrudEngine​(String name)
        Returns the named static or dynamic SQL CRUD Engine instance (the primary SQL Processor class). In fact it returns the cached instance in the case it exists (it can be a static or dynamic one). Otherwise it instantiates a new static instance.
        Specified by:
        getCrudEngine in interface SqlEngineFactory
        Parameters:
        name - the name of the required SQL CRUD Engine instance
        Returns:
        the SQL Engine instance or null value in the case the related statement is missing
      • getProcedureEngine

        public SqlProcedureEngine getProcedureEngine​(String name)
        Returns the named static or dynamic SQL Procedure Engine instance (the primary SQL Processor class). In fact it returns the cached instance in the case it exists (it can be a static or dynamic one). Otherwise it instantiates a new static instance.
        Specified by:
        getProcedureEngine in interface SqlEngineFactory
        Parameters:
        name - the name of the required SQL Procedure Engine instance
        Returns:
        the SQL Engine instance or null value in the case the related statement is missing
      • getStaticQueryEngine

        public SqlQueryEngine getStaticQueryEngine​(String name)
        Returns the named static SQL Query Engine instance (the primary SQL Processor class).
        Specified by:
        getStaticQueryEngine in interface SqlEngineFactory
        Parameters:
        name - the name of the required SQL Query Engine instance
        Returns:
        the SQL Engine instance or null value in the case the related statement is missing
      • getStaticCrudEngine

        public SqlCrudEngine getStaticCrudEngine​(String name)
        Returns the named static SQL CRUD Engine instance (the primary SQL Processor class).
        Specified by:
        getStaticCrudEngine in interface SqlEngineFactory
        Parameters:
        name - the name of the required SQL CRUD Engine instance
        Returns:
        the SQL Engine instance or null value in the case the related statement is missing
      • getStaticProcedureEngine

        public SqlProcedureEngine getStaticProcedureEngine​(String name)
        Returns the named static SQL Procedure Engine instance (the primary SQL Processor class).
        Specified by:
        getStaticProcedureEngine in interface SqlEngineFactory
        Parameters:
        name - the name of the required SQL Procedure Engine instance
        Returns:
        the SQL Engine instance or null value in the case the related statement is missing
      • check

        private void check​(String name,
                           SqlEngine sqlEngine)
        Check the SQL Engine instance is not null
        Parameters:
        name - the name of the required SQL Engine instance
        sqlEngine - the checked SQL Engine instance
        Throws:
        SqlEngineException - in the case the the SQL Engine instance is null
      • getCheckedQueryEngine

        public SqlQueryEngine getCheckedQueryEngine​(String name)
                                             throws SqlEngineException
        Returns the named static or dynamic SQL Query Engine instance (the primary SQL Processor class). In fact it returns the cached instance in the case it exists (it can be a static or dynamic one). Otherwise it instantiates a new static instance.
        Specified by:
        getCheckedQueryEngine in interface SqlEngineFactory
        Parameters:
        name - the name of the required SQL Query Engine instance
        Returns:
        the SQL Engine instance
        Throws:
        SqlEngineException - in the case the related statement is missing
      • getCheckedCrudEngine

        public SqlCrudEngine getCheckedCrudEngine​(String name)
        Returns the named static or dynamic SQL CRUD Engine instance (the primary SQL Processor class). In fact it returns the cached instance in the case it exists (it can be a static or dynamic one). Otherwise it instantiates a new static instance.
        Specified by:
        getCheckedCrudEngine in interface SqlEngineFactory
        Parameters:
        name - the name of the required SQL CRUD Engine instance
        Returns:
        the SQL Engine instance
      • getCheckedProcedureEngine

        public SqlProcedureEngine getCheckedProcedureEngine​(String name)
        Returns the named static or dynamic SQL Procedure Engine instance (the primary SQL Processor class). In fact it returns the cached instance in the case it exists (it can be a static or dynamic one). Otherwise it instantiates a new static instance.
        Specified by:
        getCheckedProcedureEngine in interface SqlEngineFactory
        Parameters:
        name - the name of the required SQL Procedure Engine instance
        Returns:
        the SQL Engine instance
      • getCheckedStaticCrudEngine

        public SqlCrudEngine getCheckedStaticCrudEngine​(String name)
        Returns the named static SQL CRUD Engine instance (the primary SQL Processor class).
        Specified by:
        getCheckedStaticCrudEngine in interface SqlEngineFactory
        Parameters:
        name - the name of the required SQL CRUD Engine instance
        Returns:
        the SQL Engine instance
      • getCheckedStaticProcedureEngine

        public SqlProcedureEngine getCheckedStaticProcedureEngine​(String name)
        Returns the named static SQL Procedure Engine instance (the primary SQL Processor class).
        Specified by:
        getCheckedStaticProcedureEngine in interface SqlEngineFactory
        Parameters:
        name - the name of the required SQL Procedure Engine instance
        Returns:
        the SQL Engine instance
      • getDynamicQueryEngine

        public SqlQueryEngine getDynamicQueryEngine​(String name,
                                                    String sqlStatement)
                                             throws SqlEngineException
        Returns the named dynamic SQL Query Engine instance (the primary SQL Processor class).
        Specified by:
        getDynamicQueryEngine in interface SqlEngineFactory
        Parameters:
        name - the name of the required SQL Query Engine instance
        sqlStatement - the new SQL statement, which is going to replace the original one
        Returns:
        the SQL Engine instance
        Throws:
        SqlEngineException - in the case the original statement is missing
      • getDynamicCrudEngine

        public SqlCrudEngine getDynamicCrudEngine​(String name,
                                                  String sqlStatement)
        Returns the named dynamic SQL CRUD Engine instance (the primary SQL Processor class).
        Specified by:
        getDynamicCrudEngine in interface SqlEngineFactory
        Parameters:
        name - the name of the required SQL CRUD Engine instance
        sqlStatement - the new SQL statement, which is going to replace the original one
        Returns:
        the SQL Engine instance
      • getDynamicProcedureEngine

        public SqlProcedureEngine getDynamicProcedureEngine​(String name,
                                                            String sqlStatement)
        Returns the named dynamic SQL Procedure Engine instance (the primary SQL Processor class).
        Specified by:
        getDynamicProcedureEngine in interface SqlEngineFactory
        Parameters:
        name - the name of the required SQL Procedure Engine instance
        sqlStatement - the new SQL statement, which is going to replace the original one
        Returns:
        the SQL Engine instance
      • getMetaFilesNames

        public List<String> getMetaFilesNames()
        Returns the names of files, which holds a collection of META SQL statements, mapping rules and optional features.
        Returns:
        the names of files, which holds a collection of META SQL statements, mapping rules and optional features
      • setMetaFilesNames

        public void setMetaFilesNames​(List<String> metaFilesNames)
        Sets the names of files, which holds a collection of META SQL statements, mapping rules and optional features.
        Parameters:
        metaFilesNames - the names of files, which holds a collection of META SQL statements, mapping rules and optional features
      • setMetaFilesNames

        public void setMetaFilesNames​(String... metaFilesNames)
        Sets the names of files, which holds a collection of META SQL statements, mapping rules and optional features.
        Parameters:
        metaFilesNames - the names of files, which holds a collection of META SQL statements, mapping rules and optional features
      • getMetaStatements

        public StringBuilder getMetaStatements()
        Returns the String representation of the META SQL statements, mapping rules and optional features.
        Returns:
        the String representation of the META SQL statements, mapping rules and optional features
      • setMetaStatements

        public void setMetaStatements​(StringBuilder metaStatements)
        Sets the String representation of the META SQL statements, mapping rules and optional features.
        Parameters:
        metaStatements - the String representation of the META SQL statements, mapping rules and optional features
      • getTypeFactory

        public SqlTypeFactory getTypeFactory()
        Returns the factory for the META types construction.
        Returns:
        the factory for the META types construction
      • setTypeFactory

        public void setTypeFactory​(SqlTypeFactory typeFactory)
        Sets the factory for the META types construction.
        Parameters:
        typeFactory - the factory for the META types construction
      • getPluginFactory

        public SqlPluginFactory getPluginFactory()
        Returns the factory for the SQL Processor plugins.
        Returns:
        the factory for the SQL Processor plugins
      • setPluginFactory

        public void setPluginFactory​(SqlPluginFactory pluginFactory)
        Sets the factory for the SQL Processor plugins.
        Parameters:
        pluginFactory - the factory for the SQL Processor plugins
      • getFilter

        public String getFilter()
        Returns the name of the filter to filter the META SQL statements, mapping rules and optional features.
        Returns:
        the name of the filter to filter the META SQL statements, mapping rules and optional features
      • setFilter

        public void setFilter​(String filter)
        Sets the name of the filter to filter the META SQL statements, mapping rules and optional features.
        Parameters:
        filter - the name of the filter to filter the META SQL statements, mapping rules and optional features
      • setFilter

        public void setFilter​(SqlFeature filter)
        Sets the name of the filter to filter the META SQL statements, mapping rules and optional features.
        Parameters:
        filter - the name of the filter to filter the META SQL statements, mapping rules and optional features
      • getMonitorFactory

        public SqlMonitorFactory getMonitorFactory()
        Returns the monitor factory used in the process of the SQL Monitor instances creation.
        Returns:
        the monitor factory used in the process of the SQL Monitor instances creation
      • setMonitorFactory

        public void setMonitorFactory​(SqlMonitorFactory monitorFactory)
        Sets the monitor factory used in the process of the SQL Monitor instances creation.
        Parameters:
        monitorFactory - the monitor factory used in the process of the SQL Monitor instances creation
      • getCustomTypes

        public List<SqlMetaType> getCustomTypes()
        Returns the custom META types.
        Returns:
        the custom META types
      • setCustomTypes

        public void setCustomTypes​(List<SqlMetaType> customTypes)
        Sets the custom META types.
        Parameters:
        customTypes - the custom META types
      • setCustomTypes

        public void setCustomTypes​(SqlMetaType... customTypes)
        Sets the custom META types.
        Parameters:
        customTypes - the custom META types
      • addCustomType

        public void addCustomType​(SqlMetaType customType)
        Adds a new custom META type.
        Parameters:
        customType - the custom META type
      • getOnlyStatements

        public String[] getOnlyStatements()
        Returns the only statements and rules, which are picked up from the properties repository.
        Returns:
        the only statements and rules, which are picked up from the properties repository
      • setOnlyStatements

        public void setOnlyStatements​(String[] selectQueries)
        Sets the only statements and rules, which are picked up from the properties repository.
        Parameters:
        selectQueries - the only statements and rules, which are picked up from the properties repository
      • isJdbc

        public boolean isJdbc()
        Returns the indicator the JDBC stack is used.
        Returns:
        the indicator the JDBC stack is used
      • setJdbc

        public void setJdbc​(boolean jdbc)
        Sets the indicator the JDBC stack is used.
        Parameters:
        jdbc - the indicator the JDBC stack is used
      • isCollectionsAreStandardTypes

        public boolean isCollectionsAreStandardTypes()
        Returns the indicator that Collections should be handled as standard types.
        Returns:
        the indicator that Collections should be handled as standard types.
      • setCollectionsAreStandardTypes

        public void setCollectionsAreStandardTypes​(boolean collectionsAreStandardTypes)
        Sets the indicator that Collections should be handled as standard types.
        Parameters:
        collectionsAreStandardTypes - the indicator that Collections should be handled as standard types.
      • isSkipAliasesInQqlCommand

        public boolean isSkipAliasesInQqlCommand()
        Returns the indicator that column aliases are not included in generated SQL command.
        Returns:
        the indicator that column aliases are not included in generated SQL command
      • setSkipAliasesInQqlCommand

        public void setSkipAliasesInQqlCommand​(boolean skipAliasesInQqlCommand)
        Sets the indicator that column aliases are not included in generated SQL command.
        Parameters:
        skipAliasesInQqlCommand - the indicator that column aliases are not included in generated SQL command
      • isLazyInit

        public boolean isLazyInit()
        Returns the indicator to speed up the initialization process
        Specified by:
        isLazyInit in interface SqlEngineFactory
        Returns:
        the indicator to speed up the initialization process
      • setLazyInit

        public void setLazyInit​(Boolean lazyInit)
        Sets the indicator to speed up the initialization process
        Parameters:
        lazyInit - the indicator to speed up the initialization process
      • getAsyncInitThreads

        public int getAsyncInitThreads()
        Returns the number of threads used for asynchronous initialization
        Specified by:
        getAsyncInitThreads in interface SqlEngineFactory
        Returns:
        the number of threads used for asynchronous initialization
      • setAsyncInitThreads

        public void setAsyncInitThreads​(Integer asyncInitThreads)
        Sets the number of threads used for asynchronous initialization
        Parameters:
        asyncInitThreads - the number of threads used for asynchronous initialization
      • isAsyncInitFinished

        public Boolean isAsyncInitFinished()
        Returns the flag indicating the asynchronous SQL Processor engines initialization has been finished.
        Specified by:
        isAsyncInitFinished in interface SqlEngineFactory
        Returns:
        the flag indicating the asynchronous SQL Processor engines initialization has been finished
      • getLoader

        public SqlProcessorLoader getLoader()
        Returns the internal SQL engine or processor loader.
        Returns:
        the internal SQL engine or processor loader
      • getValidatorFactory

        public SqlValidatorFactory getValidatorFactory()
        Returns the validator factory used in the process of the SQL Monitor instances creation.
        Returns:
        the validator factory used in the process of the SQL Monitor instances creation
      • setValidatorFactory

        public void setValidatorFactory​(SqlValidatorFactory validatorFactory)
        Sets the validator factory used in the process of the SQL Monitor instances creation.
        Parameters:
        validatorFactory - the validator factory used in the process of the SQL Monitor instances creation
      • getQueryNames

        public Collection<String> getQueryNames()
        Returns the collection of names of all initialized/constructed static SQL Query Engine instances.
        Specified by:
        getQueryNames in interface SqlEngineFactory
        Returns:
        The collection of all initialized static SQL Query Engine instances' names
      • getQueryDynamicNames

        public Collection<String> getQueryDynamicNames()
        Returns the collection of names of all initialized/constructed dynamic SQL Query Engine instances.
        Specified by:
        getQueryDynamicNames in interface SqlEngineFactory
        Returns:
        The collection of all initialized dynamic SQL Query Engine instances' names
      • getQueryEngines

        public Map<String,​SqlEngine> getQueryEngines()
        Returns the collection of named dynamic SQL Query Engines (the primary SQL Processor class) instances.
        Specified by:
        getQueryEngines in interface SqlEngineFactory
        Returns:
        The collection of named dynamic SQL Query Engines (the primary SQL Processor class) instances
      • getQueryDynamicEngines

        public Map<String,​SqlEngine> getQueryDynamicEngines()
        Returns the collection of names of all initialized/constructed dynamic SQL Query Engine instances.
        Specified by:
        getQueryDynamicEngines in interface SqlEngineFactory
        Returns:
        The collection of all initialized dynamic SQL Query Engine instances' names
      • getCrudNames

        public Collection<String> getCrudNames()
        Returns the collection of names of all initialized/constructed static SQL CRUD Engine instances.
        Specified by:
        getCrudNames in interface SqlEngineFactory
        Returns:
        The collection of all initialized static SQL CRUD Engine instances' names
      • getCrudDynamicNames

        public Collection<String> getCrudDynamicNames()
        Returns the collection of names of all initialized/constructed dynamic SQL CRUD Engine instances.
        Specified by:
        getCrudDynamicNames in interface SqlEngineFactory
        Returns:
        The collection of all initialized dynamic SQL CRUD Engine instances' names
      • getCrudEngines

        public Map<String,​SqlEngine> getCrudEngines()
        Returns the collection of named dynamic SQL CRUD Engines (the primary SQL Processor class) instances.
        Specified by:
        getCrudEngines in interface SqlEngineFactory
        Returns:
        The collection of named dynamic SQL CRUD Engines (the primary SQL Processor class) instances
      • getCrudDynamicEngines

        public Map<String,​SqlEngine> getCrudDynamicEngines()
        Returns the collection of names of all initialized/constructed dynamic SQL CRUD Engine instances.
        Specified by:
        getCrudDynamicEngines in interface SqlEngineFactory
        Returns:
        The collection of all initialized dynamic SQL CRUD Engine instances' names
      • getProcedureNames

        public Collection<String> getProcedureNames()
        Returns the collection of names of all initialized/constructed static SQL Procedure Engine instances.
        Specified by:
        getProcedureNames in interface SqlEngineFactory
        Returns:
        The collection of all initialized static SQL Procedure Engine instances' names
      • getProcedureDynamicNames

        public Collection<String> getProcedureDynamicNames()
        Returns the collection of names of all initialized/constructed dynamic SQL Procedure Engine instances.
        Specified by:
        getProcedureDynamicNames in interface SqlEngineFactory
        Returns:
        The collection of all initialized dynamic SQL Procedure Engine instances' names
      • getProcedureEngines

        public Map<String,​SqlEngine> getProcedureEngines()
        Returns the collection of named dynamic SQL Procedure Engines (the primary SQL Processor class) instances.
        Specified by:
        getProcedureEngines in interface SqlEngineFactory
        Returns:
        The collection of named dynamic SQL Procedure Engines (the primary SQL Processor class) instances
      • getProcedureDynamicEngines

        public Map<String,​SqlEngine> getProcedureDynamicEngines()
        Returns the collection of names of all initialized/constructed dynamic SQL Procedure Engine instances.
        Specified by:
        getProcedureDynamicEngines in interface SqlEngineFactory
        Returns:
        The collection of all initialized dynamic SQL Procedure Engine instances' names
      • getEnginesInitErrors

        public Map<String,​String> 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.
        Specified by:
        getEnginesInitErrors in interface SqlEngineFactory
        Returns:
        the result of engines initialization process
      • getEnginesInitErrorsMsg

        public String 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.
        Specified by:
        getEnginesInitErrorsMsg in interface SqlEngineFactory
        Returns:
        the result of engines initialization process
      • setConfiguration

        public void setConfiguration​(SqlEngineConfiguration configuration)
        Sets the overall dynamic configuration
        Parameters:
        configuration - the overall dynamic configuration
      • getExecutor

        protected Executor getExecutor()
        Returns the asynchronous SQL Processor engines initialization executor. It can be a Spring TaskExecutor or null for the case of synchronous SQL Processor engines initialization.
        Returns:
        the asynchronous SQL Processor engines initialization executor
      • setExecutor

        public void setExecutor​(Executor executor)
        Sets the asynchronous SQL Processor engines initialization executor. It can be a Spring TaskExecutor or null for the case of synchronous SQL Processor engines initialization.
        Parameters:
        executor - the asynchronous SQL Processor engines initialization executor