org.apache.ojb.broker.accesslayer
Class RowReaderDefaultImpl
java.lang.Object
org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl
- All Implemented Interfaces:
- RowReader, java.io.Serializable
- public class RowReaderDefaultImpl
- extends java.lang.Object
- implements RowReader
Default implementation of the RowReader
interface.
- Version:
- $Id: RowReaderDefaultImpl.java,v 1.30.2.2 2004/09/12 00:50:49 arminw Exp $
- See Also:
- Serialized Form
Method Summary |
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. |
void |
setClassDescriptor(ClassDescriptor cld)
Set the descriptor this RowReader worked with. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
RowReaderDefaultImpl
public RowReaderDefaultImpl(ClassDescriptor cld)
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
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 refreshrow
- the Map containing the new values- See Also:
RowReader.refreshObject(Object, Map)
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
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
(C) 2002 - 2004 Apache Software Foundation
All rights reserved. Published under the Apache License 2.0.
http://db.apache.org/ojb
Version: 1.0.3, 2005-04-2