org.sqlproc.engine
Class SqlEngineLoader

java.lang.Object
  extended by org.sqlproc.engine.SqlEngineLoader

public class SqlEngineLoader
extends java.lang.Object

Helper class for the parsing of META SQL statements and Mapping rules located in properties file. The purpose of this class is to load and analyze (=parse) 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.

All the properties with the key LIST_..._SQL are parsed as META SQL statements using ANTLR based grammar.
All the properties with the key LIST_..._FIELDS are parsed as Mapping rules using ANTLR based grammar.
A pair of META SQL statement and Mapping rule forms one named SQL Engine instance.
All the properties with the key SET_... are taken as optional features used in the process of SQL Engine instance construction.

In the process of ANTLR based parsing different kinds of incorrect stuff can cause SqlEngineException to be raised.

To initialize this class, Spring DI configuration can be utilized, like the next one:

 <beans ...>
   ...
   <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" />
   </bean>
 </beans>
 
and use the next code to obtain instance of SQL Engine
 SqlEngine sqlEngine = sqlLoader.getSqlEngine("ALL");
 

Another possibility is to utilize SqlPropertiesLoader.

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

For more info please see the User's tutorial.

Author:
Vladimir Hudec

Field Summary
private static java.lang.String COMMON_PREFIX
           
private  java.util.Map<java.lang.String,SqlEngine> engines
          The collection of named SQL Engine (the primary SQL Processor class) instances.
private  java.util.Map<java.lang.String,java.lang.Object> features
          The collection of SQL Processor optional features
private  java.util.Map<java.lang.String,java.lang.String> fields
          The collection of named Mapping rules
private static java.lang.String FIELDS_REFERENCE
           
private static java.lang.String FIELDS_SUFFIX
           
private static int lCOMMON_PREFIX
           
private static int lFIELDS_REFERENCE
           
private static int lFIELDS_SUFFIX
           
protected  org.slf4j.Logger logger
          The internal slf4j logger.
private static int lSET_PREFIX
           
private static int lSQL_SUFFIX
           
private static java.lang.String SET_PREFIX
           
private static java.lang.String SQL_SUFFIX
           
private  java.util.Map<java.lang.String,java.lang.String> sqls
          The collection of named META SQL statements
 
Constructor Summary
SqlEngineLoader(java.util.Properties props)
          Creates a new instance of SqlEngineLoader from the properties repository (which is in fact a collection of META SQL statements, Mapping rules and Optional features.
SqlEngineLoader(java.util.Properties props, SqlMonitorFactory monitorFactory)
          Creates a new instance of SqlEngineLoader from the properties repository (which is in fact a collection of META SQL statements, Mapping rules and Optional features.
SqlEngineLoader(java.util.Properties props, SqlMonitorFactory monitorFactory, java.lang.String... selectQueries)
          Creates a new instance of SqlEngineLoader from the properties repository (which is in fact a collection of META SQL statements, Mapping rules and Optional features.
 
Method Summary
 java.lang.String getMappingRule(java.lang.String name)
          Returns the named Mapping rule.
 java.lang.String getMetaSql(java.lang.String name)
          Returns the named META SQL statement.
 java.util.Collection<java.lang.String> getNames()
          Returns the collection of names of all initialized/constructed SQL Engine instances.
 SqlEngine getSqlEngine(java.lang.String name)
          Returns the named SQL Engine instance (the primary SQL Processor class).
 SqlMonitor getSqlMonitor(java.lang.String name)
          Returns the SQL Monitor instance devoted to the named SQL Engine instance.
 
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.


COMMON_PREFIX

private static final java.lang.String COMMON_PREFIX
See Also:
Constant Field Values

SQL_SUFFIX

private static final java.lang.String SQL_SUFFIX
See Also:
Constant Field Values

FIELDS_SUFFIX

private static final java.lang.String FIELDS_SUFFIX
See Also:
Constant Field Values

lCOMMON_PREFIX

private static final int lCOMMON_PREFIX

lSQL_SUFFIX

private static final int lSQL_SUFFIX

lFIELDS_SUFFIX

private static final int lFIELDS_SUFFIX

SET_PREFIX

private static final java.lang.String SET_PREFIX
See Also:
Constant Field Values

lSET_PREFIX

private static final int lSET_PREFIX

FIELDS_REFERENCE

private static final java.lang.String FIELDS_REFERENCE
See Also:
Constant Field Values

lFIELDS_REFERENCE

private static final int lFIELDS_REFERENCE

engines

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


sqls

private java.util.Map<java.lang.String,java.lang.String> sqls
The collection of named META SQL statements


fields

private java.util.Map<java.lang.String,java.lang.String> fields
The collection of named Mapping rules


features

private java.util.Map<java.lang.String,java.lang.Object> features
The collection of SQL Processor optional features

Constructor Detail

SqlEngineLoader

public SqlEngineLoader(java.util.Properties props)
                throws SqlEngineException
Creates a new instance of SqlEngineLoader from the properties repository (which is in fact a collection of 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 are established. Later these instances are used for the SQL queries invocation.

Parameters:
props - The collection of 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(java.util.Properties props,
                       SqlMonitorFactory monitorFactory)
                throws SqlEngineException
Creates a new instance of SqlEngineLoader from the properties repository (which is in fact a collection of 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 are established. Later these instances are used for the SQL queries invocation. Every instance of SQL Engined is accompanied with 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
monitorFactory - The monitor factory used in the process of 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(java.util.Properties props,
                       SqlMonitorFactory monitorFactory,
                       java.lang.String... selectQueries)
                throws SqlEngineException
Creates a new instance of SqlEngineLoader from the properties repository (which is in fact a collection of 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 are established. Later these instances are used for the SQL queries invocation. Every instance of SQL Engined is accompanied with 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
monitorFactory - The monitor factory used in the process of 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.
Method Detail

getNames

public java.util.Collection<java.lang.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 java.lang.String getMetaSql(java.lang.String name)
Returns the named META SQL statement.

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

getMappingRule

public java.lang.String getMappingRule(java.lang.String name)
Returns the named Mapping rule.

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

getSqlEngine

public SqlEngine getSqlEngine(java.lang.String name)
Returns the named SQL Engine instance (the primary SQL Processor class).

Parameters:
name - the name of the required SQL Engine instance
Returns:
the SQL Engine instance

getSqlMonitor

public SqlMonitor getSqlMonitor(java.lang.String name)
Returns the SQL Monitor instance devoted to the named SQL Engine instance.

Parameters:
name - the name of the SQL Engine instance
Returns:
the SQL Monitor instance


Copyright © 2010. All Rights Reserved.