From: luukkainen Date: Tue, 4 Feb 2014 14:47:14 +0000 (+0000) Subject: Wrong query id caused query cache to store model variables separately for each variable X-Git-Tag: 1.8.1~145 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=41325aaea25e7e552de28e5776be82759bf658dc;p=simantics%2Fsysdyn.git Wrong query id caused query cache to store model variables separately for each variable Dispose methods for clearing local caches. fixes #4694 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28771 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/AllVariablesOfModel.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/AllVariablesOfModel.java index f64435be..f3fcd7dd 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/AllVariablesOfModel.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/AllVariablesOfModel.java @@ -6,22 +6,52 @@ import java.util.Collections; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.simulation.ontology.SimulationResource; public class AllVariablesOfModel implements Read> { - public Resource res; + public Resource model; + /** + * Queries all variables of a model + * @param res the model. + */ public AllVariablesOfModel(Resource res) { - this.res = res; + this.model = res; + } + + public Resource getModel() { + return model; } @Override public Collection perform(ReadGraph graph) throws DatabaseException { - if(!graph.hasStatement(res)) + if(!graph.hasStatement(model)) return Collections.emptyList(); - IAllVariablesOfModel query = graph.adapt(res, IAllVariablesOfModel.class); + IAllVariablesOfModel query = graph.adapt(model, IAllVariablesOfModel.class); return graph.syncRequest(query.getVariablesQuery()); } + + public static AllVariablesOfModel withRandomResource(ISessionContext context, final Resource resource) throws DatabaseException { + Resource model = context.getSession().syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + Resource r = resource; + while((r = graph.getPossibleObject(r, Layer0.getInstance(graph).PartOf)) != null) { + if(graph.isInstanceOf(r, SimulationResource.getInstance(graph).Model)) + return r; + } + return null; + } + + }); + if (model == null) + return null; + return new AllVariablesOfModel(model); + } } diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/StringChooser.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/StringChooser.java index 892e9986..ce1b351b 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/StringChooser.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/StringChooser.java @@ -8,7 +8,6 @@ import java.util.Set; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.ListenerList; -import org.eclipse.jface.dialogs.IInputValidator; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.LocalResourceManager; import org.eclipse.jface.resource.ResourceManager; @@ -31,7 +30,6 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Text; import org.simantics.browsing.ui.swt.widgets.DefaultColorProvider; import org.simantics.browsing.ui.swt.widgets.impl.ITrackedColorProvider; - import org.simantics.browsing.ui.swt.widgets.impl.ReadFactory; import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; @@ -253,7 +251,8 @@ public class StringChooser implements Widget{ state |= EDITING | MOUSE_DOWN_FIRST_TIME; } - private void applyEdit() { + @SuppressWarnings("unchecked") + private void applyEdit() { try { if (isTextValid() != null) { text.setText(textBeforeEdit); @@ -261,9 +260,9 @@ public class StringChooser implements Widget{ setSelected(text.getText()); //System.out.println("apply"); if (modifyListeners != null) { - StringChooserModifyEvent event = new StringChooserModifyEvent(text, selected, text.getText()); + StringChooserModifyEvent event = new StringChooserModifyEvent(text, selected, text.getText()); for (Object o : modifyListeners.getListeners()) { - ((StringChooserModifyListener) o).modifySelection(event); + ((StringChooserModifyListener) o).modifySelection(event); } } } @@ -360,14 +359,14 @@ public class StringChooser implements Widget{ return text; } - public synchronized void addModifyListener(StringChooserModifyListener listener) { + public synchronized void addModifyListener(StringChooserModifyListener listener) { if (modifyListeners == null) { modifyListeners = new ListenerList(ListenerList.IDENTITY); } modifyListeners.add(listener); } - public synchronized void removeModifyListener(StringChooserModifyListener listener) { + public synchronized void removeModifyListener(StringChooserModifyListener listener) { if (modifyListeners == null) return; modifyListeners.remove(listener); @@ -587,4 +586,15 @@ public class StringChooser implements Widget{ } } } + + public void dispose() { + allowedLabels.clear(); + allowedLabels = null; + objectFactory = null; + objectToLabel.clear(); + objectToLabel = null; + + } + + } diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableExistsValidator.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableExistsValidator.java index e8c8e03b..32abe9e6 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableExistsValidator.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableExistsValidator.java @@ -7,14 +7,10 @@ import org.eclipse.jface.dialogs.IInputValidator; import org.simantics.browsing.ui.swt.widgets.TrackedText; import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; import org.simantics.db.procedure.Listener; -import org.simantics.db.request.Read; -import org.simantics.layer0.Layer0; -import org.simantics.simulation.ontology.SimulationResource; import org.simantics.ui.SimanticsUI; import org.simantics.utils.ui.AdaptionUtils; @@ -97,28 +93,15 @@ public class VariableExistsValidator implements IInputValidator, Widget { return; } - Resource model = null; + try { /* Find the model resource. It can be found with PartOf relations from series resource in a chart */ - model = context.getSession().syncRequest(new Read() { - - @Override - public Resource perform(ReadGraph graph) throws DatabaseException { - Resource r = resource; - while((r = graph.getPossibleObject(r, Layer0.getInstance(graph).PartOf)) != null) { - if(graph.isInstanceOf(r, SimulationResource.getInstance(graph).Model)) - return r; - } - return null; - } - - }); + AllVariablesOfModel query = AllVariablesOfModel.withRandomResource(context, resource); - if(model != null) { + if(query != null) { // Find all variables and set them as the reference for isValid(String) - SimanticsUI.getSession().asyncRequest( - new AllVariablesOfModel(model) + SimanticsUI.getSession().asyncRequest(query , new Listener>() { @Override diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableProposalProvider.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableProposalProvider.java index c3229747..da399f6b 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableProposalProvider.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableProposalProvider.java @@ -22,6 +22,7 @@ import org.eclipse.swt.widgets.Control; import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; import org.simantics.db.procedure.Listener; import org.simantics.ui.SimanticsUI; @@ -156,29 +157,37 @@ public class VariableProposalProvider implements IContentProposalProvider, Widge if(resource == null) return; this.resource = resource; + /* Find the model resource. It can be found with PartOf + relations from series resource in a chart */ + try { + AllVariablesOfModel query = AllVariablesOfModel.withRandomResource(context, resource); + SimanticsUI.getSession().asyncRequest(query + , new Listener>() { + + @Override + public void execute(Collection result) { + setProposals(result); + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return control == null || + control.isDisposed() || + !resource.equals(VariableProposalProvider.this.resource); + } + + }); + } catch (DatabaseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - SimanticsUI.getSession().asyncRequest( - new AllVariablesOfModel(resource) - , new Listener>() { - - @Override - public void execute(Collection result) { - setProposals(result); - } - - @Override - public void exception(Throwable t) { - t.printStackTrace(); - } - - @Override - public boolean isDisposed() { - return control == null || - control.isDisposed() || - !resource.equals(VariableProposalProvider.this.resource); - } - - }); + } diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesPropertyComposite2.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesPropertyComposite2.java index 9cb7fdc2..a9a1d48d 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesPropertyComposite2.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesPropertyComposite2.java @@ -114,4 +114,11 @@ public class BarSeriesPropertyComposite2 extends Composite { GridDataFactory.fillDefaults().applyTo(time.getWidget()); } } + + @Override + public void dispose() { + variable.dispose(); + variable = null; + super.dispose(); + } } diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesTab2.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesTab2.java index 0f6d81f2..24076dda 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesTab2.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesTab2.java @@ -132,7 +132,8 @@ public class BarSeriesTab2 extends LabelPropertyTabContributor implements Widget } try { - Collection variables = context.getSession().syncRequest(new AllVariablesOfModel(resource)); + AllVariablesOfModel query = AllVariablesOfModel.withRandomResource(context, resource); + Collection variables = context.getSession().syncRequest(query); spc = new BarSeriesPropertyComposite2(propertyContainer, context, additionalSupport, variables, options, SWT.NONE); diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesPropertyComposite2.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesPropertyComposite2.java index 181f78ca..3f3c4aff 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesPropertyComposite2.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesPropertyComposite2.java @@ -125,5 +125,12 @@ public class PieSeriesPropertyComposite2 extends Composite { exploded.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Series_exploded)); GridDataFactory.fillDefaults().applyTo(exploded.getWidget()); } + + @Override + public void dispose() { + variable.dispose(); + variable = null; + super.dispose(); + } } diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesTab2.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesTab2.java index 42076996..7103b6f8 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesTab2.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesTab2.java @@ -131,7 +131,8 @@ public class PieSeriesTab2 extends LabelPropertyTabContributor implements Widget } try { - Collection variables = context.getSession().syncRequest(new AllVariablesOfModel(resource)); + AllVariablesOfModel query = AllVariablesOfModel.withRandomResource(context, resource); + Collection variables = context.getSession().syncRequest(query); PieSeriesPropertyComposite2 spc = new PieSeriesPropertyComposite2(propertyContainer, context, additionalSupport, variables, options, SWT.NONE); propertyContainer.setContent(spc); Point size = spc.computeSize(SWT.DEFAULT, SWT.DEFAULT);