Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-09-04 17:22:52 +0000
committerEike Stepper2013-09-04 17:31:11 +0000
commit1c2ba406f5c8150a50efe39da2aa4db5b75fa1d8 (patch)
tree36f8fbb830f619a90dcbdb5da63262093133bd04 /plugins/org.eclipse.emf.cdo.server
parent7855866044ccf3a32cbbb6916ffd6c5121edf9ab (diff)
downloadcdo-1c2ba406f5c8150a50efe39da2aa4db5b75fa1d8.tar.gz
cdo-1c2ba406f5c8150a50efe39da2aa4db5b75fa1d8.tar.xz
cdo-1c2ba406f5c8150a50efe39da2aa4db5b75fa1d8.zip
[416555] Provide CDOView.queryInstances(EClass)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=416555
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server')
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/InstancesQueryHandler.java98
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java5
2 files changed, 103 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/InstancesQueryHandler.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/InstancesQueryHandler.java
new file mode 100644
index 0000000000..1343909e2d
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/InstancesQueryHandler.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2013 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.internal.server;
+
+import org.eclipse.emf.cdo.common.branch.CDOBranch;
+import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
+import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
+import org.eclipse.emf.cdo.server.IQueryContext;
+import org.eclipse.emf.cdo.server.IQueryHandler;
+import org.eclipse.emf.cdo.spi.server.InternalRepository;
+import org.eclipse.emf.cdo.spi.server.QueryHandlerFactory;
+
+import org.eclipse.net4j.util.factory.ProductCreationException;
+
+import org.eclipse.emf.ecore.EClass;
+
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public class InstancesQueryHandler implements IQueryHandler
+{
+ public InstancesQueryHandler()
+ {
+ }
+
+ public void executeQuery(CDOQueryInfo info, IQueryContext context)
+ {
+ EClass type = (EClass)info.getParameters().get(CDOProtocolConstants.QUERY_LANGUAGE_INSTANCES_TYPE);
+ executeQuery(type, context);
+
+ boolean exact = Boolean.TRUE.equals(info.getParameters().get(CDOProtocolConstants.QUERY_LANGUAGE_INSTANCES_EXACT));
+ if (!exact)
+ {
+ List<EClass> subTypes = context.getView().getRepository().getPackageRegistry().getSubTypes().get(type);
+ if (subTypes != null && !subTypes.isEmpty())
+ {
+ for (EClass subType : subTypes)
+ {
+ if (context.getResultCount() == 0)
+ {
+ break;
+ }
+
+ executeQuery(subType, context);
+ }
+ }
+ }
+ }
+
+ private void executeQuery(EClass type, final IQueryContext context)
+ {
+ if (type.isInterface() || type.isAbstract())
+ {
+ return;
+ }
+
+ CDOBranch branch = context.getBranch();
+ long timeStamp = context.getTimeStamp();
+
+ InternalRepository repository = (InternalRepository)context.getView().getRepository();
+ repository.handleRevisions(type, branch, false, timeStamp, false, new CDORevisionHandler()
+ {
+ public boolean handleRevision(CDORevision revision)
+ {
+ return context.addResult(revision);
+ }
+ });
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class Factory extends QueryHandlerFactory
+ {
+ public Factory()
+ {
+ super(CDOProtocolConstants.QUERY_LANGUAGE_INSTANCES);
+ }
+
+ @Override
+ public InstancesQueryHandler create(String description) throws ProductCreationException
+ {
+ return new InstancesQueryHandler();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
index 32fe8afe2f..84a9d1ac5b 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
@@ -1079,6 +1079,11 @@ public class Repository extends Container<Object> implements InternalRepository
return new ResourcesQueryHandler();
}
+ if (CDOProtocolConstants.QUERY_LANGUAGE_INSTANCES.equals(language))
+ {
+ return new InstancesQueryHandler();
+ }
+
if (CDOProtocolConstants.QUERY_LANGUAGE_XREFS.equals(language))
{
return new XRefsQueryHandler();

Back to the top