[Opensource] DBObject.clear() does not "clear" boolean
fields - bug or feature
larry hamel
expresso at codeguild.com
Wed Jun 12 09:56:31 PDT 2002
hi Milen,
good bug description.
it seems to me that DBObject.clear() is the culprit here. A DBObject is "born" with nulls in the underlying hashtable, so I propose the following change to DBObject.clear() to reset that hash to all nulls. I assume that the resulting object would behave then just as a newly created DBObject. (BTW, the short-term workaround would be to create a new DBObject rather than using clear() for now.)
does anyone see problems with this?
hmm, I guess for one thing is the "log update" logic that is present in setField(). that seems easy to add (and deserves a separate method in DBObject).
larry
-------------------------------
public synchronized void clear()
throws DBException {
DBField oneField = null;
for (Iterator i = getAllFieldsIterator(); i.hasNext();) {
oneField = (DBField)i.next();
if (!oneField.isVirtual()) {
// avoid use of setField() here
//setField(oneField.getName(), "");
if (getDef().isLoggingEnabled()) {
// make this new method
logChange( oneField, null );
}
// reset underlying hash
setFieldData(oneField.getName(), null);
}
}
}
----------------------------
At 08:01 AM 6/12/2002, you wrote:
>Hi,
>
>We are having some problems with boolean fields in Expresso v4.1.
>When we execute SQL query using new instance of a particular DBObject,
>(for example:
>DBObj myDBObj=new DBObj();
>myDBObj.setField("id","1");
>Vector v=myDBObj.searchAndRetrieve();
>)
>the query result set contains all the records we expect.
>But if we want to reuse the same DBObject and just execute .clear()
>- result set contains only the records that have boolean fields set to "false".
>(
>myDBObj.clear();
>myDBObj.setField("id","1");
>Vector v=myDBObj.searchAndRetrieve();
>)
>
>In Expresso DBObject, when DBObject.clear() is invoked the following fragment is executed:
>setField(oneField.getName(), "");
>
>and later in setField(String,String) we have:
>....
>if (oneField.getTypeString().equalsIgnoreCase("boolean")) {
> if (fieldValue.equalsIgnoreCase("Y") || fieldValue.equalsIgnoreCase("t")
> || fieldValue.equalsIgnoreCase("true")) {
> fieldValue = getBooleanFieldValue(true);
> } else {
> fieldValue = getBooleanFieldValue(false);
> }
> }
>....
>The outcome is that the boolean fields will be set to "false".
>Hence when one does searchAndRetrieve() only the records with "false" value will be returned.
>At least we think this is causing the trouble - but this is what we encounter.
>Do you have any solution for that problem?
>Or this is the way that method DBObject.clear() is supposed to work?
>Thank you in advance!
>Milen
>
>_______________________________________________
>Opensource mailing list
>Opensource at jcorporate.com
>http://mail.jcorporate.com/mailman/listinfo/opensource
>Archives: http://mail.jcorporate.com/pipermail/opensource/
More information about the Opensource
mailing list