db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <fisc...@seitenbau.net>
Subject RE: Problems with CLOB and Peer.doDelete(obj)
Date Tue, 14 Feb 2006 08:18:32 GMT
My personal feeling as a user is that the doDelete( SomeTable obj ) will be
used in most cases to delete an obkject that was read from the database. If
the user wants a "template delete", usage of doDelete(Criteria crit) feels
more appropriate in my eyes.

As objects are identified by their primary key, I would think the following
behaviour to be appropriate:
- If the table has a primary key, only the primary key thould be used to
find the object to ber deleted (even if the primary key is not set in the
object, then the table row which has no primary key set should be deleted).
This is the behaviour Greg described below.
- If the table has no primary key, then the object's values should be used.
But then, I am rather of the opinion that a doDelete() on an object with
blob and clob values should throw an error rather than ignore the blob and
clob value, for the following reason: An object without primary key is
identified solely by all its values. If all values are the same, then the
object is the same. It is not "if all values except BLOB and CLOB values
are the same, the object is the same". So, doing a doDelete() on an object
without primary key and with BLOB and CLOB values should throw an error,
because the database is not able to test which objects are identical to the
supplied object. Making exceptions for BLOB and CLOB values renders the API
inconsistent.
If the user wants to delete an object based on the other columns except
BLOB and CLOB values, he should do so using doDelete(Criteria crit). This
Criteria can be constructed the following way:

SomeDBObject o = new SomeDBObject();
// ... fill Object's values here
// for whatever reasons, buildCriteria only works for Objects which are not
null.
o.setNew(false);
Criteria criteria = SomeDBObjectPeer.buildCriteria(o);
criteria.remove(SomeDBObjectPeer.SOME_LOB_COLUMN);
SomeDBObjectPeer.doDelete(criteria);

So although this seems complicated, it is entirely clear from reading the
code what is happening here. If instead the LOB-column would be left out
automatically, this would result in

SomeDBObject o = new SomeDBObject();
// ... fill Object's values here
SomeDBObjectPeer.doDelete(o);

and it is not at all clear to the unsuspecting reader that the
SOME_LOB_COLUMN would be left out in constructing the criteria.

    Thomas


"Greg Monroe" <Greg.Monroe@DukeCE.com> schrieb am 13.02.2006 17:00:26:

> Gareth's method is correct.  However, I was looking at the code
> and wondering if there is not a bug here.  The main question
> IMHO is:
>
> What is the specific purpose of the the doDelete( SomeTable obj )
> method?
>
> Is it intended to only delete a single records or is it supposed
> to allow for deleting multiple records identified by a template
> object?  E.g., should code like:
>
>    SomeTable obj = new SomeTable();
>    obj.setCategory(value);
>    obj.setSubCategory(value2);
>    SomeTablePeer.doDelete(obj);
>
> 1) Delete only records that have Category=value, subcategory
> = value2, and ALL other fields = null or default values.
>
> or.
>
> 2) Delete all records that had category=value and subcategory
> = value2, regardless of other field values.
>
> In either case, there probably should be a test to see if the
> object has a primary key defined and then do a delete by PK
> call.
>
> If the intent is to allow "template" deletes, the code here is
> wrong because it does not check for null values, which should
> be excluded from the criteria unless the object is ! isNew().
>
> If the intent is to allow only for deletion of records that
> are "exact" matches. Then the code is OK except for the issue
> of some DB's not allowing = for long fields (use like in
> this case?).  However, if the test for a PK is added, then
> this only occures in the limited case of tables without a PK
> (which is highly recommended in any good DB design).
>
> Anyway, if we can come to a concensus on the purpose of this
> method, I'll put in the Issue and a patch for the Template
> file.
>
>
>
> > -----Original Message-----
> > From: Gareth Boden [mailto:gareth.boden@egsgroup.com]
> > Sent: Monday, February 13, 2006 6:46 AM
> > To: torque-user@db.apache.org
> > Subject: Re: Problems with CLOB and Peer.doDelete(obj)
> >
> >
> > > I got a problem with torque3.1.1 when deleting and object using its
> > > peer. I think the problem is with the definition of the
> > > buildCriteria method.
> >
> > You want to just delete it with the primary key, not the whole object:
> >    SomeTablePeer.doDelete(((SomeTable) obj).getPrimaryKey());
> >
> > Gareth
> >


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


Mime
View raw message