db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Clute, Andrew" <Andrew.Cl...@osn.state.oh.us>
Subject Bug (and Fix) with a custom RowReader and PB.getObjectByQuery()
Date Tue, 24 Feb 2004 17:42:36 GMT
I have implemented a custom RowReader that filters out deleted items for
me. I have a "deleted_date" column on all my tables, and this RowReader
checks to see if this column is not null, and if it is null, returns the
object, otherwise returns null.

Easy and effective way for me to "soft" delete items -- still in the
database, but not in my object model.

However, in the getObjectByQuery() call, it assumes the first result
that is returned from the RsIterator is the only result, and returns
that.

I have a situation where an item with a certain criteria is in my
database twice -- once deleted, and then a non-deleted version of it.
When I do a PB.getObjectByQuery(), the RsIterator get's both results
from the database, but the first row is the deleted row, so my RowReader
filters it out, and do not get the right result.

The current code in PersistenceBrokerImpl looks like this:

 	OJBIterator it = getIteratorFromQuery(query, cld);
      Object result = null;
      if (it.hasNext())
      {
      	result = it.next();
      }
      it.releaseDbResources();
      return result;

As you can see, there are distinct cases where the user will not get the
right results if using a custom RowReader, since the assumption is the
first one will always be the case.

I would like to change the code to the following:

	 OJBIterator it = getIteratorFromQuery(query, cld);
       Object result = null;
       while (result==null && it.hasNext())
       {
       	result = it.next();
       }
       it.releaseDbResources();
       return result;

This will ensure that if there are multiple possible results for a
query, that a custom RowReader will have a chance to find the first
instance of a result that will work.

Any thoughts or reasons why we could not change this?

-Andrew

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message