com.objectwave.persist.objectConstruction
Class ProcessResultSet

java.lang.Object
  |
  +--com.objectwave.persist.objectConstruction.ProcessResultSet

public class ProcessResultSet
extends java.lang.Object

A utitlity class that converts a database result set into a collection of objects.

Version:
$Id: ProcessResultSet.java,v 2.6 2002/03/23 13:42:10 dave_hoag Exp $
Author:
dhoag
See Also:
processResults(java.lang.Object[], java.sql.ResultSet, com.objectwave.persist.SQLQuery, com.objectwave.persist.sqlConstruction.SQLSelect, com.objectwave.persist.CollectionAdapter)

Nested Class Summary
static class ProcessResultSet.Test
          Unit tests.
 
Constructor Summary
ProcessResultSet()
           
 
Method Summary
protected  boolean buildAttributes(Persistence obj, RDBPersistence refObj, RDBPersistence originalObject, RDBPersistence orgRef, java.lang.Object[] record)
          Set all of the attribute values that were found from the query.
 void buildCollectionProxies(Persistence obj, RDBPersistence refObj, RDBPersistence origObj, RDBPersistence orgRef)
          Create a SQLQuery object that will find the elements in this collection.
 Persistence buildFkProxy(AttributeTypeColumn col, java.lang.Object[] joinValues, Persistence obj, RDBPersistence pObj, RDBPersistence refObj)
          Build proxy for ForeignKey references.
protected  void buildForeignKeyObjects(Persistence obj, RDBPersistence refObj, RDBPersistence origObj, RDBPersistence orgRef, java.lang.Object[] record)
          Fill all the foreign key instance variables in obj as defined in the foreign key map.
protected  void buildInstanceLinkObjects(Persistence obj, RDBPersistence refObj, RDBPersistence origObj, RDBPersistence orgRef, java.lang.Object[] record)
          Fill all the instance link instance variables in obj as defined in the instance link map.
 Persistence buildObject(RDBPersistence refObj, RDBPersistence origObj, RDBPersistence origRef, java.lang.Object[] dataRow)
          Builds a new object from the data in record.
 Persistence buildProxy(AttributeTypeColumn col, java.lang.Object primaryKeyField, RDBPersistence pObj, RDBPersistence refObj)
          Build a proxy for an instance link.
protected  Persistence checkObjectPool(Persistence obj, RDBPersistence refObj, RDBPersistence originalObject, RDBPersistence orgRef, java.lang.Object[] record)
          See if we can find the Obj in the object pool.
protected  Persistence createNewObject(RDBPersistence refObj, RDBPersistence pObj, RDBPersistence origRef, java.lang.Object[] dataRow)
          Create a new object of the correct class.
protected  Persistence determineAndCreateInstance(RDBPersistence refObj, RDBExtendablePersistentAdapter origObj, java.lang.Object[] dataRow)
          The first data element should be the type id of the class.
protected  java.lang.Object determinePrimaryKey(java.lang.Object primaryKey, AttributeTypeColumn col)
          Ignore primary keys that are blank or zero.
protected  int getAttributeCount(RDBPersistence pObj, java.lang.Object refObj)
          Convience method to count the number of pObj attributeColumns.
protected  java.lang.Object[] getAttributeData(java.lang.Object[] objArrays, java.lang.Object[] record, int size, int start)
          Deprecated. No long used.
static ProcessResultSet getInstance(java.lang.String instanceType)
          We don't want singleton instances.
protected  Persistence getNewInstance(AttributeTypeColumn column, RDBPersistence refObj)
           
 ObjectPool getObjectPool()
           
protected  int getPrimaryKeyCount(RDBPersistence pObj, java.lang.Object refObj)
          Convience method to count the number of pObj primaryKeyColumns.
protected  boolean isDifferentType(Persistence oneObject, RDBPersistence secondObject)
          If the class of oneObject is the same as the class of secondObject.getDomainObject() then return false, otherwise return true.
protected  boolean isMatch(AttributeTypeColumn col, RDBPersistence refObj, java.lang.Object[] values)
          A foreign key attribute type column has found a reference object, our values may point to this instance.
protected  boolean isPrimitiveZero(java.lang.String pkString, AttributeTypeColumn col)
          is a primitive and value is zero
protected  void populateJoinFields(JoinField[] fields, java.lang.Object[] data, Persistence newObject, RDBPersistence adapter)
          Fill in the fields on the other object with the correct values
static void println(java.lang.String str)
          Utility method to assist with migration to logger interface.
 CollectionAdapter processResults(java.lang.Object[] objArrays, java.sql.ResultSet set, SQLQuery obj, SQLSelect sqlObj, CollectionAdapter adapt)
          Main entry point for this class.
 void setBrokerProperty(BrokerPropertyIF b)
           
 void setObjectFormatter(ObjectFormatter of)
          An object formatter is used to convert data from one type to another.
 void setObjectPool(ObjectPool p)
           
protected  boolean setVals(AttributeTypeColumn[] allCols, JoinField[] fields, java.lang.Object[] data, Persistence newObject)
           
 void updateBackReferences(Persistence obj, RDBPersistence origObj, RDBPersistence refObj)
          This is used only be objects generated by the createInstance() method of RDBExtendablePersitentAdapter objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProcessResultSet

public ProcessResultSet()
Method Detail

getInstance

public static ProcessResultSet getInstance(java.lang.String instanceType)
We don't want singleton instances. Each instance of this class will relate to a single RDBBroker instance.

Parameters:
instanceType -
Returns:
The Instance value

println

public static void println(java.lang.String str)
Utility method to assist with migration to logger interface.

Parameters:
str -

setObjectFormatter

public void setObjectFormatter(ObjectFormatter of)
An object formatter is used to convert data from one type to another. This can be customized as needed.

Parameters:
of - The formatter this class is to use.

setBrokerProperty

public void setBrokerProperty(BrokerPropertyIF b)
Parameters:
b - The new BrokerProperty value

setObjectPool

public void setObjectPool(ObjectPool p)
Parameters:
p - The new ObjectPool value

setVals

protected boolean setVals(AttributeTypeColumn[] allCols,
                          JoinField[] fields,
                          java.lang.Object[] data,
                          Persistence newObject)
Parameters:
allCols - The new Vals value
fields - The new Vals value
data - The new Vals value
newObject - The new Vals value
Returns:
boolean indicating if there is any data left to set

getObjectPool

public ObjectPool getObjectPool()
Returns:
The ObjectPool value

isDifferentType

protected boolean isDifferentType(Persistence oneObject,
                                  RDBPersistence secondObject)
If the class of oneObject is the same as the class of secondObject.getDomainObject() then return false, otherwise return true.

Parameters:
oneObject -
secondObject -
Returns:
The DifferentType value

isPrimitiveZero

protected boolean isPrimitiveZero(java.lang.String pkString,
                                  AttributeTypeColumn col)
is a primitive and value is zero

Parameters:
pkString - A string retrieved from the database
col -
Returns:
true if the string is series of zeros and the column type is a number.

getAttributeCount

protected int getAttributeCount(RDBPersistence pObj,
                                java.lang.Object refObj)
Convience method to count the number of pObj attributeColumns.

Parameters:
pObj -
refObj -
Returns:
The AttributeCount value

getPrimaryKeyCount

protected int getPrimaryKeyCount(RDBPersistence pObj,
                                 java.lang.Object refObj)
Convience method to count the number of pObj primaryKeyColumns.

Parameters:
pObj -
refObj -
Returns:
The AttributeCount value

getAttributeData

protected java.lang.Object[] getAttributeData(java.lang.Object[] objArrays,
                                              java.lang.Object[] record,
                                              int size,
                                              int start)
Deprecated. No long used.

Get an Object [] that contains the data for the attributes of the object we are building.

Parameters:
objArrays - Object [] of cached Object arrays. This is to minimize allocation and deallocation of Object arrays.
record -
size -
start -
Returns:
The AttributeData value

getNewInstance

protected Persistence getNewInstance(AttributeTypeColumn column,
                                     RDBPersistence refObj)
                              throws java.lang.InstantiationException,
                                     java.lang.IllegalAccessException
Parameters:
column -
refObj -
Returns:
Persistence New persistent object. Will either be used as a proxy, or populated with data.
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException

isMatch

protected boolean isMatch(AttributeTypeColumn col,
                          RDBPersistence refObj,
                          java.lang.Object[] values)
A foreign key attribute type column has found a reference object, our values may point to this instance. To find out, check the join values.

Parameters:
col -
refObj -
values -
Returns:
The Match value

buildCollectionProxies

public void buildCollectionProxies(Persistence obj,
                                   RDBPersistence refObj,
                                   RDBPersistence origObj,
                                   RDBPersistence orgRef)
                            throws java.lang.InstantiationException,
                                   java.lang.IllegalAccessException
Create a SQLQuery object that will find the elements in this collection. When an attempt to reference the field that contains this collection proxy occurs the SQLQuery will be executed and the results will be placed into the field.

Parameters:
obj - Persistence The object we are buliding.
refObj -
origObj -
orgRef -
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException

buildObject

public Persistence buildObject(RDBPersistence refObj,
                               RDBPersistence origObj,
                               RDBPersistence origRef,
                               java.lang.Object[] dataRow)
                        throws java.lang.InstantiationException,
                               java.lang.IllegalAccessException
Builds a new object from the data in record. The build process is broken down into the same logical units as the select statement process was.

Parameters:
refObj - is the object that was retrieved and build because of the presence of orgRef. It must reference the new object in the new object structure and the new object may have to reference it back.
origObj -
origRef -
dataRow -
Returns:
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException

buildFkProxy

public Persistence buildFkProxy(AttributeTypeColumn col,
                                java.lang.Object[] joinValues,
                                Persistence obj,
                                RDBPersistence pObj,
                                RDBPersistence refObj)
                         throws java.lang.InstantiationException,
                                java.lang.IllegalAccessException
Build proxy for ForeignKey references.

Parameters:
obj - The Persistence object being built.
pObj - The RDBPersistent adapter for the object being built.
col - The column on the object being built that is to contain the proxy.
refObj - If I'm part of a Join, this is the object from which this build process has begun
joinValues -
Returns:
The proxy reference.
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException

buildProxy

public Persistence buildProxy(AttributeTypeColumn col,
                              java.lang.Object primaryKeyField,
                              RDBPersistence pObj,
                              RDBPersistence refObj)
                       throws java.lang.InstantiationException,
                              java.lang.IllegalAccessException
Build a proxy for an instance link.

Parameters:
col -
primaryKeyField -
pObj -
refObj -
Returns:
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException

processResults

public CollectionAdapter processResults(java.lang.Object[] objArrays,
                                        java.sql.ResultSet set,
                                        SQLQuery obj,
                                        SQLSelect sqlObj,
                                        CollectionAdapter adapt)
                                 throws java.sql.SQLException,
                                        java.lang.InstantiationException,
                                        java.lang.IllegalAccessException
Main entry point for this class. Every other method in this class facilitiates the processing of the result set. Only one thread has access the objArrays at any given time. If there are multiple connections, each connection has an objArray field, and can use this processResults method.

Parameters:
adapt - CollectionAdapter The adapter to use in place of the default adapter.
objArrays - Only two methods actually use the objArrays. This one to contain the full result set of data. buildAttributes to contain the converted data values.
set -
obj -
sqlObj -
Returns:
com.objectwave.persist.CollectionAdapter Used to support multiple collection types.
Throws:
java.sql.SQLException
java.lang.InstantiationException
java.lang.IllegalAccessException

updateBackReferences

public void updateBackReferences(Persistence obj,
                                 RDBPersistence origObj,
                                 RDBPersistence refObj)
This is used only be objects generated by the createInstance() method of RDBExtendablePersitentAdapter objects. This mehtod is used to udpate the backreferences to database-retrieved objects used in the original query structure. We need to make sure that any foreign and instance objects will be properly back-referenced to the same instance if they were from the database in the orignal query object.

Parameters:
obj - com.objectwave.persist.Persistence
origObj - com.objectwave.persist.RDBPersistence
refObj -

populateJoinFields

protected void populateJoinFields(JoinField[] fields,
                                  java.lang.Object[] data,
                                  Persistence newObject,
                                  RDBPersistence adapter)
Fill in the fields on the other object with the correct values

Parameters:
fields -
data -
newObject -
adapter -

determineAndCreateInstance

protected Persistence determineAndCreateInstance(RDBPersistence refObj,
                                                 RDBExtendablePersistentAdapter origObj,
                                                 java.lang.Object[] dataRow)
                                          throws java.lang.InstantiationException,
                                                 java.lang.IllegalAccessException
The first data element should be the type id of the class. This should have been guaranteed by the getAttributeDescriptions() method in the RDBExtendablePersistentAdapter class. In this case, we may need to convert the datatype of the TYPEATT column before accessing that field value.

Parameters:
origObj -
refObj -
dataRow -
Returns:
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException

buildAttributes

protected boolean buildAttributes(Persistence obj,
                                  RDBPersistence refObj,
                                  RDBPersistence originalObject,
                                  RDBPersistence orgRef,
                                  java.lang.Object[] record)
Set all of the attribute values that were found from the query.

Parameters:
obj -
refObj -
originalObject -
orgRef -
record -
Returns:
boolean True A valid primary key field.

buildForeignKeyObjects

protected void buildForeignKeyObjects(Persistence obj,
                                      RDBPersistence refObj,
                                      RDBPersistence origObj,
                                      RDBPersistence orgRef,
                                      java.lang.Object[] record)
                               throws java.lang.InstantiationException,
                                      java.lang.IllegalAccessException
Fill all the foreign key instance variables in obj as defined in the foreign key map.

Parameters:
orgRef - The object from the search object that was referencing originalObject. It is needed to retrieve the same maps as we did when the select statement was build.
refObj - The object that was retrieved and build because of the presence of orgRef. It must reference obj in the new object structure and obj may have to reference it back.
obj -
origObj -
record -
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException

buildInstanceLinkObjects

protected void buildInstanceLinkObjects(Persistence obj,
                                        RDBPersistence refObj,
                                        RDBPersistence origObj,
                                        RDBPersistence orgRef,
                                        java.lang.Object[] record)
                                 throws java.lang.InstantiationException,
                                        java.lang.IllegalAccessException
Fill all the instance link instance variables in obj as defined in the instance link map. If an instance link instance variable was not nil in originalObject we have retrieved the object and must build it from the data in record. If it was nil in originalObject we must build a proxy object for that instance link relationship. The exception to this is if obj has a instance link relationship to the forObj which has already been build. In that case we must establish the back reference to refObj instead of creating a proxy.

Parameters:
obj -
refObj -
origObj -
orgRef -
record -
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException - @ param orgRef The object from the search object that was referencing originalObject. It is needed to retrieve the same maps as we did when the select statement was build. @ param refObj The object that was retrieved and build because of the presence of orgRef. It must reference obj in the new object structure and obj may have to reference it back.

checkObjectPool

protected Persistence checkObjectPool(Persistence obj,
                                      RDBPersistence refObj,
                                      RDBPersistence originalObject,
                                      RDBPersistence orgRef,
                                      java.lang.Object[] record)
See if we can find the Obj in the object pool. If not, add it to the object pool. If we are not using an ObjectPool, just return the object.

Parameters:
obj -
refObj -
originalObject -
orgRef -
record -
Returns:
Either the original object or the object that is found in the pool.

createNewObject

protected Persistence createNewObject(RDBPersistence refObj,
                                      RDBPersistence pObj,
                                      RDBPersistence origRef,
                                      java.lang.Object[] dataRow)
                               throws java.lang.InstantiationException,
                                      java.lang.IllegalAccessException
Create a new object of the correct class.

Parameters:
refObj - is the object that was retrieved and build because of the presence of orgRef. It must reference the new object in the new object structure and the new object may have to reference it back.
pObj -
origRef -
dataRow -
Returns:
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException

determinePrimaryKey

protected java.lang.Object determinePrimaryKey(java.lang.Object primaryKey,
                                               AttributeTypeColumn col)
Ignore primary keys that are blank or zero.

Parameters:
primaryKey - The original value for the primary key.
col -
Returns:
null if the original value is zero or a blank string.