You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cayenne.apache.org by "Marcin Skladaniec (JIRA)" <ji...@apache.org> on 2006/05/14 10:35:35 UTC
[JIRA] Created: (CAY-547) Deleting new objects leaves null object
in context.
Deleting new objects leaves null object in context.
---------------------------------------------------
Key: CAY-547
URL: http://issues.apache.org/cayenne/browse/CAY-547
Project: Cayenne
Type: Bug
Components: Cayenne Core Library
Versions: 1.2 [BETA]
Environment: Cayenne 3t.
Reporter: Marcin Skladaniec
Priority: Minor
to reproduce this bug:
Persistent someObject = (Persistent) context.newObject(someClass);
context.deleteObject(someObject);
Collection collection = context.uncommittedObjects();
collection will contain a null object.
The reason of that is that there are two references to (persistent) objects in context kept at all times. One is in GraphMap, and second is in GraphMap subclass CayenneContextGraphManager in stateLog field.
I have not found that GraphMap is used to keep reference to all PersistentObjects in context as a whole objects.
CayenneContextGraphManager is used rather for keeping atomic changes, and later for sending only those to the server. From what I found it looks like there is no mechanism for removing those atomic changes from stateLog. It is very simple, when object is created/modified/deleted it has to affect the database, so after any operation objectId is added to dirtyNodes. But there is one case when this behaviour is not right, that is when reverting some changes, like deleting a new object.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/cayenne/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
Re: [JIRA] Created: (CAY-547) Deleting new objects leaves null object in context.
Posted by Marcin Skladaniec <po...@gmail.com>.
Hello !
I would like to propose fix for this bug. This is a svn diff from my working
copy:
Index:
cayenne-java/src/cayenne/java/org/objectstyle/cayenne/ObjectContextStateLog.java
===================================================================
---
cayenne-java/src/cayenne/java/org/objectstyle/cayenne/ObjectContextStateLog.java
(revision 406077)
+++
cayenne-java/src/cayenne/java/org/objectstyle/cayenne/ObjectContextStateLog.java
(working copy)
@@ -180,8 +180,19 @@
dirtyIds.add(nodeId);
}
+
+ /**
+ * When deleting a persistent object add it to dirtyIds,
+ * when deleting a new object there is no need to keep reference to it
anymore
+ * (ObjectContextDeleteAction sets NEW object state to TRANSIENT state
before processing delete rules)
+ */
public void nodeRemoved(Object nodeId) {
- dirtyIds.add(nodeId);
+ if
(((Persistent)graphManager.getNode(nodeId)).getPersistenceState() ==
PersistenceState.NEW ||
+
((Persistent)graphManager.getNode(nodeId)).getPersistenceState() ==
PersistenceState.TRANSIENT) {
+ dirtyIds.remove(nodeId);
+ } else {
+ dirtyIds.add(nodeId);
+ }
}
public void nodePropertyChanged(
Index:
cayenne-java/src/cayenne/java/org/objectstyle/cayenne/ObjectContextDeleteAction.java
===================================================================
---
cayenne-java/src/cayenne/java/org/objectstyle/cayenne/ObjectContextDeleteAction.java
(revision 406077)
+++
cayenne-java/src/cayenne/java/org/objectstyle/cayenne/ObjectContextDeleteAction.java
(working copy)
@@ -119,6 +119,7 @@
private void deleteNew(Persistent object) {
object.setPersistenceState(PersistenceState.TRANSIENT);
processDeleteRules(object, PersistenceState.NEW);
+ context.getGraphManager().nodeRemoved(object.getObjectId());
context.getGraphManager().unregisterNode(object.getObjectId());
}
I have tested it on my test project. I tried to use junit tests, but I had
some problems runnig them.
Cheers
Marcin.
On 5/14/06, Marcin Skladaniec (JIRA) <ji...@apache.org> wrote:
>
> Deleting new objects leaves null object in context.
> ---------------------------------------------------
>
> Key: CAY-547
> URL: http://issues.apache.org/cayenne/browse/CAY-547
> Project: Cayenne
> Type: Bug
>
> Components: Cayenne Core Library
> Versions: 1.2 [BETA]
> Environment: Cayenne 3t.
> Reporter: Marcin Skladaniec
> Priority: Minor
>
>
> to reproduce this bug:
>
> Persistent someObject = (Persistent) context.newObject(someClass);
> context.deleteObject(someObject);
> Collection collection = context.uncommittedObjects();
>
> collection will contain a null object.
>
> The reason of that is that there are two references to (persistent)
> objects in context kept at all times. One is in GraphMap, and second is in
> GraphMap subclass CayenneContextGraphManager in stateLog field.
> I have not found that GraphMap is used to keep reference to all
> PersistentObjects in context as a whole objects.
> CayenneContextGraphManager is used rather for keeping atomic changes, and
> later for sending only those to the server. From what I found it looks like
> there is no mechanism for removing those atomic changes from stateLog. It is
> very simple, when object is created/modified/deleted it has to affect the
> database, so after any operation objectId is added to dirtyNodes. But there
> is one case when this behaviour is not right, that is when reverting some
> changes, like deleting a new object.
>
>
>
> --
> This message is automatically generated by JIRA.
> -
> If you think it was sent incorrectly contact one of the administrators:
> http://issues.apache.org/cayenne/secure/Administrators.jspa
> -
> For more information on JIRA, see:
> http://www.atlassian.com/software/jira
>
>