From: Tuukka Lehtonen Date: Thu, 2 Nov 2017 13:37:32 +0000 (+0200) Subject: Fixed SCLScriptAnnotationModel script validation threading X-Git-Tag: v1.31.0~65 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F83%2F1183%2F1;p=simantics%2Fplatform.git Fixed SCLScriptAnnotationModel script validation threading Previously the code performed the script validation directly in the DB listener thread, which is essentially QueryThread-0 without putting the related ReadGraph into the current SCLContext while doing so. This caused the validation code to crash because the validation code tries to start a new database transaction from within the transaction thread calling the listener. The solution schedules the validation to a BUILD priority Job thread. refs #7450 Change-Id: I01c030be032890638919c3800e04e14670f8726c --- diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/scl/scriptEditor/SCLScriptAnnotationModel.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/scl/scriptEditor/SCLScriptAnnotationModel.java index fadb4f909..6653422dd 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/scl/scriptEditor/SCLScriptAnnotationModel.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/scl/scriptEditor/SCLScriptAnnotationModel.java @@ -14,6 +14,10 @@ package org.simantics.modeling.ui.scl.scriptEditor; import java.util.Arrays; import java.util.List; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.source.Annotation; @@ -51,7 +55,7 @@ public class SCLScriptAnnotationModel extends AnnotationModel { @Override public void execute(String result) { if (connected && result != null) - updateAnnotations(result); + scheduleUpdateAnnotations(result); } @Override public void exception(Throwable t) { @@ -72,6 +76,21 @@ public class SCLScriptAnnotationModel extends AnnotationModel { public void print(String text) {} }; + private void scheduleUpdateAnnotations(String sourceText) { + //LOGGER.debug("scheduleUpdateAnnotations:\n" + sourceText); + Job validateJob = new Job("Validate Script") { + @Override + protected IStatus run(IProgressMonitor monitor) { + updateAnnotations(sourceText); + return Status.OK_STATUS; + } + }; + validateJob.setPriority(Job.BUILD); + validateJob.setUser(false); + validateJob.setSystem(false); + validateJob.schedule(); + } + private void updateAnnotations(String sourceText) { //LOGGER.debug("updateAnnotations:\n" + sourceText); CompilationError[] errors = new CommandSession(repository, NOP).validate(sourceText);