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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
ResultClassROF.ResultClassFieldSetter
Class that sets a field of the ResultClass using a public field.(package private) static interface
ResultClassROF.ResultClassMemberSetter
(package private) class
ResultClassROF.ResultClassPutMethodSetter
Class that sets a field of the ResultClass using a put() method.(package private) class
ResultClassROF.ResultClassSetMethodSetter
Class that sets a field of the ResultClass using a setter method.private static interface
ResultClassROF.ResultSetGetter
Invokes a type-specific getter on given ResultSet
-
Field Summary
Fields Modifier and Type Field Description (package private) boolean
constructionDefined
private java.lang.Class<?>
resultClass
The result class that we should create for each row of results.private java.lang.reflect.Constructor
resultClassArgConstructor
private java.lang.reflect.Constructor
resultClassDefaultConstructor
private 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).private ResultClassROF.ResultClassMemberSetter[]
resultClassMemberSetters
private StatementResultMapping
resultDefinition
Definition of results when the query has a result clause.private java.lang.String[]
resultFieldNames
Names of the result field columns (in the ResultSet).private java.lang.Class[]
resultFieldTypes
Types of the result field columns (in the ResultSet).private static java.util.Map<java.lang.Class,ResultClassROF.ResultSetGetter>
resultSetGetters
MapResultSetGetters by result classes private StatementMappingIndex[]
stmtMappings
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
Constructors Constructor Description 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.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.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
getObject()
Method to convert the ResultSet row into an Object of the ResultClass type.private java.lang.Object
getResultObject(java.sql.ResultSet rs, int columnNumber)
Convenience method to read the value of a column out of the ResultSet.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.private void
populateDeclaredFieldsForUserType(java.lang.Class cls)
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 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
-
resultClassMemberSetters
private ResultClassROF.ResultClassMemberSetter[] resultClassMemberSetters
-
resultSetGetters
private static java.util.Map<java.lang.Class,ResultClassROF.ResultSetGetter> resultSetGetters
MapResultSetGetters 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
- 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, 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
- ExecutionContextrs
- ResultSet being processedcls
- The result class to useclassDefinition
- 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
- ExecutionContextrs
- ResultSet being processedcls
- The result class to useresultFieldNames
- 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 mappingec
- ExecutionContextrs
- 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
- ResultSetcolumnNumber
- 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
-
-