db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vitzethum, Daniel" <Daniel.Vitzet...@gigatronik.com>
Subject save an object tree / bug concerning the MODIFIED-flag
Date Tue, 14 Sep 2004 16:23:18 GMT
Hello,

my name is Daniel. I have just joined the list to ask one
or two related questions:

I would appreciate if Torque saved an object tree for me -
e.g. I have a Book with two Authors and want to call

 book.addAuthor(a1);
 book.addAuthor(a2);
 BookPeer.doSave(book);    // should insert or update the book and both
authors

For this purpose, and as it seems that this feature is not
implemented in Torque, I wrote the doSave(Book) method in BookPeer,
like this:

 public static void doSave(Book book) throws TorqueException {
    if (matchEinzel.isNew()) {
        BookPeer.doInsert(book);
    } else {
        if (book.isModified()) {
            BookPeer.doUpdate(matchEinzel);
        }
    }
    ObjectKey key = book.getPrimaryKey();
    List authors = book.collAuthors;
    
    // do the same for a List of author objects...
    doSaveAuthors(key, authors);
 }

That works quite well, but when I read a simple object from
DB and call the doSave() on it immediately, the object has
"true" as it's modified flag, what results in an (unwanted)
update in the above doSave()-method:

 Book oldBook = BookPeer.retrieveByPK(123);
 BookPeer.doSave(oldBook);    // performs an Update!


This can be fixed by overriding a BasePeer's method
row2Object(Record, int, Class) like this - what I don't want
to do for any generated class, as you may have guessed... ;-)

 public static Book row2Object(Record row, int offset, Class cls)
 throws TorqueException
 {
    Book obj = BaseBookPeer.row2Object(row, offset, cls);
    obj.setModified(false);
    return obj;
 }

So, finally my 2 questions:
- Did I miss a Torque feature that saves an object tree for me?
- Isn't it just wrong that a row being read freshly from DB has
  the modified-flag set to true?


Greetings from Munich, Germany,

Daniel

---------------------------------------------------------------------
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