org.sqlproc.engine.impl
Class SqlProcessor

java.lang.Object
  extended by org.sqlproc.engine.impl.SqlProcessor

public class SqlProcessor
extends Object

Pre-compiled META SQL statements, output mappings and optional features (also known as the SQL Processor artifacts). Instance of this class is created by the ANTLR parser. The grammar is defined in SqlProcessor.g.

Author:
Vladimir Hudec

Nested Class Summary
static class SqlProcessor.FeatureType
          The mapping rule type.
(package private) static class SqlProcessor.FilterStatus
          This status is the result of the filters processing, based on the next rules:
in the case there are no filters
- there are activeFilters, the artifact is dead - NOK
- otherwise the artifact is ok - OK
in the case there are filters
- there are no activeFilters, the artifact is ok, but lower priority - OK_LOWER
- there are activeFilters, and the intersection is not empty, the artifact is ok - OK
- there are activeFilters, and the intersection is empty, the artifact is dead - NOK
static class SqlProcessor.MappingType
          The mapping rule type.
static class SqlProcessor.StatementType
          The META SQL statement type.
 
Field Summary
private  Set<String> allArtifactsNames
          The collection of all artifacts to enable duplicity control.
private  Map<String,Object> defaultFeatures
          The collection of the SQL Processor default optional features.
private  List<ErrorMsg> errors
          The list of all errors.
private  Map<String,Object> features
          The collection of the SQL Processor optional features.
protected static org.slf4j.Logger logger
          The internal slf4j logger.
(package private)  Map<String,Map<String,SqlMappingRule>> mappingRules
          The collection of the output value mappings.
(package private)  Map<String,Map<String,SqlMetaStatement>> metaStatements
          The collection of the META SQL statements.
private  Set<String> onlyStatements
          Only statements and rules with the names in this set are picked up from the statements' repository.
private  List<String> warnings
          The list of all warnings.
 
Constructor Summary
SqlProcessor(Map<String,Object> defaultFeatures, Set<String> onlyStatements)
          Creates a new instance.
 
Method Summary
 boolean addFeature(String type, String name, String feature, List<ErrorMsg> errors, List<String> activeFilters, String... filters)
          Adds a new optional feature.
 boolean addMappingRule(String type, String name, SqlMappingRule mapping, List<ErrorMsg> errors, List<String> activeFilters, String... filters)
          Adds a new output value mapping.
(package private)  boolean addMetaStatement(String type, String name, SqlMetaStatement statement, List<ErrorMsg> errors, List<String> activeFilters, String... filters)
          Adds a new META SQL statement.
protected  void addWarnings(List<ErrorMsg> errors)
          Adds all parsing errors as warnings.
protected  boolean duplicityControl(String type, String name, List<String> activeFilters)
          Controls if the name of the artifact isn't already used.
protected  SqlProcessor.FilterStatus filtersControl(String[] filters, List<String> activeFilters)
          Runs the business logic for the filters related to the artifact usability.
 List<ErrorMsg> getErrors()
          Returns the list of error, which can happen in the process of this instance creation and ALTLR parsing
protected  Object getFeature(String type, String feature)
          Builds the correct class instance for the optional feature
 Map<String,Object> getFeatures()
          Returns the collection of the SQL Processor optional features.
static SqlProcessor getInstance(StringBuilder sbStatements, SqlTypeFactory typeFactory, Map<String,Object> defaultFeatures, Set<String> onlyStatements, String... filters)
          Simple factory method (design pattern).
 Map<String,SqlMappingRule> getMappingRules(SqlProcessor.MappingType type)
          Returns the collection of the output value mappings.
 Map<String,SqlMappingRule> getMappingRules(String type)
          Returns the collection of the output value mappings.
 Map<String,SqlMetaStatement> getMetaStatements(SqlProcessor.StatementType type)
          Returns the collection of the META SQL statements.
 Map<String,SqlMetaStatement> getMetaStatements(String type)
          Returns the collection of the META SQL statements.
 List<String> getWarnings()
          Returns the list of warnings, which can happen in the process of this instance creation and ALTLR parsing
protected  boolean nameControl(Set<String> onlyStatements, String name)
          Controls, if the artifact name is listed in the provided container
protected  String uniqueArtifactName(String type, String name, List<String> activeFilters)
          Builds the unique artifact name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static org.slf4j.Logger logger
The internal slf4j logger.


metaStatements

Map<String,Map<String,SqlMetaStatement>> metaStatements
The collection of the META SQL statements.


mappingRules

Map<String,Map<String,SqlMappingRule>> mappingRules
The collection of the output value mappings.


features

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


defaultFeatures

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


onlyStatements

private Set<String> onlyStatements
Only statements and rules with the names in this set are picked up from the statements' repository.


allArtifactsNames

private Set<String> allArtifactsNames
The collection of all artifacts to enable duplicity control.


warnings

private List<String> warnings
The list of all warnings.


errors

private List<ErrorMsg> errors
The list of all errors.

Constructor Detail

SqlProcessor

SqlProcessor(Map<String,Object> defaultFeatures,
             Set<String> onlyStatements)
Creates a new instance.

Method Detail

getInstance

public static SqlProcessor getInstance(StringBuilder sbStatements,
                                       SqlTypeFactory typeFactory,
                                       Map<String,Object> defaultFeatures,
                                       Set<String> onlyStatements,
                                       String... filters)
                                throws SqlEngineException
Simple factory method (design pattern). The new instance is created from the String input by the ANTLR parser.

Parameters:
sbStatements - String representation of the META SQL queries/statements/output mappings
typeFactory - the factory for the META types construction
defaultFeatures - the default features based on SqlFeature
onlyStatements - only the statements and rules with the names in this set are picked up from the statements' repository
filters - only the artifacts without active filters and the artifacts with the active filter from this collections are picked up from the statements' repository
Returns:
new container of pre-compiled META SQL queries/statements/output mappings
Throws:
SqlEngineException - in the case of ANTLR parsing exception

getMetaStatements

public Map<String,SqlMetaStatement> getMetaStatements(SqlProcessor.StatementType type)
Returns the collection of the META SQL statements.

Parameters:
type - the META SQL statement type
Returns:
the collection of the META SQL statements

getMetaStatements

public Map<String,SqlMetaStatement> getMetaStatements(String type)
Returns the collection of the META SQL statements.

Parameters:
type - the String representation of the META SQL statement type
Returns:
the collection of the META SQL statements

addMetaStatement

boolean addMetaStatement(String type,
                         String name,
                         SqlMetaStatement statement,
                         List<ErrorMsg> errors,
                         List<String> activeFilters,
                         String... filters)
Adds a new META SQL statement. It's used internally by the ANTLR parser.

Parameters:
type - the String representation of the META SQL statement type
name - the name of the META SQL statement
statement - the META SQL statement
errors - the list of potential errors created during the ANTLR based parsing
activeFilters - the active filters from the META SQL statement definition
filters - only the artifacts without active filters and the artifacts with the active filter from this collections are taken into this instance of the SQL Processor
Returns:
the indicator this statement was taken into this instance of the SQL Processor

getMappingRules

public Map<String,SqlMappingRule> getMappingRules(SqlProcessor.MappingType type)
Returns the collection of the output value mappings.

Parameters:
type - the input/output mapping rule type
Returns:
the collection of the output value mappings

getMappingRules

public Map<String,SqlMappingRule> getMappingRules(String type)
Returns the collection of the output value mappings.

Parameters:
type - the String representation of the input/output mapping rule type
Returns:
the collection of the output value mappings

addMappingRule

public boolean addMappingRule(String type,
                              String name,
                              SqlMappingRule mapping,
                              List<ErrorMsg> errors,
                              List<String> activeFilters,
                              String... filters)
Adds a new output value mapping. It's used internally by the ANTLR parser.

Parameters:
type - the String representation of the output value mapping type
name - the name of the output value mapping
mapping - the output value mapping
errors - the list of potential errors created during the ANTLR based parsing
activeFilters - the active filters from the output value mapping definition
filters - only the artifacts without active filters and the artifacts with the active filter from this collections are taken into this instance of the SQL Processor
Returns:
the indicator this output value mapping was taken into this instance of the SQL Processor

getFeatures

public Map<String,Object> getFeatures()
Returns the collection of the SQL Processor optional features.

Returns:
the collection of the SQL Processor optional features

getFeature

protected Object getFeature(String type,
                            String feature)
Builds the correct class instance for the optional feature

Parameters:
type - the type of the optional feature based on enumaration SqlProcessor.FeatureType
feature - the String representation of the optional feature
Returns:
the correct class instance for the optional feature

addFeature

public boolean addFeature(String type,
                          String name,
                          String feature,
                          List<ErrorMsg> errors,
                          List<String> activeFilters,
                          String... filters)
Adds a new optional feature. It's used internally by the ANTLR parser.

Parameters:
type - the String representation of the optional feature type
name - the name of the optional feature
feature - the optional feature
errors - the list of potential errors created during the ANTLR based parsing
activeFilters - the active filters from the optional feature definition
filters - only the artifacts without active filters and the artifacts with the active filter from this collections are taken into this instance of the SQL Processor
Returns:
the indicator this optional feature was taken into this instance of the SQL Processor

duplicityControl

protected boolean duplicityControl(String type,
                                   String name,
                                   List<String> activeFilters)
Controls if the name of the artifact isn't already used.

Parameters:
type - the String representation of the artifact type
name - the name of the artifact
activeFilters - the active filters from the artifact definition
Returns:
the indicator of the potential duplicity

uniqueArtifactName

protected String uniqueArtifactName(String type,
                                    String name,
                                    List<String> activeFilters)
Builds the unique artifact name.

Parameters:
type - the String representation of the artifact type
name - the name of the artifact
activeFilters - the active filters from the artifact definition
Returns:
the unique artifact name

addWarnings

protected void addWarnings(List<ErrorMsg> errors)
Adds all parsing errors as warnings.

Parameters:
errors - the list of potential errors created during the ANTLR based parsing

getWarnings

public List<String> getWarnings()
Returns the list of warnings, which can happen in the process of this instance creation and ALTLR parsing

Returns:
the list of warnings

getErrors

public List<ErrorMsg> getErrors()
Returns the list of error, which can happen in the process of this instance creation and ALTLR parsing

Returns:
the list of errors

filtersControl

protected SqlProcessor.FilterStatus filtersControl(String[] filters,
                                                   List<String> activeFilters)
Runs the business logic for the filters related to the artifact usability.

Parameters:
activeFilters - the active filters from the artifact definition
filters - only the artifacts without active filters and the artifacts with the active filter from this collections are taken into this instance of the SQL Processor
Returns:
the status, which control the artifact usability

nameControl

protected boolean nameControl(Set<String> onlyStatements,
                              String name)
Controls, if the artifact name is listed in the provided container

Parameters:
onlyStatements - only the statements and rules with the names in this set are picked up from the statements' repository
name - the artifact name
Returns:
the indicator if the artifact name is listed in the provided container


Copyright © 2012. All Rights Reserved.