summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2006-08-22 09:06:09 (EDT)
committerEike Stepper2006-08-22 09:06:09 (EDT)
commit1328aece732445c867ee4c444329b7245f8acd7c (patch)
tree77cf7453e49641a74c9fb4db943b44c43b8ce4c7
parent78b35453b7b4b85ac9c7beaae2a4d90f54f28a6a (diff)
downloadcdo-1328aece732445c867ee4c444329b7245f8acd7c.zip
cdo-1328aece732445c867ee4c444329b7245f8acd7c.tar.gz
cdo-1328aece732445c867ee4c444329b7245f8acd7c.tar.bz2
[151560] Query Language for CDO
https://bugs.eclipse.org/bugs/show_bug.cgi?id=151560
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ClassInfo.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/Mapper.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/PackageManager.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/ClassInfoImpl.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/MapperImpl.java84
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/PackageManagerImpl.java33
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/QueryExtentIndication.java46
-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/launches/CDO Extent Test.launch38
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/ExtentTest.java100
10 files changed, 328 insertions, 6 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ClassInfo.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ClassInfo.java
index fa34d92..63f5fa0 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ClassInfo.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ClassInfo.java
@@ -11,6 +11,9 @@
package org.eclipse.emf.cdo.server;
+import java.util.List;
+
+
public interface ClassInfo
{
public int getCID();
@@ -32,5 +35,9 @@ public interface ClassInfo
public ClassInfo getParent();
+ public boolean isParentOf(ClassInfo derived);
+
+ public List<ClassInfo> getSubClasses();
+
public String getColumnNames();
}
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 ab84e83..f8b4b6b 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
@@ -75,6 +75,8 @@ public interface Mapper extends Service
public void transmitAllResources(Channel channel);
+ public void transmitExtent(Channel channel, int cid, boolean exactMatch, int rid);
+
public void createAttributeTables(PackageInfo packageInfo);
public void insertResource(int rid, String path);
@@ -86,5 +88,4 @@ public interface Mapper extends Service
public ResourceManager getResourceManager();
public ColumnConverter getColumnConverter();
-
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/PackageManager.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/PackageManager.java
index 93aa5ec..53609a9 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/PackageManager.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/PackageManager.java
@@ -13,6 +13,8 @@ package org.eclipse.emf.cdo.server;
import org.eclipse.net4j.spring.Service;
+import java.util.List;
+
public interface PackageManager extends Service
{
@@ -29,4 +31,6 @@ public interface PackageManager extends Service
public ClassInfo getClassInfo(int cid);
public ClassInfo getClassInfo(String name);
+
+ public List<ClassInfo> getSubClassInfos(ClassInfo base);
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/ClassInfoImpl.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/ClassInfoImpl.java
index dbe8ad1..160a65f 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/ClassInfoImpl.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/ClassInfoImpl.java
@@ -119,6 +119,22 @@ public class ClassInfoImpl implements ClassInfo
return cachedParent;
}
+ public boolean isParentOf(ClassInfo derived)
+ {
+ if (derived == null)
+ {
+ return false;
+ }
+
+ ClassInfo parent = derived.getParent();
+ return parent == this || isParentOf(parent);
+ }
+
+ public List<ClassInfo> getSubClasses()
+ {
+ return packageInfo.getPackageManager().getSubClassInfos(this);
+ }
+
public String getColumnNames()
{
if (cachedColumnNames == null)
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 c325bd1..7e80fc8 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
@@ -17,6 +17,7 @@ import org.eclipse.net4j.spring.impl.ServiceImpl;
import org.eclipse.net4j.util.ImplementationError;
import org.eclipse.net4j.util.StringHelper;
+import org.eclipse.emf.cdo.core.CDOProtocol;
import org.eclipse.emf.cdo.core.CDOResProtocol;
import org.eclipse.emf.cdo.core.OIDEncoder;
import org.eclipse.emf.cdo.dbgen.ColumnType;
@@ -468,12 +469,12 @@ public class MapperImpl extends ServiceImpl implements Mapper, SQLConstants
return result;
}
- protected int selectMaxOIDFragment(int rid)
+ protected long selectMaxOIDFragment(int rid)
{
Object[] args = ridBounds(rid);
if (isDebugEnabled()) debug(StringHelper.replaceWildcards(SELECT_MAX_OID_FRAGMENT, "?", args));
long oid = jdbcTemplate.queryForLong(SELECT_MAX_OID_FRAGMENT, args);
- return (int) (oid & 0xFFFFFFFFL); // TODO Without OIDEncoder???
+ return oidEncoder.getOIDFragment(oid);
}
private Object[] ridBounds(int rid)
@@ -848,8 +849,11 @@ public class MapperImpl extends ServiceImpl implements Mapper, SQLConstants
public void transmitAllResources(final Channel channel)
{
- if (isDebugEnabled()) debug("Querying all resources");
- if (isDebugEnabled()) debug(SELECT_ALL_RESOURCES);
+ if (isDebugEnabled())
+ {
+ debug("Querying all resources");
+ debug(SELECT_ALL_RESOURCES);
+ }
jdbcTemplate.query(SELECT_ALL_RESOURCES, new RowCallbackHandler()
{
@@ -866,6 +870,78 @@ public class MapperImpl extends ServiceImpl implements Mapper, SQLConstants
channel.transmitInt(CDOResProtocol.NO_MORE_RESOURCES);
}
+ public void transmitExtent(final Channel channel, final int context, final boolean exactMatch,
+ int rid)
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("SELECT ");
+ buffer.append(OBJECT_OID_COLUMN);
+ buffer.append(exactMatch ? "" : ", " + OBJECT_CID_COLUMN);
+ buffer.append(" FROM ");
+ buffer.append(OBJECT_TABLE);
+ buffer.append(" WHERE ");
+ buffer.append(OBJECT_CID_COLUMN);
+ buffer.append(" IN (");
+ buffer.append(context);
+
+ if (!exactMatch)
+ {
+ ClassInfo classInfo = packageManager.getClassInfo(context);
+ List<ClassInfo> subClasses = classInfo.getSubClasses();
+ for (ClassInfo info : subClasses)
+ {
+ buffer.append(", ");
+ buffer.append(info.getCID());
+ }
+ }
+
+ buffer.append(")");
+
+ if (rid != CDOProtocol.GLOBAL_EXTENT)
+ {
+ Object[] bounds = ridBounds(rid);
+ buffer.append(" AND ");
+ buffer.append(OBJECT_OID_COLUMN);
+ buffer.append(" BETWEEN ");
+ buffer.append(bounds[0]);
+ buffer.append(" AND ");
+ buffer.append(bounds[1]);
+ }
+
+ buffer.append(" ORDER BY ");
+ buffer.append(OBJECT_OID_COLUMN);
+
+ String sql = buffer.toString();
+ if (isDebugEnabled())
+ {
+ debug(sql);
+
+ }
+
+ jdbcTemplate.query(sql, new RowCallbackHandler()
+ {
+ public void processRow(ResultSet resultSet) throws SQLException
+ {
+ long oid = resultSet.getLong(1);
+ int cid = exactMatch ? context : resultSet.getInt(2);
+
+ if (isDebugEnabled())
+ {
+ debug("Extent: oid=" + oidEncoder.toString(oid) + (exactMatch ? "" : ", cid=" + cid));
+ }
+
+ channel.transmitLong(oid);
+ if (!exactMatch)
+ {
+ channel.transmitInt(cid);
+ }
+ }
+ });
+
+ channel.transmitLong(CDOProtocol.NO_MORE_OBJECTS);
+
+ }
+
public void createAttributeTables(PackageInfo packageInfo)
{
if (isDebugEnabled()) debug("Creating attribute tables");
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/PackageManagerImpl.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/PackageManagerImpl.java
index ea204d9..3de6801 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/PackageManagerImpl.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/PackageManagerImpl.java
@@ -19,6 +19,7 @@ import org.eclipse.emf.cdo.server.PackageListener;
import org.eclipse.emf.cdo.server.PackageManager;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -31,6 +32,8 @@ public class PackageManagerImpl extends ServiceImpl implements PackageManager
protected Map<String, ClassInfo> nameToClassInfoMap = new HashMap<String, ClassInfo>(2111);
+ protected Map<ClassInfo, List<ClassInfo>> subClassInfoMap;
+
protected Map<String, PackageInfo> packages = new HashMap<String, PackageInfo>();
protected List<PackageListener> listeners = new ArrayList<PackageListener>();
@@ -44,7 +47,7 @@ public class PackageManagerImpl extends ServiceImpl implements PackageManager
{
PackageInfo packageInfo = new PackageInfoImpl(pid, name, this);
packages.put(name, packageInfo);
- notifyPackageListeners();
+ notifyPackageListeners(); // TODO Not useful here because classes are not registered yet
return packageInfo;
}
@@ -62,6 +65,7 @@ public class PackageManagerImpl extends ServiceImpl implements PackageManager
{
cidToClassInfoMap.put(new Integer(classInfo.getCID()), classInfo);
nameToClassInfoMap.put(classInfo.getName(), classInfo);
+ subClassInfoMap = null;
}
public ClassInfo getClassInfo(int cid)
@@ -74,6 +78,33 @@ public class PackageManagerImpl extends ServiceImpl implements PackageManager
return nameToClassInfoMap.get(name);
}
+ public List<ClassInfo> getSubClassInfos(ClassInfo base)
+ {
+ if (subClassInfoMap == null)
+ {
+ subClassInfoMap = new HashMap<ClassInfo, List<ClassInfo>>();
+ Collection<ClassInfo> values = cidToClassInfoMap.values();
+ ClassInfo[] array = (ClassInfo[]) values.toArray(new ClassInfo[values.size()]);
+ for (int i = 0; i < array.length; i++)
+ {
+ ClassInfo parent = array[i];
+ List<ClassInfo> subClasses = new ArrayList<ClassInfo>();
+ for (int j = 0; j < array.length; j++)
+ {
+ ClassInfo derived = array[j];
+ if (parent.isParentOf(derived))
+ {
+ subClasses.add(derived);
+ }
+ }
+
+ subClassInfoMap.put(parent, subClasses);
+ }
+ }
+
+ return subClassInfoMap.get(base);
+ }
+
protected void notifyPackageListeners()
{
for (Iterator<PackageListener> iter = listeners.iterator(); iter.hasNext();)
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/QueryExtentIndication.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/QueryExtentIndication.java
new file mode 100644
index 0000000..9e366f2
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/QueryExtentIndication.java
@@ -0,0 +1,46 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Fuggerstr. 39, 10777 Berlin, 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 QueryExtentIndication extends AbstractIndicationWithResponse
+{
+ private int cid;
+
+ private boolean exactMatch;
+
+ private int rid;
+
+ public short getSignalId()
+ {
+ return CDOProtocol.QUERY_EXTENT;
+ }
+
+ public void indicate()
+ {
+ cid = receiveInt();
+ exactMatch = receiveBoolean();
+ rid = receiveInt();
+ }
+
+ public void respond()
+ {
+ Mapper mapper = ((ServerCDOProtocol) getProtocol()).getMapper();
+ mapper.transmitExtent(getChannel(), cid, exactMatch, 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 fdf59a7..264ce95 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
@@ -66,6 +66,9 @@ public class ServerCDOProtocolImpl extends AbstractCDOProtocol implements Server
case COMMIT_TRANSACTION:
return new CommitTransactionIndication();
+ case QUERY_EXTENT:
+ return new QueryExtentIndication();
+
default:
throw new ImplementationError("Invalid " + CDOProtocol.PROTOCOL_NAME + " signalId: "
+ signalId);
diff --git a/plugins/org.eclipse.emf.cdo.tests/launches/CDO Extent Test.launch b/plugins/org.eclipse.emf.cdo.tests/launches/CDO Extent Test.launch
new file mode 100644
index 0000000..64aaa4e
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/launches/CDO Extent Test.launch
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<launchConfiguration type="org.eclipse.pde.ui.JunitLaunchConfig">
+<stringAttribute key="product" value="org.eclipse.platform.ide"/>
+<stringAttribute key="bootstrap" value=""/>
+<booleanAttribute key="useProduct" value="false"/>
+<stringAttribute key="deselected_workspace_plugins" value="org.eclipse.net4j.examples.mvc.swt,org.eclipse.net4j.examples.prov.client.ui,org.eclipse.net4j.examples.mvc,org.eclipse.net4j.examples.prov.server,org.eclipse.emf.cdo.dbgen.edit,org.eclipse.emf.cdo.examples.library,org.eclipse.emf.cdo.examples.library.ui,org.eclipse.emf.cdo.analysis.gmf,org.eclipse.emf.cdo.mapping.editor,org.eclipse.net4j.examples.server,org.eclipse.net4j.tests,org.eclipse.emf.cdo.doc,org.eclipse.datatools.enablement.mysql,org.eclipse.net4j.spring.tests,org.eclipse.emf.cdo,org.eclipse.emf.cdo.dbgen.editor,org.eclipse.net4j.examples.prov.edit,org.eclipse.emf.cdo.utilities.migrator,org.eclipse.emf.cdo.analysis,org.eclipse.emf.cdo.examples.server,org.eclipse.datatools.enablement.mysql.dbdefinition,org.eclipse.net4j.examples.prov,org.eclipse.emf.cdo.examples.client,org.eclipse.emf.cdo.examples.ui,org.eclipse.net4j.examples.client.ui,org.eclipse.net4j.examples.client,org.eclipse.net4j.doc,org.eclipse.net4j.examples.prov.client,org.eclipse.net4j.examples.prov.editor,org.eclipse.net4j"/>
+<booleanAttribute key="tracing" value="false"/>
+<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
+<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
+<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
+</listAttribute>
+<stringAttribute key="selected_target_plugins" value="org.apache.ant,org.eclipse.ant.core,org.eclipse.core.contenttype,org.eclipse.core.expressions,org.eclipse.core.filesystem,org.eclipse.core.filesystem.win32.x86,org.eclipse.core.jobs,org.eclipse.core.resources,org.eclipse.core.resources.compatibility,org.eclipse.core.resources.win32,org.eclipse.core.runtime,org.eclipse.core.runtime.compatibility,org.eclipse.core.runtime.compatibility.auth,org.eclipse.core.runtime.compatibility.registry,org.eclipse.core.variables,org.eclipse.emf.common,org.eclipse.emf.ecore,org.eclipse.emf.ecore.change,org.eclipse.emf.ecore.edit,org.eclipse.emf.ecore.xmi,org.eclipse.emf.edit,org.eclipse.equinox.common,org.eclipse.equinox.preferences,org.eclipse.equinox.registry,org.eclipse.osgi,org.eclipse.update.configurator,org.junit"/>
+<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
+<booleanAttribute key="automaticValidate" value="true"/>
+<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
+<booleanAttribute key="automaticAdd" value="false"/>
+<stringAttribute key="checked" value="[NONE]"/>
+<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/>
+<stringAttribute key="selected_workspace_plugins" value="org.eclipse.emf.cdo.jdbc,org.eclipse.net4j.spring,org.eclipse.net4j.socket,org.eclipse.net4j.core,org.eclipse.net4j.spring.db,org.eclipse.emf.cdo.dbgen,org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo.mapping,org.eclipse.emf.cdo.core,org.eclipse.emf.cdo.client,org.eclipse.net4j.util,org.eclipse.emf.cdo.server,org.eclipse.net4j.embedded,org.eclipse.emf.cdo.jdbc.derby,org.eclipse.emf.cdo.dbgen.derby,org.eclipse.emf.cdo.dbgen.oracle,org.eclipse.emf.cdo.jdbc.hsqldb,org.eclipse.emf.cdo.jdbc.mysql,org.eclipse.emf.cdo.dbgen.ansi92,org.eclipse.emf.cdo.dbgen.mysql,org.eclipse.emf.cdo.dbgen.hsqldb"/>
+<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/>
+<stringAttribute key="application" value="org.eclipse.pde.junit.runtime.coretestapplication"/>
+<booleanAttribute key="clearws" value="true"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.emf.cdo.tests.model1.ExtentTest"/>
+<stringAttribute key="pde.version" value="3.2a"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dcdo.test.mode=client-separated-server"/>
+<stringAttribute key="templateConfig" value="${target_home}\configuration\config.ini"/>
+<booleanAttribute key="default" value="false"/>
+<booleanAttribute key="clearConfig" value="true"/>
+<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
+<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
+<booleanAttribute key="useDefaultConfigArea" value="false"/>
+<booleanAttribute key="useDefaultConfig" value="true"/>
+<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.emf.cdo.tests"/>
+<booleanAttribute key="askclear" value="false"/>
+<booleanAttribute key="includeOptional" value="true"/>
+<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
+</launchConfiguration>
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/ExtentTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/ExtentTest.java
new file mode 100644
index 0000000..6e2c5a6
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/ExtentTest.java
@@ -0,0 +1,100 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Fuggerstr. 39, 10777 Berlin, 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.cdo.client.CDOResource;
+import org.eclipse.emf.cdo.client.ClassInfo;
+import org.eclipse.emf.cdo.client.PackageManager;
+import org.eclipse.emf.cdo.client.ResourceManager;
+import org.eclipse.emf.cdo.client.protocol.ClientCDOProtocolImpl;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
+
+import org.eclipse.net4j.core.Channel;
+
+import testmodel1.ExtendedNode;
+import testmodel1.TestModel1Package;
+import testmodel1.TreeNode;
+
+
+public class ExtentTest extends AbstractModel1Test
+{
+ public void testExactGlobal() throws Exception
+ {
+ final String RESOURCE = "/test/res";
+ final String ROOT = "root";
+ final String[] CHILDREN = { "a", "b", "c"};
+ final String OTHER_CHILD = "XYZ";
+
+ TreeNode root = createNode(ROOT);
+ TreeNode[] exactChildren = createChildren(CHILDREN, root);
+ createExtended(OTHER_CHILD, root);
+
+ CDOResource resource = saveRoot(root, RESOURCE);
+ ResourceManager resourceManager = resource.getResourceManager();
+ Channel channel = resourceManager.getChannel();
+
+ PackageManager packageManager = resourceManager.getPackageManager();
+ EClass eClass = TestModel1Package.eINSTANCE.getTreeNode();
+ ClassInfo classInfo = packageManager.getClassInfo(eClass);
+ int cid = classInfo.getCID();
+
+ EList extent = ClientCDOProtocolImpl.requestQueryExtent(channel, cid, true);
+ assertEquals(1 + CHILDREN.length, extent.size());
+
+ assertTrue(extent.contains(root));
+ assertResource(RESOURCE, root);
+
+ for (TreeNode child : exactChildren)
+ {
+ assertTrue(extent.contains(child));
+ assertResource(RESOURCE, child);
+ }
+ }
+
+ public void testDerivedGlobal() throws Exception
+ {
+ final String RESOURCE = "/test/res";
+ final String ROOT = "root";
+ final String[] CHILDREN = { "a", "b", "c"};
+ final String OTHER_CHILD = "XYZ";
+
+ TreeNode root = createNode(ROOT);
+ TreeNode[] exactChildren = createChildren(CHILDREN, root);
+ ExtendedNode otherChild = createExtended(OTHER_CHILD, root);
+
+ CDOResource resource = saveRoot(root, RESOURCE);
+ ResourceManager resourceManager = resource.getResourceManager();
+ Channel channel = resourceManager.getChannel();
+
+ PackageManager packageManager = resourceManager.getPackageManager();
+ EClass eClass = TestModel1Package.eINSTANCE.getTreeNode();
+ ClassInfo classInfo = packageManager.getClassInfo(eClass);
+ int cid = classInfo.getCID();
+
+ EList extent = ClientCDOProtocolImpl.requestQueryExtent(channel, cid, false);
+ assertEquals(2 + CHILDREN.length, extent.size());
+
+ assertTrue(extent.contains(root));
+ assertResource(RESOURCE, root);
+
+ assertTrue(extent.contains(otherChild));
+ assertResource(RESOURCE, otherChild);
+
+ for (TreeNode child : exactChildren)
+ {
+ assertTrue(extent.contains(child));
+ assertResource(RESOURCE, child);
+ }
+ }
+}