The documentation says that transactions can only be done within a
single entity group. Does this mean the tr tansaction in the
'removeMessage', is not safe?
In the following code, I need to break the link between the parent and
the child, ie by removing the child, and re-inserting it with no
parent. Perhaps what I am doing is crazy? (:
// Not meant to compile, it is for example only
public class UndeliveredMessages {
private Key key;
private long count = 0;
private Set<Message> messages = HashSet<Message>();
public void removeMessage(Message message) {
Transaction tx = pm.currentTransaction();
try {
count--;
messages.remove(message);
pm.makePersistent(this);
Message item = new Message();
item.setFrom(message.getFrom());
item.setTo(message.getTo());
item.setText(message.getText());
pm.makePersistent(message); // If this one fails,
will all of the above be rolled back?
tx.commit();
} finally {
if (tx.isActive())
tx.rollback();
}
}
public void addMessage(String from, String to, String message) {
count++;
messages.put(new Message(from, to, message));
pm.makePersistent();
}
public Message getNextMessage() {
if(!messages.isEmpty())
return messages.iterator().next();
return null;
}
}
This is a contrived example to help me understand if this will work. I
realise/suspect I could use "weak" references, ie just store a set of
references to the child objects, ie "Set<Key>".
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.