Package org.sqlproc.engine.impl
Class SqlMappingItem
- java.lang.Object
-
- org.sqlproc.engine.impl.SqlMappingItem
-
- All Implemented Interfaces:
SqlMetaElement
class SqlMappingItem extends Object implements SqlMetaElement
The mapping rule element for one output attribute, which is a mapping item. Instance of this class is created by the ANTLR parser. In the case of explicit mapping rule the grammar itself is defined in SqlMapping.g. In the case of implicit mapping rule the grammar itself is defined in SqlStatement.g. This instance can be also created in the process of merging the explicit and implicit mapping rule in the runtime, seeprocess(SqlProcessContext).- Author:
- Vladimir Hudec
-
-
Field Summary
Fields Modifier and Type Field Description private List<SqlMappingAttribute>attributesThe list of all partial attribute names in the result class.private Map<String,SqlMappingAttribute>attributesMapThe map of all partial attribute names in the result class.private static Set<String>CONTAINER_TYPESprivate StringdbNameThe name of a database query output.private StringBuilderfullNameThe full name of the attribute in the result class in the form name1.name2...nameX.private booleanidentityThe indicator this is an identity column.(package private) org.slf4j.LoggerloggerThe internal slf4j logger.private SqlTypesqlTypeThe (META) type of an attribute in the result class and/or the database column type.(package private) Map<String,String>valuesSupplements values for a special handling, for example the identification of an identity column or the partial attribute type.-
Fields inherited from interface org.sqlproc.engine.impl.SqlMetaElement
AND_PREFIX, CONST_PREFIX, IDENT_PREFIX, IDENT_SEPARATOR, lCONST_PREFIX, lIDENT_PREFIX, OR_PREFIX, SET_PREFIX, VALUES_PREFIX, WHERE_PREFIX
-
-
Constructor Summary
Constructors Constructor Description SqlMappingItem(String dbName)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) SqlMappingAttributeaddAttributeName(String name)Adds a partial name of an attribute.(package private) List<SqlMappingAttribute>getAttributes()Returns the list of all partial attribute names in the result class.(package private) StringgetDbName()Returns the name of a database query output.(package private) StringgetFullName()Returns the full attribute name.(package private) StringgetName()Returns the last attribute name.(package private) SqlTypegetSqlType()Returns the internal type of an attribute in the result class.(package private) booleanisIdentity(SqlProcessContext ctx)Returns the indicator this is an identity column.(package private) SqlMappingItemmerge(SqlMappingItem outputMapping)Merge mapping rules for one output column based on SqlMapping.g and SqlStatement.g.SqlProcessResultprocess(SqlProcessContext ctx)The main contract for a dynamic ANSI SQL Query generation.(package private) voidsetAttributes(List<SqlMappingAttribute> attributes)Sets the list of all partial attribute names in the result class.(package private) voidsetAttributesMap(Map<String,SqlMappingAttribute> attributesMap)Sets the map of all partial attribute names in the result class.(package private) SqlMappingAttributesetAttributeValue(String attrName, String value)Injects value to the named attribute.(package private) voidsetMetaType(String metaTypeName, SqlMetaType metaType)Assigns the internal type.(package private) voidsetQueryResultData(SqlProcessContext ctx, Object resultInstance, int resultIndex, Object[] resultValues, Map<String,Object> ids, Map<String,Object> idsProcessed, Map<String,SqlMappingIdentity> identities, Map<String,Class<?>> moreResultClasses)Initializes the attribute of the result class with the output value from the SQL query execution.(package private) voidsetQueryResultMapping(SqlProcessContext ctx, Class<?> resultClass, Map<String,Class<?>> moreResultClasses, SqlQuery query)Declares a scalar query result for this mapping rule item.(package private) voidsetSqlType(SqlType sqlType)Sets the internal type of an attribute in the result class.(package private) voidsetValues(String value, String value2)Sets the modifiers.(package private) voidsetValues(String name, String value, String value2)Sets the modifiers.StringtoString()For debug purposes.
-
-
-
Field Detail
-
logger
final org.slf4j.Logger logger
The internal slf4j logger.
-
attributes
private List<SqlMappingAttribute> attributes
The list of all partial attribute names in the result class. This list has more items in the case of embedded classes, where names are in the form name1.name2...nameX. This list can be empty. In this case the name of the attribute is the same as the name of the query column or alias output.
-
attributesMap
private Map<String,SqlMappingAttribute> attributesMap
The map of all partial attribute names in the result class.
-
dbName
private String dbName
The name of a database query output. It can be the column name or the alias name.
-
fullName
private StringBuilder fullName
The full name of the attribute in the result class in the form name1.name2...nameX.
-
sqlType
private SqlType sqlType
The (META) type of an attribute in the result class and/or the database column type.
-
identity
private boolean identity
The indicator this is an identity column.
-
values
Map<String,String> values
Supplements values for a special handling, for example the identification of an identity column or the partial attribute type.
-
-
Constructor Detail
-
SqlMappingItem
SqlMappingItem(String dbName)
Creates a new instance. It's used from inside ANTLR parser or in the process of merging.- Parameters:
dbName- the name of a database query output
-
-
Method Detail
-
getDbName
String getDbName()
Returns the name of a database query output. It can be the column name or the alias name.- Returns:
- the name of a database query output
-
addAttributeName
SqlMappingAttribute addAttributeName(String name)
Adds a partial name of an attribute.- Parameters:
name- the partial name of an attribute in the result class
-
setAttributeValue
SqlMappingAttribute setAttributeValue(String attrName, String value)
Injects value to the named attribute.- Parameters:
attrName- the attribute namevalue- value for the named attribute
-
getAttributes
List<SqlMappingAttribute> getAttributes()
Returns the list of all partial attribute names in the result class.- Returns:
- the list of all partial attribute names
-
setAttributes
void setAttributes(List<SqlMappingAttribute> attributes)
Sets the list of all partial attribute names in the result class.- Parameters:
attributes- the list of all partial attribute names
-
setAttributesMap
void setAttributesMap(Map<String,SqlMappingAttribute> attributesMap)
Sets the map of all partial attribute names in the result class.- Parameters:
attributesMap- the map of all partial attribute names
-
isIdentity
boolean isIdentity(SqlProcessContext ctx)
Returns the indicator this is an identity column.- Parameters:
ctx- the crate for all input parameters and the context of processing- Returns:
- the indicator this is an identity column
-
getFullName
String getFullName()
Returns the full attribute name.- Returns:
- the full attribute name
-
getName
String getName()
Returns the last attribute name.- Returns:
- the last attribute name
-
setMetaType
void setMetaType(String metaTypeName, SqlMetaType metaType)
Assigns the internal type. This type it's used in a conversion process of SQL query output values. It can be a META type or an Hibernate type.- Parameters:
metaTypeName- an internal type name for this mapping rule itemmetaType- an internal type for this mapping rule item
-
getSqlType
SqlType getSqlType()
Returns the internal type of an attribute in the result class.- Returns:
- the internal type of an attribute in the result class
-
setSqlType
void setSqlType(SqlType sqlType)
Sets the internal type of an attribute in the result class.- Parameters:
sqlType- the internal type of an attribute in the result class
-
setValues
void setValues(String value, String value2)
Sets the modifiers. They are used to identify an identity column or the partial attribute type.- Parameters:
value- the value for a special treatment, might be an identifier of value2value2- the value for a special treatment, might be an attribute type
-
setValues
void setValues(String name, String value, String value2)
Sets the modifiers. They are used to identify an identity column or the partial attribute type.- Parameters:
name- the partial name in the case this modifier is related to itvalue- the value for a special treatment, might be an identifier of value2value2- the value for a special treatment, might be an attribute type
-
setQueryResultMapping
void setQueryResultMapping(SqlProcessContext ctx, Class<?> resultClass, Map<String,Class<?>> moreResultClasses, SqlQuery query) throws SqlRuntimeException
Declares a scalar query result for this mapping rule item.- Parameters:
ctx- the crate for all input parameters and the context of processingresultClass- the class used for the return values, the SQL execution outputmoreResultClasses- more classes used for the return values, like the classes for the collections or the collections itemsquery- the SQL Engine query, an adapter or proxy to the internal JDBC or ORM staff- Throws:
SqlRuntimeException- in the case of any problem with output values preparation
-
setQueryResultData
void setQueryResultData(SqlProcessContext ctx, Object resultInstance, int resultIndex, Object[] resultValues, Map<String,Object> ids, Map<String,Object> idsProcessed, Map<String,SqlMappingIdentity> identities, Map<String,Class<?>> moreResultClasses) throws SqlRuntimeException
Initializes the attribute of the result class with the output value from the SQL query execution.- Parameters:
ctx- the crate for all input parameters and the context of processingresultInstance- the instance of the result classresultIndex- the index of the processed query execution output valueresultValues- the query execution output valuesids- the instances of all already used identities together with the related result instances based on identities indicesidsProcessed- the instances of all already used identities together with the related result instances based on identities indices - the working copyidentities- the collection of identities related to all output columnsmoreResultClasses- more result classes used for the return values, like the classes for the collections or the collections items- Throws:
SqlRuntimeException- in the case of any problem with output values handling
-
merge
SqlMappingItem merge(SqlMappingItem outputMapping)
Merge mapping rules for one output column based on SqlMapping.g and SqlStatement.g. This mapping rule has the higher priority.- Parameters:
outputMapping- the mapping rule based on SqlStatement.g- Returns:
- a new merged mapping rule item
-
process
public SqlProcessResult process(SqlProcessContext ctx)
The main contract for a dynamic ANSI SQL Query generation. Also known as a META SQL processing. The composite pattern main contract. All ANTLR grammar based elements must implement this contract.- Specified by:
processin interfaceSqlMetaElement- Parameters:
ctx- the crate for all input parameters and the context of processing
-
-