You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Thomas Fischer <fi...@seitenbau.net> on 2008/03/28 16:23:04 UTC

saving the state of a object collection

Has anybody found a simple way to  save the state of object collections ?
To illustrate what I mean, here's an example (I'm using complexObjectModel
= true and objectIsCaching = true):

I have two tables, Book and Author. A foreign key exists from book to
Author, so an author can have several books associated.
Now I load one author including the associated books. I modify the
associated set (i.e modify, add and delete books) and want to save it as it
is (i.e. after saving, the list of associated books in the database should
be exactly equal to the list of books in the author object).

The algorithm I can come up with is the following:
1) select the ids of all books in the author object which are not new in a
collection
2) delete all books for the author which have an id not in the above
collection of ids
3) save the author (this will save the underlying books as well)

2) is painful if the book table has a composite primary key (as I cannot
see how Criteria.NOT_IN should work in this case (or does It ? please tell
me!))
Does anybody see an easier way to do this ? Hitting the database during
modifying the book list is not an option in my case because the possibility
to NOT save the changes should exist after making the changes in the GUI

   Thomas


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


RE: saving the state of a object collection

Posted by Thomas Fischer <fi...@seitenbau.net>.
"Greg Monroe" <Gr...@DukeCE.com> schrieb am 28.03.2008 17:54:31:

> Only things that come to mind quickly are:
>
> Use a custom Criteria to build a NOT IN clause that with
> an expression to combine your keys.  E.g. build the
> following sort of Custom criteria:
>
> CONCAT(CAST(Book.ID1 AS CHAR),'-',CAST(Book.ID2 AS CHAR))
> NOT IN ( '1-1', '2-1',...)

Good point. But only works correctly under all circumstances when keys are
integers. When keys are random strings, one would have to do escaping,
which is even more painfull than criteria juggling.

>
> Alternatively, you could just add a unique non-key record id
> to book table.  It doesn't have to be the key, just an
> auto increment field.  Then you could just use a normal
> NOT IN criteria.

This will always work, you are right. Basically, you are saying "Not using
composite keys will make life easier". Hm, I should have taken this advice
when designing the db schema....

   Thanks,

        Thomas


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


RE: saving the state of a object collection

Posted by Greg Monroe <Gr...@DukeCE.com>.
Only things that come to mind quickly are:

Use a custom Criteria to build a NOT IN clause that with
an expression to combine your keys.  E.g. build the 
following sort of Custom criteria:

CONCAT(CAST(Book.ID1 AS CHAR),'-',CAST(Book.ID2 AS CHAR)) 
NOT IN ( '1-1', '2-1',...)

Alternatively, you could just add a unique non-key record id 
to book table.  It doesn't have to be the key, just an 
auto increment field.  Then you could just use a normal
NOT IN criteria.

> -----Original Message-----
> From: Thomas Fischer [mailto:fischer@seitenbau.net]
> Sent: Friday, March 28, 2008 11:23 AM
> To: torque-user@db.apache.org
> Subject: saving the state of a object collection
> 
> 
> Has anybody found a simple way to  save the state of object
collections
> ?
> To illustrate what I mean, here's an example (I'm using
> complexObjectModel
> = true and objectIsCaching = true):
> 
> I have two tables, Book and Author. A foreign key exists from book to
> Author, so an author can have several books associated.
> Now I load one author including the associated books. I modify the
> associated set (i.e modify, add and delete books) and want to save it
> as it
> is (i.e. after saving, the list of associated books in the database
> should
> be exactly equal to the list of books in the author object).
> 
> The algorithm I can come up with is the following:
> 1) select the ids of all books in the author object which are not new
> in a
> collection
> 2) delete all books for the author which have an id not in the above
> collection of ids
> 3) save the author (this will save the underlying books as well)
> 
> 2) is painful if the book table has a composite primary key (as I
> cannot
> see how Criteria.NOT_IN should work in this case (or does It ? please
> tell
> me!))
> Does anybody see an easier way to do this ? Hitting the database
during
> modifying the book list is not an option in my case because the
> possibility
> to NOT save the changes should exist after making the changes in the
> GUI
> 
>    Thomas
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org

DukeCE Privacy Statement:
Please be advised that this e-mail and any files transmitted with
it are confidential communication or may otherwise be privileged or
confidential and are intended solely for the individual or entity
to whom they are addressed. If you are not the intended recipient
you may not rely on the contents of this email or any attachments,
and we ask that you please not read, copy or retransmit this
communication, but reply to the sender and destroy the email, its
contents, and all copies thereof immediately. Any unauthorized
dissemination, distribution or copying of this communication is
strictly prohibited.

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