Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2010-06-15 15:30:31 +0000
committerEike Stepper2010-06-15 15:30:31 +0000
commit63b7453bbb2d477303f7cfcc0e6609f6102f6914 (patch)
tree84db841ea8d5930584c87d12211bf823aa94a93b
parent23a973a6fc99a07edea6b74e8710df37f543e388 (diff)
downloadcdo-63b7453bbb2d477303f7cfcc0e6609f6102f6914.tar.gz
cdo-63b7453bbb2d477303f7cfcc0e6609f6102f6914.tar.xz
cdo-63b7453bbb2d477303f7cfcc0e6609f6102f6914.zip
[300149] Support remote cross referencing with a convenient API on the client and SPI on the server for the stores to implement
https://bugs.eclipse.org/bugs/show_bug.cgi?id=300149
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/XRefTest.java346
1 files changed, 346 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/XRefTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/XRefTest.java
new file mode 100644
index 0000000000..e6f2ac399b
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/XRefTest.java
@@ -0,0 +1,346 @@
+/**
+ * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others.
+ * 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;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.CDOObjectReference;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.model1.PurchaseOrder;
+import org.eclipse.emf.cdo.tests.model1.Supplier;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * 300149: Support remote cross referencing with a convenient API on the client and SPI on the server for the stores to
+ * implement https://bugs.eclipse.org/bugs/show_bug.cgi?id=300149
+ *
+ * @author Eike Stepper
+ */
+public class XRefTest extends AbstractCDOTest
+{
+ public void testCrossReferenceMultivalueEReferenceQuery() throws Exception
+ {
+ Supplier supplier1 = getModel1Factory().createSupplier();
+ PurchaseOrder purchaseOrder1 = getModel1Factory().createPurchaseOrder();
+ PurchaseOrder purchaseOrder2 = getModel1Factory().createPurchaseOrder();
+ PurchaseOrder purchaseOrder3 = getModel1Factory().createPurchaseOrder();
+ PurchaseOrder purchaseOrder4 = getModel1Factory().createPurchaseOrder();
+ supplier1.getPurchaseOrders().add(purchaseOrder1);
+ supplier1.getPurchaseOrders().add(purchaseOrder2);
+ supplier1.getPurchaseOrders().add(purchaseOrder3);
+ supplier1.getPurchaseOrders().add(purchaseOrder4);
+
+ CDOSession session1 = openSession();
+ CDOTransaction transaction1 = session1.openTransaction();
+ CDOResource resource = transaction1.createResource("/test1");
+
+ resource.getContents().add(supplier1);
+ resource.getContents().add(purchaseOrder1);
+ resource.getContents().add(purchaseOrder2);
+ resource.getContents().add(purchaseOrder3);
+ resource.getContents().add(purchaseOrder4);
+ transaction1.commit();
+
+ session1.close();
+
+ /******************/
+
+ CDOSession session2 = openSession();
+ CDOView view = session2.openView();
+
+ List<CDOObjectReference> results = view.queryXRefs(Collections.singleton(CDOUtil.getCDOObject(supplier1)));
+ assertEquals(4, results.size());
+
+ for (CDOObjectReference result : results)
+ {
+ CDOObject sourceObject = result.getSourceObject();
+ assertInstanceOf(PurchaseOrder.class, sourceObject);
+ }
+ }
+
+ // public void testCrossReferenceSimpleEReferenceQuery() throws Exception
+ // {
+ // msg("Opening session");
+ //
+ // CDOSession session1 = openSession();
+ //
+ // msg("Opening transaction");
+ // CDOTransaction transaction1 = session1.openTransaction();
+ //
+ // msg("Creating resource");
+ // CDOResource resource = transaction1.createResource("/test1");
+ //
+ // msg("Creating test data");
+ // Supplier supplier1 = getModel1Factory().createSupplier();
+ // PurchaseOrder purchaseOrder1 = getModel1Factory().createPurchaseOrder();
+ // PurchaseOrder purchaseOrder2 = getModel1Factory().createPurchaseOrder();
+ // PurchaseOrder purchaseOrder3 = getModel1Factory().createPurchaseOrder();
+ // PurchaseOrder purchaseOrder4 = getModel1Factory().createPurchaseOrder();
+ // supplier1.getPurchaseOrders().add(purchaseOrder1);
+ // supplier1.getPurchaseOrders().add(purchaseOrder2);
+ // supplier1.getPurchaseOrders().add(purchaseOrder3);
+ // supplier1.getPurchaseOrders().add(purchaseOrder4);
+ //
+ // resource.getContents().add(supplier1);
+ // resource.getContents().add(purchaseOrder1);
+ // resource.getContents().add(purchaseOrder2);
+ // resource.getContents().add(purchaseOrder3);
+ // resource.getContents().add(purchaseOrder4);
+ // transaction1.commit();
+ //
+ // CDOID referenceID = ((CDOObject)supplier1).cdoID();
+ // CDOID queryID1 = ((CDOObject)purchaseOrder1).cdoID();
+ // CDOID queryID2 = ((CDOObject)purchaseOrder2).cdoID();
+ // CDOID queryID3 = ((CDOObject)purchaseOrder3).cdoID();
+ // CDOID queryID4 = ((CDOObject)purchaseOrder4).cdoID();
+ //
+ // session1.close();
+ //
+ // /******************/
+ //
+ // CDOSession session2 = openSession();
+ // CDOView view = session2.openView();
+ //
+ // msg("Executing XREF Query 1");
+ //
+ // CDOQuery query = view.createQuery("XREF", null);
+ // query.setParameter(XREF_QUERY_TARGET_ID_ARGUMENT, queryID1);
+ // List<CDOID> results = query.getResult(CDOID.class);
+ //
+ // msg("Checking query result");
+ //
+ // assertEquals(1, results.size());
+ // CDOObject cdoObject = view.getObject(results.get(0));
+ // assertTrue(CDOIDUtil.equals(cdoObject.cdoID(), referenceID));
+ //
+ // msg("Executing XREF Query 2");
+ //
+ // query = view.createQuery("XREF", null);
+ // query.setParameter(XREF_QUERY_TARGET_ID_ARGUMENT, queryID2);
+ // results = query.getResult(CDOID.class);
+ //
+ // msg("Checking query result");
+ //
+ // assertEquals(1, results.size());
+ // cdoObject = view.getObject(results.get(0));
+ // assertTrue(CDOIDUtil.equals(cdoObject.cdoID(), referenceID));
+ //
+ // msg("Executing XREF Query 3");
+ //
+ // query = view.createQuery("XREF", null);
+ // query.setParameter(XREF_QUERY_TARGET_ID_ARGUMENT, queryID3);
+ // results = query.getResult(CDOID.class);
+ //
+ // msg("Checking query result");
+ //
+ // assertEquals(1, results.size());
+ // cdoObject = view.getObject(results.get(0));
+ // assertTrue(CDOIDUtil.equals(cdoObject.cdoID(), referenceID));
+ //
+ // msg("Executing XREF Query 4");
+ //
+ // query = view.createQuery("XREF", null);
+ // query.setParameter(XREF_QUERY_TARGET_ID_ARGUMENT, queryID4);
+ // results = query.getResult(CDOID.class);
+ //
+ // msg("Checking query result");
+ //
+ // assertEquals(1, results.size());
+ // cdoObject = view.getObject(results.get(0));
+ // assertTrue(CDOIDUtil.equals(cdoObject.cdoID(), referenceID));
+ //
+ // }
+ //
+ // public void testCrossReferenceWithFeatureQuery() throws Exception
+ // {
+ // msg("Opening session");
+ //
+ // CDOSession session1 = openSession();
+ //
+ // msg("Opening transaction");
+ // CDOTransaction transaction1 = session1.openTransaction();
+ //
+ // msg("Creating resource");
+ // CDOResource resource = transaction1.createResource("/test1");
+ //
+ // msg("Creating test data");
+ // Supplier supplier1 = getModel1Factory().createSupplier();
+ // PurchaseOrder purchaseOrder1 = getModel1Factory().createPurchaseOrder();
+ // PurchaseOrder purchaseOrder2 = getModel1Factory().createPurchaseOrder();
+ // PurchaseOrder purchaseOrder3 = getModel1Factory().createPurchaseOrder();
+ // PurchaseOrder purchaseOrder4 = getModel1Factory().createPurchaseOrder();
+ // supplier1.getPurchaseOrders().add(purchaseOrder1);
+ // supplier1.getPurchaseOrders().add(purchaseOrder2);
+ // supplier1.getPurchaseOrders().add(purchaseOrder3);
+ // supplier1.getPurchaseOrders().add(purchaseOrder4);
+ //
+ // resource.getContents().add(supplier1);
+ // resource.getContents().add(purchaseOrder1);
+ // resource.getContents().add(purchaseOrder2);
+ // resource.getContents().add(purchaseOrder3);
+ // resource.getContents().add(purchaseOrder4);
+ // transaction1.commit();
+ //
+ // CDOID querycdoID = ((CDOObject)supplier1).cdoID();
+ //
+ // session1.close();
+ //
+ // /******************/
+ //
+ // CDOSession session2 = openSession();
+ // CDOView view = session2.openView();
+ // CDOQuery query = view.createQuery("XREF", null);
+ // query.setParameter(XREF_QUERY_TARGET_ID_ARGUMENT, querycdoID);
+ // query.setParameter("provideFeatureName", Boolean.TRUE);
+ //
+ // msg("Executing XREF Query");
+ //
+ // List<Object> results = query.getResult(Object.class);
+ //
+ // assertFalse(results.isEmpty());
+ //
+ // msg("Constructing test EStructuralFeature.Setting");
+ //
+ // Collection<CDOID> matchedIdsPerEClass = new ArrayList<CDOID>();
+ // Collection<EStructuralFeature.Setting> settings = new ArrayList<EStructuralFeature.Setting>();
+ //
+ // for (Object object : results)
+ // {
+ // if (object instanceof CDOID)
+ // {
+ // matchedIdsPerEClass.add((CDOID)object);
+ // }
+ // else if (object instanceof String)
+ // {
+ // for (CDOID cdoId : matchedIdsPerEClass)
+ // {
+ // settings.add(new CDOSetting(view, cdoId, (String)object));
+ // }
+ // matchedIdsPerEClass.clear();
+ // }
+ //
+ // }
+ //
+ // msg("Checking query result");
+ //
+ // for (EStructuralFeature.Setting setting : settings)
+ // {
+ // CDOObject crossReferencedEObject = (CDOObject)setting.get(true);
+ // assertTrue(CDOIDUtil.equals(crossReferencedEObject.cdoID(), querycdoID));
+ // }
+ // }
+ //
+ // public void testCrossReferenceWithFeatureQueryUsingCDOUtil() throws Exception
+ // {
+ // msg("Opening session");
+ //
+ // CDOSession session1 = openSession();
+ //
+ // msg("Opening transaction");
+ // CDOTransaction transaction1 = session1.openTransaction();
+ //
+ // msg("Creating resource");
+ // CDOResource resource = transaction1.createResource("/test1");
+ //
+ // msg("Creating test data");
+ // Supplier supplier1 = getModel1Factory().createSupplier();
+ // PurchaseOrder purchaseOrder1 = getModel1Factory().createPurchaseOrder();
+ // PurchaseOrder purchaseOrder2 = getModel1Factory().createPurchaseOrder();
+ // PurchaseOrder purchaseOrder3 = getModel1Factory().createPurchaseOrder();
+ // PurchaseOrder purchaseOrder4 = getModel1Factory().createPurchaseOrder();
+ // supplier1.getPurchaseOrders().add(purchaseOrder1);
+ // supplier1.getPurchaseOrders().add(purchaseOrder2);
+ // supplier1.getPurchaseOrders().add(purchaseOrder3);
+ // supplier1.getPurchaseOrders().add(purchaseOrder4);
+ //
+ // resource.getContents().add(supplier1);
+ // resource.getContents().add(purchaseOrder1);
+ // resource.getContents().add(purchaseOrder2);
+ // resource.getContents().add(purchaseOrder3);
+ // resource.getContents().add(purchaseOrder4);
+ // transaction1.commit();
+ //
+ // CDOID querycdoID = ((CDOObject)supplier1).cdoID();
+ //
+ // session1.close();
+ //
+ // /******************/
+ //
+ // CDOSession session2 = openSession();
+ // CDOView view = session2.openView();
+ // CDOObject cdoObject = view.getObject(querycdoID);
+ //
+ // Collection<EStructuralFeature.Setting> settings = getCrossReferences(cdoObject);
+ //
+ // for (EStructuralFeature.Setting setting : settings)
+ // {
+ // CDOObject crossReferencedEObject = (CDOObject)setting.get(true);
+ // assertTrue(CDOIDUtil.equals(crossReferencedEObject.cdoID(), querycdoID));
+ // }
+ // }
+ //
+ // public void testEmptyCrossReferenceQuery() throws Exception
+ // {
+ // msg("Opening session");
+ //
+ // CDOSession session1 = openSession();
+ //
+ // msg("Opening transaction");
+ // CDOTransaction transaction1 = session1.openTransaction();
+ //
+ // msg("Creating resource");
+ // CDOResource resource = transaction1.createResource("/test1");
+ //
+ // msg("Creating test data");
+ // Supplier supplier1 = getModel1Factory().createSupplier();
+ //
+ // resource.getContents().add(supplier1);
+ // transaction1.commit();
+ //
+ // CDOID queryID = ((CDOObject)supplier1).cdoID();
+ //
+ // session1.close();
+ //
+ // /******************/
+ //
+ // CDOSession session2 = openSession();
+ // CDOView view = session2.openView();
+ // CDOQuery query = view.createQuery("XREF", null);
+ // query.setParameter(XREF_QUERY_TARGET_ID_ARGUMENT, queryID);
+ //
+ // msg("Executing XREF Query");
+ // List<CDOID> results = query.getResult(CDOID.class);
+ //
+ // msg("Checking query result");
+ //
+ // assertEquals(0, results.size());
+ // }
+ //
+ // public void testInexistentTargetForCrossReferenceQuery() throws Exception
+ // {
+ // CDOSession session2 = openSession();
+ // CDOView view = session2.openView();
+ // CDOQuery query = view.createQuery("XREF", null);
+ // query.setParameter(XREF_QUERY_TARGET_ID_ARGUMENT, CDOIDUtil.createLong(10000));
+ //
+ // msg("Executing XREF Query");
+ // List<CDOID> results = query.getResult(CDOID.class);
+ //
+ // msg("Checking query result");
+ //
+ // assertEquals(0, results.size());
+ // }
+}

Back to the top