You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by "Clute, Andrew" <An...@osn.state.oh.us> on 2004/02/24 18:42:36 UTC

Bug (and Fix) with a custom RowReader and PB.getObjectByQuery()

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


Re: Bug (and Fix) with a custom RowReader and PB.getObjectByQuery()

Posted by Armin Waibel <ar...@apache.org>.
Hi Andrew,

 >
 > Any thoughts or reasons why we could not change this?

I don't see any reason not to do this, checked in your patch.

regards,
Armin

Clute, Andrew wrote:
> 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-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 

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