Class SqlMappingResult


  • public class SqlMappingResult
    extends Object
    Holds the results of an explicit and an implicit mapping rules merging. 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. The internal mapping rule is a dynamic one, and it's finalized in the process of the final ANSI SQL query generation. For the purpose of correct left join handling, the identities are identified. They are used to prevent the repeated rows in the output result set. This is used for the associations (one-to-one, one-to-many and many-to-many). The main runtime contracts are setQueryResultMapping(Class, Map, SqlQuery) and setQueryResultData(Object, Object[], Map, Map).
    Author:
    Vladimir Hudec
    • Field Detail

      • logger

        final org.slf4j.Logger logger
        The internal slf4j logger.
      • ctx

        private SqlProcessContext ctx
        The crate for all input parameters and the context of processing.
      • mappings

        private Map<String,​SqlMappingItem> mappings
        All sub-elements based on ANTLR grammar defined in SqlMapping.g or SqlStatement.g. Every sub-element is one Mapping item.
      • identitiesIndexes

        List<Integer> identitiesIndexes
        The list of identities indexes in the list of output values.
      • mainIdentityIndex

        Integer mainIdentityIndex
        The main identity index in the list of output values. The main identity is related to the top level result class.
    • Constructor Detail

      • SqlMappingResult

        SqlMappingResult​(SqlProcessContext ctx,
                         SqlMappingRule mapping,
                         Map<String,​SqlMappingItem> outputMappings)
        Creates a new instance. This instances is based on the merging of an explicit and an implicit mapping rules.
        Parameters:
        ctx - the crate for all input parameters and the context of processing
        mapping - mapping rule based on SqlMapping.g or the empty one
        outputMappings - mapping rule items based on SqlStatement.g
    • Method Detail

      • getMainIdentityIndex

        public Integer getMainIdentityIndex()
        Returns the main identity index in the list of output values. The main identity is related to the top level result class.
        Returns:
        the main identity index in the list of output values
      • getIdentitiesIndexes

        public List<Integer> getIdentitiesIndexes()
        Return the list of identities indexes in the list of output values
        Returns:
        the list of identities indexes in the list of output values
      • getRuntimeContext

        public SqlRuntimeContext getRuntimeContext()
        Returns the public runtime context
        Returns:
        the public runtime context
      • addMapping

        void addMapping​(SqlMappingItem item)
        Adds a new mapping rule item in the merging process.
        Parameters:
        item - a new mapping rule item
      • calculateIdentities

        void calculateIdentities()
        Calculates all identities related information. They are used to prevent the repeated rows in the output result set. This is used for the associations (one-to-one, one-to-many and many-to-many).
      • setQueryResultMapping

        public void setQueryResultMapping​(Class<?> resultClass,
                                          Map<String,​Class<?>> moreResultClasses,
                                          SqlQuery query)
                                   throws SqlRuntimeException
        Declares a scalar query results for all mapping rule items.
        Parameters:
        resultClass - the class used for the return values
        moreResultClasses - more result classes used for the return values, like the collections classes or the collections items
        query - 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

        public void setQueryResultData​(Object resultInstance,
                                       Object[] resultValues,
                                       Map<String,​Object> ids,
                                       Map<String,​Class<?>> moreResultClasses)
                                throws SqlRuntimeException
        Fills the instance of the result class with output values from the SQL query execution.
        Parameters:
        resultInstance - the instance of the result class
        resultValues - the query execution output values
        ids - the instances of all already used identities together with the related result instances based on identities indices
        moreResultClasses - more result classes used for the return values, like the collections classes or the collections items
        Throws:
        SqlRuntimeException - in the case of any problem with output values handling
      • merge

        private void merge​(SqlMappingRule mapping,
                           Map<String,​SqlMappingItem> outputMappings)
        Merge mapping rule for one META SQL query based on SqlMapping.g and SqlStatement.g. The external mapping rule has the higher priority. The internal mapping rule holds the list of real output values.
        Parameters:
        mapping - mapping rule based on SqlMapping.g or the empty one
        outputMappings - mapping rule items based on SqlStatement.g
      • getIds

        public Map<String,​Object> getIds()
        Construct the empty structure used for the instances of all already used identities together with the related result instances based on identities indices.
        Returns:
        the empty structure used for the instances of all already used identities together with the related result instances based on identities indices
      • getFunctionResultData

        public Object getFunctionResultData​(Map<String,​Object> result)
        Devoted to function output value conversion.
        Parameters:
        result - the JDBC output value
        Returns:
        the output value after possible conversion