Package org.sqlproc.engine.impl
Class SqlProcessor
- java.lang.Object
-
- 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
Nested Classes Modifier and Type Class Description 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 - NOKstatic class
SqlProcessor.MappingType
The mapping rule type.static class
SqlProcessor.StatementType
The META SQL statement type.
-
Field Summary
Fields Modifier and Type Field Description 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.private static String
IDGEN
private static String
IDSEL
private static int
lIDGEN
private static int
lIDSEL
protected static org.slf4j.Logger
logger
The internal slf4j logger.private static int
lSEQ
private Pattern
mapPattern
Pattern for MOPT(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 static String
SEQ
private Map<String,Map<String,Object>>
statementsFeatures
The collection of the SQL Processor optional features in the statement context.private Map<String,Set<String>>
statementsFeaturesUnset
The collection of the SQL Processor optional features to be cleared in the statement context.private List<String>
warnings
The list of all warnings.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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, String raw, SqlMappingRule mapping, List<ErrorMsg> errors, List<String> activeFilters, String... filters)
Adds a new output value mapping.(package private) boolean
addMetaStatement(String type, String name, String raw, 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.private List<String>
filterActiveFilters(List<String> activeFilters)
Filter the active filters removing all values, which contain the character '='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 parsingprotected Object
getFeature(String type, String feature)
Builds the correct class instance for the optional featureMap<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).static SqlProcessor
getLazyInstance(StringBuilder sbStatements, SqlTypeFactory typeFactory, Map<String,Object> defaultFeatures, Set<String> onlyStatements, String... filters)
Simple factory method (design pattern).Map<String,SqlMappingRule>
getMappingRules(String type)
Returns the collection of the output value mappings.Map<String,SqlMappingRule>
getMappingRules(SqlProcessor.MappingType type)
Returns the collection of the output value mappings.Map<String,SqlMetaStatement>
getMetaStatements(String type)
Returns the collection of the META SQL statements.Map<String,SqlMetaStatement>
getMetaStatements(SqlProcessor.StatementType type)
Returns the collection of the META SQL statements.Map<String,Map<String,Object>>
getStatementsFeatures()
Returns the collection of the SQL Processor optional features in the statement context.Map<String,Set<String>>
getStatementsFeaturesUnset()
Returns the collection of the SQL Processor optional features to be cleared in the statement context.List<String>
getWarnings()
Returns the list of warnings, which can happen in the process of this instance creation and ALTLR parsingprivate void
loadStatementFeatures(String name, List<String> activeFilters)
Some filters can be the optional features in the statement context.protected boolean
nameControl(Set<String> onlyStatements, String name)
Controls, if the artifact name is listed in the provided containerprotected String
uniqueArtifactName(String type, String name, List<String> activeFilters)
Builds the unique artifact name.
-
-
-
Field Detail
-
logger
protected static org.slf4j.Logger logger
The internal slf4j logger.
-
mapPattern
private Pattern mapPattern
Pattern for MOPT
-
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.
-
statementsFeatures
private Map<String,Map<String,Object>> statementsFeatures
The collection of the SQL Processor optional features in the statement context.
-
statementsFeaturesUnset
private Map<String,Set<String>> statementsFeaturesUnset
The collection of the SQL Processor optional features to be cleared in the statement context.
-
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.
-
IDGEN
private static final String IDGEN
-
lIDGEN
private static final int lIDGEN
-
SEQ
private static final String SEQ
-
lSEQ
private static final int lSEQ
-
IDSEL
private static final String IDSEL
-
lIDSEL
private static final int lIDSEL
-
-
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 mappingstypeFactory
- the factory for the META types constructiondefaultFeatures
- the default features based onSqlFeature
onlyStatements
- only the statements and rules with the names in this set are picked up from the statements' repositoryfilters
- 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
-
getLazyInstance
public static SqlProcessor getLazyInstance(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 mappingstypeFactory
- the factory for the META types constructiondefaultFeatures
- the default features based onSqlFeature
onlyStatements
- only the statements and rules with the names in this set are picked up from the statements' repositoryfilters
- 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 raw (not 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, String raw, 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 typename
- the name of the META SQL statementraw
- the raw (not pre-compiled) representation of the META SQL statementstatement
- the META SQL statementerrors
- the list of potential errors created during the ANTLR based parsingactiveFilters
- the active filters from the META SQL statement definitionfilters
- 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, String raw, 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 typename
- the name of the output value mappingraw
- the raw (not pre-compiled) representation of the output value mappingmapping
- the output value mappingerrors
- the list of potential errors created during the ANTLR based parsingactiveFilters
- the active filters from the output value mapping definitionfilters
- 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
-
getStatementsFeatures
public Map<String,Map<String,Object>> getStatementsFeatures()
Returns the collection of the SQL Processor optional features in the statement context.- Returns:
- the collection of the SQL Processor optional features in the statement context
-
getStatementsFeaturesUnset
public Map<String,Set<String>> getStatementsFeaturesUnset()
Returns the collection of the SQL Processor optional features to be cleared in the statement context.- Returns:
- the collection of the SQL Processor optional features to be cleared in the statement context
-
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 enumarationSqlProcessor.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 typename
- the name of the optional featurefeature
- the optional featureerrors
- the list of potential errors created during the ANTLR based parsingactiveFilters
- the active filters from the optional feature definitionfilters
- 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 typename
- the name of the artifactactiveFilters
- 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 typename
- the name of the artifactactiveFilters
- 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 definitionfilters
- 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' repositoryname
- the artifact name- Returns:
- the indicator if the artifact name is listed in the provided container
-
filterActiveFilters
private List<String> filterActiveFilters(List<String> activeFilters)
Filter the active filters removing all values, which contain the character '='- Parameters:
activeFilters
- the active filters from the artifact definition- Returns:
- filtered active filters
-
-