I am trying to remove an object from the datastore and I want to know
if my approach can be made to work with transactions.

I have a collection of entities that all participate in owned
relationships. However, one entity has an unowned collection of keys
that refer to another entity.

Here is the basic structure:
EmailList owns DirectContacts (1 to M)
EmailList owns IndirectContactLists (1 to M)
IndirectContactList owns IndirectContacts (1 to M)
DirectContact has an unowned collection of keys of IndirectContacts
(because an entity can only have one parent)

If I grab an IndirectContactList from the datastore and get the owning
EmailList and then proceed to traverse through the EmailList's
DirectContacts and remove the key of the IndirectContacts can I do
this within the context of a transaction? Here is a code snippet
without transactions:

//used to interact with the datastore
//create the entity manager
EntityManager em = EMF.get().createEntityManager();

try
{
        //get the indirect contact list from the datastore
        IndirectContactList icl = em.find(IndirectContactList.class,
keyOfIndirectContactList);

        //if the requested icl was in the datastore
        if(icl != null)
        {
                //get the email list from the icl
                EmailList eml = icl.getOwningEmailList();

                //get the direct contacts from the email list
                for(DirectContactEmail dce : eml.getDirectContactEmails())
                {
                        //go through the indirect contacts in the icl
                        for(IndirectContactEmail ice : 
icl.getIndirectContactEmails())
                        {
                                //now remove the key of the indirect contact 
from the
                                //direct contact (if it is there)
                                
dce.getKeysOfIndirectContactEmails().remove(ice.getId());

                                //is it possible to do all of this in a 
transaction?
                                //if not, would grabbing the email list first 
make it
                                //possible? Or, is there no way to guarantee 
removal
                                //of the unowned keys along with the icl
                        }
                }

                //remove the indirect contact list and all owned indirect 
contact
emails
                em.remove(icl);
        }
        else
        {
                throw new IndirectContactListDoesNotExistException();
        }
}
finally
{
        em.close();
}


Can I add transaction code and expect that removing the unowned keys
will succeed/fail along with the removal of the indirect contact list?

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to