org.sqlproc.engine
Class SqlEngineLoader

java.lang.Object
  extended by org.sqlproc.engine.SqlEngineLoader
All Implemented Interfaces:
SqlEngineFactory

public class SqlEngineLoader
extends Object
implements SqlEngineFactory

The helper class for the META SQL statements and mapping rules parsing. These statements and rules are taken from the Properties.
The purpose of this class is to load and analyze (=parse) the META SQL statements and mapping rules located in the properties repository. The standard properties repository is the external properties file with the name queries.properties.

This is rather a low level helper class. For more simple approach please see SqlSimpleFactory

All the properties with the key QRY_... are parsed as the META SQL queries using the ANTLR based grammar.
All the properties with the key CRUD_... are parsed as the META SQL CRUD statements using the ANTLR based grammar.
All the properties with the key 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 properties with the key SET_... 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 SqlEngineLoader, Spring DI configuration can be utilized, like the next one:

 <beans ...>
   ...
   <bean id="typeFactory" class="org.sqlproc.engine.jdbc.type.JdbcTypeFactory" factory-method="getInstance" />
 
   <bean id="sqlQueries" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
     <property name="location">
       <value>classpath:queries.properties</value>
     </property>
   </bean>
   
   <bean id="sqlLoader" class="org.sqlproc.engine.SqlEngineLoader">
     <constructor-arg ref="sqlQueries" />
     <constructor-arg ref="typeFactory" />
   </bean>
 </beans>
 
and use the next code to obtain an instance of the SQL Query engine
 SqlQueryEngine sqlEngine = sqlLoader.getQueryEngine("ALL");
 
or the next code to obtain an instance of the SQL CRUD engine
 SqlCrudEngine sqlEngine = sqlLoader.getCrudEngine("ALL");
 

Another possibility is to utilize SqlPropertiesLoader.

 SqlPropertiesLoader loader = new SqlPropertiesLoader("queries.properties", this.getClass());
 SqlEngineLoader sqlLoader = new SqlEngineLoader(loader.getProperties(), JdbcTypeFactory.getInstance());
 SqlEngine sqlEngine = sqlLoader.getQueryEngine("ALL");
 

For more info please see the Reference Guide or the tutorials.

Author:
Vladimir Hudec

Field Summary
private  SqlTypeFactory composedTypeFactory
           
private static String CRUD_PREFIX
           
private  Map<String,String> cruds
          The collection of named META SQL CRUD statements.
private  Map<String,SqlEngine> engines
          The collection of named SQL Engine (the primary SQL Processor class) instances.
private  Map<String,Object> features
          The collection of the SQL Processor optional features.
private  Map<String,String> fields
          The collection of named explicitly defined mapping rules.
private static String FIELDS_REFERENCE
           
private static String INPUT_MAPPING_PREFIX
           
private static int lCRUD_PREFIX
           
private static int lFIELDS_REFERENCE
           
private static int lINPUT_MAPPING_PREFIX
           
protected  org.slf4j.Logger logger
          The internal slf4j logger.
private static int lOUTPUT_MAPPING_PREFIX
           
private static int lQUERY_PREFIX
           
private static int lSET_PREFIX
           
private static String OUTPUT_MAPPING_PREFIX
           
private static String QUERY_PREFIX
           
private static String SET_PREFIX
           
private  Map<String,String> sqls
          The collection of named META SQL queries.
 
Constructor Summary
SqlEngineLoader(Properties props, SqlTypeFactory typeFactory)
          Creates a new instance of the SqlEngineLoader from the properties repository (which is in fact a collection of the META SQL statements, mapping rules and optional features.
SqlEngineLoader(Properties props, SqlTypeFactory typeFactory, String filter)
          Creates a new instance of the SqlEngineLoader from the properties repository (which is in fact a collection of the META SQL statements, mapping rules and optional features.
SqlEngineLoader(Properties props, SqlTypeFactory typeFactory, String filter, SqlMonitorFactory monitorFactory)
          Creates a new instance of the SqlEngineLoader from the properties repository (which is in fact a collection of the META SQL statements, mapping rules and optional features.
SqlEngineLoader(Properties props, SqlTypeFactory typeFactory, String filter, SqlMonitorFactory monitorFactory, List<SqlInternalType> customTypes, String... selectQueries)
          Creates a new instance of the SqlEngineLoader from the properties repository (which is in fact a collection of the META SQL statements, mapping rules and optional features.
SqlEngineLoader(Properties props, SqlTypeFactory typeFactory, String filter, SqlMonitorFactory monitorFactory, String... selectQueries)
          Creates a new instance of the SqlEngineLoader from the properties repository (which is in fact a collection of the META SQL statements, mapping rules and optional features.
 
Method Summary
 SqlCrudEngine getCrudEngine(String name)
          Returns the named SQL CRUD Engine instance (the primary SQL Processor class).
 String getMappingRule(String name)
          Returns the named mapping rule.
 String getMetaSql(String name)
          Returns the named META SQL query/statement.
 Collection<String> getNames()
          Returns the collection of names of all initialized/constructed SQL Engine instances.
 SqlQueryEngine getQueryEngine(String name)
          Returns the named SQL Query Engine instance (the primary SQL Processor class).
 
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.


SET_PREFIX

private static final String SET_PREFIX
See Also:
Constant Field Values

lSET_PREFIX

private static final int lSET_PREFIX

FIELDS_REFERENCE

private static final String FIELDS_REFERENCE
See Also:
Constant Field Values

lFIELDS_REFERENCE

private static final int lFIELDS_REFERENCE

QUERY_PREFIX

private static final String QUERY_PREFIX
See Also:
Constant Field Values

lQUERY_PREFIX

private static final int lQUERY_PREFIX

INPUT_MAPPING_PREFIX

private static final String INPUT_MAPPING_PREFIX
See Also:
Constant Field Values

lINPUT_MAPPING_PREFIX

private static final int lINPUT_MAPPING_PREFIX

OUTPUT_MAPPING_PREFIX

private static final String OUTPUT_MAPPING_PREFIX
See Also:
Constant Field Values

lOUTPUT_MAPPING_PREFIX

private static final int lOUTPUT_MAPPING_PREFIX

CRUD_PREFIX

private static final String CRUD_PREFIX
See Also:
Constant Field Values

lCRUD_PREFIX

private static final int lCRUD_PREFIX

composedTypeFactory

private SqlTypeFactory composedTypeFactory

engines

private Map<String,SqlEngine> engines
The collection of named SQL Engine (the primary SQL Processor class) instances.


sqls

private Map<String,String> sqls
The collection of named META SQL queries.


cruds

private Map<String,String> cruds
The collection of named META SQL CRUD statements.


fields

private Map<String,String> fields
The collection of named explicitly defined mapping rules.


features

private Map<String,Object> features
The collection of the SQL Processor optional features.

Constructor Detail

SqlEngineLoader

public SqlEngineLoader(Properties props,
                       SqlTypeFactory typeFactory)
                throws SqlEngineException
Creates a new instance of the SqlEngineLoader from the properties 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:
props - the collection of META SQL statements, mapping rules and optional features located in the properties repository
typeFactory - the factory for the META types construction
Throws:
SqlEngineException - mainly in the case the provided statements or rules are not compliant with the ANTLR based grammar

SqlEngineLoader

public SqlEngineLoader(Properties props,
                       SqlTypeFactory typeFactory,
                       String filter)
                throws SqlEngineException
Creates a new instance of the SqlEngineLoader from the properties 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:
props - the collection of META SQL statements, mapping rules and optional features
typeFactory - the factory for the META types construction
filter - 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

SqlEngineLoader

public SqlEngineLoader(Properties props,
                       SqlTypeFactory typeFactory,
                       String filter,
                       SqlMonitorFactory monitorFactory)
                throws SqlEngineException
Creates a new instance of the SqlEngineLoader from the properties 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:
props - the collection of META SQL statements, mapping rules and optional features
typeFactory - the factory for the META types construction
filter - the properties name prefix to filter the META SQL statements, mapping rules and optional features
monitorFactory - 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

SqlEngineLoader

public SqlEngineLoader(Properties props,
                       SqlTypeFactory typeFactory,
                       String filter,
                       SqlMonitorFactory monitorFactory,
                       String... selectQueries)
Creates a new instance of the SqlEngineLoader from the properties 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:
props - the collection of META SQL statements, mapping rules and optional features
typeFactory - the factory for the META types construction
filter - the properties name prefix to filter the META SQL statements, mapping rules and optional features
monitorFactory - the monitor factory used in the process of the SQL Monitor instances creation
selectQueries - only statements and rules with the names in this set 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

SqlEngineLoader

public SqlEngineLoader(Properties props,
                       SqlTypeFactory typeFactory,
                       String filter,
                       SqlMonitorFactory monitorFactory,
                       List<SqlInternalType> customTypes,
                       String... selectQueries)
                throws SqlEngineException
Creates a new instance of the SqlEngineLoader from the properties 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:
props - the collection of META SQL statements, mapping rules and optional features
typeFactory - the factory for the META types construction
filter - the properties name prefix to filter the META SQL statements, mapping rules and optional features
monitorFactory - the monitor factory used in the process of the SQL Monitor instances creation
customTypes - the custom META types
selectQueries - only statements and rules with the names in this set 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 Detail

getNames

public Collection<String> getNames()
Returns the collection of names of all initialized/constructed SQL Engine instances.

Returns:
Collection of all initialized SQL Engine instances' names

getMetaSql

public String getMetaSql(String name)
Returns the named META SQL query/statement.

Parameters:
name - the name of the required META SQL query/statement
Returns:
the META SQL query/statement

getMappingRule

public String getMappingRule(String name)
Returns the named mapping rule.

Parameters:
name - the name of the required mapping rule
Returns:
the mapping rule

getQueryEngine

public SqlQueryEngine getQueryEngine(String name)
Returns the named SQL Query Engine instance (the primary SQL Processor class).

Specified by:
getQueryEngine in interface SqlEngineFactory
Parameters:
name - the name of the required SQL Query Engine instance
Returns:
the SQL Engine instance

getCrudEngine

public SqlCrudEngine getCrudEngine(String name)
Returns the named SQL CRUD Engine instance (the primary SQL Processor class).

Specified by:
getCrudEngine in interface SqlEngineFactory
Parameters:
name - the name of the required SQL CRUD Engine instance
Returns:
the SQL Engine instance


Copyright © 2011. All Rights Reserved.