db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Gallagher <rgall...@bellsouth.net>
Subject Patch for o.a.o.b.util.BrokerHelper
Date Tue, 22 Apr 2003 17:13:42 GMT
I encountered a problem that occurs during the storage of an object where the class-descriptor
has an auto-increment field with field conversion defined for it.

Here are the relevant parts from my repository.xml:
<jdbc-connection-descriptor ... platform="Oracle">
    <sequence-manager className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl"/>
</jdbc-connection-descriptor>
<class-descriptor class="com.ge.ps.pdb.data.SiteData" schema="&pdb_schema;" table="SITE">
  <field-descriptor autoincrement="true" column="SITE_ID" conversion="com.ge.ps.cosmos.data.ojb.BigDecimal2LongConversion"
id="1" jdbc-type="DECIMAL" name="siteId" nullable="false" primarykey="true" sequence-name="SEQ_SITE_ID"/>
  <!-- other field-descriptors removed for brevity -->
</class-descriptor>

Here's my diagnosis...

At the very beginning of PersistenceBrokerImpl::store(Object,ObjectModification), an Identity
object is created.  During the creation of this Identity object, the primary key of my SiteData
object is assigned a value using the next value of the SEQ_SITE_ID sequence.  During that
process, the value is converted to it's java type (Long) via the conversion routine I've specified
and 'set' on the object that's being identified.  So far so good.  Control then flows down
this call stack:

PersistenceBrokerImpl::storeToDb(Object,ClassDescriptor,Identity,boolean)
JdbcAccess::executeInsert(ClassDescriptor,Object)
StatementManager::bindInsert(PreparedStatement,ClassDescriptor,Object)
StatementManager::getAllValues(ClassDescriptor,Object)
BrokerHelper::getAllRwValues(ClassDescriptor,Object)
BrokerHelper::getAutoIncrementValue(FieldDescriptor,Object,Object)

In getAllRwValues, if a field is not defined as auto-increment, then the value that's on the
object is converted to it's sql type and put in an Object array that's returned by the method.
 However, if the field is defined as an auto-increment field, the value that's returned by
the getAutoIncrementValue method is put into the Object array as-is.  The problem is that
getAutoIncrementValue returns a value whose datatype is the java-equivalent, not the sql-equivalent.
 So, the array that getAllRwValues returns has a mixture of data types.  Some are compatible
with the java world.  Some are compatible with the sql world.

I thought about changing getAutoIncrementValue  to always return a sql-compatible data type.
 However, this doesn't fit well with the getKeyValues(ClassDescriptor,Object,boolean) method
since the decision to convert to sql datatypes is determined based on an argument.

My solution is to always convert the value that's returned by getAutoIncrementValue to the
sql-compatible datatype in the following methods:
getNonKeyRwValues(ClassDescriptor,Object)
getAllRwValues(ClassDescriptor,Object)
In getKeyValues(ClassDescriptor,Object,boolean), the value is only converted to the sql-compatible
datatype if the 3rd arguments indicates so.

I've attached an update to org.apache.ojb.broker.util.BrokerHelper.java as well as a difference
report.

Ron Gallagher
Atlanta, GA
rongallagher@bellsouth.net


Mime
View raw message