From 2bc508bb935f99de104bd25935f23c474de7f1ca Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Thu, 2 Nov 2017 15:37:32 +0200 Subject: [PATCH] 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 --- .../SCLScriptAnnotationModel.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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); -- 2.43.2