From: Tuukka Lehtonen Date: Tue, 27 Sep 2016 22:54:05 +0000 (+0300) Subject: Merge commit 'ffdf837' X-Git-Tag: v1.25.0~84 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=5930811a7911090a0c4984380c3b45ed81a93cde;hp=5134e3d53a652adc5b1936c17fe3ec6fb8ef433e Merge commit 'ffdf837' Resolved conflicts from: bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/GraphSessionVirtual.java bundles/org.simantics.db.server/src/org/simantics/db/server/internal/SessionI.java bundles/org.simantics.db/src/org/simantics/db/Database.java bundles/org.simantics.db/src/org/simantics/db/service/ClusterSetsSupport.java bundles/org.simantics.modeling/src/org/simantics/modeling/SCL.java bundles/org.simantics.workbench/src/org/simantics/workbench/internal/SimanticsWorkbenchAdvisor.java bundles/org.simantics/src/org/simantics/SimanticsPlatform.java --- diff --git a/bundles/org.simantics.charts/src/org/simantics/charts/ui/CSVExportPage.java b/bundles/org.simantics.charts/src/org/simantics/charts/ui/CSVExportPage.java index b5a177e7e..0f5a1751d 100644 --- a/bundles/org.simantics.charts/src/org/simantics/charts/ui/CSVExportPage.java +++ b/bundles/org.simantics.charts/src/org/simantics/charts/ui/CSVExportPage.java @@ -27,6 +27,7 @@ import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -113,7 +114,12 @@ public class CSVExportPage extends WizardPage { @Override public void createControl(Composite parent) { - Composite container = new Composite(parent, SWT.NONE); + ScrolledComposite scroller = new ScrolledComposite(parent, SWT.V_SCROLL); + scroller.setExpandHorizontal(true); + scroller.setExpandVertical(true); + + Composite container = new Composite(scroller, SWT.NONE); + scroller.setContent(container); GridLayoutFactory.swtDefaults().spacing(20, 10).numColumns(3).applyTo(container); new Label(container, SWT.NONE).setText("Select a model:"); model = new CCombo(container, SWT.BORDER); @@ -128,7 +134,7 @@ public class CSVExportPage extends WizardPage { item = new Table(container, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK); { item.setToolTipText("Selects the Subscription Items"); - GridDataFactory.fillDefaults().grab(true, false).span(2, 1).hint(SWT.DEFAULT, 105).applyTo(item); + GridDataFactory.fillDefaults().grab(true, true).span(2, 1).hint(SWT.DEFAULT, 105).applyTo(item); } item.addSelectionListener(new SelectionAdapter() { @Override @@ -292,7 +298,9 @@ public class CSVExportPage extends WizardPage { model.addSelectionListener(s); - setControl(container); + scroller.setMinSize(container.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + + setControl(scroller); validatePage(); } diff --git a/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcherBase.java b/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcherBase.java index f26f9a961..4afbb174e 100644 --- a/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcherBase.java +++ b/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcherBase.java @@ -705,27 +705,22 @@ abstract public class IndexedRelationsSearcherBase { mon.worked(1); } } - - s.release(); - } catch (DatabaseException e) { - throw new IllegalStateException(e); + Logger.defaultLogError("DatabaseException occured during initializing index", e); + } catch (Throwable t) { + Logger.defaultLogError("Fatal error occured during initializing index", t); + } finally { + s.release(); } - } - }); - } - try { s.acquire(INDEXING_THREAD_COUNT); } catch (InterruptedException e) { e.printStackTrace(); } - } - }); // http://www.gossamer-threads.com/lists/lucene/java-dev/47895 diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/changeset/MetadataUtils.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/changeset/MetadataUtils.java index 31f29554c..ef1753396 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/changeset/MetadataUtils.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/changeset/MetadataUtils.java @@ -122,22 +122,9 @@ public class MetadataUtils { // Map> metadatas = getMetadatas(graph, support, revisionId, Long.MAX_VALUE); for(Map.Entry> e : metadatas.entrySet()) { -// System.err.println("metadata " + e.getKey() + " " + e.getValue()); -// long csid = e.getKey(); + Map metadata = e.getValue(); -// if(metadata == null) -// continue; -// if(metadata != null) { - -// for(ChangeSetIdentifier csi : csis) { -// if(csi.getId() < fromRevision) { // TODO remove this test when DB api is fixed -// System.err.println("ManagementSupport.getChangeSetIdentifiers returned identifiers outside of the requested range."); -// continue; -// } -// Map metadata = getMetadata(graph, support, csi); -// if(metadata == null) -// continue; - + browseChanges: { byte[] changesData = metadata.get(DependencyChanges.class.getName()); if(changesData == null || changesData.length == 0) @@ -152,35 +139,13 @@ public class MetadataUtils { visitor.visit(graph, change, inverted); } - browseUndos: { - byte[] undoMetadata = metadata.get(UndoMetadata.class.getName()); - if(undoMetadata == null || undoMetadata.length == 0) - break browseUndos; + byte[] undoMetadata = metadata.get(UndoMetadata.class.getName()); + if(undoMetadata != null && undoMetadata.length != 0) { UndoMetadata undo = UndoMetadata.deserialise(graph.getSession(), undoMetadata); visitDependencyChangesBetween(graph, model, undo.getBeginCSId(), undo.getEndCSId(), visitor, undo.isRedo() ? inverted : !inverted); } } - } + } -// public static Map> getDependencyChangeIndexFrom(ReadGraph graph, long revisionId) throws DatabaseException { -// -// -// -// Map> index = new HashMap>(); -// -// for(Map> entry : getDependencyChangesFrom(graph, revisionId)) { -// if(DEBUG) System.out.println("getDependencyChangeIndexFrom process " + entry); -// Collection list = index.get(entry.getOwner()); -// if(list == null) { -// list = new ArrayList(); -// index.put(entry.getOwner(), list); -// } -// list.add(entry); -// } -// -// return index; -// -// } - } diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterSetsSupportImpl.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterSetsSupportImpl.java index da2c88f21..b81a6e734 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterSetsSupportImpl.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterSetsSupportImpl.java @@ -69,6 +69,12 @@ public class ClusterSetsSupportImpl implements ClusterSetsSupport, Disposable { public void clear() { clusterSets.clear(); } + + @Override + public void setReadDirectory(Path read) { + // TODO Auto-generated method stub + + } @Override public void updateWriteDirectory(Path write) { // Nothing to do here diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterSetsSupportImpl2.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterSetsSupportImpl2.java index ed1689ea4..33950652c 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterSetsSupportImpl2.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterSetsSupportImpl2.java @@ -13,8 +13,8 @@ public class ClusterSetsSupportImpl2 implements ClusterSetsSupport, Disposable { final private static boolean DEBUG = false; final private static Map sClusterSets = new HashMap(); - private Path writeDirectory; private Path readDirectory; + private Path writeDirectory; private String databaseId; // Unique identifier for database of session. Initialized in connect. private ClusterSets clusterSets; // Cluster sets for session. Initialized in connect. public ClusterSetsSupportImpl2() { @@ -83,4 +83,9 @@ public class ClusterSetsSupportImpl2 implements ClusterSetsSupport, Disposable { this.readDirectory = read; } + @Override + public void setReadDirectory(Path read) { + this.readDirectory = read; + } + } diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/GraphSession.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/GraphSession.java index 054ee1d60..58917ae74 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/GraphSession.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/GraphSession.java @@ -29,13 +29,13 @@ import org.simantics.databoard.binding.impl.TreeMapBinding; import org.simantics.databoard.serialization.Serializer; import org.simantics.db.ChangeSetIdentifier; import org.simantics.db.Database; -import org.simantics.db.Operation; -import org.simantics.db.SessionReference; import org.simantics.db.Database.Session.ChangeSetData; import org.simantics.db.Database.Session.ChangeSetIds; import org.simantics.db.Database.Session.ClusterChanges; import org.simantics.db.Database.Session.ClusterIds; import org.simantics.db.Database.Session.Refresh; +import org.simantics.db.Operation; +import org.simantics.db.SessionReference; import org.simantics.db.common.UndoContextEx; import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; @@ -49,7 +49,6 @@ import org.simantics.scl.runtime.function.Function1; import org.simantics.scl.runtime.function.FunctionImpl1; import org.simantics.utils.threads.ThreadUtils; -import fi.vtt.simantics.procore.ProCoreSessionReference; import gnu.trove.iterator.TLongObjectIterator; import gnu.trove.map.hash.THashMap; import gnu.trove.map.hash.TLongObjectHashMap; @@ -725,6 +724,9 @@ public abstract class GraphSession { clusters[i] = new ClusterUID(first[i], second[i]); return clusters; } + public boolean rolledback() { + return dbSession.rolledback(); + } } class BuiltinData { final long id; diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/GraphSessionVirtual.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/GraphSessionVirtual.java index d1e006424..f6eba7eb8 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/GraphSessionVirtual.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/GraphSessionVirtual.java @@ -129,7 +129,6 @@ class GraphSessionVirtual extends GraphSession { // Äsh! This extends relation } @Override public boolean rolledback() { - // TODO Auto-generated method stub return false; } } @@ -215,4 +214,4 @@ class GraphSessionVirtual extends GraphSession { // Äsh! This extends relation id = virtualGraphServerSupport.createVirtual(); return id; } -} \ No newline at end of file +} diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplDb.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplDb.java index 3c0f71eaf..d0e9d55f0 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplDb.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplDb.java @@ -12,7 +12,6 @@ package fi.vtt.simantics.procore.internal; import java.io.File; -import java.io.IOException; import org.simantics.db.Database; import org.simantics.db.SessionManager; @@ -32,8 +31,6 @@ import org.simantics.db.impl.query.QueryProcessor; import org.simantics.db.impl.query.QuerySupport; import org.simantics.db.service.ServerInformation; -import fi.vtt.simantics.procore.BackdoorAuthenticator; - final public class SessionImplDb extends SessionImplSocket { /** diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplVirtual.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplVirtual.java index 1a109d2e0..377208f22 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplVirtual.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplVirtual.java @@ -53,9 +53,9 @@ public class SessionImplVirtual extends SessionImplSocket { // This is used by QueryProcessor among others. String databaseId = GraphSessionVirtual.serverInfo.databaseId; String serverId = GraphSessionVirtual.serverInfo.serverId; - virtualGraphServerSupport.connect(databaseId + "." + serverId); - virtualGraphImpl = (VirtualGraphImpl)virtualGraphServerSupport.getWorkspacePersistent("virtualGraph" + "." + serverId); try { + virtualGraphServerSupport.connect(databaseId + "." + serverId); + virtualGraphImpl = (VirtualGraphImpl)virtualGraphServerSupport.getWorkspacePersistent("virtualGraph" + "." + serverId); requestManager = new SessionRequestManager(this, state); clusterStream = new ClusterStream(this, graphSession, true); clusterTranslator = new ClusterTranslatorImpl(this); diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/VirtualGraphServerSupportImpl.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/VirtualGraphServerSupportImpl.java index 6c86c100a..227d9bcff 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/VirtualGraphServerSupportImpl.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/VirtualGraphServerSupportImpl.java @@ -38,6 +38,7 @@ import org.simantics.db.service.SerialisationSupport; import org.simantics.db.service.ServerInformation; import org.simantics.db.service.TransferableGraphSupport; import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.service.XSupport; import org.simantics.layer0.Layer0; import org.simantics.utils.FileUtils; @@ -63,14 +64,21 @@ public class VirtualGraphServerSupportImpl implements VirtualGraphSupport, Virtu this.virtualGraphStoragePath = path; } - void connect(String dbString) { + void connect(String dbString) throws Exception { + virtualId = new AtomicInteger(-2); + this.dbString = dbString; - virtualId = new AtomicInteger(-2); - - this.dbString = dbString; + XSupport support = session.getService(XSupport.class); + if (support.rolledback()) { + for (File file : virtualGraphStoragePath.listFiles()) { + if (!file.delete()) { + throw new IOException("Could not delete file " + file.getAbsolutePath()); + } + } + } File file = new File(virtualGraphStoragePath, "virtualGraphs." + dbString + ".dat"); - + // System.out.println("scanning " + file.getAbsolutePath()); if(file.exists()) { @@ -84,11 +92,15 @@ public class VirtualGraphServerSupportImpl implements VirtualGraphSupport, Virtu hasVirtuals = true; + String databaseId = session.getService(ServerInformation.class).getDatabaseId(); + String matcher = ".W." + databaseId + ".vg."; + // Load existing workspace persistent graphs for(File virtualGraph : virtualGraphStoragePath.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { - return name.endsWith(".vg"); + boolean matches = name.contains(matcher); + return matches; } })) { String name = virtualGraph.getName(); diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/XSupportImpl.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/XSupportImpl.java index 662effbfb..f6ca16af4 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/XSupportImpl.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/XSupportImpl.java @@ -157,4 +157,9 @@ public class XSupportImpl implements XSupport { Database db = session.graphSession.dbSession.getDatabase(); db.purgeDatabase(); } + + @Override + public boolean rolledback() { + return session.graphSession.rolledback(); + } } diff --git a/bundles/org.simantics.db.server/src/org/simantics/db/server/internal/SessionI.java b/bundles/org.simantics.db.server/src/org/simantics/db/server/internal/SessionI.java index 2d08de4a6..04eb991f6 100644 --- a/bundles/org.simantics.db.server/src/org/simantics/db/server/internal/SessionI.java +++ b/bundles/org.simantics.db.server/src/org/simantics/db/server/internal/SessionI.java @@ -234,7 +234,6 @@ public class SessionI implements Session { } @Override public boolean rolledback() { - // TODO Auto-generated method stub return false; } } diff --git a/bundles/org.simantics.db/src/org/simantics/db/Database.java b/bundles/org.simantics.db/src/org/simantics/db/Database.java index 35f384100..c80abd27d 100644 --- a/bundles/org.simantics.db/src/org/simantics/db/Database.java +++ b/bundles/org.simantics.db/src/org/simantics/db/Database.java @@ -135,7 +135,7 @@ public interface Database { public T clone(ClusterUID clusterUID, ClusterCreator clusterCreator) throws DatabaseException; public boolean refreshEnabled(); - boolean rolledback(); + public boolean rolledback(); } public Session newSession(ServiceLocator locator) throws SDBException; interface Journal { diff --git a/bundles/org.simantics.db/src/org/simantics/db/service/XSupport.java b/bundles/org.simantics.db/src/org/simantics/db/service/XSupport.java index d365d002a..d5de10140 100644 --- a/bundles/org.simantics.db/src/org/simantics/db/service/XSupport.java +++ b/bundles/org.simantics.db/src/org/simantics/db/service/XSupport.java @@ -157,4 +157,6 @@ public interface XSupport { throws DatabaseException; public void purge() throws DatabaseException; + public boolean rolledback(); + } diff --git a/bundles/org.simantics.fileimport/build.properties b/bundles/org.simantics.fileimport/build.properties index f760fc222..770ef5dc7 100644 --- a/bundles/org.simantics.fileimport/build.properties +++ b/bundles/org.simantics.fileimport/build.properties @@ -2,8 +2,10 @@ output.. = bin/ bin.includes = META-INF/,\ .,\ OSGI-INF/,\ - plugin.xml + plugin.xml,\ + scl/ OSGI-INF/FileReferenceFileImport.xml,\ OSGI-INF/LibraryFolderFileImport.xml,\ scl/ source.. = src/ +src.includes = scl/ diff --git a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java index c65b7c7d8..1fa4e3f5b 100644 --- a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java +++ b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java @@ -133,6 +133,11 @@ public class FileImportService { return; service.remove(resource.get()); removeResourceForPath(file); + try { + Files.delete(file); + } catch (IOException e) { + Files.delete(file); + } } catch (Throwable t) { if (callback.isPresent()) { callback.get().accept(t); diff --git a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/dropins/FileImportDropins.java b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/dropins/FileImportDropins.java index 5942c5deb..6c07f92aa 100644 --- a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/dropins/FileImportDropins.java +++ b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/dropins/FileImportDropins.java @@ -5,6 +5,7 @@ import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE; import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY; import static java.nio.file.StandardWatchEventKinds.OVERFLOW; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.file.FileSystem; @@ -141,7 +142,7 @@ public class FileImportDropins { } FileImportService.performFileImport(newPath, Optional.of(t -> { - if (t instanceof FileSystemException) { + if ((t instanceof FileSystemException) || (t instanceof FileNotFoundException)) { try { syncPath(newPath); } catch (IOException e) { diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/function/All.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/function/All.java index 6cfd6193c..57c1b040a 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/function/All.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/function/All.java @@ -13,7 +13,6 @@ import org.simantics.db.Session; import org.simantics.db.common.NamedResource; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.Variable; -import org.simantics.db.procedure.Procedure; import org.simantics.modeling.typicals.TypicalUtil; import org.simantics.modeling.ui.typicals.NewTypicalDiagramInstance; import org.simantics.scenegraph.loader.ScenegraphLoaderUtils; @@ -50,15 +49,10 @@ public class All { } final Collection namedTypicals = TypicalUtil.toNamedResources(session, typicals); - return TypicalUtil.syncExec(new Consumer>() { - @Override - public void accept(final Procedure procedure) { - NewTypicalDiagramInstance.asyncQueryFromList(namedTypicals, selectedTypical -> { - if (selectedTypical == null) { - procedure.execute(null); - return; - } - try { + return TypicalUtil.syncExec(procedure -> { + NewTypicalDiagramInstance.asyncQueryFromList(namedTypicals, selectedTypical -> { + try { + if (selectedTypical != null) { session.syncRequest(TypicalUtil.instantiateTemplate(target, selectedTypical, instance -> { try { Set customlyNamed = new HashSet(); @@ -71,14 +65,14 @@ public class All { procedure.exception(e); } })); - } catch (Throwable e) { - procedure.exception(e); - } finally { - procedure.execute(null); } - }); - } + } catch (Throwable e) { + procedure.exception(e); + } finally { + procedure.execute(null); + } + }); }); } -} \ No newline at end of file +} diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/NewTypicalDiagramInstance.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/NewTypicalDiagramInstance.java index 2bb0f9dfc..25fd46e69 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/NewTypicalDiagramInstance.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/NewTypicalDiagramInstance.java @@ -47,47 +47,44 @@ public class NewTypicalDiagramInstance implements ActionFactory { @Override public Runnable create(Object target_) { - final Resource target = (Resource) target_; - return new Runnable() { - @Override - public void run() { - Job job = new DatabaseJob("Instantiate Typical") { - @Override - protected IStatus run(IProgressMonitor monitor) { - monitor.beginTask("Instantiate Typical...", IProgressMonitor.UNKNOWN); + Resource target = (Resource) target_; + return () -> { + Job job = new DatabaseJob("Instantiate Typical") { + @Override + protected IStatus run(IProgressMonitor monitor) { + monitor.beginTask("Instantiate Typical...", IProgressMonitor.UNKNOWN); - final Session session = Simantics.getSession(); - session.markUndoPoint(); - try { - final AtomicReference model = new AtomicReference(); - Function2 instantiator = session.syncRequest(new UniqueRead>() { - @Override - public Function2 perform(ReadGraph graph) throws DatabaseException { - model.set( graph.sync(new PossibleModel(target)) ); - if (model.get() == null) - throw new CancelTransactionException("Cannot find a model from the input selection. Typical diagram instantiation not possible."); + Session session = Simantics.getSession(); + session.markUndoPoint(); + try { + AtomicReference model = new AtomicReference(); + Function2 instantiator = session.syncRequest(new UniqueRead>() { + @Override + public Function2 perform(ReadGraph graph) throws DatabaseException { + model.set( graph.sync(new PossibleModel(target)) ); + if (model.get() == null) + throw new CancelTransactionException("Cannot find a model from the input selection. Typical diagram instantiation not possible."); - ModelingResources MOD = ModelingResources.getInstance(graph); - Function2 instantiator = graph.getRelatedValue2(model.get(), MOD.StructuralModel_typicalInstantiationFunction); - return instantiator; - } - }); + ModelingResources MOD = ModelingResources.getInstance(graph); + Function2 instantiator = graph.getRelatedValue2(model.get(), MOD.StructuralModel_typicalInstantiationFunction); + return instantiator; + } + }); - instantiator.apply(model.get(), target); + instantiator.apply(model.get(), target); - return Status.OK_STATUS; - } catch (CancelTransactionException e) { - return new Status(IStatus.INFO , Activator.PLUGIN_ID, e.getMessage()); - } catch (DatabaseException e) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); - } finally { - monitor.done(); - } + return Status.OK_STATUS; + } catch (CancelTransactionException e) { + return new Status(IStatus.INFO , Activator.PLUGIN_ID, e.getMessage()); + } catch (DatabaseException e) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); + } finally { + monitor.done(); } - }; - //job.setUser(true); - job.schedule(); - } + } + }; + //job.setUser(true); + job.schedule(); }; } diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCL.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCL.java index bfa42b40e..24e50c0f7 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCL.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCL.java @@ -16,13 +16,13 @@ import org.simantics.SimanticsPlatform.OntologyRecoveryPolicy; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.request.external.EclipsePreferencePrimitiveRead; import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.db.layer0.util.SimanticsClipboard; import org.simantics.db.service.DebugSupport; +import org.simantics.db.service.ServiceActivityMonitor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,29 +64,33 @@ public class SCL { // but unfortunately this does not work either... // so we synchronize by a familiar write transaction // And then wait still some more - for(int i=0;i<3;i++) { - Simantics.getSession().syncRequest(new WriteRequest() { - @Override - public void perform(WriteGraph graph) throws DatabaseException { - } - - @Override - public String toString() { - return "Utils sync"; - } - }); - - // And then wait still some more - Simantics.getSession().syncRequest(new ReadRequest() { - @Override - public void run(ReadGraph graph) throws DatabaseException { - } - }); - } +// for(int i=0;i<3;i++) { + Simantics.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + } + + @Override + public String toString() { + return "Utils sync"; + } + }); +// +// // And then wait still some more +// Simantics.getSession().syncRequest(new ReadRequest() { +// @Override +// public void run(ReadGraph graph) throws DatabaseException { +// } +// }); +// } } public static void syncGraph() throws Exception { - sync(); + try { + Simantics.getSession().getService(ServiceActivityMonitor.class).waitForCompletion(); + } catch (InterruptedException e) { + throw new DatabaseException(e); + } // OK, now the experiment activate job should be scheduled // Wait for the job to finish diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/TypicalUtil.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/TypicalUtil.java index e15f5036d..952cd2862 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/TypicalUtil.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/TypicalUtil.java @@ -130,21 +130,21 @@ public class TypicalUtil { } }; - public static Collection toNamedResources(RequestProcessor processor, final Collection rs) throws DatabaseException { + public static List toNamedResources(RequestProcessor processor, final Collection rs) throws DatabaseException { return toNamedResources(processor, rs, new TypicalNamingFunction()); } - public static Collection toNamedResources(RequestProcessor processor, final Collection rs, final Function2 namingFunction) throws DatabaseException { - return processor.syncRequest(new UniqueRead>() { + public static List toNamedResources(RequestProcessor processor, final Collection rs, final Function2 namingFunction) throws DatabaseException { + return processor.syncRequest(new UniqueRead>() { @Override - public Collection perform(ReadGraph graph) throws DatabaseException { + public List perform(ReadGraph graph) throws DatabaseException { return toNamedResources(graph, rs, namingFunction); } }); } - public static Collection toNamedResources(ReadGraph graph, Collection rs, final Function2 namingFunction) throws DatabaseException { - Collection result = new ArrayList(rs.size()); + public static List toNamedResources(ReadGraph graph, Collection rs, final Function2 namingFunction) throws DatabaseException { + List result = new ArrayList<>(rs.size()); for (Resource r : rs) result.add(new NamedResource(namingFunction.apply(graph, r), r)); return result; @@ -157,8 +157,11 @@ public class TypicalUtil { return s; } - public static WriteResult instantiateTemplate(final Resource target, final NamedResource template, - final Consumer> successContinuation) { + public static WriteResult instantiateTemplate( + Resource target, + NamedResource template, + Consumer> successContinuation) + { return new WriteResultRequest() { @Override public Resource perform(WriteGraph graph) throws DatabaseException { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/coverage/CoverageBuilder.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/coverage/CoverageBuilder.java index b3bfcd889..835db7420 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/coverage/CoverageBuilder.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/coverage/CoverageBuilder.java @@ -10,7 +10,7 @@ public class CoverageBuilder { THashMap> combined = new THashMap>(); - public void addCoverage(Module module) { + public void addCoverage(Module module, boolean persistOverBranchpointReset) { THashMap branchPointMap = module.getBranchPoints(); if(branchPointMap == null) return; @@ -24,25 +24,43 @@ public class CoverageBuilder { @Override public boolean execute(String name, BranchPoint[] branchPoints) { BranchPoint[] oldBranchPoints = oldBranchPointMap_.get(name); - if(oldBranchPoints == null) - oldBranchPointMap_.put(name, branchPoints); - else + if(oldBranchPoints == null) { + if (persistOverBranchpointReset) { + // Clone the branchPoints array so that if will last over a reset + BranchPoint[] clonedBranchPoints = cloneBranchPoints(branchPoints); + oldBranchPointMap_.put(name, clonedBranchPoints); + } else { + // No need to copy so resetting branchpoints will reset this as well + oldBranchPointMap_.put(name, branchPoints); + } + } else { combineCounters(oldBranchPoints, branchPoints); + } return true; } }); } + private static BranchPoint[] cloneBranchPoints(BranchPoint[] oldBranchPoints) { + BranchPoint[] newBranchPoints = new BranchPoint[oldBranchPoints.length]; + for (int i = 0; i < oldBranchPoints.length; i++) { + BranchPoint bp = oldBranchPoints[i]; + BranchPoint[] children = cloneBranchPoints(bp.getChildren()); + newBranchPoints[i] = new BranchPoint(bp.getLocation(), bp.getCodeSize(), children); + } + return newBranchPoints; + } + private static void combineCounters(BranchPoint[] oldBranchPoints, BranchPoint[] branchPoints) { if(oldBranchPoints.length != branchPoints.length) throw new IllegalArgumentException("Incompatible branch points."); for(int i=0;i/db session = setupDatabase(databaseDriverId, progressMonitor, workspacePolicy, userAgent); TimeLogger.log("Database setup complete"); - + + // 1.1 + XSupport support = session.getService(XSupport.class); + if (support.rolledback()) { + try { + DatabaseIndexing.deleteAllIndexes(); + } catch (IOException e) { + throw new PlatformException(e); + } + } + // 2. Assert all graphs, and correct versions, are installed to the database synchronizeOntologies(progressMonitor, ontologyPolicy, requireSynchronize); TimeLogger.log("Synchronized ontologies");