summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2006-08-30 17:05:08 (EDT)
committerEike Stepper2006-08-30 17:05:08 (EDT)
commit9b2a3ad9cc9a7356815b007afd8df04fd279242c (patch)
tree92a1202c00dcdad7bca073ccfa6d2002a0ab3a5f
parentd31995f202288aa0fe0ad2f44ccb30134903376b (diff)
downloadcdo-9b2a3ad9cc9a7356815b007afd8df04fd279242c.zip
cdo-9b2a3ad9cc9a7356815b007afd8df04fd279242c.tar.gz
cdo-9b2a3ad9cc9a7356815b007afd8df04fd279242c.tar.bz2
[155725] Add support for remote cross referencing
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/Mapper.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/MapperImpl.java24
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/SQLConstants.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/CommitTransactionIndication.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/QueryXRefsIndication.java43
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/ServerCDOProtocolImpl.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AllTests.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/XRefsTest.java102
8 files changed, 183 insertions, 1 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/Mapper.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/Mapper.java
index 66eb60e..7fe1225 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/Mapper.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/Mapper.java
@@ -77,6 +77,8 @@ public interface Mapper extends Service
public void transmitExtent(Channel channel, int cid, boolean exactMatch, int rid);
+ public void transmitXRefs(Channel channel, long oid, int rid);
+
public void createAttributeTables(PackageInfo packageInfo);
public void insertResource(int rid, String path);
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/MapperImpl.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/MapperImpl.java
index 90bd517..411878d 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/MapperImpl.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/MapperImpl.java
@@ -939,7 +939,31 @@ public class MapperImpl extends ServiceImpl implements Mapper, SQLConstants
});
channel.transmitLong(CDOProtocol.NO_MORE_OBJECTS);
+ }
+
+ public void transmitXRefs(final Channel channel, final long oid, int rid)
+ {
+ Object[] args = { new Long(oid)};
+ if (isDebugEnabled()) debug(StringHelper.replaceWildcards(SELECT_XREFS_OF_OBJECT, "?", args));
+ jdbcTemplate.query(SELECT_XREFS_OF_OBJECT, args, new RowCallbackHandler()
+ {
+ public void processRow(ResultSet resultSet) throws SQLException
+ {
+ long referer = resultSet.getLong(1);
+ int feature = resultSet.getInt(2);
+ int cid = resultSet.getInt(3);
+ if (isDebugEnabled())
+ debug("XRef: referer=" + oidEncoder.toString(referer) + ", feature=" + feature + ", cid="
+ + cid);
+
+ channel.transmitLong(referer);
+ channel.transmitInt(feature);
+ channel.transmitInt(cid);
+ }
+ });
+
+ channel.transmitLong(CDOProtocol.NO_MORE_OBJECTS);
}
public void createAttributeTables(PackageInfo packageInfo)
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/SQLConstants.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/SQLConstants.java
index e89ae95..7b0ceef 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/SQLConstants.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/SQLConstants.java
@@ -135,6 +135,13 @@ public interface SQLConstants
+ "=? AND " + REFERENCE_TABLE + "." + REFERENCE_OID_COLUMN + "=" + OBJECT_TABLE + "."
+ OBJECT_OID_COLUMN;
+ public static final String SELECT_XREFS_OF_OBJECT = "SELECT " + REFERENCE_TABLE + "."
+ + REFERENCE_OID_COLUMN + ", " + REFERENCE_TABLE + "." + REFERENCE_FEATUREID_COLUMN + ", "
+ + OBJECT_TABLE + "." + OBJECT_CID_COLUMN + " FROM " + REFERENCE_TABLE + ", " + OBJECT_TABLE
+ + " WHERE " + REFERENCE_TABLE + "." + REFERENCE_TARGET_COLUMN + "=? AND " + REFERENCE_TABLE
+ + "." + REFERENCE_CONTENT_COLUMN + "=FALSE AND " + REFERENCE_TABLE + "."
+ + REFERENCE_OID_COLUMN + "=" + OBJECT_TABLE + "." + OBJECT_OID_COLUMN;
+
public static final String SELECT_ALL_RESOURCES = "SELECT " + RESOURCE_RID_COLUMN + ", "
+ RESOURCE_PATH_COLUMN + " FROM " + RESOURCE_TABLE;
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/CommitTransactionIndication.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/CommitTransactionIndication.java
index e7e8f0c..6068090 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/CommitTransactionIndication.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/CommitTransactionIndication.java
@@ -150,7 +150,7 @@ public class CommitTransactionIndication extends AbstractIndicationWithResponse
{
long oid = receiveLong();
- if (oid == 0)
+ if (oid == CDOProtocol.NO_MORE_OBJECTS)
{
break;
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/QueryXRefsIndication.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/QueryXRefsIndication.java
new file mode 100644
index 0000000..d52954e
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/QueryXRefsIndication.java
@@ -0,0 +1,43 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.server.protocol;
+
+
+import org.eclipse.net4j.core.impl.AbstractIndicationWithResponse;
+
+import org.eclipse.emf.cdo.core.CDOProtocol;
+import org.eclipse.emf.cdo.server.Mapper;
+import org.eclipse.emf.cdo.server.ServerCDOProtocol;
+
+
+public class QueryXRefsIndication extends AbstractIndicationWithResponse
+{
+ private long oid;
+
+ private int rid;
+
+ public short getSignalId()
+ {
+ return CDOProtocol.QUERY_EXTENT;
+ }
+
+ public void indicate()
+ {
+ oid = receiveLong();
+ rid = receiveInt();
+ }
+
+ public void respond()
+ {
+ Mapper mapper = ((ServerCDOProtocol) getProtocol()).getMapper();
+ mapper.transmitXRefs(getChannel(), oid, rid);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/ServerCDOProtocolImpl.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/ServerCDOProtocolImpl.java
index 3da09f3..b0a3eb2 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/ServerCDOProtocolImpl.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/ServerCDOProtocolImpl.java
@@ -69,6 +69,9 @@ public class ServerCDOProtocolImpl extends AbstractCDOProtocol implements Server
case QUERY_EXTENT:
return new QueryExtentIndication();
+ case QUERY_XREFS:
+ return new QueryXRefsIndication();
+
default:
throw new ImplementationError("Invalid " + CDOProtocol.PROTOCOL_NAME + " signalId: "
+ signalId);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AllTests.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AllTests.java
index 346a6b2..4b5fdd1 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AllTests.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AllTests.java
@@ -25,6 +25,7 @@ public class AllTests
suite.addTestSuite(SerializationTest.class);
suite.addTestSuite(NotificationTest.class);
suite.addTestSuite(RollbackTest.class);
+ suite.addTestSuite(XRefsTest.class);
suite.addTestSuite(ExtentTest.class);
suite.addTestSuite(OCLTest.class);
suite.addTestSuite(Bugzilla154389Test.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/XRefsTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/XRefsTest.java
new file mode 100644
index 0000000..ba7497b
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/XRefsTest.java
@@ -0,0 +1,102 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.tests.model1;
+
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.util.EContentsEList.FeatureListIterator;
+
+import testmodel1.TestModel1Package;
+import testmodel1.TreeNode;
+import junit.framework.ComparisonFailure;
+
+
+public class XRefsTest extends AbstractModel1Test
+{
+ public void testList() throws Exception
+ {
+ final String RESOURCE1 = "/test/res1";
+ final String RESOURCE2 = "/test/res2";
+ final String ROOT1 = "root1";
+ final String ROOT2 = "root2";
+ final String CHILD2 = "child2";
+
+ { // Execution
+ TreeNode root1 = createNode(ROOT1);
+ saveRoot(root1, RESOURCE1);
+
+ TreeNode root2 = createNode(ROOT2);
+ root2.getReferences().add(root1);
+
+ TreeNode child2 = createNode(CHILD2, root2);
+ child2.getReferences().add(root1);
+ saveRoot(root2, RESOURCE2);
+ }
+
+ { // Verification
+ TreeNode root1 = (TreeNode) loadRoot(RESOURCE1);
+ EList list = root1.eCrossReferences();
+ assertNotNull(list);
+ assertEquals(2, list.size());
+
+ try
+ {
+ assertNode(ROOT2, (TreeNode) list.get(0));
+ assertNode(CHILD2, (TreeNode) list.get(1));
+ }
+ catch (ComparisonFailure ex)
+ {
+ assertNode(ROOT2, (TreeNode) list.get(1));
+ assertNode(CHILD2, (TreeNode) list.get(0));
+ }
+ }
+ }
+
+ public void testIterator() throws Exception
+ {
+ final String RESOURCE1 = "/test/res1";
+ final String RESOURCE2 = "/test/res2";
+ final String ROOT1 = "root1";
+ final String ROOT2 = "root2";
+ final String CHILD2 = "child2";
+
+ { // Execution
+ TreeNode root1 = createNode(ROOT1);
+ saveRoot(root1, RESOURCE1);
+
+ TreeNode root2 = createNode(ROOT2);
+ root2.getReferences().add(root1);
+
+ TreeNode child2 = createNode(CHILD2, root2);
+ child2.getReferences().add(root1);
+ saveRoot(root2, RESOURCE2);
+ }
+
+ { // Verification
+ TreeNode root1 = (TreeNode) loadRoot(RESOURCE1);
+ EList list = root1.eCrossReferences();
+ int count = 0;
+
+ for (FeatureListIterator it = (FeatureListIterator) list.iterator(); it.hasNext();)
+ {
+ count++;
+ TreeNode node = (TreeNode) it.next();
+ assertTrue(ROOT2.equals(node.getStringFeature()) || CHILD2.equals(node.getStringFeature()));
+
+ EReference reference = (EReference) it.feature();
+ assertEquals(TestModel1Package.eINSTANCE.getTreeNode_References(), reference);
+ }
+
+ assertEquals(2, count);
+ }
+ }
+}