Class ResultClassROF
java.lang.Object
org.datanucleus.store.rdbms.query.AbstractROF
org.datanucleus.store.rdbms.query.ResultClassROF
- All Implemented Interfaces:
ResultObjectFactory
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class
Class that sets a field of the ResultClass using a public field.(package private) static interface
(package private) class
Class that sets a field of the ResultClass using a put() method.(package private) class
Class that sets a field of the ResultClass using a setter method.private static interface
Invokes a type-specific getter on given ResultSet -
Field Summary
FieldsModifier and TypeFieldDescription(package private) boolean
private final Class
<?> The result class that we should create for each row of results.private Constructor
private Constructor
Map of the ResultClass Fields, keyed by the "field" names (only for user-defined result classes).private ResultClassROF.ResultClassMemberSetter[]
private StatementResultMapping
Definition of results when the query has a result clause.private final String[]
Names of the result field columns (in the ResultSet).private final Class[]
Types of the result field columns (in the ResultSet).private static Map
<Class, ResultClassROF.ResultSetGetter> Mapinvalid input: '<'Class, ResultSetGetter> ResultSetGetters by result classesprivate final StatementMappingIndex[]
The index of fields position to mapping type.Fields inherited from class org.datanucleus.store.rdbms.query.AbstractROF
ec, fp, ignoreCache, rs, updateAllFields
-
Constructor Summary
ConstructorsConstructorDescriptionResultClassROF
(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.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.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. -
Method Summary
Modifier and TypeMethodDescriptionMethod to convert the ResultSet row into an Object of the ResultClass type.private Object
getResultObject
(ResultSet rs, int columnNumber) Convenience method to read the value of a column out of the ResultSet.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.private void
Populate a map with the declared fields of the result class and super classes.Methods inherited from class org.datanucleus.store.rdbms.query.AbstractROF
getResultSet, setIgnoreCache, setUpdateAllFields
-
Field Details
-
resultClass
The result class that we should create for each row of results. -
stmtMappings
The index of fields position to mapping type. -
resultDefinition
Definition of results when the query has a result clause. -
resultFieldNames
Names of the result field columns (in the ResultSet). -
resultFieldTypes
Types of the result field columns (in the ResultSet). -
resultClassFieldsByName
Map of the ResultClass Fields, keyed by the "field" names (only for user-defined result classes). -
constructionDefined
boolean constructionDefined -
resultClassArgConstructor
-
resultClassDefaultConstructor
-
resultClassMemberSetters
-
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
- ExecutionContextrs
- ResultSet being processedfp
- FetchPlancls
- 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
- ExecutionContextrs
- ResultSet being processedcls
- The result class to useclassDefinition
- 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
- ExecutionContextrs
- ResultSet being processedcls
- The result class to useresultFieldNames
- Names for the result fields
-
-
Method Details
-
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 mappingec
- ExecutionContextrs
- Query results- Returns:
- The value of the new object
-
populateDeclaredFieldsForUserType
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
Convenience method to read the value of a column out of the ResultSet. Uses "rs.getBoolean", "rs.getInt", etc, otherwise "rs.getObject".- Parameters:
rs
- ResultSetcolumnNumber
- Number of the column (starting at 1)- Returns:
- Value for the column for this row.
- Throws:
SQLException
- Thrown if an error occurs on reading
-