Class ResultClassROF

java.lang.Object
org.datanucleus.store.rdbms.query.AbstractROF
org.datanucleus.store.rdbms.query.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 Details

    • resultClass

      private final 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 String[] resultFieldNames
      Names of the result field columns (in the ResultSet).
    • resultFieldTypes

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

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

      boolean constructionDefined
    • resultClassArgConstructor

      private Constructor resultClassArgConstructor
    • resultClassDefaultConstructor

      private Constructor resultClassDefaultConstructor
    • resultClassMemberSetters

      private ResultClassROF.ResultClassMemberSetter[] resultClassMemberSetters
    • resultSetGetters

      private static Map<Class,ResultClassROF.ResultSetGetter> resultSetGetters
      Mapinvalid input: '<'Class, ResultSetGetter> ResultSetGetters by result classes
  • Constructor Details

    • ResultClassROF

      public ResultClassROF(org.datanucleus.ExecutionContext ec, ResultSet rs, org.datanucleus.FetchPlan fp, 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, ResultSet rs, 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, ResultSet rs, Class cls, 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 Details

    • getObject

      public 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 Object getValueForNewObject(StatementNewObjectMapping newMap, org.datanucleus.ExecutionContext ec, 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(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 Object getResultObject(ResultSet rs, int columnNumber) throws 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:
      SQLException - Thrown if an error occurs on reading