org.apache.ojb.broker.accesslayer
Class RowReaderDefaultImpl

java.lang.Object
  extended byorg.apache.ojb.broker.accesslayer.RowReaderDefaultImpl
All Implemented Interfaces:
RowReader, java.io.Serializable
Direct Known Subclasses:
RowReaderTestImpl

public class RowReaderDefaultImpl
extends java.lang.Object
implements RowReader

Version:
$Id: RowReaderDefaultImpl.java,v 1.27 2004/02/06 07:58:02 tomdz Exp $
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.apache.ojb.broker.accesslayer.RowReader
serialVersionUID
 
Constructor Summary
RowReaderDefaultImpl(ClassDescriptor cld)
           
 
Method Summary
protected  java.lang.Object buildWithMultiArgsConstructor(java.util.Map row, java.lang.reflect.Constructor multiArgsConstructor)
           
protected  java.lang.Object buildWithReflection(java.util.Map row, ClassDescriptor targetClassDescriptor)
          Creates an object instance according to clb, and fills its fileds width data provided by row.
 ClassDescriptor getClassDescriptor()
          Returns the associated ClassDescriptor
 void readObjectArrayFrom(java.sql.ResultSet rs, java.util.Map row)
          materialize a single object, described by cld, from the first row of the ResultSet rs.
 java.lang.Object readObjectFrom(java.util.Map row)
          materialize a single object, described by cld, from the first row of the ResultSet rs.
 void readPkValuesFrom(java.sql.ResultSet rs, java.util.Map row)
          Read primary key fields from the current ResultRow into the Object[] row.# ConversionStrategies are applied here!
 void refreshObject(java.lang.Object instance, java.util.Map row)
          refresh an existing instance from the values of the Map row.
protected  ClassDescriptor selectClassDescriptor(java.util.Map row)
          Check if there is an attribute which tells us which concrete class is to be instantiated.
 void setClassDescriptor(ClassDescriptor cld)
          Set the descriptor this RowReader worked with.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RowReaderDefaultImpl

public RowReaderDefaultImpl(ClassDescriptor cld)
Method Detail

readObjectFrom

public java.lang.Object readObjectFrom(java.util.Map row)
                                throws PersistenceBrokerException
materialize a single object, described by cld, from the first row of the ResultSet rs. There are two possible strategies: 1. The persistent class defines a public constructor with arguments matching the persistent primitive attributes of the class. In this case we build an array args of arguments from rs and call Constructor.newInstance(args) to build an object. 2. The persistent class does not provide such a constructor, but only a public default constructor. In this case we create an empty instance with Class.newInstance(). This empty instance is then filled by calling Field::set(obj,getObject(matchingColumn)) for each attribute. The second strategy needs n calls to Field::set() which are much more expensive than the filling of the args array in the first strategy. client applications should therefore define adequate constructors to benefit from performance gain of the first strategy. MBAIRD: The rowreader is told what type of object to materialize, so we have to trust it is asked for the right type. It is possible someone marked an extent in the repository, but not in java, or vice versa and this could cause problems in what is returned. we *have* to be able to materialize an object from a row that has a objConcreteClass, as we retrieve ALL rows belonging to that table. The objects using the rowReader will make sure they know what they are asking for, so we don't have to make sure a descriptor is assignable from the selectClassDescriptor. This allows us to map both inherited classes and unrelated classes to the same table.

Specified by:
readObjectFrom in interface RowReader
Parameters:
row - the Map containing the new values
Returns:
a properly created instance.
Throws:
PersistenceBrokerException

readObjectArrayFrom

public void readObjectArrayFrom(java.sql.ResultSet rs,
                                java.util.Map row)
materialize a single object, described by cld, from the first row of the ResultSet rs. There are two possible strategies: 1. The persistent class defines a public constructor with arguments matching the persistent primitive attributes of the class. In this case we build an array args of arguments from rs and call Constructor.newInstance(args) to build an object. 2. The persistent class does not provide such a constructor, but only a public default constructor. In this case we create an empty instance with Class.newInstance(). This empty instance is then filled by calling Field::set(obj,getObject(matchingColumn)) for each attribute. The second strategy needs n calls to Field::set() which are much more expensive than the filling of the args array in the first strategy. client applications should therefore define adequate constructors to benefit from performance gain of the first strategy.

Specified by:
readObjectArrayFrom in interface RowReader
Throws:
PersistenceBrokerException - if there is an error accessing the access layer

selectClassDescriptor

protected ClassDescriptor selectClassDescriptor(java.util.Map row)
                                         throws PersistenceBrokerException
Check if there is an attribute which tells us which concrete class is to be instantiated.

Throws:
PersistenceBrokerException

buildWithReflection

protected java.lang.Object buildWithReflection(java.util.Map row,
                                               ClassDescriptor targetClassDescriptor)
Creates an object instance according to clb, and fills its fileds width data provided by row.

Parameters:
row - A Map contain the Object/Row mapping for the object.
targetClassDescriptor - If the "ojbConcreteClass" feature was used, the target ClassDescriptor could differ from the descriptor this class was associated - see selectClassDescriptor(java.util.Map).
Throws:
PersistenceBrokerException - if there ewas an error creating the new object

buildWithMultiArgsConstructor

protected java.lang.Object buildWithMultiArgsConstructor(java.util.Map row,
                                                         java.lang.reflect.Constructor multiArgsConstructor)
                                                  throws java.sql.SQLException,
                                                         java.lang.InstantiationException,
                                                         java.lang.IllegalAccessException,
                                                         java.lang.reflect.InvocationTargetException,
                                                         PersistenceBrokerException
Throws:
java.sql.SQLException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
PersistenceBrokerException

readPkValuesFrom

public void readPkValuesFrom(java.sql.ResultSet rs,
                             java.util.Map row)
Description copied from interface: RowReader
Read primary key fields from the current ResultRow into the Object[] row.# ConversionStrategies are applied here!

Specified by:
readPkValuesFrom in interface RowReader

setClassDescriptor

public void setClassDescriptor(ClassDescriptor cld)
Description copied from interface: RowReader
Set the descriptor this RowReader worked with.

Specified by:
setClassDescriptor in interface RowReader

getClassDescriptor

public ClassDescriptor getClassDescriptor()
Description copied from interface: RowReader
Returns the associated ClassDescriptor

Specified by:
getClassDescriptor in interface RowReader

refreshObject

public void refreshObject(java.lang.Object instance,
                          java.util.Map row)
Description copied from interface: RowReader
refresh an existing instance from the values of the Map row.

Specified by:
refreshObject in interface RowReader
Parameters:
instance - the instance to refresh
row - the Map containing the new values
See Also:
RowReader.refreshObject(Object, Map)


Authors: Thomas Mahler and others. (C) 2000 - 2003 Apache Software Foundation
All rights reserved. Published under the Apache License.
http://db.apache.org/ojb
Version: 1.0.rc5, 2003-12-14