You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2006/11/26 04:50:53 UTC
svn commit: r479265 - in
/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo:
BlockingDataChannel.java ItestSetup.java PojoContextCase.java
Author: aadamchik
Date: Sat Nov 25 19:50:52 2006
New Revision: 479265
URL: http://svn.apache.org/viewvc?view=rev&rev=479265
Log:
support for blocking a DataChannel queries for an ObjectContext
Added:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/BlockingDataChannel.java
Modified:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/ItestSetup.java
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/PojoContextCase.java
Added: incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/BlockingDataChannel.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/BlockingDataChannel.java?view=auto&rev=479265
==============================================================================
--- incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/BlockingDataChannel.java (added)
+++ incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/BlockingDataChannel.java Sat Nov 25 19:50:52 2006
@@ -0,0 +1,71 @@
+/*****************************************************************
+ * 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.itest.pojo;
+
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.QueryResponse;
+import org.apache.cayenne.event.EventManager;
+import org.apache.cayenne.graph.GraphDiff;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.query.Query;
+
+/**
+ * A DataChannel that throws on all query or update attempts.
+ *
+ * @author Andrus Adamchik
+ */
+class BlockingDataChannel implements DataChannel {
+
+ protected DataChannel channel;
+
+ BlockingDataChannel(DataChannel channel) {
+ this.channel = channel;
+ }
+
+ /**
+ * Returns the first DataChannel that is not a blocking DataChannel in the channel
+ * chain.
+ */
+ public DataChannel getChannel() {
+ return (channel instanceof BlockingDataChannel) ? ((BlockingDataChannel) channel)
+ .getChannel() : channel;
+ }
+
+ public EntityResolver getEntityResolver() {
+ return channel.getEntityResolver();
+ }
+
+ public EventManager getEventManager() {
+ return channel.getEventManager();
+ }
+
+ public QueryResponse onQuery(ObjectContext originatingContext, Query query) {
+ throw new CayenneRuntimeException("Queries are not allowed. Attempted query: "
+ + query);
+ }
+
+ public GraphDiff onSync(
+ ObjectContext originatingContext,
+ GraphDiff changes,
+ int syncType) {
+ throw new CayenneRuntimeException("Commits are not allowed.");
+ }
+}
Modified: incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/ItestSetup.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/ItestSetup.java?view=diff&rev=479265&r1=479264&r2=479265
==============================================================================
--- incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/ItestSetup.java (original)
+++ incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/ItestSetup.java Sat Nov 25 19:50:52 2006
@@ -24,7 +24,7 @@
import org.apache.cayenne.CayenneRuntimeException;
import org.apache.cayenne.DataChannel;
-import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.access.DataContext;
import org.apache.cayenne.access.DataDomain;
import org.apache.cayenne.access.DataNode;
import org.apache.cayenne.access.DbGenerator;
@@ -77,7 +77,7 @@
return domain;
}
- public ObjectContext createObjectContext() {
+ public DataContext createDataContext() {
return domain.createDataContext();
}
Modified: incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/PojoContextCase.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/PojoContextCase.java?view=diff&rev=479265&r1=479264&r2=479265
==============================================================================
--- incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/PojoContextCase.java (original)
+++ incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/PojoContextCase.java Sat Nov 25 19:50:52 2006
@@ -18,22 +18,34 @@
****************************************************************/
package org.apache.cayenne.itest.pojo;
+import org.apache.cayenne.DataChannel;
import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.access.DataContext;
public class PojoContextCase extends PojoTestCase {
- protected ObjectContext context;
+ protected DataContext context;
@Override
protected void setUp() throws Exception {
- this.context = ItestSetup.getInstance().createObjectContext();
+ this.context = ItestSetup.getInstance().createDataContext();
}
public ObjectContext getContext() {
return context;
}
- public void setContext(ObjectContext context) {
- this.context = context;
+ /**
+ * Ensure that context can't send any queries doesn the channel.
+ */
+ protected void blockContextQueries() {
+ context.setChannel(new BlockingDataChannel(context.getChannel()));
+ }
+
+ protected void unblockContextQueries() {
+ DataChannel channel = context.getChannel();
+ if (channel instanceof BlockingDataChannel) {
+ context.setChannel(((BlockingDataChannel) channel).getChannel());
+ }
}
}