Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-04-07 03:51:34 -0400
committerEike Stepper2013-04-07 03:51:34 -0400
commitf2af641004b144f4e0330e20ed9a5abeaeda15b0 (patch)
treedb6fa134dbe768087c0ea45d86ce14dc58fbb43c
parentaa485a9c0e42766c1fd9fd2f9a8a49d5c2f38718 (diff)
downloadcdo-f2af641004b144f4e0330e20ed9a5abeaeda15b0.tar.gz
cdo-f2af641004b144f4e0330e20ed9a5abeaeda15b0.tar.xz
cdo-f2af641004b144f4e0330e20ed9a5abeaeda15b0.zip
[400762] OCLQueryHandler does not consider subtypes
https://bugs.eclipse.org/bugs/show_bug.cgi?id=400762
-rw-r--r--plugins/org.eclipse.emf.cdo.server.ocl/META-INF/MANIFEST.MF4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentCreator.java113
-rw-r--r--plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/OCLQueryHandler.java28
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/OCLQueryTest.java117
5 files changed, 180 insertions, 83 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.ocl/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.server.ocl/META-INF/MANIFEST.MF
index 08227b0b3f..be2b78349a 100644
--- a/plugins/org.eclipse.emf.cdo.server.ocl/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.server.ocl/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.emf.cdo.server.ocl;singleton:=true
Bundle-Name: %pluginName
-Bundle-Version: 4.0.100.qualifier
+Bundle-Version: 4.1.0.qualifier
Bundle-ClassPath: .
Bundle-Vendor: %providerName
Bundle-Localization: plugin
@@ -10,4 +10,4 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
org.eclipse.ocl.ecore;bundle-version="[3.0.0,4.0.0)",
org.eclipse.emf.cdo.server;bundle-version="[4.0.0,5.0.0)"
-Export-Package: org.eclipse.emf.cdo.server.ocl;version="4.0.100"
+Export-Package: org.eclipse.emf.cdo.server.ocl;version="4.1.0"
diff --git a/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentCreator.java b/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentCreator.java
index 984f344d64..730ea795e4 100644
--- a/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentCreator.java
+++ b/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentCreator.java
@@ -14,6 +14,7 @@ import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.commit.CDOChangeKind;
import org.eclipse.emf.cdo.common.commit.CDOChangeSetData;
import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
import org.eclipse.emf.cdo.common.revision.CDOIDAndVersion;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionCacheAdder;
@@ -110,33 +111,60 @@ public class CDOExtentCreator implements OCLExtentCreator
}
}
- accessor.handleRevisions(eClass, branch, timeStamp, false, new CDORevisionHandler.Filtered.Undetached(
- new CDORevisionHandler()
+ CDORevisionHandler revisionHandler = new CDORevisionHandler.Filtered.Undetached(new CDORevisionHandler()
+ {
+ public boolean handleRevision(CDORevision revision)
+ {
+ if (revisionCacheAdder != null)
{
- public boolean handleRevision(CDORevision revision)
- {
- if (revisionCacheAdder != null)
- {
- revisionCacheAdder.addRevision(revision);
- }
-
- CDOID id = revision.getID();
- if (!isDetached(id))
- {
- EObject object = getEObject(id);
- if (object != null)
- {
- extent.add(object);
- }
- }
+ revisionCacheAdder.addRevision(revision);
+ }
- return !canceled.get();
+ CDOID id = revision.getID();
+ if (!isDetached(id))
+ {
+ EObject object = getEObject(id);
+ if (object != null)
+ {
+ extent.add(object);
}
- }));
+ }
+
+ return !canceled.get();
+ }
+ });
+ createExtent(eClass, accessor, branch, timeStamp, canceled, revisionHandler);
return extent;
}
+ /**
+ * @since 4.1
+ */
+ protected void createExtent(EClass eClass, IStoreAccessor accessor, CDOBranch branch, long timeStamp,
+ final AtomicBoolean canceled, CDORevisionHandler revisionHandler)
+ {
+ if (!eClass.isAbstract() && !eClass.isInterface())
+ {
+ accessor.handleRevisions(eClass, branch, timeStamp, false, revisionHandler);
+ }
+
+ CDOPackageRegistry packageRegistry = accessor.getStore().getRepository().getPackageRegistry();
+ List<EClass> subTypes = packageRegistry.getSubTypes().get(eClass);
+ if (subTypes != null)
+ {
+ for (EClass subType : subTypes)
+ {
+ if (canceled.get())
+ {
+ break;
+ }
+
+ accessor.handleRevisions(subType, branch, timeStamp, false, revisionHandler);
+ }
+ }
+ }
+
protected boolean isDetached(CDOID id)
{
if (changeSetData == null)
@@ -255,29 +283,30 @@ public class CDOExtentCreator implements OCLExtentCreator
private void handlePersistentState()
{
- accessor.handleRevisions(eClass, branch, timeStamp, false, new CDORevisionHandler.Filtered.Undetached(
- new CDORevisionHandler()
+ CDORevisionHandler revisionHandler = new CDORevisionHandler.Filtered.Undetached(new CDORevisionHandler()
+ {
+ public boolean handleRevision(CDORevision revision)
+ {
+ empty = false;
+ emptyKnown.countDown();
+
+ CDORevisionCacheAdder revisionCacheAdder = getRevisionCacheAdder();
+ if (revisionCacheAdder != null)
{
- public boolean handleRevision(CDORevision revision)
- {
- empty = false;
- emptyKnown.countDown();
-
- CDORevisionCacheAdder revisionCacheAdder = getRevisionCacheAdder();
- if (revisionCacheAdder != null)
- {
- revisionCacheAdder.addRevision(revision);
- }
-
- CDOID id = revision.getID();
- if (!isDetached(id))
- {
- enqueue(id);
- }
-
- return !canceled.get();
- }
- }));
+ revisionCacheAdder.addRevision(revision);
+ }
+
+ CDOID id = revision.getID();
+ if (!isDetached(id))
+ {
+ enqueue(id);
+ }
+
+ return !canceled.get();
+ }
+ });
+
+ createExtent(eClass, accessor, branch, timeStamp, canceled, revisionHandler);
}
private void enqueue(CDOID id)
diff --git a/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/OCLQueryHandler.java b/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/OCLQueryHandler.java
index f855507f7c..a97e4604ea 100644
--- a/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/OCLQueryHandler.java
+++ b/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/OCLQueryHandler.java
@@ -72,9 +72,16 @@ import java.util.Set;
*/
public class OCLQueryHandler implements IQueryHandler
{
+ public static final String LANGUAGE_NAME = "ocl"; //$NON-NLS-1$
+
+ /**
+ * @since 4.1
+ */
+ public static final String LAZY_EXTENTS_PARAMETER = "cdoLazyExtents";
+
private static final EcoreFactory FACTORY = EcoreFactory.eINSTANCE;
- public static final String LANGUAGE_NAME = "ocl"; //$NON-NLS-1$
+ private boolean lazyExtents = true;
public OCLQueryHandler()
{
@@ -87,6 +94,21 @@ public class OCLQueryHandler implements IQueryHandler
try
{
+ Map<String, Object> queryParameters = info.getParameters();
+ Object o = queryParameters.get(LAZY_EXTENTS_PARAMETER);
+ if (o != null)
+ {
+ try
+ {
+ lazyExtents = (Boolean)o;
+ }
+ catch (ClassCastException ex)
+ {
+ throw new IllegalArgumentException("Parameter " + LAZY_EXTENTS_PARAMETER + " must be a boolean but it is a "
+ + o + " class " + o.getClass().getName(), ex);
+ }
+ }
+
CDORevisionProvider revisionProvider = context.getView();
CDOChangeSetData changeSetData = info.getChangeSetData();
if (changeSetData != null)
@@ -135,7 +157,7 @@ public class OCLQueryHandler implements IQueryHandler
helper.setContext(classifier);
- Map<String, Object> parameters = new HashMap<String, Object>(info.getParameters());
+ Map<String, Object> parameters = new HashMap<String, Object>(queryParameters);
initEnvironment(ocl.getEnvironment(), packageRegistry, parameters);
OCLExpression<EClassifier> expr = helper.createQuery(queryString);
@@ -224,7 +246,7 @@ public class OCLQueryHandler implements IQueryHandler
protected boolean createsLazyExtents()
{
- return false;
+ return lazyExtents;
}
protected EClassifier getArbitraryContextClassifier(CDOPackageRegistry packageRegistry)
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
index a5c715be7a..f4079adadb 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
@@ -101,6 +101,7 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(LobTest.class);
testClasses.add(EMFCompareTest.class);
testClasses.add(OCLQueryTest.class);
+ testClasses.add(OCLQueryTest.Lazy.class);
testClasses.add(ViewProviderTest.class);
testClasses.add(WorkspaceTest.class);
testClasses.add(BackupTest.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/OCLQueryTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/OCLQueryTest.java
index de9d85949f..23bd264b35 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/OCLQueryTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/OCLQueryTest.java
@@ -15,6 +15,7 @@ import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.CleanRepositoriesBefore;
import org.eclipse.emf.cdo.tests.model1.Customer;
+import org.eclipse.emf.cdo.tests.model1.Order;
import org.eclipse.emf.cdo.tests.model1.OrderDetail;
import org.eclipse.emf.cdo.tests.model1.Product1;
import org.eclipse.emf.cdo.tests.model1.SalesOrder;
@@ -26,6 +27,8 @@ import org.eclipse.emf.cdo.view.CDOQuery;
import org.eclipse.net4j.util.collection.CloseableIterator;
import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.emf.ecore.EObject;
+
import java.util.ArrayList;
import java.util.List;
@@ -43,6 +46,8 @@ public class OCLQueryTest extends AbstractCDOTest
private static final int NUM_OF_SALES_ORDERS = 5;
+ private static final int NUM_OF_PURCHASE_ORDERS = 3;
+
private CDOTransaction transaction;
private CDOResource resource;
@@ -80,45 +85,52 @@ public class OCLQueryTest extends AbstractCDOTest
public void testAllProducts() throws Exception
{
- CDOQuery query = transaction.createQuery("ocl", "Product1.allInstances()", getModel1Package().getProduct1());
+ CDOQuery query = createQuery("Product1.allInstances()", getModel1Package().getProduct1());
- List<Product1> products = query.getResult(Product1.class);
+ List<Product1> products = query.getResult();
assertEquals(NUM_OF_PRODUCTS, products.size());
}
public void testAllCustomers() throws Exception
{
- CDOQuery query = transaction.createQuery("ocl", "Customer.allInstances()", getModel1Package().getCustomer());
+ CDOQuery query = createQuery("Customer.allInstances()", getModel1Package().getCustomer());
- List<Customer> customers = query.getResult(Customer.class);
+ List<Customer> customers = query.getResult();
assertEquals(NUM_OF_CUSTOMERS, customers.size());
}
+ public void testAllOrdersAndSubtypes() throws Exception
+ {
+ CDOQuery query = createQuery("Order.allInstances()", getModel1Package().getOrder());
+ // CDOQuery query = createQuery("Order.allInstances()", getModel1Package().getOrder());
+
+ List<Order> orders = query.getResult();
+ assertEquals(NUM_OF_CUSTOMERS * NUM_OF_SALES_ORDERS + NUM_OF_PURCHASE_ORDERS, orders.size());
+ }
+
public void testAllProductsWithName() throws Exception
{
- CDOQuery query = transaction.createQuery("ocl", "Product1.allInstances()->select(p | p.name='1')",
- getModel1Package().getProduct1());
+ CDOQuery query = createQuery("Product1.allInstances()->select(p | p.name='1')", getModel1Package().getProduct1());
- List<Product1> products = query.getResult(Product1.class);
+ List<Product1> products = query.getResult();
assertEquals(1, products.size());
}
public void testAllProductsWithNameParameter() throws Exception
{
- CDOQuery query = transaction.createQuery("ocl", "Product1.allInstances()->select(p | p.name=myname)",
- getModel1Package().getProduct1());
+ CDOQuery query = createQuery("Product1.allInstances()->select(p | p.name=myname)", getModel1Package().getProduct1());
query.setParameter("myname", "1");
- List<Product1> products = query.getResult(Product1.class);
+ List<Product1> products = query.getResult();
assertEquals(1, products.size());
}
public void testAllProductsWithVAT() throws Exception
{
- CDOQuery query = transaction.createQuery("ocl", "Product1.allInstances()->select(p | p.vat=VAT::vat15)",
- getModel1Package().getProduct1());
+ CDOQuery query = createQuery("Product1.allInstances()->select(p | p.vat=VAT::vat15)", getModel1Package()
+ .getProduct1());
- List<Product1> products = query.getResult(Product1.class);
+ List<Product1> products = query.getResult();
assertEquals(10, products.size());
for (Product1 p : products)
{
@@ -128,11 +140,10 @@ public class OCLQueryTest extends AbstractCDOTest
public void testAllProductsWithVATParameter() throws Exception
{
- CDOQuery query = transaction.createQuery("ocl", "Product1.allInstances()->select(p | p.vat=myvat)",
- getModel1Package().getProduct1());
+ CDOQuery query = createQuery("Product1.allInstances()->select(p | p.vat=myvat)", getModel1Package().getProduct1());
query.setParameter("myvat", VAT.VAT15);
- List<Product1> products = query.getResult(Product1.class);
+ List<Product1> products = query.getResult();
assertEquals(10, products.size());
for (Product1 p : products)
{
@@ -142,7 +153,7 @@ public class OCLQueryTest extends AbstractCDOTest
public void testAllProductNames() throws Exception
{
- CDOQuery query = transaction.createQuery("ocl", "Product1.allInstances().name", getModel1Package().getProduct1());
+ CDOQuery query = createQuery("Product1.allInstances().name", getModel1Package().getProduct1());
List<String> names = query.getResult(String.class);
assertEquals(NUM_OF_PRODUCTS, names.size());
@@ -153,7 +164,7 @@ public class OCLQueryTest extends AbstractCDOTest
public void testSelfNavigation() throws Exception
{
SalesOrder salesOrder = salesOrders.get(0);
- CDOQuery query = transaction.createQuery("ocl", "self.orderDetails", salesOrder);
+ CDOQuery query = createQuery("self.orderDetails", salesOrder);
List<OrderDetail> orderDetails = query.getResult(OrderDetail.class);
assertEquals(salesOrder.getOrderDetails().size(), orderDetails.size());
@@ -161,7 +172,7 @@ public class OCLQueryTest extends AbstractCDOTest
public void testProductIterator() throws Exception
{
- CDOQuery query = transaction.createQuery("ocl", "Product1.allInstances()", getModel1Package().getProduct1());
+ CDOQuery query = createQuery("Product1.allInstances()", getModel1Package().getProduct1());
int counter = 0;
for (CloseableIterator<Product1> it = query.getResultAsync(Product1.class); it.hasNext();)
@@ -182,9 +193,9 @@ public class OCLQueryTest extends AbstractCDOTest
resource.getContents().add(getModel1Factory().createProduct1());
assertEquals(true, transaction.isDirty());
- CDOQuery query = transaction.createQuery("ocl", "Product1.allInstances()", getModel1Package().getProduct1(), true);
+ CDOQuery query = createQuery("Product1.allInstances()", getModel1Package().getProduct1(), true);
- List<Product1> products = query.getResult(Product1.class);
+ List<Product1> products = query.getResult();
assertEquals(NUM_OF_PRODUCTS + 1, products.size());
}
@@ -193,10 +204,10 @@ public class OCLQueryTest extends AbstractCDOTest
Product1 product = products.get(2);
product.setName("1");
- CDOQuery query = transaction.createQuery("ocl", "Product1.allInstances()->select(p | p.name='1')",
- getModel1Package().getProduct1(), true);
+ CDOQuery query = createQuery("Product1.allInstances()->select(p | p.name='1')", getModel1Package().getProduct1(),
+ true);
- List<Product1> products = query.getResult(Product1.class);
+ List<Product1> products = query.getResult();
assertEquals(2, products.size());
}
@@ -207,25 +218,25 @@ public class OCLQueryTest extends AbstractCDOTest
resource.getContents().add(0, p1);
transaction.commit();
- CDOQuery query = transaction.createQuery("ocl", "Product1.allInstances()", getModel1Package().getProduct1(), true);
+ CDOQuery query = createQuery("Product1.allInstances()", getModel1Package().getProduct1(), true);
- List<Product1> products = query.getResult(Product1.class);
+ List<Product1> products = query.getResult();
assertEquals(NUM_OF_PRODUCTS + 1, products.size());
resource.getContents().remove(0);
assertEquals(true, transaction.isDirty());
- query = transaction.createQuery("ocl", "Product1.allInstances()", getModel1Package().getProduct1(), true);
+ query = createQuery("Product1.allInstances()", getModel1Package().getProduct1(), true);
- products = query.getResult(Product1.class);
+ products = query.getResult();
assertEquals(NUM_OF_PRODUCTS, products.size());
}
public void testDeletedObject() throws Exception
{
- CDOQuery query = transaction.createQuery("ocl", "Product1.allInstances()", getModel1Package().getProduct1(), true);
+ CDOQuery query = createQuery("Product1.allInstances()", getModel1Package().getProduct1(), true);
- List<Product1> products = query.getResult(Product1.class);
+ List<Product1> products = query.getResult();
int numOfProducts = products.size();
Product1 p1 = getModel1Factory().createProduct1();
@@ -236,9 +247,9 @@ public class OCLQueryTest extends AbstractCDOTest
resource.getContents().remove(0);
transaction.commit();
- query = transaction.createQuery("ocl", "Product1.allInstances()", getModel1Package().getProduct1(), true);
+ query = createQuery("Product1.allInstances()", getModel1Package().getProduct1(), true);
- products = query.getResult(Product1.class);
+ products = query.getResult();
assertEquals(numOfProducts, products.size());
}
@@ -252,9 +263,9 @@ public class OCLQueryTest extends AbstractCDOTest
resource.getContents().remove(0);
transaction.commit();
- CDOQuery query = transaction.createQuery("ocl", "Product1.allInstances()", getModel1Package().getProduct1(), false);
+ CDOQuery query = createQuery("Product1.allInstances()", getModel1Package().getProduct1(), false);
- List<Product1> products = query.getResult(Product1.class);
+ List<Product1> products = query.getResult();
assertEquals(NUM_OF_PRODUCTS, products.size());
}
@@ -263,9 +274,9 @@ public class OCLQueryTest extends AbstractCDOTest
ISession session = getRepository().getSessionManager().getElements()[0];
int originalLength = session.getListeners().length;
- for (int counter = 0; counter < 1000; counter++)
+ for (int counter = 0; counter < 10; counter++)
{
- CDOQuery query = transaction.createQuery("ocl", "Product1.allInstances().name", getModel1Package().getProduct1());
+ CDOQuery query = createQuery("Product1.allInstances().name", getModel1Package().getProduct1());
query.getResult(String.class);
}
@@ -307,6 +318,11 @@ public class OCLQueryTest extends AbstractCDOTest
productCounter += NUM_OF_PRODUCTS_CUSTOMER;
}
+
+ for (int k = 0; k < NUM_OF_PURCHASE_ORDERS; k++)
+ {
+ resource.getContents().add(getModel1Factory().createPurchaseOrder());
+ }
}
private Customer createCustomer(int i)
@@ -372,4 +388,33 @@ public class OCLQueryTest extends AbstractCDOTest
products.add(product);
return product;
}
+
+ private CDOQuery createQuery(String queryString, EObject context)
+ {
+ return createQuery(queryString, context, false);
+ }
+
+ private CDOQuery createQuery(String queryString, EObject context, boolean considerDirtyState)
+ {
+ CDOQuery query = transaction.createQuery("ocl", queryString, context, considerDirtyState);
+ query.setParameter("cdoLazyExtents", useLazyExtents());
+ return query;
+ }
+
+ protected boolean useLazyExtents()
+ {
+ return false;
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class Lazy extends OCLQueryTest
+ {
+ @Override
+ protected boolean useLazyExtents()
+ {
+ return true;
+ }
+ }
}

Back to the top