Hello !
On 10/05/2006, at 12:53 PM, Marcin Skladaniec wrote:
Hello
I think someone already asked about that, but I cant find this post.
I have a problem with removing objects from context. I tried :
CayenneContext context = new CayenneContext(channel, true,
true);
CSite site = (CSite) context.newObject(CSite.class);
context.getGraphManager().unregisterNode(site);
but the object is still in the context (it is still in getContext
().uncommittedObjects() list ).
I was wrong. I shall do context.getGraphManager().unregisterNode
(site.getObjectId()); and now it works.
but the second part is still a problem
if I do
CayenneContext context = new CayenneContext(channel, true,
true);
CSite site = (CSite) context.newObject(CSite.class);
context.deleteObject(site);
there is a null object in context, so I feel like I'm hitting some
bug. I started to browse code (Its good to have access to
repository again !).
I have noticed that in ObjectContextDeleteAction there is a
deleteNew method which makes a call to
context.getGraphManager().unregisterNode(object.getObjectId());
so I followed it futher to GraphMap and CayenneContextGraphManager
and I realized that the latter does not pay attention to
unregisterNode(), and therefore stateLog which keeps dirtyIds is
not updated.
I have taken a second look at CayenneContextGraphManager and
GraphMap. Why there are two locations where nodes are being stored ?
One is in GraphMap as nodes, and the second is in
CayenneContextGraphManager in stateLog. (It looks like the stateLog
is more important)
In the ObjectContextDeleteAction there are separate methods for
deleting !(NEW) and NEW objects :
private void deletePersistent(Persistent object) {
int oldState = object.getPersistenceState();
object.setPersistenceState(PersistenceState.DELETED);
processDeleteRules(object, oldState);
context.getGraphManager().nodeRemoved(object.getObjectId());
}
private void deleteNew(Persistent object) {
object.setPersistenceState(PersistenceState.TRANSIENT);
processDeleteRules(object, PersistenceState.NEW);
context.getGraphManager().unregisterNode(object.getObjectId());
}
I believe that the last line shall in both method should be the same,
because now those methods are affecting different lists of nodes.
unregisterNode has no impact on list which returned by
uncommitedObjects() method, so I believe this is causing the phantom
object to be committed. Now I have tried it, the phantom object is
committed to the database.
Beside, the anonymous svn access to cayenne repository does not work.
Clicking on http://svn.apache.org/repos/asf/incubator/cayenne/main/
trunk/cayenne/ gives ' (111) Connection refused '
Regards
Marcin
-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001 fax +61 2 9550 4001
-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001 fax +61 2 9550 4001