Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2014-05-05 14:21:52 +0000
committerCamille Letavernier2014-05-05 14:21:52 +0000
commit104dfca0657fbbe9e068d5198e4d77b5a9f2e15b (patch)
tree51cafc8e8dc2b381f417aeda48a0d1bd36b2f563 /plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core
parent14e558d60d79f5b1f4d3ec2dcdc0cf81694d8cd5 (diff)
downloadorg.eclipse.papyrus-104dfca0657fbbe9e068d5198e4d77b5a9f2e15b.tar.gz
org.eclipse.papyrus-104dfca0657fbbe9e068d5198e4d77b5a9f2e15b.tar.xz
org.eclipse.papyrus-104dfca0657fbbe9e068d5198e4d77b5a9f2e15b.zip
434106: [Performances - EMF Facet] Major performance degration when
using OCL queries in EMF Facet Customizations https://bugs.eclipse.org/bugs/show_bug.cgi?id=434106
Diffstat (limited to 'plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core')
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/internal/query/QueryImplementationFactoryRegistry.java91
1 files changed, 52 insertions, 39 deletions
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/internal/query/QueryImplementationFactoryRegistry.java b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/internal/query/QueryImplementationFactoryRegistry.java
index 6df882e3d4e..29fb70de1e0 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/internal/query/QueryImplementationFactoryRegistry.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/internal/query/QueryImplementationFactoryRegistry.java
@@ -11,7 +11,9 @@
package org.eclipse.papyrus.emf.facet.efacet.core.internal.query;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
@@ -31,10 +33,15 @@ import org.eclipse.papyrus.emf.facet.util.emf.core.ICatalogSetManagerFactory;
import org.osgi.framework.Bundle;
public class QueryImplementationFactoryRegistry {
+
private static final String EXT_ID = "org.eclipse.papyrus.emf.facet.efacet.core.queryImplementationRegistration"; //$NON-NLS-1$
+
private static final String CLASS = "class"; //$NON-NLS-1$
+
public static final QueryImplementationFactoryRegistry INSTANCE = new QueryImplementationFactoryRegistry();
+ private static final Map<Query, IQueryImplementation> cache = new HashMap<Query, IQueryImplementation>();
+
private final List<IQueryImplementationFactory> factories = new ArrayList<IQueryImplementationFactory>();
public QueryImplementationFactoryRegistry() {
@@ -44,17 +51,17 @@ public class QueryImplementationFactoryRegistry {
private void initRegisteredEntries() {
final IExtensionRegistry registry = Platform.getExtensionRegistry();
final IExtensionPoint extPoint = registry.getExtensionPoint(QueryImplementationFactoryRegistry.EXT_ID);
- if (extPoint != null) {
- for (final IExtension ext : extPoint.getExtensions()) {
- for (final IConfigurationElement configElt : ext.getConfigurationElements()) {
+ if(extPoint != null) {
+ for(final IExtension ext : extPoint.getExtensions()) {
+ for(final IConfigurationElement configElt : ext.getConfigurationElements()) {
try {
final Object impl = configElt.createExecutableExtension(QueryImplementationFactoryRegistry.CLASS);
- if (impl instanceof IQueryImplementationFactory) {
- final IQueryImplementationFactory factory = (IQueryImplementationFactory) impl;
+ if(impl instanceof IQueryImplementationFactory) {
+ final IQueryImplementationFactory factory = (IQueryImplementationFactory)impl;
this.factories.add(factory);
} else {
Logger.logError("Invalid extension in " + ext.getNamespaceIdentifier() + "." + //$NON-NLS-1$ //$NON-NLS-2$
- ". The factory must be an instance of " + IQueryImplementationFactory.class.getName(), Activator.getDefault()); //$NON-NLS-1$
+ ". The factory must be an instance of " + IQueryImplementationFactory.class.getName(), Activator.getDefault()); //$NON-NLS-1$
}
} catch (final CoreException e) {
Logger.logError(e, Activator.getDefault());
@@ -66,49 +73,55 @@ public class QueryImplementationFactoryRegistry {
/**
* Returns the query evaluator that handles the given type of query
- *
+ *
* @param query
- * the type of query for which an {@link IQueryImplementation} is searched
+ * the type of query for which an {@link IQueryImplementation} is searched
* @return the {@link IQueryImplementation}
* @throws DerivedTypedElementException
- * if no factory implementation was registered for the type of the given query
+ * if no factory implementation was registered for the type of the given query
*/
- public IQueryImplementation getEvaluatorFor(final Query query, final IDerivedTypedElementManager manager)
- throws DerivedTypedElementException {
- if (query == null) {
+ public IQueryImplementation getEvaluatorFor(final Query query, final IDerivedTypedElementManager manager) throws DerivedTypedElementException {
+ if(query == null) {
throw new IllegalArgumentException("query cannot be null"); //$NON-NLS-1$
}
- IQueryImplementation queryImpl = null;
- boolean factoryFound = false;
- for (final IQueryImplementationFactory queryImplFactory : this.factories) {
- factoryFound = queryImplFactory.getManagedQueryType() == query.eClass();
- if (factoryFound) {
- final Resource queryResource = query.eResource();
- Bundle bundle = null;
- if (queryResource != null) {
- bundle = ICatalogSetManagerFactory.DEFAULT.createICatalogSetManager(query.eResource().getResourceSet()).getBundleByResource(queryResource);
+
+ if(!cache.containsKey(query)) {
+
+ IQueryImplementation queryImpl = null;
+ boolean factoryFound = false;
+ for(final IQueryImplementationFactory queryImplFactory : this.factories) {
+ factoryFound = queryImplFactory.getManagedQueryType() == query.eClass();
+ if(factoryFound) {
+ final Resource queryResource = query.eResource();
+ Bundle bundle = null;
+ if(queryResource != null) {
+ bundle = ICatalogSetManagerFactory.DEFAULT.createICatalogSetManager(query.eResource().getResourceSet()).getBundleByResource(queryResource);
+ }
+ queryImpl = queryImplFactory.create(query, bundle, manager);
+ break;
}
- queryImpl = queryImplFactory.create(query, bundle, manager);
- break;
}
- }
- if (!factoryFound) {
- final StringBuffer buffer = new StringBuffer();
- buffer.append("No factory implementation found for "); //$NON-NLS-1$
- buffer.append(QueryUtils.getQueryDescription(query));
- buffer.append(".\nA factory should be registered through the "); //$NON-NLS-1$
- buffer.append(QueryImplementationFactoryRegistry.EXT_ID);
- buffer.append(" extension point."); //$NON-NLS-1$ // NOPMD: cannot merge with extracted constant string
- buffer.append("\nAvailable Query types are: "); //$NON-NLS-1$
- for (int i = 0; i < this.factories.size(); i++) {
- if (i > 0) {
- buffer.append(", "); //$NON-NLS-1$
+ if(!factoryFound) {
+ final StringBuffer buffer = new StringBuffer();
+ buffer.append("No factory implementation found for "); //$NON-NLS-1$
+ buffer.append(QueryUtils.getQueryDescription(query));
+ buffer.append(".\nA factory should be registered through the "); //$NON-NLS-1$
+ buffer.append(QueryImplementationFactoryRegistry.EXT_ID);
+ buffer.append(" extension point."); //$NON-NLS-1$ // NOPMD: cannot merge with extracted constant string
+ buffer.append("\nAvailable Query types are: "); //$NON-NLS-1$
+ for(int i = 0; i < this.factories.size(); i++) {
+ if(i > 0) {
+ buffer.append(", "); //$NON-NLS-1$
+ }
+ final IQueryImplementationFactory factory = this.factories.get(i);
+ buffer.append(factory.getManagedQueryType().getName());
}
- final IQueryImplementationFactory factory = this.factories.get(i);
- buffer.append(factory.getManagedQueryType().getName());
+ throw new DerivedTypedElementException(buffer.toString());
}
- throw new DerivedTypedElementException(buffer.toString());
+
+ cache.put(query, queryImpl);
}
- return queryImpl;
+
+ return cache.get(query);
}
}

Back to the top