Author: aadamchik
Date: Thu Sep 21 08:54:07 2006
New Revision: 448592
URL: http://svn.apache.org/viewvc?view=rev&rev=448592
Log:
CAY-660 - added support for callbacks that are done by intercepting traffic
between DD and DC.
Added:
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptor.java
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptorTst.java
Modified:
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/QueryResponse.java
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/CallbackMap.java
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptor.java
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/Artist.java
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptorTst.java
Modified:
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/QueryResponse.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/QueryResponse.java?view=diff&rev=448592&r1=448591&r2=448592
==============================================================================
---
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/QueryResponse.java
(original)
+++
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/QueryResponse.java
Thu Sep 21 08:54:07 2006
@@ -94,8 +94,9 @@
void reset();
/**
- * A utility method for quickly retrieving the first list in the response.
Note that
- * this method resets current iterator to an undefined state.
+ * A utility method for quickly retrieving the first list in the response.
Returns
+ * null if the query has no lists. Note that this method resets current
iterator to an
+ * undefined state.
*/
List firstList();
Modified:
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/CallbackMap.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/CallbackMap.java?view=diff&rev=448592&r1=448591&r2=448592
==============================================================================
---
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/CallbackMap.java
(original)
+++
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/CallbackMap.java
Thu Sep 21 08:54:07 2006
@@ -39,7 +39,7 @@
CallbackMap() {
this.callbacks = new HashMap();
}
-
+
boolean isEmpty() {
return callbacks.isEmpty();
}
@@ -48,11 +48,13 @@
addCallback(entityClass, new EntityCallback(entityClass, methodName));
}
- void addCallback(Class objectClass, String methodName, Class entityClass) {
- addCallback(entityClass, new ListenerCallback(
+ Object addCallback(Class objectClass, String methodName, Class
entityClass) {
+ ListenerCallback callback = new ListenerCallback(
objectClass,
methodName,
- entityClass));
+ entityClass);
+ addCallback(entityClass, callback);
+ return callback.getListener();
}
private void addCallback(Class entityClass, Closure callback) {
@@ -67,7 +69,7 @@
}
/**
- * Utility method applying callbacks to a collection.
+ * Utility method for applying callbacks to a single object.
*/
void applyCallbacks(Object object) {
Collection callbacks = getCallbacks(object.getClass());
@@ -76,6 +78,17 @@
while (it.hasNext()) {
((Closure) it.next()).execute(object);
}
+ }
+ }
+
+ /**
+ * Utility method for applying callbacks to a collection of objects.
+ */
+ void applyCallbacks(Collection objects) {
+ Iterator it = objects.iterator();
+ while (it.hasNext()) {
+ Object object = it.next();
+ applyCallbacks(object);
}
}
Added:
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptor.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptor.java?view=auto&rev=448592
==============================================================================
---
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptor.java
(added)
+++
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptor.java
Thu Sep 21 08:54:07 2006
@@ -0,0 +1,276 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+package org.apache.cayenne.intercept;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.QueryResponse;
+import org.apache.cayenne.graph.GraphChangeHandler;
+import org.apache.cayenne.graph.GraphDiff;
+import org.apache.cayenne.graph.GraphManager;
+import org.apache.cayenne.query.Query;
+
+/**
+ * Implements JPA-compliant "PreUpdate", "PostUpdate", "PostPersist",
"PostRemove",
+ * "PostLoad" callbacks for the DataChannel operations. Most often this
interceptor is
+ * inserted between a DataContext and its DataDomain. <p/>Depending on how
callbacks are
+ * registered, they are invoked either on the persistent object instances
themselves or on
+ * an instance of an arbitrary listener class. Signature of a method of a
persistent
+ * object is <code>"void method()"</code>, while for a non-persistent listener
it is
+ * <code>"void
+ * method(Object)"</code>.
+ *
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+public class DataChannelCallbackInterceptor extends DataChannelDecorator {
+
+ protected boolean empty;
+
+ CallbackMap preUpdate = new CallbackMap();
+ CallbackMap postUpdate = new CallbackMap();
+ CallbackMap postPersist = new CallbackMap();
+ CallbackMap postRemove = new CallbackMap();
+ CallbackMap postLoad = new CallbackMap();
+
+ public QueryResponse onQuery(ObjectContext originatingContext, Query
query) {
+ QueryResponse response = super.onQuery(originatingContext, query);
+
+ if (!postLoad.isEmpty()) {
+
+ List list = response.firstList();
+ if (list != null
+ && !list.isEmpty()
+ &&
!(query.getMetaData(originatingContext.getEntityResolver()))
+ .isFetchingDataRows()) {
+ postLoad.applyCallbacks(list);
+ }
+ }
+
+ return response;
+ }
+
+ public GraphDiff onSync(
+ ObjectContext originatingContext,
+ GraphDiff changes,
+ int syncType) {
+
+ if (isEmpty() || syncType == DataChannel.ROLLBACK_CASCADE_SYNC) {
+ return super.onSync(originatingContext, changes, syncType);
+ }
+
+ CommitState commitState = new CommitState(originatingContext, changes);
+ commitState.applyPreUpdate();
+
+ GraphDiff parentDiff = super.onSync(originatingContext, changes,
syncType);
+
+ commitState.applyPostUpdate();
+ commitState.applyPostRemove();
+ commitState.applyPostPersist();
+
+ return parentDiff;
+ }
+
+ public boolean isEmpty() {
+ return empty;
+ }
+
+ public void addPreUpdateCallback(Class entityClass, String methodName) {
+ preUpdate.addCallback(entityClass, methodName);
+ empty = false;
+ }
+
+ public Object addPreUpdateCallback(
+ Class objectClass,
+ String methodName,
+ Class entityClass) {
+
+ Object callback = preUpdate.addCallback(objectClass, methodName,
entityClass);
+ empty = false;
+ return callback;
+ }
+
+ public void addPostPersistCallback(Class entityClass, String methodName) {
+ postPersist.addCallback(entityClass, methodName);
+ empty = false;
+ }
+
+ public Object addPostPersistCallback(
+ Class objectClass,
+ String methodName,
+ Class entityClass) {
+ Object callback = postPersist.addCallback(objectClass, methodName,
entityClass);
+ empty = false;
+ return callback;
+ }
+
+ public void addPostRemoveCallback(Class entityClass, String methodName) {
+ postRemove.addCallback(entityClass, methodName);
+ empty = false;
+ }
+
+ public Object addPostRemoveCallback(
+ Class objectClass,
+ String methodName,
+ Class entityClass) {
+ Object callback = postRemove.addCallback(objectClass, methodName,
entityClass);
+ empty = false;
+ return callback;
+ }
+
+ public void addPostUpdateCallback(Class entityClass, String methodName) {
+ postUpdate.addCallback(entityClass, methodName);
+ empty = false;
+ }
+
+ public Object addPostUpdateCallback(
+ Class objectClass,
+ String methodName,
+ Class entityClass) {
+ Object callback = postUpdate.addCallback(objectClass, methodName,
entityClass);
+ empty = false;
+ return callback;
+ }
+
+ public void addPostLoadCallback(Class entityClass, String methodName) {
+ postLoad.addCallback(entityClass, methodName);
+ empty = false;
+ }
+
+ public Object addPostLoadCallback(
+ Class objectClass,
+ String methodName,
+ Class entityClass) {
+
+ Object callback = postLoad.addCallback(objectClass, methodName,
entityClass);
+ empty = false;
+ return callback;
+ }
+
+ class CommitState implements GraphChangeHandler {
+
+ private GraphManager graphManager;
+ private Collection updated;
+ private Collection persisted;
+ private Collection removed;
+ private Set seenIds;
+
+ CommitState(ObjectContext originatingContext, GraphDiff changes) {
+ this.seenIds = new HashSet();
+ this.graphManager = originatingContext.getGraphManager();
+ changes.apply(this);
+ }
+
+ void applyPreUpdate() {
+ if (updated != null && !preUpdate.isEmpty()) {
+ preUpdate.applyCallbacks(updated);
+ }
+ }
+
+ void applyPostUpdate() {
+ if (updated != null && !postUpdate.isEmpty()) {
+ postUpdate.applyCallbacks(updated);
+ }
+ }
+
+ void applyPostPersist() {
+ if (persisted != null && !postPersist.isEmpty()) {
+ postPersist.applyCallbacks(persisted);
+ }
+ }
+
+ void applyPostRemove() {
+ if (removed != null && !postRemove.isEmpty()) {
+ postRemove.applyCallbacks(removed);
+ }
+ }
+
+ public void nodeCreated(Object nodeId) {
+ if (seenIds.add(nodeId)) {
+
+ Object node = graphManager.getNode(nodeId);
+ if (node != null) {
+
+ if (persisted == null) {
+ persisted = new ArrayList();
+ }
+
+ persisted.add(node);
+ }
+ }
+ }
+
+ public void nodeRemoved(Object nodeId) {
+ if (seenIds.add(nodeId)) {
+
+ Object node = graphManager.getNode(nodeId);
+ if (node != null) {
+
+ if (removed == null) {
+ removed = new ArrayList();
+ }
+
+ removed.add(node);
+ }
+ }
+ }
+
+ public void arcCreated(Object nodeId, Object targetNodeId, Object
arcId) {
+ // TODO: andrus, 9/21/2006 - should we register to-many
relationship updates?
+ nodeUpdated(nodeId);
+ }
+
+ public void arcDeleted(Object nodeId, Object targetNodeId, Object
arcId) {
+ // TODO: andrus, 9/21/2006 - should we register to-many
relationship updates?
+ nodeUpdated(nodeId);
+ }
+
+ public void nodeIdChanged(Object nodeId, Object newId) {
+ }
+
+ public void nodePropertyChanged(
+ Object nodeId,
+ String property,
+ Object oldValue,
+ Object newValue) {
+ nodeUpdated(nodeId);
+ }
+
+ private void nodeUpdated(Object nodeId) {
+ if (seenIds.add(nodeId)) {
+
+ Object node = graphManager.getNode(nodeId);
+ if (node != null) {
+
+ if (updated == null) {
+ updated = new ArrayList();
+ }
+
+ updated.add(node);
+ }
+ }
+ }
+ }
+}
Modified:
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptor.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptor.java?view=diff&rev=448592&r1=448591&r2=448592
==============================================================================
---
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptor.java
(original)
+++
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptor.java
Thu Sep 21 08:54:07 2006
@@ -31,11 +31,11 @@
/**
* Implements JPA-compliant "PrePersist", "PreRemove" callbacks for the
ObjectContext
- * operations. Callbacks can be invoked either on the persistent object
instances
- * themselves or on an instance of an arbitrary class. Signature of a method
of a
- * persistent object is {code}"void method()"{code}, while for a
non-persistent object it
- * is {code}"void method(Object)"{code}. Note that if a new object is later
removed,
- * "PrePersist" callbacks will be invoked, while "PreRemove" will not.
+ * operations. <p/>Depending on how callbacks are registered, they are invoked
either on
+ * the persistent object instances themselves or on an instance of an
arbitrary listener
+ * class. Signature of a method of a persistent object is <code>"void
method()"</code>,
+ * while for a non-persistent listener it is <code>"void
+ * method(Object)"</code>.
*
* @since 3.0
* @author Andrus Adamchik
@@ -69,23 +69,23 @@
prePersist.addCallback(entityClass, methodName);
}
- public void addPrePersistCallback(
+ public Object addPrePersistCallback(
Class objectClass,
String methodName,
Class entityClass) {
- prePersist.addCallback(objectClass, methodName, entityClass);
+ return prePersist.addCallback(objectClass, methodName, entityClass);
}
public void addPreRemoveCallback(Class entityClass, String methodName) {
preRemove.addCallback(entityClass, methodName);
}
- public void addPreRemoveCallback(
+ public Object addPreRemoveCallback(
Class objectClass,
String methodName,
Class entityClass) {
- preRemove.addCallback(objectClass, methodName, entityClass);
+ return preRemove.addCallback(objectClass, methodName, entityClass);
}
/**
Modified:
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/Artist.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/Artist.java?view=diff&rev=448592&r1=448591&r2=448592
==============================================================================
---
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/Artist.java
(original)
+++
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/Artist.java
Thu Sep 21 08:54:07 2006
@@ -9,6 +9,10 @@
protected boolean prePersisted;
protected boolean preRemoved;
protected boolean preUpdated;
+ protected boolean postUpdated;
+ protected boolean postRemoved;
+ protected boolean postPersisted;
+ protected boolean postLoaded;
public boolean isValidateForSaveCalled() {
return validateForSaveCalled;
@@ -22,6 +26,10 @@
prePersisted = false;
preRemoved = false;
preUpdated = false;
+ postUpdated = false;
+ postRemoved = false;
+ postPersisted = false;
+ postLoaded = false;
}
public void validateForSave(ValidationResult validationResult) {
@@ -32,15 +40,31 @@
public void prePersistCallback() {
prePersisted = true;
}
-
+
public void preRemoveCallback() {
preRemoved = true;
}
-
+
public void preUpdateCallback() {
preUpdated = true;
}
+ public void postUpdateCallback() {
+ postUpdated = true;
+ }
+
+ public void postPersistCallback() {
+ postPersisted = true;
+ }
+
+ public void postRemoveCallback() {
+ postRemoved = true;
+ }
+
+ public void postLoadCallback() {
+ postLoaded = true;
+ }
+
public boolean isPrePersisted() {
return prePersisted;
}
@@ -51,5 +75,21 @@
public boolean isPreUpdated() {
return preUpdated;
+ }
+
+ public boolean isPostUpdated() {
+ return postUpdated;
+ }
+
+ public boolean isPostRemoved() {
+ return postRemoved;
+ }
+
+ public boolean isPostPersisted() {
+ return postPersisted;
+ }
+
+ public boolean isPostLoaded() {
+ return postLoaded;
}
}
Added:
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptorTst.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptorTst.java?view=auto&rev=448592
==============================================================================
---
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptorTst.java
(added)
+++
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptorTst.java
Thu Sep 21 08:54:07 2006
@@ -0,0 +1,159 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+package org.apache.cayenne.intercept;
+
+import org.apache.art.Artist;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.access.ObjectStore;
+import org.apache.cayenne.unit.CayenneTestCase;
+
+public class DataChannelCallbackInterceptorTst extends CayenneTestCase {
+
+ public void testPreUpdate() {
+
+ DataChannelCallbackInterceptor i = new
DataChannelCallbackInterceptor();
+ i.setChannel(getDomain());
+
+ ObjectContext context = new DataContext(i, new ObjectStore(getDomain()
+ .getSharedSnapshotCache()));
+
+ Artist a1 = (Artist) context.newObject(Artist.class);
+ a1.setArtistName("XX");
+ context.commitChanges();
+ assertFalse(a1.isPreUpdated());
+
+ a1.setArtistName("YY");
+ context.commitChanges();
+ assertFalse(a1.isPreUpdated());
+
+ i.addPreUpdateCallback(Artist.class, "preUpdateCallback");
+ a1.setArtistName("ZZ");
+ context.commitChanges();
+ assertTrue(a1.isPreUpdated());
+
+ a1.resetCallbackFlags();
+ assertFalse(a1.isPreUpdated());
+
+ MockCallingBackListener listener2 = (MockCallingBackListener) i
+ .addPreUpdateCallback(
+ MockCallingBackListener.class,
+ "publicCallback",
+ Artist.class);
+
+ a1.setArtistName("AA");
+ context.commitChanges();
+
+ assertTrue(a1.isPreUpdated());
+ assertSame(a1, listener2.publicCalledbackEntity);
+ }
+
+ public void testPostUpdate() {
+
+ DataChannelCallbackInterceptor i = new
DataChannelCallbackInterceptor();
+ i.setChannel(getDomain());
+
+ ObjectContext context = new DataContext(i, new ObjectStore(getDomain()
+ .getSharedSnapshotCache()));
+
+ Artist a1 = (Artist) context.newObject(Artist.class);
+ a1.setArtistName("XX");
+ context.commitChanges();
+ assertFalse(a1.isPostUpdated());
+
+ a1.setArtistName("YY");
+ context.commitChanges();
+ assertFalse(a1.isPostUpdated());
+
+ i.addPostUpdateCallback(Artist.class, "postUpdateCallback");
+ a1.setArtistName("ZZ");
+ context.commitChanges();
+ assertTrue(a1.isPostUpdated());
+
+ a1.resetCallbackFlags();
+ assertFalse(a1.isPostUpdated());
+
+ MockCallingBackListener listener2 = (MockCallingBackListener) i
+ .addPostUpdateCallback(
+ MockCallingBackListener.class,
+ "publicCallback",
+ Artist.class);
+
+ a1.setArtistName("AA");
+ context.commitChanges();
+
+ assertTrue(a1.isPostUpdated());
+ assertSame(a1, listener2.publicCalledbackEntity);
+ }
+
+ public void testPostRemove() {
+
+ DataChannelCallbackInterceptor i = new
DataChannelCallbackInterceptor();
+ i.setChannel(getDomain());
+
+ ObjectContext context = new DataContext(i, new ObjectStore(getDomain()
+ .getSharedSnapshotCache()));
+
+ Artist a1 = (Artist) context.newObject(Artist.class);
+ a1.setArtistName("XX");
+ context.commitChanges();
+
+ i.addPostRemoveCallback(Artist.class, "postRemoveCallback");
+ MockCallingBackListener listener2 = (MockCallingBackListener) i
+ .addPostRemoveCallback(
+ MockCallingBackListener.class,
+ "publicCallback",
+ Artist.class);
+
+ context.deleteObject(a1);
+ context.commitChanges();
+
+ assertTrue(a1.isPostRemoved());
+ assertSame(a1, listener2.publicCalledbackEntity);
+ }
+
+ public void testPostPersist() {
+
+ DataChannelCallbackInterceptor i = new
DataChannelCallbackInterceptor();
+ i.setChannel(getDomain());
+
+ ObjectContext context = new DataContext(i, new ObjectStore(getDomain()
+ .getSharedSnapshotCache()));
+
+ Artist a1 = (Artist) context.newObject(Artist.class);
+ a1.setArtistName("XX");
+ context.commitChanges();
+ assertFalse(a1.isPostPersisted());
+
+ i.addPostPersistCallback(Artist.class, "postPersistCallback");
+ MockCallingBackListener listener2 = (MockCallingBackListener) i
+ .addPostPersistCallback(
+ MockCallingBackListener.class,
+ "publicCallback",
+ Artist.class);
+
+ Artist a2 = (Artist) context.newObject(Artist.class);
+ a2.setArtistName("XX");
+ context.commitChanges();
+
+ assertFalse(a1.isPostPersisted());
+ assertTrue(a2.isPostPersisted());
+ assertSame(a2, listener2.publicCalledbackEntity);
+ }
+}
Modified:
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptorTst.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptorTst.java?view=diff&rev=448592&r1=448591&r2=448592
==============================================================================
---
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptorTst.java
(original)
+++
incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptorTst.java
Thu Sep 21 08:54:07 2006
@@ -18,9 +18,6 @@
****************************************************************/
package org.apache.cayenne.intercept;
-import java.util.Collection;
-import java.util.Iterator;
-
import org.apache.art.Artist;
import org.apache.art.Painting;
import org.apache.cayenne.unit.CayenneTestCase;
@@ -46,24 +43,16 @@
assertNotNull(a2);
assertTrue(a2.isPrePersisted());
- i.addPrePersistCallback(
- MockCallingBackListener.class,
- "publicCallback",
- Artist.class);
+ MockCallingBackListener listener2 = (MockCallingBackListener) i
+ .addPrePersistCallback(
+ MockCallingBackListener.class,
+ "publicCallback",
+ Artist.class);
Artist a3 = (Artist) i.newObject(Artist.class);
assertNotNull(a3);
assertTrue(a3.isPrePersisted());
- Collection prepersist = i.prePersist.getCallbacks(Artist.class);
- assertNotNull(prepersist);
- assertEquals(2, prepersist.size());
-
- Iterator it = prepersist.iterator();
- it.next();
- ListenerCallback callback2 = (ListenerCallback) it.next();
- MockCallingBackListener listener2 = (MockCallingBackListener) callback2
- .getListener();
assertSame(a3, listener2.publicCalledbackEntity);
Painting p3 = (Painting) i.newObject(Painting.class);
@@ -93,10 +82,11 @@
assertFalse(a2.isPrePersisted());
assertTrue(a2.isPreRemoved());
- i.addPreRemoveCallback(
- MockCallingBackListener.class,
- "publicCallback",
- Artist.class);
+ MockCallingBackListener listener2 = (MockCallingBackListener) i
+ .addPreRemoveCallback(
+ MockCallingBackListener.class,
+ "publicCallback",
+ Artist.class);
Artist a3 = (Artist) i.newObject(Artist.class);
a3.setArtistName("XX");
@@ -105,15 +95,6 @@
assertFalse(a3.isPrePersisted());
assertTrue(a3.isPreRemoved());
- Collection preremove = i.preRemove.getCallbacks(Artist.class);
- assertNotNull(preremove);
- assertEquals(2, preremove.size());
-
- Iterator it = preremove.iterator();
- it.next();
- ListenerCallback callback2 = (ListenerCallback) it.next();
- MockCallingBackListener listener2 = (MockCallingBackListener) callback2
- .getListener();
assertSame(a3, listener2.publicCalledbackEntity);
Painting p3 = (Painting) i.newObject(Painting.class);