org.sqlproc.engine.impl
Class SqlMappingRule

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

public class SqlMappingRule
extends java.lang.Object

The precompiled Mapping entity for one META SQL statement. Instances of this class are created by the ANTLR parser. The grammar itself is defined in SqlMapping.g. The main runtime contracts are setQueryResultData(Object, Object[]) and setQueryResultMapping(Class, SQLQuery).

Schematically:

 SqlMappingRule = SqlMappingItem+
 
     SqlMappingItem = dbName.sqlType.javaName.javaName...
 


Field Summary
protected static org.slf4j.Logger logger
          The internal slf4j logger.
private  java.util.Map<java.lang.String,SqlMappingItem> mappings
          All sub-elements based on ANTLR grammar defined in SqlMapping.g.
 
Constructor Summary
SqlMappingRule()
          Creates a new instance.
SqlMappingRule(java.util.Map<java.lang.String,SqlMappingItem> mappings)
          Creates a new instance.
 
Method Summary
(package private)  void addMapping(SqlMappingItem item)
          Adds a new Mapping item, which is a mapping rule for one column.
static SqlMappingRule getInstance(java.lang.String mappingStatement)
          Simple factory method (design pattern).
(package private)  SqlMappingRule merge(java.util.Map<java.lang.String,SqlMappingItem> outputMappings)
          Merge mapping rule for one META SQL query based on SqlMapping.g and SqlStatement.g.
static SqlMappingRule merge(SqlMappingRule mapping, SqlProcessResult processResult)
          Merge mapping rule for one META SQL query based on SqlMapping.g and SqlStatement.g.
 void setQueryResultData(java.lang.Object resultInstance, java.lang.Object[] resultValues)
          Fills the instance of the result class with output values from the SQL query execution.
 void setQueryResultMapping(java.lang.Class<?> resultClass, org.hibernate.SQLQuery query)
          Declares a scalar query result for all Mapping rule items.
 
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.


mappings

private java.util.Map<java.lang.String,SqlMappingItem> mappings
All sub-elements based on ANTLR grammar defined in SqlMapping.g. Every sub-element is one Mapping item.

Constructor Detail

SqlMappingRule

public SqlMappingRule()
Creates a new instance. It's used from inside ANTLR parser.


SqlMappingRule

SqlMappingRule(java.util.Map<java.lang.String,SqlMappingItem> mappings)
Creates a new instance.

Parameters:
mappings - sub-elements based on ANTLR grammar defined in SqlStatement.g
Method Detail

getInstance

public static SqlMappingRule getInstance(java.lang.String mappingStatement)
                                  throws SqlEngineException
Simple factory method (design pattern). The new instance of precompiled Mapping rule is created from the String input by the ANTLR parser.

Parameters:
mappingStatement - String representation of Mapping rule
Returns:
new instance of precompiled Mapping rule
Throws:
SqlEngineException - in the case of ANTRL parsing exception

addMapping

void addMapping(SqlMappingItem item)
Adds a new Mapping item, which is a mapping rule for one column.

Parameters:
item - the Mapping item

setQueryResultMapping

public void setQueryResultMapping(java.lang.Class<?> resultClass,
                                  org.hibernate.SQLQuery query)
Declares a scalar query result for all Mapping rule items.

Parameters:
resultClass - The class used for the return values, the SQL execution output.
query - Hibernate SQL Query instance

setQueryResultData

public void setQueryResultData(java.lang.Object resultInstance,
                               java.lang.Object[] resultValues)
Fills the instance of the result class with output values from the SQL query execution.

Parameters:
resultInstance - The instance of the result class.
resultValues - Query execution output values

merge

public static SqlMappingRule merge(SqlMappingRule mapping,
                                   SqlProcessResult processResult)
Merge mapping rule for one META SQL query based on SqlMapping.g and SqlStatement.g. The mapping rule based on SqlMapping.g has the higher priority compared to mapping rule based on SqlStatement.g. The mapping rule based on SqlStatement.g obtains a list of real output values.

Parameters:
mapping - the mapping rule based on SqlMapping.g
processResult - obtains a mapping rule based on SqlStatement.g
Returns:
a new merged mapping rule

merge

SqlMappingRule merge(java.util.Map<java.lang.String,SqlMappingItem> outputMappings)
Merge mapping rule for one META SQL query based on SqlMapping.g and SqlStatement.g. This mapping rule has the higher priority. The mapping rule based on SqlStatement.g obtains a list of real output values.

Parameters:
outputMappings - mapping rule based on SqlStatement.g
Returns:
a new merged mapping rule


Copyright © 2011. All Rights Reserved.