You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by "Thomas Fox (Created) (JIRA)" <ji...@apache.org> on 2012/02/25 15:31:48 UTC

[jira] [Created] (TORQUE-182) Additional methods for handling associated objects

Additional methods for handling associated objects
--------------------------------------------------

                 Key: TORQUE-182
                 URL: https://issues.apache.org/jira/browse/TORQUE-182
             Project: Torque
          Issue Type: New Feature
            Reporter: Thomas Fox
            Assignee: Thomas Fox


Assuming complexObjectModel=true and objectIsCaching=true (the default settings for generation)
Consider a table (book) having a foreign key on another table (author).
Couurently, in the Author object, the method addBook() is implemented, by which a book can be associated with the author and which adds it to the collection obtained by getBooks(). These books are also saved when the author object is saved.

However, there are no methods by which associations can be removed, an associated book can be deleted or all associated books can be deleted.
It would be nice if one could do these operations on an object level and these operations would be written to the database on save().
The first possibility to implement this would be to generate methods removeBook(), deleteBook() and deleteAllBooks().
The other possibility would be to use a custom list object which intercepts the calls to the add(), remove() etc methods and translates these operations to database operations (with the problem that remove() can be interpreted as removing the association as well as deleting the associated object, my preference being the latter)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

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


[jira] [Commented] (TORQUE-182) Additional methods for handling associated objects

Posted by "Thomas Fox (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/TORQUE-182?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13216484#comment-13216484 ] 

Thomas Fox commented on TORQUE-182:
-----------------------------------

Thinking further on it, the use case I encounter most in practice is to ascertain that the associated books consist of a given set.
So, given a random collection of books (newAssociatedBooks), I would like to call author.setBooks(newAssociatedBooks) and expect the following is done
- delete all books which are currently associated to the author in the database and are not in newAssociatedBooks
- update all books which are currently associated to the author in the database and are in newAssociatedBooks to the book values in newAssociatedBooks
- insert all books which are currently not associated to the author in the database and are in newAssociatedBooks to the book values in newAssociatedBooks
- fill the collection which is returned by author.getBooks() by the books in newAssociatedBooks
                
> Additional methods for handling associated objects
> --------------------------------------------------
>
>                 Key: TORQUE-182
>                 URL: https://issues.apache.org/jira/browse/TORQUE-182
>             Project: Torque
>          Issue Type: New Feature
>            Reporter: Thomas Fox
>            Assignee: Thomas Fox
>
> Assuming complexObjectModel=true and objectIsCaching=true (the default settings for generation)
> Consider a table (book) having a foreign key on another table (author).
> Couurently, in the Author object, the method addBook() is implemented, by which a book can be associated with the author and which adds it to the collection obtained by getBooks(). These books are also saved when the author object is saved.
> However, there are no methods by which associations can be removed, an associated book can be deleted or all associated books can be deleted.
> It would be nice if one could do these operations on an object level and these operations would be written to the database on save().
> The first possibility to implement this would be to generate methods removeBook(), deleteBook() and deleteAllBooks().
> The other possibility would be to use a custom list object which intercepts the calls to the add(), remove() etc methods and translates these operations to database operations (with the problem that remove() can be interpreted as removing the association as well as deleting the associated object, my preference being the latter)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

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


[jira] [Resolved] (TORQUE-182) Additional methods for handling associated objects

Posted by "Thomas Fox (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/TORQUE-182?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas Fox resolved TORQUE-182.
-------------------------------

       Resolution: Fixed
    Fix Version/s: 4.0
    
> Additional methods for handling associated objects
> --------------------------------------------------
>
>                 Key: TORQUE-182
>                 URL: https://issues.apache.org/jira/browse/TORQUE-182
>             Project: Torque
>          Issue Type: New Feature
>            Reporter: Thomas Fox
>            Assignee: Thomas Fox
>             Fix For: 4.0
>
>
> Assuming complexObjectModel=true and objectIsCaching=true (the default settings for generation)
> Consider a table (book) having a foreign key on another table (author).
> Couurently, in the Author object, the method addBook() is implemented, by which a book can be associated with the author and which adds it to the collection obtained by getBooks(). These books are also saved when the author object is saved.
> However, there are no methods by which associations can be removed, an associated book can be deleted or all associated books can be deleted.
> It would be nice if one could do these operations on an object level and these operations would be written to the database on save().
> The first possibility to implement this would be to generate methods removeBook(), deleteBook() and deleteAllBooks().
> The other possibility would be to use a custom list object which intercepts the calls to the add(), remove() etc methods and translates these operations to database operations (with the problem that remove() can be interpreted as removing the association as well as deleting the associated object, my preference being the latter)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

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


[jira] [Commented] (TORQUE-182) Additional methods for handling associated objects

Posted by "Thomas Fox (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/TORQUE-182?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13467459#comment-13467459 ] 

Thomas Fox commented on TORQUE-182:
-----------------------------------

So there should be a new method e.g. author.setAndSaveBooks(Collection<Book> newAssociatedBooks) 
Saving amkes sense because deletion of other objects also happens during the method.

There might be the following special cases to consider for the delete part
- singular primary key: The delete can be done like "delete from book where author_id=? and book_id not in (?,...?);
- composite primary key (e.g. in m:n association table). The deletes must be done like  "delete from book where author_id=? and not ((book_pk1=?and book_pk2=?) or (book_pk1=? and book_pk2=) or ...)
- no primary key or primary key disregarded (e.g. by boolean flag): delete like composite primary key but with value attrs instead of pk attrs

Updating/saving is done by loading all remaining associated objects and comparing them to the newAssociatedBooks.
Either by pk values or by value attrs, depending whether pk exists and is not disregarded. If a equivalent object is found in both lists, the modified flag and the new flag must be set in the newAssociatedBooks entry accordingly.
Perhaps there should be also a forceSave mode which saves all associated objects, regardless whether they are modified or not (note that loading is still necessary for that, to decide between update and insert)

                
> Additional methods for handling associated objects
> --------------------------------------------------
>
>                 Key: TORQUE-182
>                 URL: https://issues.apache.org/jira/browse/TORQUE-182
>             Project: Torque
>          Issue Type: New Feature
>            Reporter: Thomas Fox
>            Assignee: Thomas Fox
>
> Assuming complexObjectModel=true and objectIsCaching=true (the default settings for generation)
> Consider a table (book) having a foreign key on another table (author).
> Couurently, in the Author object, the method addBook() is implemented, by which a book can be associated with the author and which adds it to the collection obtained by getBooks(). These books are also saved when the author object is saved.
> However, there are no methods by which associations can be removed, an associated book can be deleted or all associated books can be deleted.
> It would be nice if one could do these operations on an object level and these operations would be written to the database on save().
> The first possibility to implement this would be to generate methods removeBook(), deleteBook() and deleteAllBooks().
> The other possibility would be to use a custom list object which intercepts the calls to the add(), remove() etc methods and translates these operations to database operations (with the problem that remove() can be interpreted as removing the association as well as deleting the associated object, my preference being the latter)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

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


[jira] [Commented] (TORQUE-182) Additional methods for handling associated objects

Posted by "CG Monroe (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/TORQUE-182?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13217237#comment-13217237 ] 

CG Monroe commented on TORQUE-182:
----------------------------------

I think this should be done either as a set of new methods rather than automatically doing this on save.  

Just because something is related does not mean there is automatically a one to one relationship.  So, deleting the related information automatically and by default is not a good thing IMHO.

For instance, take the case of an object that maps a user to application permissions.  If you delete or modify the user mapping, you don't want to automatically delete the permission records, since there are used by multiple other users and application tables.

If you are going to do a "cascade" delete, it should be clear in the code that this is happening.  Just like in a DB schema, you can decide exactly where this happens.
                
> Additional methods for handling associated objects
> --------------------------------------------------
>
>                 Key: TORQUE-182
>                 URL: https://issues.apache.org/jira/browse/TORQUE-182
>             Project: Torque
>          Issue Type: New Feature
>            Reporter: Thomas Fox
>            Assignee: Thomas Fox
>
> Assuming complexObjectModel=true and objectIsCaching=true (the default settings for generation)
> Consider a table (book) having a foreign key on another table (author).
> Couurently, in the Author object, the method addBook() is implemented, by which a book can be associated with the author and which adds it to the collection obtained by getBooks(). These books are also saved when the author object is saved.
> However, there are no methods by which associations can be removed, an associated book can be deleted or all associated books can be deleted.
> It would be nice if one could do these operations on an object level and these operations would be written to the database on save().
> The first possibility to implement this would be to generate methods removeBook(), deleteBook() and deleteAllBooks().
> The other possibility would be to use a custom list object which intercepts the calls to the add(), remove() etc methods and translates these operations to database operations (with the problem that remove() can be interpreted as removing the association as well as deleting the associated object, my preference being the latter)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

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