db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Gallagher <rgall...@bellsouth.net>
Subject Possible performance enhancement for o.a.o.b.util.BrokerHelper
Date Tue, 22 Apr 2003 17:22:20 GMT
While diagnosing the problem I was having regarding auto-increment fields with field conversions,
I came across something that may improve the performance of OJB.

In BrokerHelper::getAutoIncrementValue(FieldDescriptor,Object,Object), the third argument
that's passed to this method is the current value of the attribute.  However, once the code
determines that the current value is null/0, the code re-retrieves the current value.  To
me, this seems like an unnecessary step.  The current value is available, why should the code
go back to the object and get the value again?  I didn't include this in the patch I sent
earlier, but here's what I would suggest changing BrokerHelper::getAutoIncrementValue(FieldDescriptor,Object,Object)
to:

protected Object getAutoIncrementValue(FieldDescriptor fmd, Object obj, Object cv)
{
    if ((cv == null) || ((cv instanceof Number) && (((Number) cv).intValue() == 0)))
    {
        PersistentField f = fmd.getPersistentField();
        try
        {
            // lookup SeqMan for a value matching db column an fieldconversion
            Object result = broker.serviceSequenceManager().getUniqueValue(fmd);
            // reflect autoincrement value back into object
            f.set(obj, result);
            return result;
        }
        catch (MetadataException e)
        {
            throw new PersistenceBrokerException(
                "Error while trying to autoincrement field " +
                f.getDeclaringClass() + "#" + f.getName(), e);
        }
        catch (SequenceManagerException e)
        {
            throw new PersistenceBrokerException("Could not get key value", e);
        }
    }
    else
    {
        return cv;
    }
}

Ron Gallagher
Atlanta, GA
rongallagher@bellsouth.net



Mime
View raw message