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
  • Field Details

    • logger

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

      private Pattern mapPattern
      Pattern for MOPT
    • metaStatements

      The collection of the META SQL statements.
    • 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.
    • warnings

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

      private List<ErrorMsg> errors
      The list of all errors.
    • 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
  • Constructor Details

  • Method Details

    • 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
    • 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 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 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 type
      name - the name of the META SQL statement
      raw - the raw (not pre-compiled) representation 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, 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 type
      name - the name of the output value mapping
      raw - the raw (not pre-compiled) representation 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
    • 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 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:
      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
      activeFilters - the active filters from the artifact definition
      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
    • 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
    • loadStatementFeatures

      private void loadStatementFeatures(String name, List<String> activeFilters)
      Some filters can be the optional features in the statement context.
      Parameters:
      name - the name of the META SQL statement
      activeFilters - the active filters from the META SQL statement definition