Class ResultClassROF

  • All Implemented Interfaces:
    ResultObjectFactory

    public class ResultClassROF
    extends AbstractROF
    Take a ResultSet, and for each row retrieves an object of a specified result class type. Follows the rules in the JDO spec [14.6.12] regarding the result class.

    The resultClass will be used to create objects of that type when calling getObject(). The resultClass can be one of the following

    • Simple type - String, Long, Integer, Float, Boolean, Byte, Character, Double, Short, BigDecimal, BigInteger, java.util.Date, java.sql.Date, java.sql.Time, java.sql.Timestamp
    • java.util.Map - DataNucleus will choose the concrete impl of java.util.Map to use
    • Object[]
    • User defined type with either a constructor taking the result set fields, or a default constructor and setting the fields using a put(Object,Object) method, setXXX methods, or public fields

    Objects of this class are created in 2 distinct situations. The first is where a candidate class is available, and consequently field position mappings are available. The second is where no candidate class is available and so only the field names are available, and the results are taken in ResultSet order. These 2 modes have their own constructor.

    • Field Detail

      • resultClass

        private final java.lang.Class<?> resultClass
        The result class that we should create for each row of results.
      • stmtMappings

        private final StatementMappingIndex[] stmtMappings
        The index of fields position to mapping type.
      • resultDefinition

        private StatementResultMapping resultDefinition
        Definition of results when the query has a result clause.
      • resultFieldNames

        private final java.lang.String[] resultFieldNames
        Names of the result field columns (in the ResultSet).
      • resultFieldTypes

        private final java.lang.Class[] resultFieldTypes
        Types of the result field columns (in the ResultSet).
      • resultClassFieldsByName

        private final java.util.Map<java.lang.String,​java.lang.reflect.Field> resultClassFieldsByName
        Map of the ResultClass Fields, keyed by the "field" names (only for user-defined result classes).
      • constructionDefined

        boolean constructionDefined
      • resultClassArgConstructor

        private java.lang.reflect.Constructor resultClassArgConstructor
      • resultClassDefaultConstructor

        private java.lang.reflect.Constructor resultClassDefaultConstructor
      • resultSetGetters

        private static java.util.Map<java.lang.Class,​ResultClassROF.ResultSetGetter> resultSetGetters
        Map ResultSetGetters by result classes
    • Constructor Detail

      • ResultClassROF

        public ResultClassROF​(org.datanucleus.ExecutionContext ec,
                              java.sql.ResultSet rs,
                              org.datanucleus.FetchPlan fp,
                              java.lang.Class cls,
                              StatementResultMapping resultDefinition)
        Constructor for a resultClass object factory where we have a result clause specified.
        Parameters:
        ec - ExecutionContext
        rs - ResultSet being processed
        fp - FetchPlan
        cls - The result class to use (if any)
        resultDefinition - The mapping information for the result expressions
      • ResultClassROF

        public ResultClassROF​(org.datanucleus.ExecutionContext ec,
                              java.sql.ResultSet rs,
                              java.lang.Class cls,
                              StatementClassMapping classDefinition)
        Constructor for a resultClass object factory where we have no result clause specified but a result class. In this case the result will match the candidate class, but may not be the actual candidate class (e.g Object[])
        Parameters:
        ec - ExecutionContext
        rs - ResultSet being processed
        cls - The result class to use
        classDefinition - The mapping information for the (candidate) class
      • ResultClassROF

        public ResultClassROF​(org.datanucleus.ExecutionContext ec,
                              java.sql.ResultSet rs,
                              java.lang.Class cls,
                              java.lang.String[] resultFieldNames)
        Constructor for cases where we have no candidate class and so have no mapping information to base field positions on. The fields will be retrieved in the ResultSet order. Used for SQL queries.
        Parameters:
        ec - ExecutionContext
        rs - ResultSet being processed
        cls - The result class to use
        resultFieldNames - Names for the result fields
    • Method Detail

      • getObject

        public java.lang.Object getObject()
        Method to convert the ResultSet row into an Object of the ResultClass type. We have a special handling for "result" expressions when they include literals or "new Object()" expression due to the fact that complex literals and "new Object()" cannot be added to the SQL queries.
        Returns:
        The ResultClass object.
      • getValueForNewObject

        protected java.lang.Object getValueForNewObject​(StatementNewObjectMapping newMap,
                                                        org.datanucleus.ExecutionContext ec,
                                                        java.sql.ResultSet rs)
        Convenience method to return the value of a NewObject mapping for the current row of the provided query results.
        Parameters:
        newMap - new object mapping
        ec - ExecutionContext
        rs - Query results
        Returns:
        The value of the new object
      • populateDeclaredFieldsForUserType

        private void populateDeclaredFieldsForUserType​(java.lang.Class cls)
        Populate a map with the declared fields of the result class and super classes.
        Parameters:
        cls - the class to find the declared fields and populate the map
      • getResultObject

        private java.lang.Object getResultObject​(java.sql.ResultSet rs,
                                                 int columnNumber)
                                          throws java.sql.SQLException
        Convenience method to read the value of a column out of the ResultSet. Uses "rs.getBoolean", "rs.getInt", etc, otherwise "rs.getObject".
        Parameters:
        rs - ResultSet
        columnNumber - Number of the column (starting at 1)
        Returns:
        Value for the column for this row.
        Throws:
        java.sql.SQLException - Thrown if an error occurs on reading