]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fixed multiple issues causing dangling references to discarded queries 19/4419/4 master
authorJussi Koskela <jussi.koskela@semantum.fi>
Wed, 2 Sep 2020 09:17:31 +0000 (12:17 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 8 Oct 2020 07:56:28 +0000 (07:56 +0000)
gitlab #594

Change-Id: Iaa6b12f60d7dfa2bbcbc9614ef837973885586cc

129 files changed:
bundles/org.simantics.charts/src/org/simantics/charts/query/ChartAndSubscriptionItemData.java
bundles/org.simantics.db.common/META-INF/MANIFEST.MF
bundles/org.simantics.db.common/src/org/simantics/db/common/utils/ErrorLogger.java [deleted file]
bundles/org.simantics.db.common/src/org/simantics/db/common/utils/LogManager.java [deleted file]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ArraySet.java [deleted file]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AssertedPredicates.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AssertedPredicatesFactory.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AssertedStatementsFactory.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncMultiReadEntry.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/BinaryQuery.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CacheEntry.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CacheEntryBase.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ChildMap.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ChildMapFactory.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CollectionBinaryQuery.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CollectionUnaryQuery.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/DirectObjectsFactory.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/DirectPredicates.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/DirectPredicatesFactory.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ExternalReadEntry.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/IntArray.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/IntSet.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Objects.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ObjectsFactory.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/OrderedSetFactory.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Predicates.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/PredicatesFactory.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/PrincipalTypesFactory.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCollectorImpl.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryDeserializer.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryFactory.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryFactoryBase.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryIdentityHash.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryIdentityHashSet.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryListening.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QuerySerializer.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QuerySupport.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ReadEntry.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/RelationInfoQuery.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/RelationInfoQueryFactory.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/StatementsFactory.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/SuperRelations.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/SuperRelationsFactory.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/SuperTypes.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/SuperTypesFactory.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/TypeHierarchy.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/TypeHierarchyFactory.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Types.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/TypesFactory.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/URIToResource.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/URIToResourceFactory.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/UnaryQuery.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/UnaryQueryPIntSet.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ValueQuery.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ValueQueryFactory.java [new file with mode: 0644]
bundles/org.simantics.db.layer0/META-INF/MANIFEST.MF
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/AbstractExpressionCompilationRequest.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/NodeStructureRequest.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/NodeValueRequest.java
bundles/org.simantics.db.procore/META-INF/MANIFEST.MF
bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/DebugSupportImpl.java
bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ObjectResourceMap.java
bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QuerySupportImpl.java
bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplDb.java
bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/XSupportImpl.java
bundles/org.simantics.db.server/META-INF/MANIFEST.MF
bundles/org.simantics.db/src/org/simantics/db/RelationInfo.java
bundles/org.simantics.db/src/org/simantics/db/service/XSupport.java
bundles/org.simantics.debug.graphical/scl/Simantics/GraphicalDebugger.scl
bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/DebuggerCanvasProxy.java [new file with mode: 0644]
bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/GraphicalDebugger.java
bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteLine.java
bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/segments/Segment.java
bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/splitting/SplittedRouteGraph.java
bundles/org.simantics.diagram.profile/META-INF/MANIFEST.MF
bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/CreateGroupAction.java
bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/CreateProfileAction.java
bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/CreateStyleAction.java
bundles/org.simantics.diagram/META-INF/MANIFEST.MF
bundles/org.simantics.diagram/src/org/simantics/diagram/LogManager.java [deleted file]
bundles/org.simantics.diagram/src/org/simantics/diagram/Logger.java [deleted file]
bundles/org.simantics.diagram/src/org/simantics/diagram/export/ExportDiagramPdf.java
bundles/org.simantics.diagram/src/org/simantics/diagram/flag/FlagUtil.java
bundles/org.simantics.diagram/src/org/simantics/diagram/flag/RouteGraphConnectionSplitter.java
bundles/org.simantics.diagram/src/org/simantics/diagram/function/All.java
bundles/org.simantics.diagram/src/org/simantics/diagram/handler/CopyPasteHandler.java
bundles/org.simantics.diagram/src/org/simantics/diagram/handler/e4/CopyPasteHandler.java
bundles/org.simantics.diagram/src/org/simantics/diagram/participant/PopulateSelectionDropParticipant.java
bundles/org.simantics.diagram/src/org/simantics/diagram/symbollibrary/ui/SymbolLibraryComposite.java
bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/CopyAdvisorUtil.java
bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/RouteGraphModification.java
bundles/org.simantics.document.server/src/org/simantics/document/server/request/DocumentRequest.java
bundles/org.simantics.document.server/src/org/simantics/document/server/request/HandleEventRequest.java
bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodesRequest.java
bundles/org.simantics.fileimport/META-INF/MANIFEST.MF
bundles/org.simantics.g2d.ontology/graph/G2D.pgraph
bundles/org.simantics.g2d/src/org/simantics/g2d/gallery/GalleryViewer.java
bundles/org.simantics.graph/src/org/simantics/graph/refactoring/FixExportedOntology.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewerSelectionProvider.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/e4/PopulateElementDropParticipant.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/ContextualHelp.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/pdf/PDFPainter.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sg/DiagramSceneGraphProvider.java
bundles/org.simantics.modeling/META-INF/MANIFEST.MF
bundles/org.simantics.modeling/src/org/simantics/modeling/SCLAction.java
bundles/org.simantics.modeling/src/org/simantics/modeling/SCLDropAction.java
bundles/org.simantics.modeling/src/org/simantics/modeling/actions/Help.java
bundles/org.simantics.modeling/src/org/simantics/modeling/help/HelpContexts.java [new file with mode: 0644]
bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/ComponentCopyAdvisor.java
bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphModuleSourceRepository.java
bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/common/ObserverGroupListener.java
bundles/org.simantics.spreadsheet.common/META-INF/MANIFEST.MF
bundles/org.simantics/META-INF/MANIFEST.MF
bundles/org.simantics/src/org/simantics/LogManager.java [deleted file]
bundles/org.simantics/src/org/simantics/Simantics.java
bundles/org.simantics/src/org/simantics/SimanticsPlatform.java
features/org.simantics.rcp.feature/feature.xml
features/org.simantics.sdk.feature/feature.xml
license.html
releng/org.simantics.sdk.build.p2.site/pom.xml
releng/org.simantics.sdk.build.targetdefinition/org.simantics.sdk.build.targetdefinition.target
releng/org.simantics.sdk.build.targetdefinition/org.simantics.sdk.build.targetdefinition.tpd
releng/org.simantics.sdk.build.targetdefinition/simantics.target
tests/org.simantics.db.tests/META-INF/MANIFEST.MF
tests/org.simantics.db.tests/build-installer.xml
tests/org.simantics.db.tests/build.xml

index 9438e404ba05d530cdeb94faddcb1f22439867a4..8f2bd26f8ccf6fc4fe348d7c44cbddf6e0d9af37 100644 (file)
@@ -48,7 +48,7 @@ public class ChartAndSubscriptionItemData extends Bean {
        
        // Output
        @Optional public String subscription = "Default";
-       @Optional public String unit = "";
+       @Optional public String unit;
        @Optional public Double min, max, deadband, interval, gain, bias;
        @Optional public DrawMode drawmode;
        @Optional public Scale scale;
index 63b3e6bfc764c47a2ad413e365f239ee12f482cf..a293714958e1da200758e09116c21861ce07f255 100644 (file)
@@ -7,7 +7,6 @@ Bundle-Vendor: VTT Technical Research Centre of Finland
 Bundle-RequiredExecutionEnvironment: JavaSE-11
 Require-Bundle: org.simantics.db;bundle-version="1.1.0";visibility:=reexport,
  gnu.trove3;bundle-version="3.0.3",
- org.apache.log4j;bundle-version="1.2.15",
  org.simantics.layer0;bundle-version="1.0.0";visibility:=reexport,
  org.simantics.graph;bundle-version="1.1.4",
  org.simantics.scl.reflection;bundle-version="1.0.0";visibility:=reexport,
diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/utils/ErrorLogger.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/utils/ErrorLogger.java
deleted file mode 100644 (file)
index 68ad374..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
- * in Industry THTH ry.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     VTT Technical Research Centre of Finland - initial API and implementation
- *******************************************************************************/
-package org.simantics.db.common.utils;
-
-import java.util.Properties;
-
-import org.apache.log4j.Logger;
-
-/*
- * 
- * @deprecated in favor of org.simantics.db.common.Logger. Will be removed in Simantics 1.2
- * 
- */
-@Deprecated
-public class ErrorLogger {
-    public static final boolean ECHO = false;
-    public static final Properties defaultProperties = new Properties();
-    static {
-        defaultProperties.put("log4j.rootCategory", "ERROR, default");
-        defaultProperties.put("log4j.appender.default", "org.apache.log4j.FileAppender");
-        defaultProperties.put("log4j.appender.default.File", "db-client-deprecated.log");
-        defaultProperties.put("log4j.appender.default.append", "false");
-        defaultProperties.put("log4j.appender.default.layout", "org.apache.log4j.PatternLayout");
-        defaultProperties.put("log4j.appender.default.layout.ConversionPattern", "%-6r [%15.15t] %-5p %30.30c - %m%n");
-    }
-    private static LogManager defaultLogManager = new LogManager(defaultProperties);
-    private static final ErrorLogger defaultErrorLogger = new ErrorLogger(LogManager.class);
-    private Logger logger;
-    ErrorLogger(Class<?> clazz) {
-       logger = defaultLogManager.getLogger(clazz);
-    }
-
-    /**
-     * Log a trace event.
-     * 
-     * @param message message of the trace
-     * @param exception the exception, or <code>null</code>
-     */
-    public void logTrace(String message, Throwable exception) {
-        // Errors are much more useful with a stack trace!
-        if (exception == null) {
-            exception = new RuntimeException();
-        }
-        logger.trace(message, exception);
-    }
-
-    /**
-     * Log an info event.
-     * 
-     * @param message message of the info
-     * @param exception the exception, or <code>null</code>
-     */
-    public void logInfo(String message, Throwable exception) {
-        // Errors are much more useful with a stack trace!
-        if (exception == null) {
-            exception = new RuntimeException();
-        }
-        logger.info(message, exception);
-    }
-
-    /**
-     * Log an error event.
-     * 
-     * @param message message of the error
-     * @param exception the exception, or <code>null</code>
-     */
-    public void logError(String message, Throwable exception) {
-        // Errors are much more useful with a stack trace!
-        if (exception == null) {
-            exception = new RuntimeException();
-        }
-        logger.error(message, exception);
-    }
-
-    public static ErrorLogger getDefault() {
-        return defaultErrorLogger;
-    }
-    
-    public static LogManager getDefaultLogManager() {
-        return defaultLogManager;
-    }
-    public static void defaultLogError(Throwable exception) {
-        getDefault().logError(exception.getLocalizedMessage(), exception);
-        if(ECHO) exception.printStackTrace();
-    }
-    public static void defaultLogError(String message) {
-        getDefault().logError(message, null);
-        if(ECHO)
-            System.err.println(message);
-    }
-    public static void defaultLogError(String message, Throwable exception) {
-        getDefault().logError(message, exception);
-        if(ECHO)
-            System.err.println(message);
-    }
-    public static void defaultLogInfo(String message) {
-        getDefault().logInfo(message, null);
-        if(ECHO)
-            System.err.println(message);
-    }
-    public static void defaultLogTrace(String message) {
-        getDefault().logTrace(message, null);
-        if(ECHO)
-            System.err.println(message);
-    }
-}
diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/utils/LogManager.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/utils/LogManager.java
deleted file mode 100644 (file)
index 9abae43..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
- * in Industry THTH ry.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     VTT Technical Research Centre of Finland - initial API and implementation
- *******************************************************************************/
-package org.simantics.db.common.utils;
-
-import java.util.Properties;
-
-import org.apache.log4j.Hierarchy;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PropertyConfigurator;
-import org.apache.log4j.spi.LoggerFactory;
-import org.apache.log4j.spi.RootLogger;
-
-/**
- * This class encapsulates a Log4J Hierarchy and centralizes all Logger access.
- */
-public class LogManager {
-
-    private Hierarchy hierarchy;
-
-    /**
-     * Creates a new LogManager. Saves the log and state location.
-     * Creates a new Hierarchy and add a new EventListener to it.
-     * Configure the hierarchy with the properties passed. Add this object to
-     * the list of active log managers.
-     * 
-     * @param properties log configuration properties
-     */
-    public LogManager(Properties properties) {
-        this.hierarchy = new Hierarchy(new RootLogger(Level.DEBUG));
-        new PropertyConfigurator().doConfigure(properties, this.hierarchy);
-    }
-
-    /**
-     * Checks if this PluginLogManager is disabled for this level.
-     * 
-     * @param level level value
-     * @return boolean true if it is disabled
-     */
-    public boolean isDisabled(int level) {
-        return this.hierarchy.isDisabled(level);
-    }
-
-    /**
-     * Enable logging for logging requests with level l or higher. By default
-     * all levels are enabled.
-     * 
-     * @param level level object
-     */
-    public void setThreshold(Level level) {
-        this.hierarchy.setThreshold(level);
-    }
-
-    /**
-     * The string version of setThreshold(Level level)
-     * 
-     * @param level level string
-     */
-    public void setThreshold(String level) {
-        this.hierarchy.setThreshold(level);
-    }
-
-    /**
-     * Get the repository-wide threshold.
-     * 
-     * @return Level
-     */
-    public Level getThreshold() {
-        return this.hierarchy.getThreshold();
-    }
-
-    /**
-     * Returns a new logger instance named as the first parameter using the
-     * default factory. If a logger of that name already exists, then it will be
-     * returned. Otherwise, a new logger will be instantiated and then linked
-     * with its existing ancestors as well as children.
-     * 
-     * @param clazz the class to get the logger for
-     * @return Logger
-     */
-    public Logger getLogger(Class<?> clazz) {
-        return this.hierarchy.getLogger(clazz.getName());
-    }
-
-    /**
-     * Returns a new logger instance named as the first parameter using the
-     * default factory. If a logger of that name already exists, then it will be
-     * returned. Otherwise, a new logger will be instantiated and then linked
-     * with its existing ancestors as well as children.
-     * 
-     * @param name logger name
-     * @return Logger
-     */
-    public Logger getLogger(String name) {
-        return this.hierarchy.getLogger(name);
-    }
-
-    /**
-     * The same as getLogger(String name) but using a factory instance instead
-     * of a default factory.
-     * 
-     * @param name logger name
-     * @param factory factory instance
-     * @return Logger
-     */
-    public Logger getLogger(String name, LoggerFactory factory) {
-        return this.hierarchy.getLogger(name, factory);
-    }
-
-    /**
-     * Returns the root of this hierarchy.
-     * 
-     * @return Logger
-     */
-    public Logger getRootLogger() {
-        return this.hierarchy.getRootLogger();
-    }
-
-    /**
-     * Checks if this logger exists.
-     * 
-     * @return Logger
-     */
-    public Logger exists(String name) {
-        return this.hierarchy.exists(name);
-    }
-
-    /**
-     * Disposes the logger hierarchy
-     */
-    public void shutdown() {
-        this.hierarchy.shutdown();
-    }
-
-    /**
-     * Resets configuration values to its defaults.
-     */
-    public void resetConfiguration() {
-        this.hierarchy.resetConfiguration();
-    }
-
-}
\ No newline at end of file
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ArraySet.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ArraySet.java
deleted file mode 100644 (file)
index 1360cef..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
- * in Industry THTH ry.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     VTT Technical Research Centre of Finland - initial API and implementation
- *******************************************************************************/
-package org.simantics.db.impl.graph;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.simantics.db.Resource;
-import org.simantics.db.impl.query.IntSet;
-import org.simantics.db.impl.query.QuerySupport;
-
-public class ArraySet implements Set<Resource> {
-    
-    final Resource[] set;
-
-    ArraySet(IntSet intSet, QuerySupport support) {
-        
-        if(intSet.data == null) {
-            if(intSet.sizeOrData != IntSet.NO_DATA) {
-                set = new Resource[] { support.getResource(intSet.sizeOrData) };
-            } else {
-                set = Resource.NONE;
-            }
-        } else {
-            set = new Resource[intSet.sizeOrData];
-            for(int i=0;i<intSet.sizeOrData;i++) set[i] = support.getResource(intSet.data[i]);
-        }
-        
-    }
-    
-    @Override
-    public boolean add(Resource e) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public boolean addAll(Collection<? extends Resource> c) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public void clear() {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public boolean contains(Object o) {
-        for(int i=0;i<set.length;i++) if(o.equals(set[i])) return true;
-        return false;
-    }
-
-    @Override
-    public boolean containsAll(Collection<?> c) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public boolean isEmpty() {
-        return set.length == 0;
-    }
-
-    @Override
-    public Iterator<Resource> iterator() {
-        
-        class ArraySetIterator implements Iterator<Resource> {
-            
-            int next = 0;
-
-            @Override
-            public boolean hasNext() {
-                return next < set.length;
-            }
-
-            @Override
-            public Resource next() {
-                return set[next++];
-            }
-
-            @Override
-            public void remove() {
-                throw new UnsupportedOperationException();
-            }
-            
-        }
-        
-        return new ArraySetIterator();
-        
-    }
-
-    @Override
-    public boolean remove(Object o) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public boolean removeAll(Collection<?> c) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public boolean retainAll(Collection<?> c) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public int size() {
-        return set.length;
-    }
-
-    @Override
-    public Object[] toArray() {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public <T> T[] toArray(T[] a) {
-        throw new UnsupportedOperationException();
-    }
-
-}
index b4104e965fbc0b56be90fc40a8f0cd07eef5ab3a..23fbe95ecd6627453202e85e94a6711e6ae0d947 100644 (file)
@@ -241,5 +241,11 @@ final public class AssertedPredicates extends UnaryQuery<IntProcedure> {
         });
         
     }
-    
+
+    @Override
+    public void serializeValue(QuerySerializer serializer) {
+        IntArray is = getResult();
+        is.serialize(serializer);
+    }
+
 }
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AssertedPredicatesFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AssertedPredicatesFactory.java
new file mode 100644 (file)
index 0000000..c76bc51
--- /dev/null
@@ -0,0 +1,21 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class AssertedPredicatesFactory extends QueryFactoryBase {
+
+    @Override
+    public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+        AssertedPredicates result = reference(deserializer);
+        IntArray ia = IntArray.deserialize(deserializer);
+        result.setResult(ia);
+        result.setReady();
+        return result;
+    }
+    
+    @Override
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+        return (T)deserializer.readAssertedPredicates();
+    }
+
+}
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AssertedStatementsFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AssertedStatementsFactory.java
new file mode 100644 (file)
index 0000000..708ce66
--- /dev/null
@@ -0,0 +1,21 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class AssertedStatementsFactory extends QueryFactoryBase {
+
+    @Override
+    public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+        AssertedStatements result = reference(deserializer);
+        IntArray ia = IntArray.deserialize(deserializer);
+        result.setResult(ia);
+        result.setReady();
+        return result;
+    }
+    
+    @Override
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+        return (T)deserializer.readAssertedStatements();
+    }
+
+}
index ea88d179107c920f9f10193f727907a56d39356e..7880448078dc0f7edb48701c4de7d9bac52e9fec 100644 (file)
@@ -190,4 +190,9 @@ final public class AsyncMultiReadEntry<T> extends CacheEntryBase<AsyncMultiProce
                return graph.processor.cache.performQuery(graph, id, this, procedure);
        }
 
+    @Override
+    public String classId() {
+        return null;
+    }
+
 }
index 5017151b10b9f8478bf1df7319326d020b0fb583..2fdb43d113332e4f33b6b131685fd8c80c112b22 100644 (file)
@@ -213,4 +213,9 @@ final public class AsyncReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> i
         }
     }
 
+    @Override
+    public String classId() {
+        return null;
+    }
+
 }
index d699ea825d9823cfb8c1f3454f13115ff4518455..04df0d00c5c8f1ea1222eee6000788e8e2a43bde 100644 (file)
@@ -66,4 +66,15 @@ public abstract class BinaryQuery<Procedure> extends CacheEntryBase<Procedure> i
 
     abstract public void removeEntry(QueryProcessor provider);
 
+    @Override
+    public long cluster(QueryProcessor processor) {
+        return processor.cluster(r1());
+    }
+
+    @Override
+    public void serializeKey(QuerySerializer serializer) {
+        serializer.addResource(r1());
+        serializer.addResource(r2());
+    }
+
 }
index 1cdcbde9dd0b11733b224877c4a5a0c7cf41cbe7..a650f32ce8dc6ee1f70166cbb3e21c31b6604f17 100644 (file)
@@ -11,6 +11,8 @@
  *******************************************************************************/
 package org.simantics.db.impl.query;
 
+import java.util.Collection;
+
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 
@@ -40,10 +42,11 @@ public abstract class CacheEntry<Procedure> {
     abstract Query getQuery();
 
     abstract CacheEntry pruneFirstParents();
+    abstract void pruneParentSet();
     abstract void removeParent(CacheEntry entry);
     abstract void addParent(CacheEntry entry);
     abstract boolean hasParents();
-    abstract Iterable<CacheEntry<?>> getParents(QueryProcessor processor);
+    abstract Collection<CacheEntry<?>> getParents(QueryProcessor processor);
     abstract CacheEntry getFirstParent(QueryProcessor processor);
     abstract boolean moreThanOneParent(QueryProcessor processor);
     abstract int parentCount(QueryProcessor processor);
index e79f99deae1d06ab4469e1496accd8fbcacb3e97..98e7f0d00554f1c3f351339d8aa4b891028966ae 100644 (file)
@@ -12,6 +12,7 @@
 package org.simantics.db.impl.query;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 
 import org.simantics.databoard.Bindings;
@@ -277,7 +278,31 @@ public abstract class CacheEntryBase<Procedure> extends CacheEntry<Procedure> {
        }
         
     }
-    
+
+    @Override
+    void pruneParentSet() {
+        // First parent is discarded => look for more parents
+        if(p2OrParents instanceof QueryIdentityHashSet) {
+
+            QueryIdentityHashSet set = (QueryIdentityHashSet)p2OrParents;
+            set.removeDiscardedReally();
+            if(set.isEmpty()) p2OrParents = null;
+
+        } else if(p2OrParents instanceof CacheEntry) {
+
+            CacheEntry entry = (CacheEntry)p2OrParents;
+            if(entry.isDiscarded()) {
+                // Second entry is also discarded => all empty
+                p2OrParents = null;
+            }
+
+        } else {
+
+            // Nothing left
+
+        }
+    }
+
     @Override
     final public void removeParent(CacheEntry entry) {
        
@@ -339,7 +364,7 @@ public abstract class CacheEntryBase<Procedure> extends CacheEntry<Procedure> {
     }
     
     @Override
-       final public Iterable<CacheEntry<?>> getParents(QueryProcessor processor) {
+       final public Collection<CacheEntry<?>> getParents(QueryProcessor processor) {
 
                ArrayList<CacheEntry<?>> result = new ArrayList<CacheEntry<?>>();
                if(p1 != null) result.add(p1);
@@ -471,5 +496,44 @@ public abstract class CacheEntryBase<Procedure> extends CacheEntry<Procedure> {
 
     public CacheEntryBase() {
     }
+    
+    public String classId() {
+        return getClass().getName();
+    }
+
+    public void serializeKey(QuerySerializer serializer) {
+        throw new IllegalStateException("Cannot serialize query key for " + this);
+    }
+    
+    public void serializeValue(QuerySerializer serializer) {
+        throw new IllegalStateException("Cannot serialize query value for " + this);
+    }
+    
+    public void serializeParents(QuerySerializer serializer) {
+        Collection<CacheEntry<?>> ps = getParents(serializer.getQueryProcessor());
+        int sizePos = serializer.writeUnknownSize();
+        int actual = 0;
+        for(CacheEntry<?> entry : ps) {
+            CacheEntryBase b = (CacheEntryBase)entry;
+            String cid = b.classId();
+            if(cid == null) 
+                continue;
+            serializer.serializeId(b.classId());
+            b.serializeKey(serializer);
+            actual++;
+        }
+        serializer.setUnknownSize(sizePos, actual);
+    }
+
+    public long cluster(QueryProcessor processor) {
+        throw new IllegalStateException("Cannot compute query cluster for " + this);
+    }
+
+    public void serialize(QuerySerializer serializer) {
+        serializer.serializeId(classId());
+        serializeKey(serializer);
+        serializeValue(serializer);
+        serializeParents(serializer);
+    }
 
 }
index 8effbb1d549152bd21f0ecdae723bc0c7c81993d..79d3106a8c0074b9ce763e2c4188b819656eb48d 100644 (file)
@@ -142,6 +142,16 @@ public final class ChildMap extends UnaryQueryP<ObjectResourceIdMap<String>> {
 
     }
 
+    @Override
+    public void serializeValue(QuerySerializer serializer) {
+        ObjectResourceIdMap<String> is = getResult();
+        serializer.writeLE(is.size());
+        for(String s : is.keySet()) {
+            serializer.addString(s);
+            serializer.addResource(is.getId(s));
+        }
+    }
+
     @Override
     public String toString() {
         return "ChildMap[" + id + "]";
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ChildMapFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ChildMapFactory.java
new file mode 100644 (file)
index 0000000..bf179b5
--- /dev/null
@@ -0,0 +1,28 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.ObjectResourceIdMap;
+import org.simantics.db.exception.DatabaseException;
+
+public class ChildMapFactory extends QueryFactoryBase {
+
+    @Override
+    public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+        ChildMap result = reference(deserializer);
+        ObjectResourceIdMap<String> map = deserializer.createChildMap();
+        int size = deserializer.readLE4();
+        for(int i=0;i<size;i++) {
+            String key = deserializer.readString();
+            int r2 = deserializer.readResource();
+            map.putId(key, r2);
+        }
+        result.setResult(map);
+        result.setReady();
+        return result;
+    }
+    
+    @Override
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+        return (T)deserializer.readChildMap();
+    }
+
+}
index cd139655cfa647080f74d825ddbafdbf02dd433b..6e1692ba462f1af084d502959f25d41513c15e89 100644 (file)
@@ -11,9 +11,6 @@
  *******************************************************************************/
 package org.simantics.db.impl.query;
 
-
-
-
 abstract public class CollectionBinaryQuery<T> extends BinaryQuery<T> {
        
     public CollectionBinaryQuery(final int r1, final int r2) {
@@ -33,5 +30,11 @@ abstract public class CollectionBinaryQuery<T> extends BinaryQuery<T> {
         if(size == 0) setResult(IntArray.EMPTY);
         else v.trim();
     }
-    
+
+    @Override
+    public void serializeValue(QuerySerializer serializer) {
+        IntArray is = getResult();
+        is.serialize(serializer);
+    }
+
 }
index 90bb0355447acfeac8089b3f080d435f062a23e8..2eaeca472c2088d7d10156cc678506004dfdacbc 100644 (file)
@@ -96,4 +96,10 @@ public abstract class CollectionUnaryQuery extends UnaryQuery<IntProcedure> impl
         except(throwable);
     }
 
+    @Override
+    public void serializeValue(QuerySerializer serializer) {
+        IntArray is = getResult();
+        is.serialize(serializer);
+    }
+    
 }
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/DirectObjectsFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/DirectObjectsFactory.java
new file mode 100644 (file)
index 0000000..323ec21
--- /dev/null
@@ -0,0 +1,21 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class DirectObjectsFactory extends QueryFactoryBase {
+
+    @Override
+    public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+        DirectObjects result = reference(deserializer);
+        IntArray ia = IntArray.deserialize(deserializer);
+        result.setResult(ia);
+        result.setReady();
+        return result;
+    }
+    
+    @Override
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+        return (T)deserializer.readDirectObjects();
+    }
+
+}
index 1a006369a1d6867c0c788449f61900eae12d55ee..ee0faa1cfdd8b607ab59a8261e7e2c38af6d9e4b 100644 (file)
@@ -16,7 +16,7 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.impl.procedure.InternalProcedure;
 
-public final class DirectPredicates extends UnaryQueryP<IntSet> {
+public final class DirectPredicates extends UnaryQueryPIntSet {
 
        DirectPredicates(final int resource) {
                super(resource);
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/DirectPredicatesFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/DirectPredicatesFactory.java
new file mode 100644 (file)
index 0000000..e707e62
--- /dev/null
@@ -0,0 +1,21 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class DirectPredicatesFactory extends QueryFactoryBase {
+
+    @Override
+    public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+        DirectPredicates result = reference(deserializer);
+        IntSet is = IntSet.deserialize(deserializer);
+        result.setResult(is);
+        result.setReady();
+        return result;
+    }
+    
+    @Override
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+        return (T)deserializer.readDirectPredicates();
+    }
+
+}
index d044043394ef771f7e7e0cfab3e5257f77883db6..2980b9b15f72e9a54b00a96fe06a397ef60b59b6 100644 (file)
@@ -28,7 +28,7 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
     final LinkedList<T> items = new LinkedList<T>();
 
     protected ExternalRead<T> id;
-    protected ReadGraphImpl graph;
+    protected QueryProcessor processor;
     protected boolean registered = false;
 
     @Override
@@ -49,7 +49,7 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
     public void discard() {
         id.unregistered();
         id = null;
-        graph = null;
+        processor = null;
         super.discard();
     }
 
@@ -65,7 +65,7 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
     public ExternalReadEntry(ExternalRead<T> request, ReadGraphImpl graph) {
         assert request != null;
         this.id = request;
-        this.graph = graph;
+        this.processor = graph.processor;
     }
     
     @Override
@@ -213,7 +213,7 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
 
                synchronized(items) {
                        items.addLast(result);
-                               graph.processor.updatePrimitive(id);
+                               processor.updatePrimitive(id);
                        // TODO: implement flags/logic in ExternalRead to state that all but the latest request result can be evaporated
                        // In some cases where data is produced really fast this might be necessary but currently this queueing will do.
                }
@@ -229,7 +229,12 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
 
        @Override
        public boolean isDisposed() {
-               return registered && (isDiscarded() || !graph.processor.isBound(this));
+               return registered && (isDiscarded() || !processor.isBound(this));
        }
-    
+
+    @Override
+    public String classId() {
+        return null;
+    }
+
 }
index 6ee30ad70fd1d341930f11c35eabe2ecdf69af87..53b447f08b3da6e081bfff9d1a0452c4bd552bde 100644 (file)
@@ -13,6 +13,8 @@ package org.simantics.db.impl.query;
 
 import java.util.Arrays;
 
+import org.simantics.db.exception.DatabaseException;
+
 
 final public class IntArray {
 
@@ -111,7 +113,27 @@ final public class IntArray {
        }
        return result;
     }
-    
+    public void serialize(QuerySerializer serializer) {
+        int size = size();
+        serializer.writeLE(size);
+        if(size == 1) {
+            serializer.addResource(sizeOrData);
+        } else {
+            for(int i=0;i<size;i++)
+                serializer.addResource(data[i]);
+        }
+    }
+    public static IntArray deserialize(QueryDeserializer deserializer) throws DatabaseException {
+        int size = deserializer.readLE4();
+        IntArray result = new IntArray();
+        for(int i=0;i<size;i++) {
+            result.add(deserializer.readResource());
+        }
+        return result;
+    }
+
     @Override
     public boolean equals(Object object) {
         if (this == object)
index 3ef19b8f335ec9dbf60aeaf1df6bf818251d67a2..3f2e0140bda6f0a2da13dea02e7e24b7a77e8230 100644 (file)
@@ -32,8 +32,7 @@ final public class IntSet implements ResourceSet {
 
     public int[] data;
 
-    /** the index after the last entry in the list */
-    public int sizeOrData;
+    private int sizeOrData;
 
     /** the default capacity for new lists */
     protected static final int DEFAULT_CAPACITY = 3;
@@ -46,6 +45,8 @@ final public class IntSet implements ResourceSet {
 
     private IntSet() {
         support = null;
+        data = null;
+        sizeOrData = NO_DATA;
     }
 
     public IntSet(QuerySupport support) {
@@ -299,5 +300,26 @@ final public class IntSet implements ResourceSet {
         }
         procedure.finished(graph);
     }
+    
+    public void serialize(QuerySerializer serializer) {
+        serializer.writeLE(size());
+        forEach(new TIntProcedure() {
+            
+            @Override
+            public boolean execute(int value) {
+                serializer.addResource(value);
+                return true;
+            }
+        });
+    }
+    
+    public static IntSet deserialize(QueryDeserializer deserializer) throws DatabaseException {
+        int size = deserializer.readLE4();
+        IntSet result = new IntSet();
+        for(int i=0;i<size;i++) {
+            result.add(deserializer.readResource());
+        }
+        return result;
+    }
 
 }
\ No newline at end of file
index 8bac422636ff9a13d8064f5ab0ef64cee6a4d476..c84b63dc61a5d6304cf52c3478c8c91a7ca9f7e3 100644 (file)
@@ -680,4 +680,10 @@ public final class Objects extends CollectionBinaryQuery<IntProcedure> implement
         except(throwable);
     }
 
+    @Override
+    public void serializeValue(QuerySerializer serializer) {
+        IntArray is = getResult();
+        is.serialize(serializer);
+    }
+    
 }
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ObjectsFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ObjectsFactory.java
new file mode 100644 (file)
index 0000000..f6758e6
--- /dev/null
@@ -0,0 +1,21 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class ObjectsFactory extends QueryFactoryBase {
+
+    @Override
+    public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+        Objects result = reference(deserializer);
+        IntArray ia = IntArray.deserialize(deserializer);
+        result.setResult(ia);
+        result.setReady();
+        return result;
+    }
+    
+    @Override
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+        return (T)deserializer.readObjects();
+    }
+
+}
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/OrderedSetFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/OrderedSetFactory.java
new file mode 100644 (file)
index 0000000..9b5f581
--- /dev/null
@@ -0,0 +1,21 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class OrderedSetFactory extends QueryFactoryBase {
+
+    @Override
+    public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+        OrderedSet result = reference(deserializer);
+        IntArray ia = IntArray.deserialize(deserializer);
+        result.setResult(ia);
+        result.setReady();
+        return result;
+    }
+    
+    @Override
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+        return (T)deserializer.readOrderedSet();
+    }
+
+}
index 9445db03b4e048ca1488cb22f45eeaa56da9bdd1..982d8019c0c7cdd6328b791fa2071baf98ece9f9 100644 (file)
@@ -19,7 +19,7 @@ import org.simantics.db.request.RequestFlags;
 
 import gnu.trove.procedure.TIntProcedure;
 
-final public class Predicates extends UnaryQueryP<IntSet> {
+final public class Predicates extends UnaryQueryPIntSet {
 
        Predicates(final int r) {
         super(r);
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/PredicatesFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/PredicatesFactory.java
new file mode 100644 (file)
index 0000000..c86e43c
--- /dev/null
@@ -0,0 +1,21 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class PredicatesFactory extends QueryFactoryBase {
+
+    @Override
+    public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+        Predicates result = reference(deserializer);
+        IntSet ia = IntSet.deserialize(deserializer);
+        result.setResult(ia);
+        result.setReady();
+        return result;
+    }
+    
+    @Override
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+        return (T)deserializer.readPredicates();
+    }
+
+}
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/PrincipalTypesFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/PrincipalTypesFactory.java
new file mode 100644 (file)
index 0000000..ccd4ddc
--- /dev/null
@@ -0,0 +1,21 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class PrincipalTypesFactory extends QueryFactoryBase {
+
+    @Override
+    public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+        PrincipalTypes result = reference(deserializer);
+        IntArray ia = IntArray.deserialize(deserializer);
+        result.setResult(ia);
+        result.setReady();
+        return result;
+    }
+    
+    @Override
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+        return (T)deserializer.readPrincipalTypes();
+    }
+
+}
index f80fb5098b847d9264768be6c833c39d38a7ac24..b0bca135042fbe99a5f07ffc3f4cab28628a164b 100644 (file)
@@ -4,13 +4,10 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.concurrent.Semaphore;
 
-import org.simantics.databoard.Bindings;
 import org.simantics.db.AsyncReadGraph;
-import org.simantics.db.DevelopmentKeys;
 import org.simantics.db.ObjectResourceIdMap;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.RelationInfo;
-import org.simantics.db.common.utils.Logger;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.impl.procedure.InternalProcedure;
@@ -24,7 +21,6 @@ import org.simantics.db.request.AsyncRead;
 import org.simantics.db.request.ExternalRead;
 import org.simantics.db.request.MultiRead;
 import org.simantics.db.request.Read;
-import org.simantics.utils.Development;
 
 import gnu.trove.map.hash.THashMap;
 import gnu.trove.map.hash.TObjectIntHashMap;
@@ -980,5 +976,158 @@ public class QueryCacheBase {
        static boolean shouldCache(QueryProcessor processor, Object o) {
                return false;
        }
+       
+       AssertedPredicates getOrCreateAssertedPredicates(int r) {
+           AssertedPredicates entry = (AssertedPredicates)assertedPredicatesMap.get(r);
+           if(entry == null) {
+               entry = new AssertedPredicates(r);
+            assertedPredicatesMap.put(keyR(r), entry);
+           }
+           return entry;
+       }
 
+    AssertedStatements getOrCreateAssertedStatements(int r1, int r2) {
+        AssertedStatements entry = (AssertedStatements)assertedStatementsMap.get(r1, r2);
+        if(entry == null) {
+            entry = new AssertedStatements(r1, r2);
+            assertedStatementsMap.put(keyR2(r1, r2), entry);
+        }
+        return entry;
+    }
+
+    ChildMap getOrCreateChildMap(int r) {
+        ChildMap entry = (ChildMap)childMapMap.get(r);
+        if(entry == null) {
+            entry = new ChildMap(r);
+            childMapMap.put(keyR(r), entry);
+        }
+        return entry;
+    }
+
+    DirectObjects getOrCreateDirectObjects(int r1, int r2) {
+        DirectObjects entry = (DirectObjects)directObjectsMap.get(r1, r2);
+        if(entry == null) {
+            entry = new DirectObjects(r1, r2);
+            directObjectsMap.put(keyR2(r1, r2), entry);
+        }
+        return entry;
+    }
+    
+    DirectPredicates getOrCreateDirectPredicates(int r) {
+        DirectPredicates entry = (DirectPredicates)directPredicatesMap.get(r);
+        if(entry == null) {
+            entry = new DirectPredicates(r);
+            directPredicatesMap.put(keyR(r), entry);
+        }
+        return entry;
+    }
+
+    Objects getOrCreateObjects(int r1, int r2) {
+        Objects entry = (Objects)objectsMap.get(r1, r2);
+        if(entry == null) {
+            entry = new Objects(r1, r2);
+            objectsMap.put(keyR2(r1, r2), entry);
+        }
+        return entry;
+    }
+
+    OrderedSet getOrCreateOrderedSet(int r) {
+        OrderedSet entry = (OrderedSet)orderedSetMap.get(r);
+        if(entry == null) {
+            entry = new OrderedSet(r);
+            orderedSetMap.put(keyR(r), entry);
+        }
+        return entry;
+    }
+
+    Predicates getOrCreatePredicates(int r) {
+        Predicates entry = (Predicates)predicatesMap.get(r);
+        if(entry == null) {
+            entry = new Predicates(r);
+            predicatesMap.put(keyR(r), entry);
+        }
+        return entry;
+    }
+
+    PrincipalTypes getOrCreatePrincipalTypes(int r) {
+        PrincipalTypes entry = (PrincipalTypes)principalTypesMap.get(r);
+        if(entry == null) {
+            entry = new PrincipalTypes(r);
+            principalTypesMap.put(keyR(r), entry);
+        }
+        return entry;
+    }
+
+    RelationInfoQuery getOrCreateRelationInfoQuery(int r) {
+        RelationInfoQuery entry = (RelationInfoQuery)relationInfoQueryMap.get(r);
+        if(entry == null) {
+            entry = new RelationInfoQuery(r);
+            relationInfoQueryMap.put(keyR(r), entry);
+        }
+        return entry;
+    }
+
+    Statements getOrCreateStatements(int r1, int r2) {
+        Statements entry = (Statements)statementsMap.get(r1, r2);
+        if(entry == null) {
+            entry = new Statements(r1, r2);
+            statementsMap.put(keyR2(r1, r2), entry);
+        }
+        return entry;
+    }
+
+    SuperRelations getOrCreateSuperRelations(int r) {
+        SuperRelations entry = (SuperRelations)superRelationsMap.get(r);
+        if(entry == null) {
+            entry = new SuperRelations(r);
+            superRelationsMap.put(keyR(r), entry);
+        }
+        return entry;
+    }
+
+    SuperTypes getOrCreateSuperTypes(int r) {
+        SuperTypes entry = (SuperTypes)superTypesMap.get(r);
+        if(entry == null) {
+            entry = new SuperTypes(r);
+            superTypesMap.put(keyR(r), entry);
+        }
+        return entry;
+    }
+
+    TypeHierarchy getOrCreateTypeHierarchy(int r) {
+        TypeHierarchy entry = (TypeHierarchy)typeHierarchyMap.get(r);
+        if(entry == null) {
+            entry = new TypeHierarchy(r);
+            typeHierarchyMap.put(keyR(r), entry);
+        }
+        return entry;
+    }
+
+    Types getOrCreateTypes(int r) {
+        Types entry = (Types)typesMap.get(r);
+        if(entry == null) {
+            entry = new Types(r);
+            typesMap.put(keyR(r), entry);
+        }
+        return entry;
+    }
+
+    URIToResource getOrCreateURIToResource(String s) {
+        URIToResource entry = (URIToResource)uRIToResourceMap.get(s);
+        if(entry == null) {
+            entry = new URIToResource(s);
+            uRIToResourceMap.put(keyID(s), entry);
+        }
+        return entry;
+    }
+
+    ValueQuery getOrCreateValueQuery(int r) {
+        ValueQuery entry = (ValueQuery)valueQueryMap.get(r);
+        if(entry == null) {
+            entry = new ValueQuery(r);
+            valueQueryMap.put(keyR(r), entry);
+        }
+        return entry;
+    }
+    
 }
\ No newline at end of file
index 0b6f6ef834411316255ac12e80f56faa3d3bdd93..e6dc252c41f210d00586895aeabe6d7c619001f3 100644 (file)
@@ -148,6 +148,7 @@ class QueryCollectorImpl implements QueryProcessor.QueryCollector {
                                                        
                                                } else {
                                                        
+                                                       entry.pruneParentSet();
                                                        support.setLevel(entry, parent.getLevel() + 1);
                                                        
                                                }
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryDeserializer.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryDeserializer.java
new file mode 100644 (file)
index 0000000..0fe9b9c
--- /dev/null
@@ -0,0 +1,227 @@
+package org.simantics.db.impl.query;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.simantics.db.ObjectResourceIdMap;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.impl.ClusterBase;
+import org.simantics.db.impl.ClusterSupport;
+import org.simantics.db.impl.ClusterTraitsBase;
+import org.simantics.db.service.Bytes;
+import org.slf4j.LoggerFactory;
+
+import gnu.trove.map.hash.TIntLongHashMap;
+
+public class QueryDeserializer {
+
+    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(QueryDeserializer.class);
+
+    QueryCache qc;
+    QuerySupport qs;
+    ClusterSupport cs;
+    
+    private byte[] bytes;
+    private int byteIndex;
+    
+    private TIntLongHashMap clusterKeys = new TIntLongHashMap();
+    private Map<Integer,QueryFactory> ids = new HashMap<Integer,QueryFactory>();
+
+    public QueryDeserializer(QueryProcessor qp, byte[] bytes) {
+        this.qc = qp.cache;
+        this.qs = qp.querySupport;
+        this.cs = qs.getClusterSupport();;
+        this.bytes = bytes;
+    }
+    
+    public byte readByte() {
+        return bytes[byteIndex++];
+    }
+    
+    public int readLE4() {
+        int result = Bytes.readLE4(bytes, byteIndex);
+        byteIndex += 4;
+        return result;
+    }
+    
+    public long readLE8() {
+        long result = Bytes.readLE8(bytes, byteIndex);
+        byteIndex += 8;
+        return result;
+    }
+
+    public byte[] readBytes(int len) {
+        byte[] result = Arrays.copyOfRange(bytes, byteIndex, byteIndex+len);
+        byteIndex += len;
+        return result;
+    }
+    
+    public void readHeaders() {
+        int idsSize = readLE4();
+        for(int i=0;i<idsSize;i++) {
+            int size = readLE4();
+            byte[] data = readBytes(size);
+            String id = new String(data);
+            int key = readLE4();
+            try {
+                Class<QueryFactory> clazz = (Class<QueryFactory>)getClass().getClassLoader().loadClass(id + "Factory");
+                QueryFactory qf = clazz.getDeclaredConstructor().newInstance(); 
+                ids.put(key, qf);
+            } catch (ClassNotFoundException e) {
+                LOGGER.error("Error while resolving QueryFactory", e);
+            } catch (InstantiationException e) {
+                LOGGER.error("Error while resolving QueryFactory", e);
+            } catch (IllegalAccessException e) {
+                LOGGER.error("Error while resolving QueryFactory", e);
+            } catch (IllegalArgumentException e) {
+                LOGGER.error("Error while resolving QueryFactory", e);
+            } catch (InvocationTargetException e) {
+                LOGGER.error("Error while resolving QueryFactory", e);
+            } catch (NoSuchMethodException e) {
+                LOGGER.error("Error while resolving QueryFactory", e);
+            } catch (SecurityException e) {
+                LOGGER.error("Error while resolving QueryFactory", e);
+            }
+        }
+        int clusterKeysSize = readLE4();
+        for(int i=0;i<clusterKeysSize;i++) {
+            long cluster = readLE8();
+            int key = readLE4();
+            clusterKeys.put(key, cluster);
+        }
+    }
+    
+    public QueryFactory readFactory() {
+        int key = readLE4();
+        return ids.get(key);
+    }
+
+    public void readQueries() {
+        int count = readLE4();
+        for(int i=0;i<count;i++) {
+            QueryFactory qf = readFactory();
+            try {
+                qf.read(this);
+            } catch (DatabaseException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    public int readResource() throws DatabaseException {
+        int key = readLE4();
+        if(key < 0)
+            return key;
+        int clusterKey = ClusterTraitsBase.getClusterKeyFromResourceKey(key);
+        long cluster = clusterKeys.get(clusterKey);
+        ClusterBase cb = cs.getClusterByClusterId(cluster);
+        return ClusterTraitsBase.createResourceKey(cb.getClusterKey(), ClusterTraitsBase.getResourceIndexFromResourceKey(key));
+    }
+    
+    public byte[] readByteArray() {
+        int len = readLE4();
+        if(len == -1)
+            return null;
+        return readBytes(len);
+    }
+    
+    public String readString() {
+        return new String(readByteArray());
+    }
+    
+    public ObjectResourceIdMap<String> createChildMap() {
+        return qs.createChildMap();
+    }
+
+    AssertedPredicates readAssertedPredicates() throws DatabaseException {
+        int r = readResource();
+        return qc.getOrCreateAssertedPredicates(r);
+    }
+
+    AssertedStatements readAssertedStatements() throws DatabaseException {
+        int r1 = readResource();
+        int r2 = readResource();
+        return qc.getOrCreateAssertedStatements(r1, r2);
+    }
+
+    ChildMap readChildMap() throws DatabaseException {
+        int r = readResource();
+        return qc.getOrCreateChildMap(r);
+    }
+
+    DirectObjects readDirectObjects() throws DatabaseException {
+        int r1 = readResource();
+        int r2 = readResource();
+        return qc.getOrCreateDirectObjects(r1, r2);
+    }
+    
+    DirectPredicates readDirectPredicates() throws DatabaseException {
+        int r = readResource();
+        return qc.getOrCreateDirectPredicates(r);
+    }
+
+    Objects readObjects() throws DatabaseException {
+        int r1 = readResource();
+        int r2 = readResource();
+        return qc.getOrCreateObjects(r1, r2);
+    }
+
+    OrderedSet readOrderedSet() throws DatabaseException {
+        int r = readResource();
+        return qc.getOrCreateOrderedSet(r);
+    }
+
+    Predicates readPredicates() throws DatabaseException {
+        int r = readResource();
+        return qc.getOrCreatePredicates(r);
+    }
+
+    PrincipalTypes readPrincipalTypes() throws DatabaseException {
+        int r = readResource();
+        return qc.getOrCreatePrincipalTypes(r);
+    }
+
+    RelationInfoQuery readRelationInfoQuery() throws DatabaseException {
+        int r = readResource();
+        return qc.getOrCreateRelationInfoQuery(r);
+    }
+
+    Statements readStatements() throws DatabaseException {
+        int r1 = readResource();
+        int r2 = readResource();
+        return qc.getOrCreateStatements(r1, r2);
+    }
+
+    SuperRelations readSuperRelations() throws DatabaseException {
+        int r = readResource();
+        return qc.getOrCreateSuperRelations(r);
+    }
+
+    SuperTypes readSuperTypes() throws DatabaseException {
+        int r = readResource();
+        return qc.getOrCreateSuperTypes(r);
+    }
+
+    TypeHierarchy readTypeHierarchy() throws DatabaseException {
+        int r = readResource();
+        return qc.getOrCreateTypeHierarchy(r);
+    }
+
+    Types readTypes() throws DatabaseException {
+        int r = readResource();
+        return qc.getOrCreateTypes(r);
+    }
+
+    URIToResource readURIToResource() throws DatabaseException {
+        String s = readString();
+        return qc.getOrCreateURIToResource(s);
+    }
+
+    ValueQuery readValueQuery() throws DatabaseException {
+        int r = readResource();
+        return qc.getOrCreateValueQuery(r);
+    }
+
+}
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryFactory.java
new file mode 100644 (file)
index 0000000..c4b3f9f
--- /dev/null
@@ -0,0 +1,8 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public interface QueryFactory {
+    public CacheEntryBase read(QueryDeserializer deserializer) throws DatabaseException;
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException;
+}
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryFactoryBase.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryFactoryBase.java
new file mode 100644 (file)
index 0000000..a193cce
--- /dev/null
@@ -0,0 +1,25 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+abstract public class QueryFactoryBase implements QueryFactory {
+
+    abstract protected CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException;
+
+    public void readParents(QueryDeserializer deserializer, CacheEntryBase entry) throws DatabaseException {
+        int ps = deserializer.readLE4();
+        for(int i=0;i<ps;i++) {
+            QueryFactory qf = deserializer.readFactory();
+            CacheEntryBase ceb = qf.reference(deserializer);
+            entry.addParent(ceb);
+        }
+    }
+    
+    @Override
+    final public CacheEntryBase read(QueryDeserializer deserializer) throws DatabaseException {
+        CacheEntryBase entry = readKeyAndValue(deserializer);
+        readParents(deserializer, entry);
+        return entry;
+    }
+
+}
index c2b21444fd17157753d2cfc303bd8b4932a488fa..2db67c67970b165f836317cbbaaabea40fa6994d 100644 (file)
  *******************************************************************************/
 package org.simantics.db.impl.query;
 
-import gnu.trove.impl.hash.THash;
+import java.util.Collection;
 
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 
+import gnu.trove.impl.hash.THash;
+
 
 /**
  * An open addressed hashing implementation for Object types.
@@ -59,7 +61,7 @@ abstract public class QueryIdentityHash extends THash {
         }
 
         @Override
-        public Iterable<CacheEntry> getParents(QueryProcessor processor) {
+        public Collection<CacheEntry> getParents(QueryProcessor processor) {
             // TODO Auto-generated method stub
             return null;
         }
@@ -227,7 +229,11 @@ abstract public class QueryIdentityHash extends THash {
                        // TODO Auto-generated method stub
                        return null;
                }
-        
+
+        @Override
+            void pruneParentSet() {
+        }
+
     };
 
     /**
index 3a7eb61820203ffc5e079d0a57b12f7fe8c86842..ac2602fcb647b4ad54e8de9edf1a8c4412313d95 100644 (file)
@@ -147,7 +147,25 @@ final public class QueryIdentityHashSet extends QueryIdentityHash implements Ite
         }
         
     }
-    
+
+    final public void removeDiscardedReally() {
+
+        tempDisableAutoCompaction();
+        try {
+
+            for(int i=0;i<_set.length;i++) {
+                CacheEntry entry = _set[i];
+                if(entry != null && REMOVED != entry) {
+                    if(entry.isDiscarded()) removeAt(i);
+                }
+            }
+
+        } finally {
+            reenableAutoCompaction(false);
+        }
+
+    }
+
     /**
      * Creates an iterator over the values of the set.  The iterator
      * supports element deletion.
index 91200f1fc3ad037393bc5e3794d6acc4c29a4e7b..e0b39d6516055656995689f90c1506c19bb26265 100644 (file)
@@ -415,7 +415,7 @@ public class QueryListening {
 
         @Override
         public void run() {
-            ListenerEntry entry = addedEntries.get(base);
+            ListenerEntry entry = addedEntries.remove(base);
             if(entry != null) entry.setLastKnown(result);
         }
 
index 6d9560940be2b1c19b73616c85a2996ee2b65d25..f61c661d19cbd7eb47fbf15de27ef4bb9035627c 100644 (file)
@@ -32,6 +32,7 @@ import java.util.concurrent.Semaphore;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.eclipse.core.runtime.Platform;
 import org.simantics.databoard.Bindings;
 import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.DevelopmentKeys;
@@ -42,6 +43,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.Statement;
 import org.simantics.db.VirtualGraph;
+import org.simantics.db.common.ByteFileReader;
 import org.simantics.db.common.procedure.adapter.AsyncMultiProcedureAdapter;
 import org.simantics.db.common.utils.Logger;
 import org.simantics.db.exception.DatabaseException;
@@ -68,9 +70,11 @@ import org.simantics.db.request.AsyncMultiRead;
 import org.simantics.db.request.ExternalRead;
 import org.simantics.db.request.MultiRead;
 import org.simantics.db.request.RequestFlags;
+import org.simantics.db.service.Bytes;
 import org.simantics.layer0.Layer0;
 import org.simantics.utils.DataContainer;
 import org.simantics.utils.Development;
+import org.simantics.utils.FileUtils;
 import org.simantics.utils.datastructures.Pair;
 import org.simantics.utils.datastructures.collections.CollectionUtils;
 import org.simantics.utils.datastructures.disposable.AbstractDisposable;
@@ -1069,6 +1073,82 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
 
        }
 
+    public synchronized void save() throws IOException {
+
+        long start = System.nanoTime();
+
+        Collection<CacheEntryBase> caches = allCaches(new CacheCollectionResult()).toCollection();
+        Map<Long,List<CacheEntryBase>> cachesByCluster = new HashMap<>();
+        for(CacheEntryBase entry : caches) {
+            String clazz = entry.classId();
+            if(clazz == null)
+                continue;
+            long cluster = entry.cluster(this);
+            List<CacheEntryBase> queries = cachesByCluster.get(cluster);
+            if(queries == null) {
+                queries = new ArrayList<>();
+                cachesByCluster.put(cluster, queries);
+            }
+            queries.add(entry);
+        }
+
+        File workspace = Platform.getLocation().toFile();
+        File dir = new File(workspace, "queryData");
+        FileUtils.deleteAll(dir);
+
+        dir.mkdir();
+
+        for(Long cluster : cachesByCluster.keySet()) {
+
+            List<CacheEntryBase> queries = cachesByCluster.get(cluster);
+            QuerySerializer serializer = new QuerySerializer(this);
+            int count = 0;
+            int pos = serializer.writeUnknownSize();
+            for(CacheEntryBase entry : queries) {
+                String clazz = entry.classId();
+                if(clazz == null)
+                    continue;
+                try {
+                    entry.serialize(serializer);
+                    count++;
+                } catch (IllegalStateException e) {
+                    System.err.println(e.getMessage());
+                }
+            }
+            serializer.setUnknownSize(pos, count);
+
+            System.err.println(serializer.bytes().length + " bytes for cluster " + cluster);
+            FileUtils.writeFile(new File(dir, "" + cluster + ".queryData"), serializer.bytes());
+
+        }
+
+        long end = System.nanoTime();
+
+        System.err.println("saved queries in " + 1e-6*(end-start) + "ms.");
+
+    }
+
+    public void restore() throws IOException {
+
+        long start = System.nanoTime();
+
+        File workspace = Platform.getLocation().toFile();
+        File dir = new File(workspace, "queryData");
+        dir.mkdir();
+
+        for(File f : FileUtils.listFilesByExtension(dir, "queryData")) {
+            byte[] bytes = FileUtils.readFile(f);
+            QueryDeserializer qd = new QueryDeserializer(this, bytes);
+            qd.readHeaders();
+            qd.readQueries();
+        }
+
+        long end = System.nanoTime();
+
+        System.err.println("restored queries in " + 1e-6*(end-start) + "ms.");
+
+    }
+
        boolean removeQuery(CacheEntry entry) {
 
                // This entry has been removed before. No need to do anything here.
@@ -1760,6 +1840,12 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
                }
                return result;
        }
+       
+       public long cluster(int resource) {
+           if(resource <= 0)
+               return 0;
+           return querySupport.getClusterId(resource);
+       }
 
        public void assertDone() {
        }
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QuerySerializer.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QuerySerializer.java
new file mode 100644 (file)
index 0000000..06b0140
--- /dev/null
@@ -0,0 +1,136 @@
+package org.simantics.db.impl.query;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.simantics.db.impl.ClusterTraitsBase;
+
+import gnu.trove.list.array.TByteArrayList;
+import gnu.trove.map.hash.TLongIntHashMap;
+import gnu.trove.procedure.TLongIntProcedure;
+
+public class QuerySerializer {
+
+    private QueryProcessor processor;
+    private QuerySupport querySupport;
+    private TByteArrayList bytes = new TByteArrayList();
+    private TLongIntHashMap clusterKeys = new TLongIntHashMap();
+    private Map<String,Integer> ids = new HashMap<String,Integer>();
+
+    public QuerySerializer(QueryProcessor processor) {
+        this.processor = processor;
+        this.querySupport = processor.querySupport;
+    }
+
+    public int writeUnknownSize() {
+        int pos = bytes.size();
+        bytes.add((byte)0);
+        bytes.add((byte)0);
+        bytes.add((byte)0);
+        bytes.add((byte)0);
+        return pos;
+    }
+
+    public void setUnknownSize(int pos, int value) {
+        bytes.set(pos, (byte) (value & 0xFF));
+        bytes.set(pos+1, (byte) ((value >>> 8) & 0xFF));
+        bytes.set(pos+2, (byte) ((value >>> 16) & 0xFF));
+        bytes.set(pos+3, (byte) ((value >>> 24) & 0xFF));
+    }
+
+    public void serializeId(String classId) {
+        Integer id = ids.get(classId);
+        if(id == null) {
+            id = ids.size() + 1;
+            ids.put(classId, id);
+        }
+        writeLE(id);
+    }
+
+    public void addResource(int r) {
+        if(r < 0) {
+            writeLE(r);
+        } else {
+            long clusterId = querySupport.getClusterId(r);
+            int clusterKey = clusterKeys.get(clusterId);
+            if(clusterKey == 0) {
+                clusterKey = clusterKeys.size() + 1;
+                clusterKeys.put(clusterId, clusterKey);
+            }
+            int i = ClusterTraitsBase.createResourceKeyNoThrow(clusterKey, ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(r));
+            writeLE(i);
+        }
+    }
+
+    public void addString(String s) {
+        byte[] b = s.getBytes();
+        writeLE(b.length);
+        bytes.add(b);
+    }
+
+    public void add(byte b) {
+        bytes.add(b);
+    }
+
+    public void add(byte[] bs) {
+        bytes.add(bs);
+    }
+
+    public byte[] bytes() {
+        TByteArrayList header = new TByteArrayList();
+        writeLE(header, ids.size());
+        for(Entry<String,Integer> entry : ids.entrySet()) {
+            String id = entry.getKey();
+            writeLE(header, id.length());
+            header.add(id.getBytes());
+            writeLE(header, entry.getValue());
+        }
+
+        writeLE(header, clusterKeys.size());
+        clusterKeys.forEachEntry(new TLongIntProcedure() {
+
+            @Override
+            public boolean execute(long a, int b) {
+                writeLE(header, a);
+                writeLE(header, b);
+                return true;
+            }
+
+        });
+
+        header.add(bytes.toArray());
+        return header.toArray();
+    }
+
+    public void writeLE(int value) {
+        writeLE(bytes, value);
+    }
+
+    public static void writeLE(TByteArrayList bytes, int value) {
+        bytes.add((byte) (value & 0xFF));
+        bytes.add((byte) ((value >>> 8) & 0xFF));
+        bytes.add((byte) ((value >>> 16) & 0xFF));
+        bytes.add((byte) ((value >>> 24) & 0xFF));
+    }
+
+    public void writeLE(long value) {
+        writeLE(bytes, value);
+    }
+
+    public static void writeLE(TByteArrayList bytes, long value) {
+        bytes.add((byte) (value & 0xFF));
+        bytes.add((byte) ((value >>> 8) & 0xFF));
+        bytes.add((byte) ((value >>> 16) & 0xFF));
+        bytes.add((byte) ((value >>> 24) & 0xFF));
+        bytes.add((byte) ((value >>> 32) & 0xFF));
+        bytes.add((byte) ((value >>> 40) & 0xFF));
+        bytes.add((byte) ((value >>> 48) & 0xFF));
+        bytes.add((byte) ((value >>> 56) & 0xFF));
+    }
+
+    public QueryProcessor getQueryProcessor() {
+        return processor;
+    }
+
+}
index 3071c30c042d8730799004eec9d10b7168b70fd4..0a0a207fdc4d8d90b51ac93e594bc417489984f8 100644 (file)
@@ -13,17 +13,23 @@ package org.simantics.db.impl.query;
 
 import java.io.InputStream;
 
+import org.simantics.db.ObjectResourceIdMap;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.VirtualGraph;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.ResourceNotFoundException;
+import org.simantics.db.impl.ClusterSupport;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 
 public interface QuerySupport extends ResourceTranslator {
 
        Session getSession();
-       
+
+       ClusterSupport getClusterSupport();
+
+       ObjectResourceIdMap<String> createChildMap();
+
        boolean isImmutable(int id);
        long getClusterId(int id);
        int getId(Resource resource);
index 8f547d22b3e950a9c3b87e035fd9a0e07a4aef08..4fb5ed996011a047659a22158477103d216c6f41 100644 (file)
@@ -214,4 +214,9 @@ public final class ReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> implem
         except(throwable);
     }
 
+    @Override
+    public String classId() {
+        return null;
+    }
+
 }
index cffd2984a0c31219acfcb740aa7cf921df0e709e..367e75f632c3cdd10e592286fb06cacdb13548b6 100644 (file)
@@ -100,4 +100,13 @@ public final class RelationInfoQuery extends UnaryQueryP<RelationInfo> {
                return RequestFlags.IMMEDIATE_UPDATE;
        }
 
+    @Override
+    public void serializeValue(QuerySerializer serializer) {
+        RelationInfo ri = getResult();
+        serializer.addResource(ri.predicate);
+        serializer.add(ri.isFunctional ? (byte)1 : 0);
+        serializer.add(ri.isFinal ? (byte)1 : 0);
+        serializer.add(ri.isAsserted ? (byte)1 : 0);
+    }
+
 }
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/RelationInfoQueryFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/RelationInfoQueryFactory.java
new file mode 100644 (file)
index 0000000..05adb56
--- /dev/null
@@ -0,0 +1,26 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.RelationInfo;
+import org.simantics.db.exception.DatabaseException;
+
+public class RelationInfoQueryFactory extends QueryFactoryBase {
+
+    @Override
+    public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+        RelationInfoQuery result = reference(deserializer);
+        int r = deserializer.readResource();
+        int isFunctional = deserializer.readByte();
+        int isFinal = deserializer.readByte();
+        int isAsserted = deserializer.readByte();
+        RelationInfo ri = new RelationInfo(r, isFunctional == 1, isFinal == 1, isAsserted == 1);
+        result.setResult(ri);
+        result.setReady();
+        return result;
+    }
+    
+    @Override
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+        return (T)deserializer.readRelationInfoQuery();
+    }
+
+}
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/StatementsFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/StatementsFactory.java
new file mode 100644 (file)
index 0000000..7639235
--- /dev/null
@@ -0,0 +1,21 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class StatementsFactory extends QueryFactoryBase {
+
+    @Override
+    public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+        Statements result = reference(deserializer);
+        IntArray ia = IntArray.deserialize(deserializer);
+        result.setResult(ia);
+        result.setReady();
+        return result;
+    }
+    
+    @Override
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+        return (T)deserializer.readStatements();
+    }
+
+}
index 1f540062e9440d2db81164ee820c05566f4a55c0..5c6e8e43947917da321343525984fdb8a362d47a 100644 (file)
@@ -21,7 +21,7 @@ import org.simantics.db.impl.procedure.InternalProcedure;
 import gnu.trove.procedure.TIntProcedure;
 import gnu.trove.set.hash.TIntHashSet;
 
-public final class SuperRelations extends UnaryQueryP<IntSet> {
+public final class SuperRelations extends UnaryQueryPIntSet {
 
     SuperRelations(final int resource) {
         super(resource);
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/SuperRelationsFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/SuperRelationsFactory.java
new file mode 100644 (file)
index 0000000..9011b46
--- /dev/null
@@ -0,0 +1,21 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class SuperRelationsFactory extends QueryFactoryBase {
+
+    @Override
+    public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+        SuperRelations result = reference(deserializer);
+        IntSet ia = IntSet.deserialize(deserializer);
+        result.setResult(ia);
+        result.setReady();
+        return result;
+    }
+    
+    @Override
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+        return (T)deserializer.readSuperRelations();
+    }
+
+}
index a02fda4623342fc7d80889f8c543f6d5aec70316..f3dc03e14ffb2c85f7f7885516a45c130ab67709 100644 (file)
@@ -17,7 +17,7 @@ import org.simantics.db.impl.procedure.InternalProcedure;
 
 import gnu.trove.procedure.TIntProcedure;
 
-public final class SuperTypes extends UnaryQueryP<IntSet> {
+public final class SuperTypes extends UnaryQueryPIntSet {
 
     SuperTypes(int resource) {
         super(resource);
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/SuperTypesFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/SuperTypesFactory.java
new file mode 100644 (file)
index 0000000..edb82ef
--- /dev/null
@@ -0,0 +1,21 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class SuperTypesFactory extends QueryFactoryBase {
+
+    @Override
+    public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+        SuperTypes result = reference(deserializer);
+        IntSet ia = IntSet.deserialize(deserializer);
+        result.setResult(ia);
+        result.setReady();
+        return result;
+    }
+    
+    @Override
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+        return (T)deserializer.readSuperTypes();
+    }
+
+}
index 5c2be0c64e6dca1908b182ee340073de9405bfa3..323bbd42dc66d811e1b2db14d8eb39c724585bd1 100644 (file)
@@ -18,7 +18,7 @@ import org.simantics.db.procedure.ListenerBase;
 
 import gnu.trove.procedure.TIntProcedure;
 
-public final class TypeHierarchy extends UnaryQueryP<IntSet> {
+public final class TypeHierarchy extends UnaryQueryPIntSet {
 
     TypeHierarchy(int resource) {
         super(resource);
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/TypeHierarchyFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/TypeHierarchyFactory.java
new file mode 100644 (file)
index 0000000..d8120b7
--- /dev/null
@@ -0,0 +1,21 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class TypeHierarchyFactory extends QueryFactoryBase {
+
+    @Override
+    public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+        TypeHierarchy result = reference(deserializer);
+        IntSet ia = IntSet.deserialize(deserializer);
+        result.setResult(ia);
+        result.setReady();
+        return result;
+    }
+    
+    @Override
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+        return (T)deserializer.readTypeHierarchy();
+    }
+
+}
index a9fe36bc6bfcb60608e2758f3a28721c165e09dc..bb0d11a243193da746bb88804696317503dc941f 100644 (file)
@@ -19,7 +19,7 @@ import org.simantics.db.impl.procedure.InternalProcedure;
 
 import gnu.trove.procedure.TIntProcedure;
 
-public final class Types extends UnaryQueryP<IntSet> {
+public final class Types extends UnaryQueryPIntSet {
 
     Types(int resource) {
         super(resource);
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/TypesFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/TypesFactory.java
new file mode 100644 (file)
index 0000000..014b0ee
--- /dev/null
@@ -0,0 +1,21 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class TypesFactory extends QueryFactoryBase {
+
+    @Override
+    public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+        Types result = reference(deserializer);
+        IntSet ia = IntSet.deserialize(deserializer);
+        result.setResult(ia);
+        result.setReady();
+        return result;
+    }
+    
+    @Override
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+        return (T)deserializer.readTypes();
+    }
+
+}
index ec7ebeed7fad0324035280af18dc69225307c1ac..9dae343e39b3e7028e2e46d0f14def1d6dfbcc1e 100644 (file)
@@ -144,4 +144,20 @@ public class URIToResource extends StringQuery<InternalProcedure<Integer>> imple
         except(throwable);
     }
 
+    @Override
+    public long cluster(QueryProcessor processor) {
+        return 0;
+    }
+    
+    @Override
+    public void serializeKey(QuerySerializer serializer) {
+        serializer.addString(id);
+    }
+
+    @Override
+    public void serializeValue(QuerySerializer serializer) {
+        Integer value = getResult();
+        serializer.addResource(value);
+    }
+
 }
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/URIToResourceFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/URIToResourceFactory.java
new file mode 100644 (file)
index 0000000..ca82ff6
--- /dev/null
@@ -0,0 +1,21 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class URIToResourceFactory extends QueryFactoryBase {
+
+    @Override
+    public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+        URIToResource result = reference(deserializer);
+        int value = deserializer.readResource();
+        result.setResult(value);
+        result.setReady();
+        return result;
+    }
+    
+    @Override
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+        return (T)deserializer.readURIToResource();
+    }
+
+}
index fd6cd7d879374bb8af81c18a40058137b46aed2e..fe24846aa318539da2524f19a0c50b4a2e382d5c 100644 (file)
@@ -15,6 +15,8 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.request.RequestFlags;
 
+import gnu.trove.list.array.TByteArrayList;
+
 public abstract class UnaryQuery<Procedure> extends CacheEntryBase<Procedure> implements Query {
 
     final public int id;
@@ -68,4 +70,14 @@ public abstract class UnaryQuery<Procedure> extends CacheEntryBase<Procedure> im
         return graph.processor.isImmutable(id);
     }
     
+    @Override
+    public long cluster(QueryProcessor processor) {
+        return processor.cluster(id);
+    }
+    
+    @Override
+    public void serializeKey(QuerySerializer serializer) {
+        serializer.addResource(id);
+    }
+    
 }
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/UnaryQueryPIntSet.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/UnaryQueryPIntSet.java
new file mode 100644 (file)
index 0000000..cf82479
--- /dev/null
@@ -0,0 +1,15 @@
+package org.simantics.db.impl.query;
+
+abstract public class UnaryQueryPIntSet extends UnaryQueryP<IntSet> {
+
+    public UnaryQueryPIntSet(int r) {
+        super(r);
+    }
+    
+    @Override
+    public void serializeValue(QuerySerializer serializer) {
+        IntSet is = getResult();
+        is.serialize(serializer);
+    }
+
+}
index ad4017f9cff863c0a2bbe42a4fb9458a655e57f2..f04df9f6846097d6b03c1f1b0bc5411ca71af248 100644 (file)
@@ -45,6 +45,17 @@ public final class ValueQuery extends UnaryQueryP<byte[]> {
         return value;
 
     }
+    
+    @Override
+    public void serializeValue(QuerySerializer serializer) {
+        byte[] result = getResult();
+        if(result == null) {
+            serializer.writeLE(-1);
+        } else {
+            serializer.writeLE(result.length);
+            serializer.add(result);
+        }
+    }
 
     @Override
     public String toString() {
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ValueQueryFactory.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ValueQueryFactory.java
new file mode 100644 (file)
index 0000000..4a746fd
--- /dev/null
@@ -0,0 +1,21 @@
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class ValueQueryFactory extends QueryFactoryBase {
+
+    @Override
+    public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+        ValueQuery result = reference(deserializer);
+        byte[] bytes = deserializer.readByteArray();
+        result.setResult(bytes);
+        result.setReady();
+        return result;
+    }
+    
+    @Override
+    public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+        return (T)deserializer.readValueQuery();
+    }
+
+}
index ac53847a3c5a8e998f5c31db0243f41afce1110e..17fc2ed8c51883fe630e9a3e66ab16913d55f5af 100644 (file)
@@ -9,7 +9,6 @@ Require-Bundle: gnu.trove3;bundle-version="3.0.3",
  org.simantics.databoard;bundle-version="0.6.2";visibility:=reexport,
  org.simantics.db.services;bundle-version="1.1.0";visibility:=reexport,
  org.simantics.db.management;bundle-version="1.1.0",
- org.apache.log4j;bundle-version="1.2.15",
  org.apache.commons.io;bundle-version="1.4.0",
  org.simantics.layer0;bundle-version="1.0.0";visibility:=reexport,
  org.simantics.graph.db;bundle-version="1.1.5";visibility:=reexport,
index 1bcd918771f3db8520507e6893b2de2376d61164..16f88a340a63e7f9dfeb9c0d7ef751a7ff8e7048 100644 (file)
@@ -179,7 +179,6 @@ implements Read<Function1<EvaluationContext,Object>> {
                 b2.append('\n');
             }
             SCLDatabaseException exception = new SCLDatabaseException(b.toString()+b2.toString(), b2.toString(), e.getErrors()); 
-            LOGGER.info(exception.getMessage(), exception);
             throw exception; 
         } catch(Throwable e) {
             // Should not happen!
index 5d21ca56bdf5ab3a0d0ba9aa7cd7a11542379920..707fdbd0ee46463a586eda41827beb5b9118085f 100644 (file)
@@ -7,174 +7,177 @@ import java.util.Map;
 import org.simantics.databoard.util.ObjectUtils;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.common.request.ParametrizedPrimitiveRead;
-import org.simantics.db.common.utils.Logger;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.Variables.NodeStructure;
 import org.simantics.db.procedure.Listener;
 import org.simantics.simulator.variable.exceptions.NodeManagerException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import gnu.trove.map.hash.THashMap;
 
 @SuppressWarnings("rawtypes")
 class NodeStructureRequest extends ParametrizedPrimitiveRead<VariableNode, NodeStructure> implements VariableNodeReadRunnable {
 
-       private Listener<NodeStructure> listener = null;
-       private NodeStructure value = Variables.PENDING_NODE_STRUCTURE;
-       private boolean wasRun = false;
-
-       static class Probe implements Runnable {
-
-               private VariableNode node;
-               public NodeStructure result;
-
-               public Probe(VariableNode node) {
-                       this.node = node;
-               }
-
-               @SuppressWarnings("unchecked")
-               @Override
-               public void run() {
-                       try {
-                               result = NodeStructureRequest.get(node);
-                               node.support.structureCache.put(node.node, result, 1000000000L);
-                       } catch (NodeManagerException e) {
-                               e.printStackTrace();
-                       }
-               }
-
-       }
-
-       public NodeStructureRequest(VariableNode node) {
-               super(node);
-       }
-
-       @SuppressWarnings("unchecked")
-       @Override
-       public void register(ReadGraph graph, final Listener<NodeStructure> procedure) {
-
-               if(procedure.isDisposed()) {
-
-                       // We are not listening
-                       NodeStructure result = (NodeStructure)parameter.support.structureCache.get(parameter.node);
-
-                       if(result != null) {
-                               // Return cached value immediately
-                               procedure.execute(result);
-                       } else {
-                               NodeStructureRequest.Probe probe = new Probe(parameter);
-                               parameter.support.manager.getRealm().asyncExec(probe);
-                               if(probe.result != null) {
-                                       procedure.execute(probe.result);
-                               } else {
-                                       procedure.execute(Variables.PENDING_NODE_STRUCTURE);
-                               }
-                       }
-
-                       return;
-
-               }
-
-               // We need to listen
-               listener = procedure;
-               // Register listening
-               parameter.support.manager.addNodeListener(parameter.node, this);
-               synchronized(this) {
-                       if(wasRun) {
-                               procedure.execute(value);
-                       } else {
-                               NodeStructure result = (NodeStructure)parameter.support.structureCache.get(parameter.node);
-                               if(result != null) {
-                                       procedure.execute(result);
-                               } else {
-                                       procedure.execute(Variables.PENDING_NODE_STRUCTURE);
-                               }
-                       }
-               }
-
-       }
-
-       static class NodeListener implements VariableNodeReadRunnable {
-
-               private VariableNode node;
-               private NodeStructureRequest request;
-
-               public NodeListener(VariableNode node, NodeStructureRequest request) {
-                       this.node = node;
-                       this.request = request;
-               }
-
-               @SuppressWarnings("unchecked")
-               @Override
-               public void run() {
-                       node.support.manager.addNodeListener(node.node, request);
-               }
-
-       }
-
-       @SuppressWarnings("unchecked")
-       @Override
-       public void unregistered() {
-               parameter.support.manager.removeNodeListener(parameter.node, this);
-               parameter.support.structureCache.removeListening(parameter.node);
-               listener = null;
-       }
-
-       @SuppressWarnings("unchecked")
-       public static NodeStructure get(VariableNode parameter) throws NodeManagerException {
-               List<?> children = parameter.support.manager.getChildren(parameter.node);
-               List<?> properties = parameter.support.manager.getProperties(parameter.node);
-               Map<String, Object> childMap = Collections.emptyMap();
-               Map<String, Object> propertyMap = childMap;
-               if(!children.isEmpty()) {
-                       childMap = new THashMap<>(children.size());
-                       for(Object o : children) {
-                               String name = parameter.support.manager.getName(o);
-                               childMap.put(name, o);
-                       }
-               }
-               if(!properties.isEmpty()) {
-                       propertyMap = new THashMap<>(properties.size());
-                       for(Object o : properties) {
-                               String name = parameter.support.manager.getName(o);
-                               propertyMap.put(name, o);
-                       }
-               }
-               return new NodeStructure(childMap, propertyMap);
-       }
-
-       @SuppressWarnings("unchecked")
-       @Override
-       public synchronized void run() {
-               try {
-                       // Cache this value with infinite cache time since we are listening
-                       NodeStructure newValue = get(parameter);
-                       if (wasRun && ObjectUtils.objectEquals(value, newValue)) {
-                               //System.out.println("CACHE VALUE MATCH (" + newValue + ") for " + node.node);
-                               return;
-                       }
-                       value = newValue;
-                       parameter.support.structureCache.put(parameter.node, value);
-               } catch (Throwable e) {
-                       // Must catch everything to prevent DB client from getting stuck.
-                       Logger.defaultLogError(e);
-                       // Invoke the exception method of the listener
-                       Listener<NodeStructure> listener = this.listener;
-                       if (listener != null) listener.exception(new DatabaseException("External data access error", e));
-                       wasRun = true;
-                       return;
-               }
-
-               // Must always invoke an existing listener, regardless of earlier errors.
-               Listener<NodeStructure> listener = this.listener;
-               if (listener != null) {
-                       listener.execute(value);
-               }
-               wasRun = true;
-       }
-
-       @Override
-       public String toString() {
-               return "NodeStructureRequest.run @ " + System.identityHashCode(this);
-       }
+    private static final Logger LOGGER = LoggerFactory.getLogger(NodeStructureRequest.class);
+
+    private Listener<NodeStructure> listener = null;
+    private NodeStructure value = Variables.PENDING_NODE_STRUCTURE;
+    private boolean wasRun = false;
+
+    static class Probe implements Runnable {
+
+        private VariableNode node;
+        public NodeStructure result;
+
+        public Probe(VariableNode node) {
+            this.node = node;
+        }
+
+        @SuppressWarnings("unchecked")
+        @Override
+        public void run() {
+            try {
+                result = NodeStructureRequest.get(node);
+                node.support.structureCache.put(node.node, result, 1000000000L);
+            } catch (NodeManagerException e) {
+                e.printStackTrace();
+            }
+        }
+
+    }
+
+    public NodeStructureRequest(VariableNode node) {
+        super(node);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void register(ReadGraph graph, final Listener<NodeStructure> procedure) {
+
+        if(procedure.isDisposed()) {
+
+            // We are not listening
+            NodeStructure result = (NodeStructure)parameter.support.structureCache.get(parameter.node);
+
+            if(result != null) {
+                // Return cached value immediately
+                procedure.execute(result);
+            } else {
+                NodeStructureRequest.Probe probe = new Probe(parameter);
+                parameter.support.manager.getRealm().asyncExec(probe);
+                if(probe.result != null) {
+                    procedure.execute(probe.result);
+                } else {
+                    procedure.execute(Variables.PENDING_NODE_STRUCTURE);
+                }
+            }
+
+            return;
+
+        }
+
+        // We need to listen
+        listener = procedure;
+        // Register listening
+        parameter.support.manager.addNodeListener(parameter.node, this);
+        synchronized(this) {
+            if(!wasRun) {
+                NodeStructure result = (NodeStructure)parameter.support.structureCache.get(parameter.node);
+                if(result != null) {
+                    procedure.execute(result);
+                } else {
+                    procedure.execute(Variables.PENDING_NODE_STRUCTURE);
+                }
+            }
+        }
+
+    }
+
+    static class NodeListener implements VariableNodeReadRunnable {
+
+        private VariableNode node;
+        private NodeStructureRequest request;
+
+        public NodeListener(VariableNode node, NodeStructureRequest request) {
+            this.node = node;
+            this.request = request;
+        }
+
+        @SuppressWarnings("unchecked")
+        @Override
+        public void run() {
+            node.support.manager.addNodeListener(node.node, request);
+        }
+
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void unregistered() {
+        parameter.support.manager.removeNodeListener(parameter.node, this);
+        parameter.support.structureCache.removeListening(parameter.node);
+        listener = null;
+    }
+
+    @SuppressWarnings("unchecked")
+    public static NodeStructure get(VariableNode parameter) throws NodeManagerException {
+        List<?> children = parameter.support.manager.getChildren(parameter.node);
+        List<?> properties = parameter.support.manager.getProperties(parameter.node);
+        Map<String, Object> childMap = Collections.emptyMap();
+        Map<String, Object> propertyMap = childMap;
+        if(!children.isEmpty()) {
+            childMap = new THashMap<>(children.size());
+            for(Object o : children) {
+                String name = parameter.support.manager.getName(o);
+                childMap.put(name, o);
+            }
+        }
+        if(!properties.isEmpty()) {
+            propertyMap = new THashMap<>(properties.size());
+            for(Object o : properties) {
+                String name = parameter.support.manager.getName(o);
+                propertyMap.put(name, o);
+            }
+        }
+        return new NodeStructure(childMap, propertyMap);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public synchronized void run() {
+        try {
+            // Cache this value with infinite cache time since we are listening
+            NodeStructure newValue = get(parameter);
+            if (wasRun && ObjectUtils.objectEquals(value, newValue)) {
+                //System.out.println("CACHE VALUE MATCH (" + newValue + ") for " + node.node);
+                return;
+            }
+            value = newValue;
+            parameter.support.structureCache.put(parameter.node, value);
+        } catch (Throwable e) {
+            // Must catch everything to prevent DB client from getting stuck.
+            LOGGER.error("Error while computing node structure", e);
+            // Invoke the exception method of the listener
+            Listener<NodeStructure> listener = this.listener;
+            if (listener != null) {
+                listener.exception(new DatabaseException("External data access error", e));
+                wasRun = true;
+            }
+            return;
+        }
+
+        // Must always invoke an existing listener, regardless of earlier errors.
+        Listener<NodeStructure> listener = this.listener;
+        if (listener != null) {
+            listener.execute(value);
+            wasRun = true;
+        }
+    }
+
+    @Override
+    public String toString() {
+        return "NodeStructureRequest.run @ " + System.identityHashCode(this);
+    }
 
 }
\ No newline at end of file
index 140ee8fa0841648805803c027686ac2b6efb2441..b44f16b30eeedc3ca7ee15fd9d023e0505703a9b 100644 (file)
@@ -110,9 +110,7 @@ class NodeValueRequest extends ParametrizedPrimitiveRead<Pair<VariableNode,Bindi
         // Register listening
         node.support.manager.addNodeListener(node.node, this);
         synchronized(this) {
-            if(wasRun) {
-                procedure.execute(value);
-            } else {
+            if(!wasRun) {
                 Variant result = (Variant)node.support.valueCache.get(node.node);
                 if(result != null) {
                     procedure.execute(result);
@@ -219,8 +217,10 @@ class NodeValueRequest extends ParametrizedPrimitiveRead<Pair<VariableNode,Bindi
                 LOGGER.error("Error while computing node value", e);
             // Invoke the exception method of the listener
             Listener<Variant> listener = this.listener;
-            if (listener != null) listener.exception(new DatabaseException("External data access error", e));
-            wasRun = true;
+            if (listener != null) {
+                listener.exception(new DatabaseException("External data access error", e));
+                wasRun = true;
+            }
             return;
         }
         // Must always invoke an existing listener, regardless of earlier errors.
@@ -228,8 +228,8 @@ class NodeValueRequest extends ParametrizedPrimitiveRead<Pair<VariableNode,Bindi
         if (listener != null) {
             //System.out.println("LISTENER " + listener + " invoked with value " + value);
             listener.execute(value);
+            wasRun = true;
         }
-        wasRun = true;
     }
 
     @Override
index d03b249ea7e2d24e5491ba13cf41996b39714bf0..ac40619dfa17c772fb96ba3b2dbdeb8c89dc0fd4 100644 (file)
@@ -4,8 +4,7 @@ Bundle-Name: ProCore Database Access
 Bundle-SymbolicName: org.simantics.db.procore
 Bundle-Version: 1.2.1.qualifier
 Bundle-Vendor: VTT Technical Research Centre of Finland
-Require-Bundle: org.apache.log4j;visibility:=reexport,
- org.simantics.db;bundle-version="0.8.0";visibility:=reexport,
+Require-Bundle: org.simantics.db;bundle-version="0.8.0";visibility:=reexport,
  org.simantics.db.common;bundle-version="0.8.0";visibility:=reexport,
  gnu.trove3;bundle-version="3.0.0",
  org.simantics.db.impl;bundle-version="0.8.0",
index 3b05bcba6d67baabc0ee5afcf48557f522f3b384..ca5eb0825a3c6462676dcee91124d4b2384b2021 100644 (file)
@@ -45,6 +45,7 @@ import org.simantics.scl.runtime.function.FunctionImpl2;
 import org.simantics.scl.runtime.function.FunctionImpl3;
 import org.simantics.utils.Development;
 import org.simantics.utils.FileUtils;
+import org.slf4j.LoggerFactory;
 
 import gnu.trove.map.hash.TIntIntHashMap;
 import gnu.trove.procedure.TIntIntProcedure;
@@ -53,6 +54,8 @@ import gnu.trove.set.hash.TIntHashSet;
 
 public class DebugSupportImpl implements DebugSupport {
 
+    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DebugSupportImpl.class);
+
        final private Map<String, Function2<WriteGraph, String, Object>> getCommands = new HashMap<String, Function2<WriteGraph, String, Object>>();
        final private Map<String, Function3<WriteGraph, File, String, String>> listCommands = new HashMap<String, Function3<WriteGraph, File, String, String>>();
        final private Map<String, Function2<WriteGraph, String, String>> execCommands = new HashMap<String, Function2<WriteGraph, String, String>>();
@@ -106,6 +109,21 @@ public class DebugSupportImpl implements DebugSupport {
 
                });
 
+        listCommands.put("queryData", new FunctionImpl3<WriteGraph, File, String, String>() {
+
+            @Override
+            public String apply(WriteGraph graph, File file, String args) {
+                try {
+                    getSession(graph).queryProvider2.save();
+                    return "Saved queries";
+                } catch (IOException e) {
+                    LOGGER.error("Error while saving queries", e);
+                    return e.getMessage();
+                }
+            }
+
+        });
+
                listCommands.put("queryActivity", new FunctionImpl3<WriteGraph, File, String, String>() {
 
                        @Override
index 8b26442d87ff6c70a6e37e4a8dfa980d9f342e2b..02daf860e7945fcb27345d264a4a36026373642a 100644 (file)
@@ -214,5 +214,5 @@ final class ObjectResourceMap<T> implements Map<T, Resource>, ObjectResourceIdMa
        public int getId(T t) {
                return backend.get(t);
        }
-
+       
 }
\ No newline at end of file
index eea97e2e0a673c0050cf0f14f6aa1d2c99494719..0febcea1b87b2781c3c5461a2adb051d929e42a9 100644 (file)
@@ -5,6 +5,7 @@ import java.io.InputStream;
 import java.util.Collection;
 import java.util.function.Consumer;
 
+import org.simantics.db.ObjectResourceIdMap;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.Statement;
@@ -83,7 +84,17 @@ public class QuerySupportImpl implements QuerySupport {
        public ResourceSupport getSupport() {
                return resourceSupport;
        }
-       
+
+    @Override
+    public ClusterSupport getClusterSupport() {
+        return clusterSupport;
+    }
+
+    @Override
+    public ObjectResourceIdMap<String> createChildMap() {
+        return new ObjectResourceMap<String>(session);
+    }
+
     @Override
     public Statement getStatement(int s, int p, int o) {
         return getStatement(null, s, p, o);
index 0178e805fd29d09b99cce3ecc5ff7d8a4b3e8fec..2b7f2da3358778d90495a7a20b59b12f69ed9ed3 100644 (file)
@@ -93,6 +93,9 @@ final public class SessionImplDb extends SessionImplSocket {
             serviceLocator.registerService(QuerySupport.class, querySupport);
 
             queryProvider2 = new QueryProcessor(getAmountOfQueryThreads(), querySupport, sessionThreads);
+            
+            if("true".equals(System.getProperty("org.simantics.db.persistQueries")))
+                queryProvider2.restore();
 
             writeSupport = new WriteSupportImpl(this);
             serviceLocator.registerService(WriteSupport.class, writeSupport);
index 05870668616b258e648634e5ac4383a88f8277f1..7a9be048055fdcff23e9831a2882917d2d5ede6d 100644 (file)
@@ -1,5 +1,7 @@
 package fi.vtt.simantics.procore.internal;
 
+import java.io.IOException;
+
 import org.simantics.db.Database;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
@@ -175,5 +177,14 @@ public class XSupportImpl implements XSupport {
                ClusterImpl clusterImpl = session.clusterTable.getClusterByClusterUIDOrMakeProxy(clusterUID);
                return clusterImpl.isLoaded();
        }
-       
+
+    @Override
+    public void saveQueries() throws DatabaseException {
+        try {
+            session.queryProvider2.save();
+        } catch (IOException e) {
+            throw new DatabaseException(e);
+        }
+    }
+
 }
index 7e9cf890ef707031d8534ae0eb28bd6108eba1a1..bd2c64b3193596f5613b1659f197528469bd5304 100644 (file)
@@ -11,8 +11,6 @@ Bundle-RequiredExecutionEnvironment: JavaSE-11
 Import-Package: gnu.trove.impl.hash,
  gnu.trove.iterator,
  gnu.trove.map.hash,
- org.apache.log4j,
- org.apache.log4j.spi,
  org.eclipse.core.runtime,
  org.osgi.framework;version="1.3.0",
  org.simantics.db,
index fb4c4820a43442dd97c8d7d545e109abfb74e78c..168816ed992852c5f5e561f84f7790e5b461b649 100644 (file)
@@ -11,8 +11,6 @@
  *******************************************************************************/
 package org.simantics.db;
 
-
-
 final public class RelationInfo {
     
     public static final RelationInfo[] NONE = new RelationInfo[0];
@@ -27,7 +25,7 @@ final public class RelationInfo {
         this.isFinal = isFinal;
         this.isAsserted = isAsserted;
     }
-    
+
     @Override
     public String toString() {
        return "RelationInfo[predicate=" + predicate + ", isFunctional=" + isFunctional + ", isFinal=" + isFinal + ", isAsserted=" + isAsserted + "]";
index cf9e96e7833421fb7617cc9ebeaef422a9dd3947..bab69074e6ca1cd30dc5fdb613dad21cfb67cf0c 100644 (file)
@@ -162,5 +162,7 @@ public interface XSupport {
     public boolean rolledback();
     
     public boolean isClusterLoaded(ClusterUID clusterUID) throws DatabaseException;
-    
+
+    public void saveQueries() throws DatabaseException;
+
 }
index 7a23274c4028d377c5a216d7e01a55bb8fca54d4..0542beb1dad91186e0b646997d3e2a7e9ba4d6c6 100644 (file)
@@ -1,6 +1,6 @@
 import "Simantics/DB"
 
-importJava "org.simantics.debug.graphical.DebuggerCanvas" where
+importJava "org.simantics.debug.graphical.DebuggerCanvasProxy" where
     data GraphDebugger
 
     setStatementFilter :: GraphDebugger -> (Statement -> <ReadGraph,Proc> Boolean) -> <Proc> ()
diff --git a/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/DebuggerCanvasProxy.java b/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/DebuggerCanvasProxy.java
new file mode 100644 (file)
index 0000000..bf7a738
--- /dev/null
@@ -0,0 +1,32 @@
+package org.simantics.debug.graphical;
+
+import org.simantics.db.Resource;
+import org.simantics.scl.runtime.function.Function;
+
+/**
+ * <code>Simantics/GraphicalDebugger</code> SCL API to avoid undesired AWT
+ * toolkit initialization.
+ * 
+ * @author Tuukka Lehtonen
+ */
+public class DebuggerCanvasProxy {
+
+    DebuggerCanvas canvas;
+
+    public void setStatementFilter(@SuppressWarnings("rawtypes") Function statementFilter) {
+        canvas.setStatementFilter(statementFilter);
+    }
+
+    public void removeStatementFilter() {
+        canvas.removeStatementFilter();
+    }
+
+    public void addResource(Resource resource) {
+        canvas.addResource(resource);
+    }
+
+    public DebuggerCanvasProxy(DebuggerCanvas canvas) {
+        this.canvas = canvas;
+    }
+
+}
index 9091a27f98d6367d340b1927e111ee393a93703c..81844e4aeb82f4310b4409eef9591ffad012b4a9 100644 (file)
@@ -11,7 +11,7 @@ import javax.swing.JFrame;
 
 public class GraphicalDebugger {
 
-    public static DebuggerCanvas newGraphDebugger() {
+    public static DebuggerCanvasProxy newGraphDebugger() {
         final JFrame frame = new JFrame();
         frame.setTitle("Graph debugger");
         Toolkit tk = Toolkit.getDefaultToolkit();
@@ -53,7 +53,7 @@ public class GraphicalDebugger {
         });        
         frame.setVisible(true);
         
-        return canvas;
+        return new DebuggerCanvasProxy(canvas);
     }
     
 }
index 2011bfa28f153afec115d4c8b3aab2baf9a1dde9..225c4abfe890ecb5250e724777fb5f2dc4659c97 100644 (file)
@@ -113,10 +113,17 @@ public class RouteLine implements RouteNode, Serializable {
             out.print("    HOR");
         else
             out.print("    VER");
+        if (hidden)
+            out.print(" HIDDEN");
+        out.print(" @ " + position);
         for(RoutePoint point : points) {
             out.print(" ("+point.x+","+point.y+")");
         }
         out.print(" (data=" + data + ")");
+        if (nextTransient != null)
+            out.print(" (next transient line=" + nextTransient.getData() + ")");
+        if (terminal != null)
+            out.print(" (terminal=" + terminal.getData() + ")");
         out.println();
     }
 
index b283cb4ed283e3cacda7abbff892a72cf3585f8b..4e4280c0aab746d3d3ea9afdb82d0a2db6f1340c 100644 (file)
@@ -28,4 +28,9 @@ public class Segment {
     public boolean isDegenerated() {
         return p1.getX() == p2.getX() && p1.getY() == p2.getY();
     }
+
+    @Override
+    public String toString() {
+        return String.format("(%f, %f) (%f, %f)", p1.getX(), p1.getY(), p2.getX(), p2.getY());
+    }
 }
index ae79dc019b3cb320f883315599a20952e2fb420d..8f7f71a299f08f5b08a51cf1adc29db72b623c03 100644 (file)
@@ -1,13 +1,17 @@
 package org.simantics.diagram.connection.splitting;
 
-import gnu.trove.set.hash.THashSet;
-
+import java.awt.geom.Line2D;
 import java.awt.geom.Point2D;
+import java.util.ArrayList;
 
 import org.simantics.diagram.connection.RouteGraph;
 import org.simantics.diagram.connection.RouteLine;
 import org.simantics.diagram.connection.RouteNode;
+import org.simantics.diagram.connection.RoutePoint;
 import org.simantics.diagram.connection.RouteTerminal;
+import org.simantics.diagram.connection.segments.Segment;
+
+import gnu.trove.set.hash.THashSet;
 
 public class SplittedRouteGraph {
     public final RouteLine splitLine;
@@ -91,7 +95,75 @@ public class SplittedRouteGraph {
         }
     }
 
-    /**
+    public static final class PickResult {
+        /**
+         * The connection route line nearest to {@link #pickPoint}.
+         */
+        public final RouteLine nearestLine;
+        /**
+         * Original pick point in canvas coordinates.
+         */
+        public final Point2D pickPoint;
+        /**
+         * Intersection point in canvas coordinates of {@link #nearestLine} and
+         * perpendicular line from {@link #pickPoint} to {@link #nearestLine}.
+         */
+        public final Point2D intersectionPoint;
+
+        public PickResult(RouteLine nearestLine, Point2D pickPoint, Point2D intersectionPoint) {
+            this.nearestLine = nearestLine;
+            this.pickPoint = pickPoint;
+            this.intersectionPoint = intersectionPoint;
+        }
+    }
+
+    public static PickResult pickNearestLine(RouteGraph rg, double x, double y) {
+        Segment nearestSegment = null;
+        RouteLine nearestLine = null;
+
+        ArrayList<Segment> segments = new ArrayList<>();
+        double minDistanceSq = Double.MAX_VALUE;
+        for (RouteLine line : rg.getAllLines()) {
+            segments.clear();
+            line.collectSegments(segments);
+            for (Segment segment : segments) {
+                RoutePoint p1 = segment.p1;
+                RoutePoint p2 = segment.p2;
+                double distanceSq = Line2D.ptSegDistSq(p1.getX(), p1.getY(), p2.getX(), p2.getY(), x, y);
+                if (distanceSq < minDistanceSq) {
+                    minDistanceSq = distanceSq;
+                    nearestSegment = segment;
+                    nearestLine = line;
+                }
+            }
+        }
+
+        if (nearestSegment == null)
+            return null;
+
+        RoutePoint p1 = nearestSegment.p1;
+        RoutePoint p2 = nearestSegment.p2;
+        Point2D p = pointToLineIntersection(p1.getX(), p1.getY(), p2.getX(), p2.getY(), x, y);
+        return new PickResult(nearestLine, new Point2D.Double(x, y), p);
+    }
+
+    private static Point2D pointToLineIntersection(double x1, double y1, double x2, double y2, double px, double py) {
+        double d = Math.pow(x2 - x1, 2.0) + Math.pow(y2 - y1, 2.0);
+        if (d == 0) {
+            return new Point2D.Double(x1, y1);
+        } else {
+            double u = ((px - x1) * (x2 - x1) + (py - y1) * (y2 - y1)) / d;
+            if (u > 1.0) {
+                return new Point2D.Double(x2, y2);
+            } else if (u <= 0.0) {
+                return new Point2D.Double(x1, y1);
+            } else {
+                return new Point2D.Double(x2 * u + x1 * (1.0-u), (y2 * u + y1 * (1.0- u)));
+            }
+        }
+    }
+
+       /**
      * @param point
      * @param line
      * @return the specified point instance snapped to the specified line
index ffc1fac85cd2731b6ed9a9b69b4a75ee418ee41f..60816536a7b56bbf434fb26dfac684e10b49afd7 100644 (file)
@@ -14,7 +14,8 @@ Require-Bundle: org.simantics.browsing.ui.swt;bundle-version="1.1.0",
  org.simantics.views.swt;bundle-version="1.0.0",
  org.simantics.views.swt.client;bundle-version="1.0.0",
  org.simantics.views.ontology;bundle-version="1.0.0",
- org.simantics.selectionview;bundle-version="1.0.0"
+ org.simantics.selectionview;bundle-version="1.0.0",
+ org.slf4j.api
 Import-Package: org.simantics.views
 Bundle-Vendor: Semantum Oy
 Export-Package: org.simantics.diagram.profile.request
index 58cd82b0e8e2156a034e6a5d83488730cfc0fb30..cbe77333fff0e439fc6e20fed11528050c8e0bb3 100644 (file)
@@ -7,13 +7,16 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.diagram.Logger;
 import org.simantics.diagram.stubs.DiagramResource;
 import org.simantics.layer0.Layer0;
 import org.simantics.operation.Layer0X;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class CreateGroupAction extends ModelledActionImpl<Resource> {
 
+       private static final Logger LOGGER = LoggerFactory.getLogger(CreateGroupAction.class);
+       
        public CreateGroupAction(Resource configuration) {
                super(configuration);
        }
@@ -49,9 +52,7 @@ public class CreateGroupAction extends ModelledActionImpl<Resource> {
                        });
                
                } catch (DatabaseException e) {
-
-                       Logger.defaultLogError(e);
-                       
+                       LOGGER.error("CreateGroupAction failed", e);
                }
 
        }
index 656159abf3cc948e36ba8f326b9268cd6f9045a6..c0fdb11e38cf11b0c53bdd51d423f0829fdd9078 100644 (file)
@@ -8,12 +8,15 @@ import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.common.utils.OrderedSetUtils;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.diagram.Logger;
 import org.simantics.diagram.stubs.DiagramResource;
 import org.simantics.layer0.Layer0;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class CreateProfileAction extends ModelledActionImpl<Resource> {
 
+       private static final Logger LOGGER = LoggerFactory.getLogger(CreateProfileAction.class);
+
        public CreateProfileAction(Resource configuration) {
                super(configuration);
        }
@@ -51,9 +54,7 @@ public class CreateProfileAction extends ModelledActionImpl<Resource> {
                        });
                
                } catch (DatabaseException e) {
-
-                       Logger.defaultLogError(e);
-                       
+                       LOGGER.error("CreateProfileAction failed", e);
                }
 
        }
index de0734156f63057f3f6d82806c5b98c8fd23a16d..6cda70f2dbf9353bee42cdf525f762cbbf586e21 100644 (file)
@@ -7,13 +7,16 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.diagram.Logger;
 import org.simantics.diagram.stubs.DiagramResource;
 import org.simantics.layer0.Layer0;
 import org.simantics.operation.Layer0X;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class CreateStyleAction extends ModelledActionImpl<Resource> {
 
+       private static final Logger LOGGER = LoggerFactory.getLogger(CreateStyleAction.class);
+
        public CreateStyleAction(Resource configuration) {
                super(configuration);
        }
@@ -49,9 +52,7 @@ public class CreateStyleAction extends ModelledActionImpl<Resource> {
                        });
                
                } catch (DatabaseException e) {
-
-                       Logger.defaultLogError(e);
-                       
+                       LOGGER.error("CreateStyleAction failed", e);
                }
 
        }
index 56776f8341dc8e43b2ff7a4892bfd86e99e9cc59..92e4d84aec581a7118d112a85475a7fbaa314705 100644 (file)
@@ -18,7 +18,6 @@ Require-Bundle: org.simantics.utils.thread.swt,
  org.simantics.diagram.ontology;bundle-version="1.0.0";visibility:=reexport,
  org.simantics.structural.ontology;bundle-version="1.0.0",
  org.simantics.layer0.utils;bundle-version="[1.0.0,2.0.0)",
- org.apache.log4j;bundle-version="1.2.15",
  org.simantics.threadlog;bundle-version="1.0.0";resolution:=optional,
  org.simantics.graph;bundle-version="1.1.5",
  org.simantics.graph.db;bundle-version="1.1.5",
diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/LogManager.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/LogManager.java
deleted file mode 100644 (file)
index a4e1eab..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
- * in Industry THTH ry.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     VTT Technical Research Centre of Finland - initial API and implementation
- *******************************************************************************/
-package org.simantics.diagram;
-
-import java.util.Properties;
-
-import org.apache.log4j.Hierarchy;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PropertyConfigurator;
-import org.apache.log4j.spi.LoggerFactory;
-import org.apache.log4j.spi.RootLogger;
-
-/**
- * This class encapsulates a Log4J Hierarchy and centralizes all Logger access.
- */
-public class LogManager {
-
-    private Hierarchy hierarchy;
-
-    /**
-     * Creates a new LogManager. Saves the log and state location.
-     * Creates a new Hierarchy and add a new EventListener to it.
-     * Configure the hierarchy with the properties passed. Add this object to
-     * the list of active log managers.
-     * 
-     * @param properties log configuration properties
-     */
-    public LogManager(Properties properties) {
-        this.hierarchy = new Hierarchy(new RootLogger(Level.DEBUG));
-        new PropertyConfigurator().doConfigure(properties, this.hierarchy);
-    }
-
-    /**
-     * Checks if this PluginLogManager is disabled for this level.
-     * 
-     * @param level level value
-     * @return boolean true if it is disabled
-     */
-    public boolean isDisabled(int level) {
-        return this.hierarchy.isDisabled(level);
-    }
-
-    /**
-     * Enable logging for logging requests with level l or higher. By default
-     * all levels are enabled.
-     * 
-     * @param level level object
-     */
-    public void setThreshold(Level level) {
-        this.hierarchy.setThreshold(level);
-    }
-
-    /**
-     * The string version of setThreshold(Level level)
-     * 
-     * @param level level string
-     */
-    public void setThreshold(String level) {
-        this.hierarchy.setThreshold(level);
-    }
-
-    /**
-     * Get the repository-wide threshold.
-     * 
-     * @return Level
-     */
-    public Level getThreshold() {
-        return this.hierarchy.getThreshold();
-    }
-
-    /**
-     * Returns a new logger instance named as the first parameter using the
-     * default factory. If a logger of that name already exists, then it will be
-     * returned. Otherwise, a new logger will be instantiated and then linked
-     * with its existing ancestors as well as children.
-     * 
-     * @param clazz the class to get the logger for
-     * @return Logger
-     */
-    public Logger getLogger(Class<?> clazz) {
-        return this.hierarchy.getLogger(clazz.getName());
-    }
-
-    /**
-     * Returns a new logger instance named as the first parameter using the
-     * default factory. If a logger of that name already exists, then it will be
-     * returned. Otherwise, a new logger will be instantiated and then linked
-     * with its existing ancestors as well as children.
-     * 
-     * @param name logger name
-     * @return Logger
-     */
-    public Logger getLogger(String name) {
-        return this.hierarchy.getLogger(name);
-    }
-
-    /**
-     * The same as getLogger(String name) but using a factory instance instead
-     * of a default factory.
-     * 
-     * @param name logger name
-     * @param factory factory instance
-     * @return Logger
-     */
-    public Logger getLogger(String name, LoggerFactory factory) {
-        return this.hierarchy.getLogger(name, factory);
-    }
-
-    /**
-     * Returns the root of this hierarchy.
-     * 
-     * @return Logger
-     */
-    public Logger getRootLogger() {
-        return this.hierarchy.getRootLogger();
-    }
-
-    /**
-     * Checks if this logger exists.
-     * 
-     * @return Logger
-     */
-    public Logger exists(String name) {
-        return this.hierarchy.exists(name);
-    }
-
-    /**
-     * Disposes the logger hierarchy
-     */
-    public void shutdown() {
-        this.hierarchy.shutdown();
-    }
-
-    /**
-     * Resets configuration values to its defaults.
-     */
-    public void resetConfiguration() {
-        this.hierarchy.resetConfiguration();
-    }
-
-}
\ No newline at end of file
diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/Logger.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/Logger.java
deleted file mode 100644 (file)
index ad93cb8..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
- * in Industry THTH ry.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     VTT Technical Research Centre of Finland - initial API and implementation
- *******************************************************************************/
-package org.simantics.diagram;
-
-import java.util.Properties;
-
-public class Logger {
-    public static final boolean ECHO = false;
-    public static final Properties defaultProperties = new Properties();
-    static {
-        defaultProperties.put("log4j.rootCategory", "ERROR, default");
-        defaultProperties.put("log4j.appender.default", "org.apache.log4j.FileAppender");
-        defaultProperties.put("log4j.appender.default.File", "diagram.log");
-        defaultProperties.put("log4j.appender.default.append", "false");
-        defaultProperties.put("log4j.appender.default.layout", "org.apache.log4j.PatternLayout");
-        defaultProperties.put("log4j.appender.default.layout.ConversionPattern", "%-6r [%15.15t] %-5p %30.30c - %m%n");
-    }
-    private static LogManager defaultLogManager = new LogManager(defaultProperties);
-    private static final Logger defaultErrorLogger = new Logger(LogManager.class);
-    private org.apache.log4j.Logger logger;
-    Logger(Class<?> clazz) {
-       logger = defaultLogManager.getLogger(clazz);
-    }
-
-    /**
-     * Log a trace event.
-     * 
-     * @param message message of the trace
-     * @param exception the exception, or <code>null</code>
-     */
-    public void logTrace(String message, Throwable exception) {
-        // Errors are much more useful with a stack trace!
-        if (exception == null) {
-            exception = new RuntimeException();
-        }
-        logger.trace(message, exception);
-    }
-
-    /**
-     * Log an info event.
-     * 
-     * @param message message of the info
-     * @param exception the exception, or <code>null</code>
-     */
-    public void logInfo(String message, Throwable exception) {
-        // Errors are much more useful with a stack trace!
-        if (exception == null) {
-            exception = new RuntimeException();
-        }
-        logger.info(message, exception);
-    }
-
-    /**
-     * Log an error event.
-     * 
-     * @param message message of the error
-     * @param exception the exception, or <code>null</code>
-     */
-    public void logError(String message, Throwable exception) {
-        // Errors are much more useful with a stack trace!
-        if (exception == null) {
-            exception = new RuntimeException();
-        }
-        logger.error(message, exception);
-    }
-
-    public static Logger getDefault() {
-        return defaultErrorLogger;
-    }
-    
-    public static LogManager getDefaultLogManager() {
-        return defaultLogManager;
-    }
-    public static void defaultLogError(Throwable exception) {
-        getDefault().logError(exception.getLocalizedMessage(), exception);
-        if(ECHO) exception.printStackTrace();
-    }
-    public static void defaultLogError(String message) {
-        getDefault().logError(message, null);
-        if(ECHO)
-            System.err.println(message);
-    }
-    public static void defaultLogError(String message, Throwable exception) {
-        getDefault().logError(message, exception);
-        if(ECHO)
-            System.err.println(message);
-    }
-    public static void defaultLogInfo(String message) {
-        getDefault().logInfo(message, null);
-        if(ECHO)
-            System.err.println(message);
-    }
-    public static void defaultLogTrace(String message) {
-        getDefault().logTrace(message, null);
-        if(ECHO)
-            System.err.println(message);
-    }
-}
index 23cb9f970f36acd3761e1ee009b3375250125b6d..25e72d984b81a277a7eda60dc1cf0ca656dae37a 100644 (file)
@@ -183,8 +183,14 @@ public class ExportDiagramPdf implements ExportClass {
                 ThreadUtils.syncExec(workerThread, new Runnable() {
                     @Override
                     public void run() {
-                               try {                                                                   
+                               try {
                                        cctx.getDefaultHintContext().setHint(Hints.KEY_PAGE_DESC, _marginaaliViiva);
+                            if (!fitDiagramContentsToPageMargins) {
+                                // Prevent PDF printing from drawing page borders if the
+                                // print area is fitted directly to the page size.
+                                // This avoids unwanted black half-visible edges.
+                                cctx.getDefaultHintContext().setHint(Hints.KEY_DISPLAY_PAGE, false);
+                            }
                                        
                                        String bottomLabel = diagramName;
                                        if ( drawingTemplate != null && activeProfileEntries.contains(TMPL.DrawingTemplate) ) bottomLabel = null;
index d38a301da3c4a9d93dc60c2de926eaa41af5aea7..e53f4b636baf8480888e72bf30b572a93e43364f 100644 (file)
@@ -176,6 +176,17 @@ public final class FlagUtil {
      * @throws DatabaseException
      */
     public static Resource join(WriteGraph g, Resource flag, Resource otherFlag) throws DatabaseException {
+        return join(g, flag, otherFlag, true);
+    }
+
+    /**
+     * @param g
+     * @param flag
+     * @param otherFlag
+     * @return the created DIA.ConnectionJoin instance
+     * @throws DatabaseException
+     */
+    public static Resource join(WriteGraph g, Resource flag, Resource otherFlag, boolean activateDiagramMapping) throws DatabaseException {
         DiagramResource DIA = DiagramResource.getInstance(g);
         StructuralResource2 STR = StructuralResource2.getInstance(g);
         Resource connectionJoin = g.newResource();
@@ -184,14 +195,24 @@ public final class FlagUtil {
         g.claim(connectionJoin, DIA.JoinsFlag, flag);
         g.claim(connectionJoin, DIA.JoinsFlag, otherFlag);
 
-        IActivationManager manager = g.getService(IActivationManager.class);
-        for(Resource diagram : OrderedSetUtils.getSubjects(g, flag))
-            manager.activateOnce(g, diagram);
-        for(Resource diagram : OrderedSetUtils.getSubjects(g, otherFlag))
-            manager.activateOnce(g, diagram);
+        if (activateDiagramMapping) {
+            activateMappingForParentDiagramsOf(g, flag, otherFlag);
+        }
+
         return connectionJoin;
     }
 
+    public static void activateMappingForParentDiagramsOf(WriteGraph graph, Resource... elements) throws DatabaseException {
+        IActivationManager manager = graph.getService(IActivationManager.class);
+        Set<Resource> diagrams = new HashSet<>(elements.length);
+        for (Resource e : elements) {
+            diagrams.addAll(OrderedSetUtils.getSubjects(graph, e));
+        }
+        for (Resource diagram : diagrams) {
+            manager.activateOnce(graph, diagram);
+        }
+    }
+
     public static void disconnectFlag(WriteGraph graph, Resource flag) throws DatabaseException {
         // Remove any :ConnectionJoin's this flag is joined by
         // if there's less than two flags joined by the join.
@@ -531,5 +552,4 @@ public final class FlagUtil {
        return flags;
     }
 
-
-}
+}
\ No newline at end of file
index 3f1076b5df48e70047cd4dae8d9531bd494c9d0d..5c85a99440a9d7efe09b2eaaff2338d56b78291f 100644 (file)
@@ -1,11 +1,10 @@
 package org.simantics.diagram.flag;
 
-import gnu.trove.map.hash.TObjectIntHashMap;
-
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Point2D;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 
 import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;
@@ -24,9 +23,11 @@ import org.simantics.diagram.connection.RouteNode;
 import org.simantics.diagram.connection.RoutePoint;
 import org.simantics.diagram.connection.RouteTerminal;
 import org.simantics.diagram.connection.splitting.SplittedRouteGraph;
+import org.simantics.diagram.connection.splitting.SplittedRouteGraph.PickResult;
 import org.simantics.diagram.content.ConnectionUtil;
 import org.simantics.diagram.stubs.DiagramResource;
 import org.simantics.diagram.synchronization.graph.AddElement;
+import org.simantics.diagram.synchronization.graph.BasicResources;
 import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
 import org.simantics.diagram.synchronization.graph.RouteGraphModification;
 import org.simantics.g2d.elementclass.FlagClass;
@@ -34,6 +35,8 @@ import org.simantics.layer0.Layer0;
 import org.simantics.modeling.ModelingResources;
 import org.simantics.structural.stubs.StructuralResource2;
 
+import gnu.trove.map.hash.TObjectIntHashMap;
+
 /**
  * A class that handles splitting a route graph connection in two with diagram
  * local flags.
@@ -87,34 +90,33 @@ public class RouteGraphConnectionSplitter {
         RouteGraphModification modis = new RouteGraphModification(ss, rg);
         TObjectIntHashMap<RouteNode> idMap = modis.getIdMap();
 
+        if (DEBUG) {
+            System.out.println("Split canvas position: " + splitCanvasPos);
+            rg.print();
+        }
+
         // Find the edge to disconnect in the graph.
         // Bisect the nearest route line.
-        RouteLine line = SplittedRouteGraph.findNearestLine(rg, splitCanvasPos);
-        if (DEBUG)
-            rg.print();
-        if (line == null)
+        PickResult picked = SplittedRouteGraph.pickNearestLine(rg, splitCanvasPos.getX(), splitCanvasPos.getY());
+        if (picked == null)
             return;
+
+        RouteLine line = picked.nearestLine;
+
         if (DEBUG) {
+            System.out.println("picked nearest line:");
             line.print(System.out);
             for (RoutePoint rp : line.getPoints())
                 System.out.println("RP: " + rp.getX() + ", " + rp.getY());
         }
 
         // Get exact intersection point on the line
-        double isectX = splitCanvasPos.getX();
-        double isectY = splitCanvasPos.getY();
-        SplittedRouteGraph srg;
-        if (line.isHorizontal()) {
-            isectY = line.getPosition();
-            srg = rg.splitGraph(line, isectX);
-        }
-        else {
-            isectX = line.getPosition();
-            srg = rg.splitGraph(line, isectY);
-        }
+        double isectX = picked.intersectionPoint.getX();
+        double isectY = picked.intersectionPoint.getY();
+        SplittedRouteGraph srg = rg.splitGraph(line, line.isHorizontal() ? isectX : isectY);
         if (DEBUG)
             System.out.println(srg);
-        
+
         // Disconnect
         if(rg.isSimpleConnection()) {
             RouteNode na = srg.terminals1.iterator().next();
@@ -141,44 +143,106 @@ public class RouteGraphConnectionSplitter {
                     idMap.get(srg.splitLine)
                     ));
         }
-        
-        ArrayList<Resource> interfaceNodes1Resources = new ArrayList<Resource>(srg.interfaceNodes1.size());
-        for(RouteNode n : srg.interfaceNodes1)
-            interfaceNodes1Resources.add(ss.getResource((Long)n.getData()));
-        ArrayList<Resource> interfaceNodes2Resources = new ArrayList<Resource>(srg.interfaceNodes2.size());
-        for(RouteNode n : srg.interfaceNodes2)
-            interfaceNodes2Resources.add(ss.getResource((Long)n.getData()));
-        
-        ArrayList<Resource> lines2Resources = new ArrayList<Resource>(srg.lines2.size());
-        for(RouteLine n : srg.lines2)
-            lines2Resources.add(ss.getResource((Long)n.getData()));
-        
-        ArrayList<Resource> terminals1Resources = new ArrayList<Resource>(srg.terminals1.size());
-        for(RouteTerminal n : srg.terminals1)
-            terminals1Resources.add(ss.getResource((Long)n.getData()));
-        ArrayList<Resource> terminals2Resources = new ArrayList<Resource>(srg.terminals2.size());
-        for(RouteTerminal n : srg.terminals2)
-            terminals2Resources.add(ss.getResource((Long)n.getData()));
+        ArrayList<Resource> terminals1Resources = toResources(srg.terminals1);
+        ArrayList<Resource> terminals2Resources = toResources(srg.terminals2);
+
+        boolean mustFlip = analyzePartInputs(graph, terminals1Resources, terminals2Resources);
+
+        ArrayList<Resource> interfaceNodes1 = toResources(mustFlip ? srg.interfaceNodes2 : srg.interfaceNodes1);
+        ArrayList<Resource> interfaceNodes2 = toResources(mustFlip ? srg.interfaceNodes1 : srg.interfaceNodes2);
+
+        ArrayList<Resource> lines2 = toResources(mustFlip ? srg.lines1 : srg.lines2);
+        ArrayList<Resource> terminals1 = mustFlip ? terminals2Resources : terminals1Resources;
+        ArrayList<Resource> terminals2 = mustFlip ? terminals1Resources : terminals2Resources;
+
         doSplit(graph, connection,
-                interfaceNodes1Resources,
-                interfaceNodes2Resources,
-                lines2Resources,
-                terminals1Resources,
-                terminals2Resources,
+                interfaceNodes1,
+                interfaceNodes2,
+                lines2,
+                terminals1,
+                terminals2,
                 line.isHorizontal(),
+                mustFlip,
                 isectX, isectY);
         modis.addModi(new RouteGraphModification.Split(
-                modis.toIds(interfaceNodes1Resources),
-                modis.toIds(interfaceNodes2Resources),
-                modis.toIds(lines2Resources),
-                modis.toIds(terminals1Resources),
-                modis.toIds(terminals2Resources),
+                modis.toIds(interfaceNodes1),
+                modis.toIds(interfaceNodes2),
+                modis.toIds(lines2),
+                modis.toIds(terminals1),
+                modis.toIds(terminals2),
                 line.isHorizontal(),
+                mustFlip,
                 isectX, isectY
                 ));
-        
     }
-    
+
+    private ArrayList<Resource> toResources(Collection<? extends RouteNode> nodes) throws DatabaseException {
+        ArrayList<Resource> result = new ArrayList<>(nodes.size());
+        for (RouteNode n : nodes)
+            result.add(ss.getResource((Long)n.getData()));
+        return result;
+    }
+
+    /**
+     * @param graph
+     * @param terminals1
+     * @param terminals2
+     * @return <code>true</code> if inputs need to be flipped, i.e. if terminals2
+     *         contains the output terminals and terminals1 doesn't.
+     * @throws DatabaseException
+     */
+    private boolean analyzePartInputs(ReadGraph graph, List<Resource> terminals1, List<Resource> terminals2) throws DatabaseException {
+        @SuppressWarnings("unused")
+        int inputs1 = 0, outputs1 = 0;
+        for(Resource connector : terminals1) {
+            if(graph.hasStatement(connector, DIA.IsHeadConnectorOf))
+                ++inputs1;
+            else
+                ++outputs1;
+        }
+        @SuppressWarnings("unused")
+        int inputs2 = 0, outputs2 = 0;
+        for(Resource connector : terminals2) {
+            if(graph.hasStatement(connector, DIA.IsHeadConnectorOf))
+                ++inputs2;
+            else
+                ++outputs2;
+        }
+
+        boolean mustFlip = outputs1 == 0;
+
+        if (DEBUG) {
+            System.out.println("inputs1:  " + inputs1);
+            System.out.println("outputs1: " + outputs1);
+            System.out.println("inputs2:  " + inputs2);
+            System.out.println("outputs2: " + outputs2);
+            System.out.println("=> type1:  " + (mustFlip ? FlagClass.Type.In : FlagClass.Type.Out));
+            System.out.println("=> type2:  " + (mustFlip ? FlagClass.Type.Out : FlagClass.Type.In));
+            System.out.println("=> must flip route graph parts to split: " + mustFlip);
+        }
+
+        return mustFlip;
+    }
+
+    private static String routeNodeDebugInfo(ReadGraph graph, Resource c) throws DatabaseException {
+        BasicResources BR = BasicResources.getInstance(graph);
+        String ctr = NameUtils.getSafeName(graph, c, true);
+        for (Resource e : graph.getObjects(c, BR.STR.Connects)) {
+            ctr += " --> " + NameUtils.getSafeName(graph, e);
+        }
+        for (Resource e : graph.getObjects(c, BR.DIA.AreConnected)) {
+            ctr += " <-> " + NameUtils.getSafeName(graph, e);
+        }
+        return ctr;
+    }
+
+    /**
+     * Internal routine that is only public because
+     * {@link RouteGraphModification#runUpdates(WriteGraph)} needs to invoke it.
+     * 
+     * Assumes that #1 parameters will stay with the existing connection and #2
+     * parameters will go to the newly created connection.
+     */
     public void doSplit(WriteGraph graph, 
             Resource connection,
             ArrayList<Resource> interfaceNodes1Resources,
@@ -186,22 +250,28 @@ public class RouteGraphConnectionSplitter {
             ArrayList<Resource> lines2Resources,
             ArrayList<Resource> terminals1Resources,
             ArrayList<Resource> terminals2Resources,
-            boolean isHorizontal, 
+            boolean isHorizontal,
+            boolean invertFlagRotation,
             double isectX, double isectY) throws DatabaseException {
 
+        // 1 = output, 2 = input
+        FlagClass.Type
+                type1 = FlagClass.Type.Out,
+                type2 = FlagClass.Type.In;
+
         if (DEBUG) {
             System.out.println("doSplit:");
             System.out.println(NameUtils.getSafeName(graph, connection, true));
             for (Resource i : interfaceNodes1Resources)
-                System.out.println("i1: " + NameUtils.getSafeName(graph, i, true));
+                System.out.println("i1: " + routeNodeDebugInfo(graph, i));
             for (Resource i : interfaceNodes2Resources)
-                System.out.println("i2: " + NameUtils.getSafeName(graph, i, true));
+                System.out.println("i2: " + routeNodeDebugInfo(graph, i));
             for (Resource l : lines2Resources)
-                System.out.println("l2r: " + NameUtils.getSafeName(graph, l, true));
+                System.out.println("l2r: " + routeNodeDebugInfo(graph, l));
             for (Resource t : terminals1Resources)
-                System.out.println("t1: " + NameUtils.getSafeName(graph, t, true));
+                System.out.println("t1: " + routeNodeDebugInfo(graph, t));
             for (Resource t : terminals2Resources)
-                System.out.println("t2: " + NameUtils.getSafeName(graph, t, true));
+                System.out.println("t2: " + routeNodeDebugInfo(graph, t));
             System.out.println("is horizontal: " + isHorizontal);
             System.out.println("@(x,y): " + isectX + ", " + isectY);
         }
@@ -209,15 +279,39 @@ public class RouteGraphConnectionSplitter {
         ConnectionUtil cu = new ConnectionUtil(graph);
         Resource diagram = OrderedSetUtils.getSingleOwnerList(graph, connection, DIA.Diagram);
 
-        Resource connectionType = graph.getSingleType(connection, DIA.Connection);
+        Resource diagramConnectionType = graph.getSingleType(connection, DIA.Connection);
         Resource hasConnectionType = graph.getPossibleObject(connection, STR.HasConnectionType);
-        Resource newConnection = cu.newConnection(diagram, connectionType);
+        Resource newConnection = cu.newConnection(diagram, diagramConnectionType);
         if (hasConnectionType != null)
             graph.claim(newConnection, STR.HasConnectionType, null, hasConnectionType);
 
         // Give running name to connection increment the counter attached to the diagram.
         AddElement.claimFreshElementName(graph, diagram, newConnection);
 
+        String commonLabel = DiagramFlagPreferences
+                .getActiveFlagLabelingScheme(graph)
+                .generateLabel(graph, diagram);
+
+        Point2D pos1, pos2;
+        double theta;
+        double flagDist = 3.0;
+        if(isHorizontal) {
+            theta = 0.0;
+            pos1 = new Point2D.Double(isectX-flagDist, isectY);
+            pos2 = new Point2D.Double(isectX+flagDist, isectY);
+        } else {
+            theta = Math.PI*0.5;
+            pos1 = new Point2D.Double(isectX, isectY-flagDist);
+            pos2 = new Point2D.Double(isectX, isectY+flagDist);
+        }
+
+        if (invertFlagRotation) {
+            theta += Math.PI;
+            Point2D p = pos1;
+            pos1 = pos2;
+            pos2 = p;
+        }
+
         // WORKAROUND for mapping problems:
         // If any terminal of the split connection contains a flag, make sure their STR.Joins relations are all removed
         // to give mapping a chance to fix them properly.
@@ -237,97 +331,31 @@ public class RouteGraphConnectionSplitter {
             graph.claim(rn, predicate, newConnection);
         }
 
-        // 1 = output, 2 = input
-        FlagClass.Type type1, type2;
-
-        FlagLabelingScheme scheme = DiagramFlagPreferences.getActiveFlagLabelingScheme(graph);
-        String commonLabel = scheme.generateLabel(graph, diagram);
-
         // Create flags and connect both disconnected ends to them.
-        Point2D pos1, pos2;
-        double theta;
-        double flagDist = 3.0;
-        if(isHorizontal) {
-            theta = 0.0;
-            pos1 = new Point2D.Double(isectX-flagDist, isectY);
-            pos2 = new Point2D.Double(isectX+flagDist, isectY);
-        }
-        else {
-            theta = Math.PI*0.5;
-            pos1 = new Point2D.Double(isectX, isectY-flagDist);
-            pos2 = new Point2D.Double(isectX, isectY+flagDist);
-        }
-
-        // Chooses flag directions
-        {
-            @SuppressWarnings("unused")
-            int inputs1 = 0, outputs1 = 0;
-            for(Resource connector : terminals1Resources) {
-                if(graph.hasStatement(connector, DIA.IsHeadConnectorOf))
-                    ++inputs1;
-                else
-                    ++outputs1;
-            }
-            @SuppressWarnings("unused")
-            int inputs2 = 0, outputs2 = 0;
-            for(Resource connector : terminals2Resources) {
-                if(graph.hasStatement(connector, DIA.IsHeadConnectorOf))
-                    ++inputs2;
-                else
-                    ++outputs2;
-            }
-            
-            if(outputs1 == 0) {
-                type1 = FlagClass.Type.In;
-                type2 = FlagClass.Type.Out;
-                theta += Math.PI;
-            }
-            else {
-                type1 = FlagClass.Type.Out;
-                type2 = FlagClass.Type.In;
-            }
-            if (DEBUG) {
-                System.out.println("inputs1:  " + inputs1);
-                System.out.println("outputs1: " + outputs1);
-                System.out.println("=> type1:  " + type1);
-                System.out.println("inputs2:  " + inputs2);
-                System.out.println("outputs2: " + outputs2);
-                System.out.println("=> type2:  " + type2);
-            }
-        }
         Resource flag1 = createFlag(graph, diagram, getFlagTransform(pos1, theta), type1, commonLabel);
         Resource flag2 = createFlag(graph, diagram, getFlagTransform(pos2, theta), type2, commonLabel);
+
         if (DEBUG) {
+            System.out.println("LABEL FOR NEW FLAGS: " + commonLabel);
             System.out.println("FLAG1: " + NameUtils.getSafeName(graph, flag1, true));
             System.out.println("FLAG2: " + NameUtils.getSafeName(graph, flag2, true));
         }
 
-//        System.out.println("conn1: " + NameUtils.getSafeLabel(graph, type1 == FlagClass.Type.In ? DIA.HasPlainConnector : DIA.HasArrowConnector));
-//        System.out.println("conn2: " + NameUtils.getSafeLabel(graph, type2 == FlagClass.Type.In ? DIA.HasPlainConnector : DIA.HasArrowConnector));
-        Resource flagConnector1 = cu.newConnector(connection, 
-                type1 == FlagClass.Type.In ? DIA.HasPlainConnector : DIA.HasArrowConnector);
-        Resource flagConnector2 = cu.newConnector(newConnection, 
-                type2 == FlagClass.Type.In ? DIA.HasPlainConnector : DIA.HasArrowConnector);
+        Resource flagConnector1 = cu.newConnector(connection, DIA.HasArrowConnector); 
+        Resource flagConnector2 = cu.newConnector(newConnection, DIA.HasPlainConnector);
         graph.claim(flag1, DIA.Flag_ConnectionPoint, flagConnector1);
         graph.claim(flag2, DIA.Flag_ConnectionPoint, flagConnector2);
 
         double position = isHorizontal ? isectY : isectX;
-        connectFlag(graph, isHorizontal, position, connection, flagConnector1, 
-                interfaceNodes1Resources);
-        connectFlag(graph, isHorizontal, position, newConnection, flagConnector2, 
-                interfaceNodes2Resources);
-
-        FlagUtil.join(graph, flag1, flag2);
-
-        // Move mapping relations to new connection if necessary
-        if(type1 == FlagClass.Type.In) {
-            moveStatements(graph, connection, newConnection, MOD.ElementToComponent);
-            moveStatements(graph, connection, newConnection, MOD.DiagramConnectionToConnection);
-            moveStatements(graph, connection, newConnection, MOD.DiagramConnectionToConnectionSpecial);
-            FlagUtil.fixBindsStatements(graph, graph.getPossibleObject(newConnection, MOD.DiagramConnectionToConnection));
-        }
-        else
-            FlagUtil.fixBindsStatements(graph, graph.getPossibleObject(connection, MOD.DiagramConnectionToConnection));
+        connectFlag(graph, isHorizontal, position, connection, flagConnector1, interfaceNodes1Resources);
+        connectFlag(graph, isHorizontal, position, newConnection, flagConnector2, interfaceNodes2Resources);
+
+        // Join the flags without activatingn diagram mapping at this point
+        FlagUtil.join(graph, flag1, flag2, false);
+        FlagUtil.fixBindsStatements(graph, graph.getPossibleObject(connection, MOD.DiagramConnectionToConnection));
+
+        // Finally ensure that all the diagrams related to the operation are mapped properly in one go
+        FlagUtil.activateMappingForParentDiagramsOf(graph, flag1, flag2);
     }
 
     /**
@@ -370,15 +398,6 @@ public class RouteGraphConnectionSplitter {
         }
     }
 
-    private static void moveStatements(WriteGraph graph, Resource from, Resource to, Resource relation) throws DatabaseException {
-       if(from.equals(to))
-               return;
-       for(Statement stat : graph.getStatements(from, relation))
-               if(stat.getSubject().equals(from))
-                       graph.claim(to, stat.getPredicate(), stat.getObject());
-       graph.deny(from, relation);
-    }
-    
     private void connectFlag(WriteGraph graph, boolean isHorizontal, double position, Resource connection, Resource flagConnector, Collection<Resource> interfaceNodes) 
             throws DatabaseException {
         if(interfaceNodes.size() > 1) {
@@ -421,6 +440,7 @@ public class RouteGraphConnectionSplitter {
     }
 
     public static void splitConnection(WriteGraph graph, Resource connection, double x, double y) throws DatabaseException {
+        // TODO: provide a proper runtimeDiagram parameter to load to support also connections attached to flags attached to diagram template flag tables
         RouteGraph rg = RouteGraphUtils.load(graph, null, connection);
         new RouteGraphConnectionSplitter(graph).split(graph, connection, rg, new Point2D.Double(x, y));
     }
index 6cd4c542f106afe53d4d80a774f4e9ace4e90e28..5bb793f7df39b6147ce72511d48664d9ba94ec95 100644 (file)
@@ -95,6 +95,8 @@ public class All {
 
                Resource flag = context.element;
                Resource runtimeDiagram = context.runtime;
+               if (runtimeDiagram == null)
+                       return flagTransformImpl(graph, converter, context);
 
                Resource diagram = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasConfiguration);
                if (diagram == null)
index 52217c3cfcf2b84a6ddc9795d7d13d3f66af80ba..de10603d3bc078257ddc27fd7c0b390915f9baa4 100644 (file)
@@ -44,7 +44,6 @@ import org.simantics.db.layer0.util.SimanticsKeys;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
 import org.simantics.db.request.Read;
-import org.simantics.diagram.Logger;
 import org.simantics.diagram.content.Change;
 import org.simantics.diagram.content.ConnectionUtil;
 import org.simantics.diagram.content.DiagramContentChanges;
@@ -114,6 +113,8 @@ import org.simantics.utils.threads.SWTThread;
 import org.simantics.utils.threads.ThreadUtils;
 import org.simantics.utils.ui.ErrorLogger;
 import org.simantics.utils.ui.SWTUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * CopyPasteHandler is a canvas handler for Commands.CUT, Commands.COPY and
@@ -141,6 +142,8 @@ import org.simantics.utils.ui.SWTUtils;
  */
 public class CopyPasteHandler extends AbstractDiagramParticipant {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(CopyPasteHandler.class);
+
     public static final Key KEY_CUT_SELECTION_FRAME_COLOR      = new KeyOf(Color.class, "CUT_SELECTION_FRAME_COLOR");
     public static final Key KEY_CUT_SELECTION_CONTENT_COLOR    = new KeyOf(Color.class, "CUT_SELECTION_CONTENT_COLOR");
     public static final Key KEY_COPIED_SELECTION_FRAME_COLOR   = new KeyOf(Color.class, "COPY_SELECTION_FRAME_COLOR");
@@ -1294,7 +1297,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant {
                     });
                 }
             } catch (DatabaseException e1) {
-               Logger.defaultLogError(e1);
+                LOGGER.error("Monitor paste failed", e1);
             }
         }
         return true;
index 76149412702b67c364b3e81e302f934ab6b2274c..7f709c70993eb62839ed8d0a283cbdfd8f54e9ad 100644 (file)
@@ -44,7 +44,6 @@ import org.simantics.db.layer0.util.SimanticsKeys;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
 import org.simantics.db.request.Read;
-import org.simantics.diagram.Logger;
 import org.simantics.diagram.content.Change;
 import org.simantics.diagram.content.ConnectionUtil;
 import org.simantics.diagram.content.DiagramContentChanges;
@@ -125,6 +124,8 @@ import org.simantics.utils.threads.SWTThread;
 import org.simantics.utils.threads.ThreadUtils;
 import org.simantics.utils.ui.ErrorLogger;
 import org.simantics.utils.ui.SWTUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * CopyPasteHandler is a canvas handler for Commands.CUT, Commands.COPY and
@@ -152,6 +153,8 @@ import org.simantics.utils.ui.SWTUtils;
  */
 public class CopyPasteHandler extends AbstractDiagramParticipant {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(CopyPasteHandler.class);
+
     public static final Key KEY_CUT_SELECTION_FRAME_COLOR      = new KeyOf(Color.class, "CUT_SELECTION_FRAME_COLOR");
     public static final Key KEY_CUT_SELECTION_CONTENT_COLOR    = new KeyOf(Color.class, "CUT_SELECTION_CONTENT_COLOR");
     public static final Key KEY_COPIED_SELECTION_FRAME_COLOR   = new KeyOf(Color.class, "COPY_SELECTION_FRAME_COLOR");
@@ -1291,7 +1294,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant {
                     });
                 }
             } catch (DatabaseException e1) {
-               Logger.defaultLogError(e1);
+                LOGGER.error("Monitor paste failed", e1);
             }
         }
         return true;
index 3e1140a07f358b3fbef42905254677d99bed65aa..0731bd90d7f3c542797e6c4f590e77d27324ba92 100644 (file)
@@ -24,10 +24,8 @@ import java.util.List;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.simantics.db.Session;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.diagram.Logger;
 import org.simantics.diagram.adapter.GraphToDiagramSynchronizer;
 import org.simantics.g2d.diagram.DiagramHints;
-import org.simantics.g2d.diagram.DiagramMutator;
 import org.simantics.g2d.diagram.DiagramUtils;
 import org.simantics.g2d.diagram.IDiagram;
 import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant;
@@ -42,11 +40,14 @@ import org.simantics.g2d.element.IElement;
 import org.simantics.scenegraph.g2d.snap.ISnapAdvisor;
 import org.simantics.ui.dnd.LocalObjectTransfer;
 import org.simantics.ui.dnd.LocalObjectTransferable;
-import org.simantics.utils.datastructures.Callback;
 import org.simantics.utils.logging.TimeLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 abstract public class PopulateSelectionDropParticipant extends AbstractDiagramParticipant implements IDropTargetParticipant {
 
+       private static final Logger LOGGER = LoggerFactory.getLogger(PopulateSelectionDropParticipant.class);
+
        public abstract List<ElementClassDragItem> getElements(Session session, IStructuredSelection selection) throws DatabaseException;
        
        protected GraphToDiagramSynchronizer synchronizer;
@@ -96,12 +97,8 @@ abstract public class PopulateSelectionDropParticipant extends AbstractDiagramPa
 
                                }
 
-                       } catch (UnsupportedFlavorException e) {
-                               Logger.defaultLogError(e);
-                       } catch (IOException e) {
-                               Logger.defaultLogError(e);
-                       } catch (DatabaseException e) {
-                               Logger.defaultLogError(e);
+                       } catch (DatabaseException | IOException | UnsupportedFlavorException e) {
+                               LOGGER.error("Unexpected failure", e);
                        }
 
                }
index af58be479ec1c7bf7ac4687d11ed478e26995155..31c091fd4eed1041e9b869639463f0ec5e4adfbb 100644 (file)
@@ -88,7 +88,6 @@ import org.simantics.diagram.internal.Activator;
 import org.simantics.diagram.symbolcontribution.CompositeSymbolGroup;
 import org.simantics.diagram.symbolcontribution.IIdentifiedObject;
 import org.simantics.diagram.symbolcontribution.ISymbolProvider;
-import org.simantics.diagram.symbolcontribution.IdentifiedObject;
 import org.simantics.diagram.symbolcontribution.SymbolProviderFactory;
 import org.simantics.diagram.symbollibrary.IModifiableSymbolGroup;
 import org.simantics.diagram.symbollibrary.ISymbolGroup;
@@ -1118,24 +1117,22 @@ public class SymbolLibraryComposite extends Composite {
             json.append(" \"res\" : [");
             int pos = 0;
             for(int i=0;i<res.length;i++) {
-               if(pos > 0) json.append(",");
-               Object r = res[i];
-               if(r instanceof IdentifiedObject) {
-                       Object id = ((IdentifiedObject) r).getId();
-                       if(id instanceof IAdaptable) {
-                               Object resource = ((IAdaptable) id).getAdapter(Resource.class);
-                               if(resource != null) {
-                                       long rid = ((Resource)resource).getResourceId();
-                               json.append(Long.toString(rid));
-                               pos++;
-                               }
-                       }
-               }
+                if(pos > 0) json.append(",");
+                Object r = res[i];
+                if(r instanceof IAdaptable) {
+                    Resource resource = ((IAdaptable) r).getAdapter(Resource.class);
+                    if(resource != null) {
+                        long rid = resource.getResourceId();
+                        json.append(Long.toString(rid));
+                        pos++;
+                    }
+                }
             }
             json.append("] }");
             
-            StringSelection text = new StringSelection(json.toString());
-            PlaintextTransfer plainText = new PlaintextTransfer(json.toString()); 
+            String jsonText = json.toString();
+            StringSelection text = new StringSelection(jsonText);
+            PlaintextTransfer plainText = new PlaintextTransfer(jsonText); 
             
             return new MultiTransferable(local, text, plainText);
             
index ab28463e84d5a8e3d3ae81af98b52f990393f167..bbf9a8e5b23d2134f536bacb21cae26d058e815e 100644 (file)
@@ -11,8 +11,6 @@
  *******************************************************************************/
 package org.simantics.diagram.synchronization.graph;
 
-import gnu.trove.map.hash.THashMap;
-
 import java.util.Map;
 import java.util.Set;
 import java.util.function.BiFunction;
@@ -46,6 +44,10 @@ import org.simantics.diagram.synchronization.SynchronizationHints;
 import org.simantics.graph.db.TransferableGraphs;
 import org.simantics.graph.representation.TransferableGraph1;
 import org.simantics.layer0.Layer0;
+import org.simantics.utils.datastructures.BinaryFunction;
+
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
 
 /**
  * This class contains utility methods for the basic cut/copy operations
@@ -82,6 +84,15 @@ public class CopyAdvisorUtil {
 
     public static final boolean DEBUG_COPY = DebugPolicy.DEBUG_COPY_PASTE;
 
+    private static class Statement4 {
+        public final Statement stm;
+        public final Resource inverse;
+        public Statement4(Statement stm, Resource inverse) {
+            this.stm = stm;
+            this.inverse = inverse;
+        }
+    }
+
     /**
      * @param context a synchronization context instance, such as
      *        {@link GraphToDiagramSynchronizer}
@@ -364,8 +375,10 @@ public class CopyAdvisorUtil {
      * @throws DatabaseException
      */
     public static Resource copy2(WriteGraph graph, Resource source,
-            BiFunction<ReadGraph, Statement, StatementEvaluation> advisor) throws DatabaseException {
-        return copy2(graph, source, 0, advisor, new THashMap<Object, Object>());
+            BiFunction<ReadGraph, Statement, StatementEvaluation> advisor)
+                    throws DatabaseException
+    {
+        return copy2(graph, source, advisor, new THashMap<>());
     }
 
     /**
@@ -380,13 +393,52 @@ public class CopyAdvisorUtil {
      * @throws DatabaseException 
      */
     public static Resource copy2(WriteGraph graph, Resource source,
-            BiFunction<ReadGraph, Statement, StatementEvaluation> advisor, Map<Object, Object> copyMap)
-            throws DatabaseException {
-        return copy2(graph, source, 0, advisor, copyMap);
+            BiFunction<ReadGraph, Statement, StatementEvaluation> advisor,
+            Map<Object, Object> copyMap)
+                    throws DatabaseException
+    {
+        Set<Statement4> pendingStatements = new THashSet<>();
+        Resource result = copy2(graph, source, 0, advisor, copyMap, pendingStatements);
+        postProcessStatements(graph, copyMap, pendingStatements);
+        return result;
+    }
+
+    /**
+     * Post-process pending statement
+     *  
+     * Rule: If both the subject and object of a pending source statement have
+     *       been copied, then the pending statement should also be copied.
+     */
+    private static void postProcessStatements(
+            WriteGraph graph,
+            Map<Object, Object> copyMap,
+            Set<Statement4> pendingStatements)
+                    throws DatabaseException
+    {
+        if (pendingStatements.isEmpty())
+            return;
+
+        if (DEBUG_COPY)
+            System.out.println("post processing " + pendingStatements.size() + " pending statements");
+        for (Statement4 srcStm : pendingStatements) {
+            // At this point, it is certain that srcStm subject has been copied
+            // but test it anyway.
+            Resource subjectCopy = (Resource) copyMap.get(srcStm.stm.getSubject());
+            Resource objectCopy = (Resource) copyMap.get(srcStm.stm.getObject());
+            if (subjectCopy == null || objectCopy == null) {
+                if (DEBUG_COPY)
+                    System.out.println("skipping pending statement: " + NameUtils.toString(graph, srcStm.stm));
+                continue;
+            }
+            if (DEBUG_COPY)
+                System.out.println("copying pending statement: " + NameUtils.toString(graph, srcStm.stm));
+            graph.claim(subjectCopy, srcStm.stm.getPredicate(), srcStm.inverse, objectCopy);
+        }
     }
 
     private static Resource copy2(final WriteGraph graph, final Resource source, final int level,
-            BiFunction<ReadGraph, Statement, StatementEvaluation> advisor, Map<Object, Object> copyMap)
+            BiFunction<ReadGraph, Statement, StatementEvaluation> advisor, Map<Object, Object> copyMap,
+            Set<Statement4> pendingSourceStatements)
     throws DatabaseException {
         if (DEBUG_COPY)
             System.out.println("[" + level + "] CopyAdvisorUtil.copy(" + NameUtils.getSafeName(graph, source) + ", advisor=" + advisor + ")");
@@ -497,12 +549,18 @@ public class CopyAdvisorUtil {
                             if (DEBUG_COPY)
                                 System.out.println("[" + level + "]\t\tcopy whole object");
 
-                            Resource clone = copy2(graph, obj, level + 1, advisor, copyMap);
+                            Resource clone = copy2(graph, obj, level + 1, advisor, copyMap, pendingSourceStatements);
                             graph.claim(copy, relation, inverse, clone);
                         }
                     } else {
-                        if (DEBUG_COPY)
-                            System.out.println("[" + level + "]\t\tskipping statement");
+                        if (graph.isSubrelationOf(relation, L0.IsRelatedTo)) {
+                            if (DEBUG_COPY)
+                                System.out.println("[" + level + "]\t\tmarking statement as pending for post-processing");
+                            pendingSourceStatements.add(new Statement4(stm, inverse));
+                        } else {
+                            if (DEBUG_COPY)
+                                System.out.println("[" + level + "]\t\tskipping weak statement");
+                        }
                     }
                 }
             }
index a15b99bc45907eeb319cdc7bc5925c0bb1af95be..41f4c00e621641ce6b46f02f8c7266d08d3b20d4 100644 (file)
@@ -162,12 +162,14 @@ public class RouteGraphModification {
         int[] lines2; 
         int[] terminals1; 
         int[] terminals2;
-        boolean isHorizontal; 
+        boolean isHorizontal;
+        boolean invertFlagRotation;
         double isectX;
         double isectY;
         
         public Split(int[] interface1, int[] interface2, int[] lines2,
                 int[] terminals1, int[] terminals2, boolean isHorizontal,
+                boolean invertFlagRotation,
                 double isectX, double isectY) {
             this.interface1 = interface1;
             this.interface2 = interface2;
@@ -175,6 +177,7 @@ public class RouteGraphModification {
             this.terminals1 = terminals1;
             this.terminals2 = terminals2;
             this.isHorizontal = isHorizontal;
+            this.invertFlagRotation = invertFlagRotation;
             this.isectX = isectX;
             this.isectY = isectY;
         }
@@ -188,6 +191,7 @@ public class RouteGraphModification {
             this.terminals1 = readInts(it);
             this.terminals2 = readInts(it);
             this.isHorizontal = Boolean.parseBoolean(it.next());
+            this.invertFlagRotation = Boolean.parseBoolean(it.next());
             this.isectX = Double.parseDouble(it.next());
             this.isectY = Double.parseDouble(it.next());
         }
@@ -208,6 +212,8 @@ public class RouteGraphModification {
             b.append("$");
             b.append(isHorizontal);
             b.append("$");
+            b.append(invertFlagRotation);
+            b.append("$");
             b.append(isectX);
             b.append("$");
             b.append(isectY);
@@ -531,6 +537,7 @@ public class RouteGraphModification {
                         toResources(modi.terminals1),
                         toResources(modi.terminals2),
                         modi.isHorizontal,
+                        modi.invertFlagRotation,
                         modi.isectX,
                         modi.isectY
                         );
index 8acc2f0d192899316c870cfba8ce27366b93d699..5b76cd344043f10dd05428642bee688c418ed12f 100644 (file)
@@ -1,6 +1,7 @@
 package org.simantics.document.server.request;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashSet;
@@ -10,7 +11,7 @@ import java.util.Set;
 import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
-import org.simantics.db.common.request.AsyncReadRequest;
+import org.simantics.db.common.request.UnaryAsyncRead;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.request.VariableRead;
 import org.simantics.db.layer0.variable.Variable;
@@ -28,49 +29,55 @@ public class DocumentRequest extends VariableRead<List<JSONObject>> {
         super(var);
        }
 
-       @Override
-       public List<JSONObject> perform(ReadGraph graph) throws DatabaseException {
-               
-               long s = System.nanoTime();
-               
-        Set<Variable> nodes = graph.syncRequest(new NodesRequest(variable), TransientCacheAsyncListener.<Set<Variable>>instance());
-        HashSet<JSONObject> rs = new HashSet<JSONObject>(); // result
-        if(nodes.isEmpty()) {
-            return Collections.emptyList();
-        }
+    static class CollectNodesRequest extends UnaryAsyncRead<Collection<Variable>, Collection<JSONObject>> {
 
-        if(PROFILE) {
-            long dura = System.nanoTime()-s;
-            System.err.println("DocumentRequest1 " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));
+        public CollectNodesRequest(Collection<Variable> nodes) {
+            super(nodes);
         }
 
-        graph.syncRequest(new AsyncReadRequest() {
+        @Override
+        public void perform(AsyncReadGraph graph, AsyncProcedure<Collection<JSONObject>> procedure) {
+            HashSet<JSONObject> rs = new HashSet<JSONObject>(); // result
 
-            @Override
-            public void run(AsyncReadGraph graph) throws DatabaseException {
+            for(Variable node : parameter) {
+                graph.asyncRequest(new NodeRequest(node), new AsyncProcedure<JSONObject> () {
 
-                for(Variable node : nodes) {
-                    graph.asyncRequest(new NodeRequest(node), new AsyncProcedure<JSONObject> () {
-
-                        @Override
-                        public void execute(AsyncReadGraph graph, JSONObject result) {
-                            synchronized (rs) {
-                                rs.add(result);
-                            }
+                    @Override
+                    public void execute(AsyncReadGraph graph, JSONObject result) {
+                        synchronized(rs) {
+                            rs.add(result);
                         }
+                    }
 
-                        @Override
-                        public void exception(AsyncReadGraph graph, Throwable throwable) {
-                        }
+                    @Override
+                    public void exception(AsyncReadGraph graph, Throwable throwable) {
+                    }
+
+                });
 
-                    });
-                    
-                }
-                
             }
-            
-        });
+            procedure.execute(graph, rs);
+
+        }
+
+    }
+
+    @Override
+    public List<JSONObject> perform(ReadGraph graph) throws DatabaseException {
+
+        long s = System.nanoTime();
+
+        Set<Variable> nodes = graph.syncRequest(new NodesRequest(variable), TransientCacheAsyncListener.<Set<Variable>>instance());
+        if(nodes.isEmpty()) {
+            return Collections.emptyList();
+        }
+
+        if(PROFILE) {
+            long dura = System.nanoTime()-s;
+            System.err.println("DocumentRequest1 " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));
+        }
 
+        Collection<JSONObject> rs = graph.syncRequest(new CollectNodesRequest(nodes));
 
         if(PROFILE) {
             long dura = System.nanoTime()-s;
index 606b361b62729ef2f5b74cdb8ad7f379a974049c..4c611a9aab043d749f0be7c4158b0fce95a0da76 100644 (file)
@@ -1,19 +1,17 @@
 package org.simantics.document.server.request;
 
 import org.simantics.db.ReadGraph;
+import org.simantics.db.common.request.UnaryRead;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
-import org.simantics.db.request.Read;
 import org.simantics.document.server.handler.AbstractEventHandler;
 import org.simantics.structural.stubs.StructuralResource2;
 
-public class HandleEventRequest implements Read<AbstractEventHandler> {
-
-    final String id;
+public class HandleEventRequest extends UnaryRead<String, AbstractEventHandler> {
 
     public HandleEventRequest(String id) {
-        this.id = id;
+        super(id);
     }
 
     @Override
@@ -21,7 +19,7 @@ public class HandleEventRequest implements Read<AbstractEventHandler> {
 
         StructuralResource2.getInstance(graph);
 
-        Variable variable = Variables.getPossibleVariable(graph, id);
+        Variable variable = Variables.getPossibleVariable(graph, parameter);
         if(variable == null) return null;
 
 //        System.err.println("EVENT " + variable.getURI(graph));
@@ -29,7 +27,7 @@ public class HandleEventRequest implements Read<AbstractEventHandler> {
         if(handler instanceof AbstractEventHandler)
             return (AbstractEventHandler) handler;
         else
-            throw new DatabaseException("Handler for " + id + " is not instance of AbstractEventHandler (it is instance of " + (handler != null ? handler.getClass() : null) + ")");
+            throw new DatabaseException("Handler for " + parameter + " is not instance of AbstractEventHandler (it is instance of " + (handler != null ? handler.getClass() : null) + ")");
     }
 
 }
\ No newline at end of file
index 99526368e8cc3e21e1b92451f4dd915db45d40ba..133264e29b09321e399831600106ce0227ba0a04 100644 (file)
@@ -2,11 +2,12 @@ package org.simantics.document.server.request;
 
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Set;
 
 import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ReadGraph;
-import org.simantics.db.common.request.AsyncReadRequest;
+import org.simantics.db.common.request.UnaryAsyncRead;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.request.VariableChildren;
 import org.simantics.db.layer0.request.VariableRead;
@@ -16,52 +17,57 @@ import org.simantics.structural.stubs.StructuralResource2;
 import org.simantics.utils.threads.logger.ITask;
 import org.simantics.utils.threads.logger.ThreadLogger;
 
-import gnu.trove.set.hash.THashSet;
-
 public class NodesRequest extends VariableRead<Set<Variable>> {
 
     public NodesRequest(Variable var) {
         super(var);
     }
 
-    @Override
-    public Set<Variable> perform(ReadGraph graph) throws DatabaseException {
+    static class CollectNodesRequest2 extends UnaryAsyncRead<Collection<Variable>, Set<Variable>> {
 
-        ITask task = DocumentRequest.PROFILE ? ThreadLogger.task(this) : null;
+        public CollectNodesRequest2(Collection<Variable> nodes) {
+            super(nodes);
+        }
 
-        StructuralResource2.getInstance(graph);
-        if(variable == null)
-            return Collections.emptySet();
+        @Override
+        public void perform(AsyncReadGraph graph, AsyncProcedure<Set<Variable>> procedure) {
+            HashSet<Variable> rs = new HashSet<Variable>(); // result
 
-        Set<Variable> nodes = new THashSet<Variable>();
+            for(Variable node : parameter) {
+                graph.asyncRequest(new NodesRequest2(node), new AsyncProcedure<Set<Variable>> () {
 
-        Collection<Variable> children = graph.syncRequest(new VariableChildren(variable));
+                    @Override
+                    public void execute(AsyncReadGraph graph, Set<Variable> result) {
+                        synchronized(rs) {
+                            rs.addAll(result);
+                        }
+                    }
 
-        graph.syncRequest(new AsyncReadRequest() {
+                    @Override
+                    public void exception(AsyncReadGraph graph, Throwable throwable) {
+                    }
 
-            @Override
-            public void run(AsyncReadGraph graph) throws DatabaseException {
+                });
 
-                for(Variable child : children) {
-                    graph.asyncRequest(new NodesRequest2(child), new AsyncProcedure<Set<Variable>>() {
+            }
+            procedure.execute(graph, rs);
 
-                        @Override
-                        public void execute(AsyncReadGraph graph, Set<Variable> result) {
-                            synchronized(nodes) {
-                                nodes.addAll(result);
-                            }
-                        }
+        }
 
-                        @Override
-                        public void exception(AsyncReadGraph graph, Throwable throwable) {
-                        }
-                        
-                    });
-                }
+    }
 
-            }
+    @Override
+    public Set<Variable> perform(ReadGraph graph) throws DatabaseException {
+
+        ITask task = DocumentRequest.PROFILE ? ThreadLogger.task(this) : null;
+
+        StructuralResource2.getInstance(graph);
+        if(variable == null)
+            return Collections.emptySet();
+
+        Collection<Variable> children = graph.syncRequest(new VariableChildren(variable));
 
-        });
+        Set<Variable> nodes = graph.syncRequest(new CollectNodesRequest2(children));
 
         if(DocumentRequest.PROFILE) task.finish();
 
index 57c7e90ba7d88929a3ec844760d4b48570d50069..7adcb430e65df93942b38aeee9313bfcb69a8dd2 100644 (file)
@@ -5,7 +5,6 @@ Bundle-SymbolicName: org.simantics.fileimport;singleton:=true
 Bundle-Version: 1.0.0.qualifier
 Bundle-Activator: org.simantics.fileimport.Activator
 Require-Bundle: org.eclipse.core.runtime,
- org.apache.log4j,
  org.simantics.db,
  org.simantics,
  org.simantics.graphfile;bundle-version="0.1.0",
index 4c44b6152372a26490808edc8da6251fad824e70..269f6a4fbe0a08f01f3dcbc0d0ed8d0c58b642d9 100644 (file)
@@ -212,7 +212,9 @@ G2D.HasVerticalAlignment <R L0.IsRelatedTo : L0.FunctionalRelation
 
 G2D.Color <T L0.Literal
     @L0.assert L0.HasDataType $(Float[4])
+    @L0.assert L0.HasValueType "Vector Float"
     L0.HasDescription "A 4-component BGRA color as floats."
+    
 G2D.HasColor <R L0.HasProperty : L0.FunctionalRelation
     L0.HasLabel "Color"
     --> G2D.Color
index 5bbe9f26e7de24047b90c875f8e66809d542b897..d09ecf4a6b6f753f7f0adbf57060b3a36ac987c1 100644 (file)
@@ -631,8 +631,10 @@ public class GalleryViewer extends ContentViewer {
                 ctx.getThreadAccess().asyncExec(() -> {
                     //System.out.println(Thread.currentThread() + ": update scene graph(" + el + ")");
                     // Update scene graph and repaint.
-                    el.getElementClass().getSingleItem(GalleryItemSGNode.class).update(el);
-                    ctx.getContentContext().setDirty();
+                    if (!ctx.isDisposed()) {
+                        el.getElementClass().getSingleItem(GalleryItemSGNode.class).update(el);
+                        ctx.getContentContext().setDirty();
+                    }
                 });
                 break;
             }
index 17aa3ed26af30ab5143a2cacf7fb16b01d2a27d3..33291cdf108e75cef32b35e64e69b19d8583c589 100644 (file)
@@ -41,8 +41,9 @@ public class FixExportedOntology {
 
        private static Path replaceExtension(Path p, String newExtension) {
                String newName = p.getFileName().toString();
-               if (newName.contains("."))
-                       newName = newName.split("\\.")[0];
+               int lastDot = newName.lastIndexOf('.');
+               if (lastDot > -1)
+                       newName = newName.substring(0, lastDot);
                return p.resolveSibling(newName + newExtension);
        }
 
index b7ea5ac78a1efff4769b267fdaa7ddf565cdea41..d9d14c37eada50ab64cddc9a9e55c0e94cf64249 100644 (file)
@@ -17,7 +17,6 @@ import org.simantics.db.layer0.SelectionHints;
 import org.simantics.db.layer0.request.PossibleModel;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
-import org.simantics.diagram.Logger;
 import org.simantics.diagram.flag.FlagUtil;
 import org.simantics.diagram.stubs.DiagramResource;
 import org.simantics.diagram.ui.DiagramModelHints;
@@ -36,6 +35,8 @@ import org.simantics.ui.selection.WorkbenchSelectionContentType;
 import org.simantics.utils.DataContainer;
 import org.simantics.utils.threads.IThreadWorkQueue;
 import org.simantics.utils.ui.ErrorLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @author Antti Villberg
@@ -44,6 +45,8 @@ public class DiagramViewerSelectionProvider extends WorkbenchSelectionProvider {
 
     protected static class SelectionElement extends AdaptableHintContext {
 
+        private static final Logger LOGGER = LoggerFactory.getLogger(SelectionElement.class);
+
         final public Resource runtime;
         final public Resource element;
 
@@ -108,7 +111,7 @@ public class DiagramViewerSelectionProvider extends WorkbenchSelectionProvider {
                         }
                     });
                 } catch (DatabaseException e) {
-                    Logger.defaultLogError(e);
+                    LOGGER.error("WorkbenchSelectionElement.getContent failed for type AnyVariable", e);
                 }
             }
             else if(contentType instanceof ParentVariable) {
@@ -117,10 +120,7 @@ public class DiagramViewerSelectionProvider extends WorkbenchSelectionProvider {
                     return (T) type.processor.sync(new ResourceRead2<Variable>(runtime, element) {
                         @Override
                         public Variable perform(ReadGraph graph) throws DatabaseException {
-
                             DiagramResource DIA = DiagramResource.getInstance(graph);
-                            ModelingResources MOD = ModelingResources.getInstance(graph);
-                            Layer0 L0 = Layer0.getInstance(graph);
 
                             String uri = graph.getPossibleRelatedValue(resource, DIA.RuntimeDiagram_HasVariable);
                             if (uri == null)
@@ -134,7 +134,7 @@ public class DiagramViewerSelectionProvider extends WorkbenchSelectionProvider {
                         }
                     });
                 } catch (DatabaseException e) {
-                    Logger.defaultLogError(e);
+                    LOGGER.error("WorkbenchSelectionElement.getContent failed for type ParentVariable", e);
                 }
             } 
 
index ac9413064a7b8b222e401a820e0e552a582dc198..4e7ac0ab815ab3b8605c5f67ed466018c69c047e 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2020 Association for Decentralized Information Management
  * in Industry THTH ry.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -45,7 +45,6 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.request.IsLinkedTo;
 import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.db.service.SerialisationSupport;
-import org.simantics.diagram.Logger;
 import org.simantics.diagram.adapter.GraphToDiagramSynchronizer;
 import org.simantics.diagram.content.Change;
 import org.simantics.diagram.content.DiagramContentChanges;
@@ -83,12 +82,16 @@ import org.simantics.ui.dnd.LocalObjectTransferable;
 import org.simantics.ui.selection.WorkbenchSelectionElement;
 import org.simantics.ui.workbench.e4.E4WorkbenchUtils;
 import org.simantics.utils.logging.TimeLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * This participant populates Elements from ElementClass-resources drops
  */
 public class PopulateElementDropParticipant extends AbstractDiagramParticipant implements IDropTargetParticipant {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(PopulateElementDropParticipant.class);
+
     @Dependency PickContext pickContext;
     @Dependency TransformUtil transformUtil;
        
@@ -321,7 +324,7 @@ public class PopulateElementDropParticipant extends AbstractDiagramParticipant i
                                        });
                                        
                                } catch (DatabaseException e) {
-                                       Logger.defaultLogError(e);
+                                       LOGGER.error("symbolDropHandler invocation failed", e);
                                }
                
                return;
index 0d0ec7ce64d5554b46e1913ebb3cd33a21f3ddde..e7bfd35fa5477550aeb68fd0aead0342d9b2a406 100644 (file)
@@ -20,16 +20,13 @@ import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.handlers.HandlerUtil;
 import org.simantics.Simantics;
-import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.request.UniqueRead;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.Variable;
-import org.simantics.modeling.ModelingResources;
-import org.simantics.modeling.PropertyVariables;
+import org.simantics.modeling.help.HelpContexts;
 import org.simantics.ui.selection.WorkbenchSelectionUtils;
-import org.simantics.utils.ui.AdaptionUtils;
 import org.slf4j.LoggerFactory;
 
 public class ContextualHelp extends AbstractHandler {
@@ -47,7 +44,7 @@ public class ContextualHelp extends AbstractHandler {
             return Simantics.getSession().syncRequest(new UniqueRead<String>() {
                 @Override
                 public String perform(ReadGraph graph) throws DatabaseException {
-                    return getPossibleId(graph, resource, variable, sel);
+                    return HelpContexts.getPossibleId(graph, resource, variable, sel);
                 }
             });
         } catch (DatabaseException e) {
@@ -64,34 +61,12 @@ public class ContextualHelp extends AbstractHandler {
         return null;
     }
 
+    /**
+     * @deprecated use {@link HelpContexts#getPossibleId(ReadGraph, Resource, Variable, Object)} instead
+     */
+    @Deprecated
     public static String getPossibleId(ReadGraph graph, Resource resource, Variable variable, ISelection sel) throws DatabaseException {
-        ModelingResources MOD = ModelingResources.getInstance(graph);
-        if (resource != null) {
-            Resource component = graph.getPossibleObject(resource, MOD.ElementToComponent);
-            String id = component != null ? graph.getPossibleRelatedValue2(component, MOD.contextualHelpId, Bindings.STRING) : null;
-            if (id != null)
-                return id;
-            id = graph.getPossibleRelatedValue2(resource, MOD.contextualHelpId, Bindings.STRING);
-            if (id != null)
-                return id;
-        }
-
-        if (variable != null) {
-            String id = variable.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING);
-            if (id != null)
-                return id;
-        }
-
-        // TODO: consider removing this block
-        if (sel != null) {
-            PropertyVariables vars = AdaptionUtils.adaptToSingle(sel, PropertyVariables.class);
-            Variable var = vars != null ? vars.getConfiguration() : null;
-            String id = var != null ? var.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING) : null;
-            if (id != null)
-                return id;
-        }
-
-        return null;
+        return HelpContexts.getPossibleId(graph, resource, variable, sel);
     }
 
 }
index bec1e5408ae414c82c568b102cff6743cefec5ac..0b7cd63e4c55eed107eb552c9707a382beffc974 100644 (file)
@@ -89,7 +89,15 @@ public class PDFPainter {
 
                     ThreadUtils.asyncExec(thread, () -> {
                         try {
-                            PDFBuilder chassis = new PDFBuilder(writer, mapper, pageSize, pageDesc, fitDiagramContentsToPageMargins || isSymbol);
+                            boolean fitToContent = fitDiagramContentsToPageMargins || isSymbol;
+                            if (!fitToContent) {
+                                // Prevent PDF printing from drawing page borders if the
+                                // print area is fitted directly to the page size.
+                                // This avoids unwanted black half-visible edges.
+                                ctx.getDefaultHintContext().setHint(Hints.KEY_DISPLAY_PAGE, false);
+                            }
+
+                            PDFBuilder chassis = new PDFBuilder(writer, mapper, pageSize, pageDesc, fitToContent);
                             chassis.paint(ctx, true);
                         } catch (Throwable e) {
                             exception[0] = new DatabaseException(e);
index 8f223a62285bbf6892240019deea73d6ed68a31b..302e074fce35fe9a202c743119e15afd397eb23f 100644 (file)
@@ -26,6 +26,7 @@ import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
 import org.simantics.db.exception.NoSingleResultException;
 import org.simantics.db.exception.ServiceException;
 import org.simantics.db.management.ISessionContext;
+import org.simantics.db.procedure.Listener;
 import org.simantics.db.request.Read;
 import org.simantics.diagram.adapter.DefaultConnectionClassFactory;
 import org.simantics.diagram.adapter.FlagClassFactory;
@@ -98,6 +99,7 @@ import org.simantics.utils.page.PageDesc;
 import org.simantics.utils.page.PageOrientation;
 import org.simantics.utils.threads.AWTThread;
 import org.simantics.utils.threads.IThreadWorkQueue;
+import org.simantics.utils.threads.ThreadUtils;
 import org.simantics.utils.ui.ErrorLogger;
 
 
@@ -290,6 +292,30 @@ public class DiagramSceneGraphProvider implements ICanvasSceneGraphProvider, IDi
             DiagramDesc diagramDesc = Simantics.getSession().syncRequest(DiagramRequests.getDiagramDesc(diagramResource));
             if (diagramDesc != null)
                 setDiagramDesc(ctx, diagramDesc);
+
+            // Create a listener to react to page setting changes.
+            Simantics.getSession().asyncRequest(DiagramRequests.getDiagramDesc(diagramResource), new Listener<DiagramDesc>() {
+                @Override
+                public void execute(DiagramDesc result) {
+                    if (result != null && ctx != null) {
+                        ThreadUtils.asyncExec(ctx.getThreadAccess(), () -> {
+                            if (ctx != null) {
+                                setDiagramDesc(ctx, result);
+                            }
+                        });
+                    }
+                }
+
+                @Override
+                public void exception(Throwable t) {
+                    ErrorLogger.defaultLogError(t);
+                }
+
+                @Override
+                public boolean isDisposed() {
+                    return DiagramSceneGraphProvider.this.ctx == null;
+                }
+            });
         } catch (DatabaseException e) {
             ErrorLogger.defaultLogError(e);
         }
@@ -298,7 +324,7 @@ public class DiagramSceneGraphProvider implements ICanvasSceneGraphProvider, IDi
     protected void setDiagramDesc(ICanvasContext ctx, DiagramDesc diagramDesc) {
         IHintContext hints = ctx.getDefaultHintContext();
         hints.setHint(Hints.KEY_PAGE_DESC, diagramDesc.getPageDesc());
-        //hints.setHint(Hints.KEY_DISPLAY_PAGE, diagramDesc.isPageBordersVisible());
+        hints.setHint(Hints.KEY_DISPLAY_PAGE, diagramDesc.isPageBordersVisible());
         hints.setHint(Hints.KEY_DISPLAY_MARGINS, diagramDesc.isMarginsVisible());
     }
 
index 067521a89ff9a38eaece27e3c91fecd48264ed0b..e00a8e1147cdac344a36d52cd45f858dff5e6b72 100644 (file)
@@ -47,6 +47,7 @@ Export-Package: org.simantics.modeling,
  org.simantics.modeling.adapters,
  org.simantics.modeling.export,
  org.simantics.modeling.flags,
+ org.simantics.modeling.help,
  org.simantics.modeling.mapping,
  org.simantics.modeling.migration,
  org.simantics.modeling.preferences,
index 47c7d346657d2caa7116a332a5f79860a6fb6e4a..ba7e7117fea1dc28202803be58e7961f6a34266d 100644 (file)
@@ -8,11 +8,14 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.adapter.ActionFactory;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
-import org.simantics.diagram.Logger;
 import org.simantics.scl.runtime.function.Function1;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class SCLAction implements ActionFactory {
 
+       private static final Logger LOGGER = LoggerFactory.getLogger(SCLAction.class);
+
        final private Resource rule;
     
     public SCLAction(ReadGraph graph, Resource rule) throws DatabaseException {
@@ -52,7 +55,7 @@ public class SCLAction implements ActionFactory {
                                Function1<Resource, Object> function = Simantics.getSession().syncRequest(new RuleFunctionRequest(rule));
                                function.apply(resource);
                        } catch (DatabaseException e) {
-                               Logger.defaultLogError(e);
+                               LOGGER.error("SCLActionRunnable failed to request/apply RuleFunction {}", rule, e);
                        }
                }
        
index 74b19a2144f77229c6ba338a5f3cf5ad461bf829..f1d38554572d1f3d6260636241095d980c97da59 100644 (file)
@@ -8,11 +8,14 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.adapter.DropActionFactory;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
-import org.simantics.diagram.Logger;
 import org.simantics.scl.runtime.function.Function3;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class SCLDropAction implements DropActionFactory {
 
+       private static final Logger LOGGER = LoggerFactory.getLogger(SCLDropAction.class);
+
        final private Resource rule;
 
        public SCLDropAction(ReadGraph graph, Resource rule) throws DatabaseException {
@@ -55,7 +58,7 @@ public class SCLDropAction implements DropActionFactory {
                                Function3<Resource, Object, Integer, Object> function = Simantics.getSession().syncRequest(new RuleFunctionRequest(rule));
                                function.apply(target, source, operation);
                        } catch (DatabaseException e) {
-                               Logger.defaultLogError(e);
+                               LOGGER.error("SCLDropActionRunnable failed to request/apply RuleFunction {}", rule, e);
                        }
                }
 
index ba124310800bb29b87988d85144176fa19f7bc96..22327aeb3f71b833ea002af5705ca7080a87ac96 100644 (file)
@@ -16,38 +16,36 @@ import org.simantics.Simantics;
 import org.simantics.databoard.Bindings;
 import org.simantics.db.Resource;
 import org.simantics.db.common.primitiverequest.PossibleRelatedValue2;
-import org.simantics.db.common.utils.Logger;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.adapter.ActionFactory;
 import org.simantics.modeling.ModelingResources;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class Help implements ActionFactory {
 
+       private static final Logger LOGGER = LoggerFactory.getLogger(Help.class);
+
        @Override
        public Runnable create(Object target) {
-
-               if(!(target instanceof Resource))
+               if (!(target instanceof Resource))
                        return null;
 
-               final Resource resource = (Resource)target;
-               
-               return new Runnable() {
-                       @Override
-                       public void run() {
-                               
-                               try {
-                                       ModelingResources MOD = ModelingResources.getInstance(Simantics.getSession());
-                                       String id = Simantics.sync(new PossibleRelatedValue2<String>(resource, MOD.contextualHelpId, Bindings.STRING));
-                                       if(id == null) {
-                                               PlatformUI.getWorkbench().getHelpSystem().displayDynamicHelp();
-                                               return;
-                                       }
-                                       PlatformUI.getWorkbench().getHelpSystem().displayHelp(id);
-                               } catch (DatabaseException e) {
-                                       Logger.defaultLogError(e);
+               final Resource resource = (Resource) target;
+
+               return () -> {
+                       try {
+                               ModelingResources MOD = ModelingResources.getInstance(Simantics.getSession());
+                               String id = Simantics.sync(new PossibleRelatedValue2<String>(resource, MOD.contextualHelpId, Bindings.STRING));
+                               if (id == null) {
+                                       PlatformUI.getWorkbench().getHelpSystem().displayDynamicHelp();
+                                       return;
                                }
-                               
+                               PlatformUI.getWorkbench().getHelpSystem().displayHelp(id);
+                       } catch (DatabaseException e) {
+                               LOGGER.error("Failed to display help for resource {}", resource, e);
                        }
                }; 
        }
+
 }
diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/help/HelpContexts.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/help/HelpContexts.java
new file mode 100644 (file)
index 0000000..ca25cf4
--- /dev/null
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2020 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Semantum Oy- initial API and implementation
+ *******************************************************************************/
+package org.simantics.modeling.help;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.PropertyVariables;
+import org.simantics.utils.ui.AdaptionUtils;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 1.46.0
+ */
+public class HelpContexts {
+
+    /**
+     * @param graph
+     * @param resource
+     * @param variable
+     * @param selection optional <code>ISelection</code> 
+     * @return
+     * @throws DatabaseException
+     */
+    public static String getPossibleId(ReadGraph graph, Resource resource, Variable variable, Object selection) throws DatabaseException {
+        ModelingResources MOD = ModelingResources.getInstance(graph);
+        if (resource != null) {
+            Resource component = graph.getPossibleObject(resource, MOD.ElementToComponent);
+            String id = component != null ? graph.getPossibleRelatedValue2(component, MOD.contextualHelpId, Bindings.STRING) : null;
+            if (id != null)
+                return id;
+            id = graph.getPossibleRelatedValue2(resource, MOD.contextualHelpId, Bindings.STRING);
+            if (id != null)
+                return id;
+        }
+
+        if (variable != null) {
+            String id = variable.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING);
+            if (id != null)
+                return id;
+        }
+
+        // TODO: consider removing this block
+        if (selection != null) {
+            PropertyVariables vars = AdaptionUtils.adaptToSingle(selection, PropertyVariables.class);
+            Variable var = vars != null ? vars.getConfiguration() : null;
+            String id = var != null ? var.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING) : null;
+            if (id != null)
+                return id;
+        }
+
+        return null;
+    }
+
+    public static String getPossibleId(ReadGraph graph, Variable variable, String property) throws DatabaseException {
+        ModelingResources MOD = ModelingResources.getInstance(graph);
+        Variable prop = variable != null ? variable.getPossibleProperty(graph, property) : null;
+        return prop != null ? prop.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING) : null;
+    }
+
+}
index 3e6e9c1b9527096cfa1835a50e43f6b2dfb97c7f..021ecc436b86c5d82af28d062cd45d4a88b38148 100644 (file)
@@ -32,7 +32,6 @@ import org.simantics.modeling.ModelingUtils;
 import org.simantics.modeling.services.ComponentNamingUtil;
 import org.simantics.modeling.services.NamingException;
 import org.simantics.project.IProject;
-import org.simantics.structural.stubs.StructuralResource2;
 
 import gnu.trove.map.hash.THashMap;
 
@@ -58,7 +57,6 @@ public class ComponentCopyAdvisor extends GraphCopyAdvisor {
     @Override
     public Object copy(ISynchronizationContext context, WriteGraph graph, Resource source, Resource sourceContainer,
             Resource targetContainer, Map<Object, Object> map) throws DatabaseException {
-        StructuralResource2 STR = StructuralResource2.getInstance(graph);
         Resource copy = CopyAdvisorUtil.copy2(graph, source, null, map);
 
         Layer0 L0 = Layer0.getInstance(graph);
index 8eed51aca7ed70401b7ddafb7da5a13bab85b2ff..a70844cd375c8956adb593cb71406e92d782e963 100644 (file)
@@ -12,6 +12,8 @@ import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.procedure.SyncListener;
 import org.simantics.db.request.Read;
+import org.simantics.db.request.ReadExt;
+import org.simantics.db.request.RequestFlags;
 import org.simantics.layer0.Layer0;
 import org.simantics.modeling.ModelingUtils;
 import org.simantics.modeling.internal.Activator;
@@ -137,6 +139,29 @@ public enum GraphModuleSourceRepository implements ModuleSourceRepository {
         }
     }
 
+    static class PossibleResourceIU extends UnaryRead<String,Resource> implements ReadExt {
+
+        public PossibleResourceIU(String parameter) {
+            super(parameter);
+        }
+
+        @Override
+        public Resource perform(ReadGraph graph) throws DatabaseException {
+            return graph.getPossibleResource(parameter);
+        }
+
+        @Override
+        public boolean isImmutable(ReadGraph graph) throws DatabaseException {
+            return false;
+        }
+
+        @Override
+        public int getType() {
+            return RequestFlags.IMMEDIATE_UPDATE;
+        }
+        
+    }
+    
     static class ReadModuleSource extends UnaryRead<String, ModuleSource> {
         public ReadModuleSource(String moduleName) {
             super(moduleName);
@@ -144,7 +169,7 @@ public enum GraphModuleSourceRepository implements ModuleSourceRepository {
 
         @Override
         public ModuleSource perform(ReadGraph graph) throws DatabaseException {
-            Resource moduleResource = graph.getPossibleResource(parameter);
+            Resource moduleResource = graph.syncRequest(new PossibleResourceIU(parameter));
             if(moduleResource == null)
                 return null;
             Layer0 L0 = Layer0.getInstance(graph);
index 31295b9b692f60178c422ad7dda719089d87b76c..10e2abe67fb1f347ce8cc91dcf9553d9abc7c529 100644 (file)
@@ -44,7 +44,7 @@ public class ObserverGroupListener implements SetListener<Resource> {
     public void add(Resource item) {
         //System.out.println("Add to group(" + this + "): " + item);
         items.put(item, item);
-        observer.update();
+        observer.update(style, item);
     }
 
     @Override
@@ -52,7 +52,7 @@ public class ObserverGroupListener implements SetListener<Resource> {
 //        new Exception().printStackTrace();
         //System.out.println("Remove from group(" + this + "): " + item);
         items.remove(item);
-        observer.update();
+        observer.update(style, item);
     }
 
     @Override
index b019ac5cc0b60dbd0870fa732eb699632d46e659..3e2330afef2734b0c71931a23fd801557301589a 100644 (file)
@@ -6,7 +6,6 @@ Bundle-Version: 1.1.0.qualifier
 Bundle-RequiredExecutionEnvironment: JavaSE-11
 Require-Bundle: org.simantics.utils.datastructures;bundle-version="1.0.0",
  org.simantics.utils.ui;bundle-version="1.0.0",
- org.apache.log4j;bundle-version="1.2.15",
  org.simantics.spreadsheet;bundle-version="1.1.0",
  org.simantics.db.layer0;bundle-version="1.1.0",
  org.simantics.scl.runtime;bundle-version="0.1.2",
index 604255263f07c7a4ec345348286e5f35c1970f67..4829d00c5a4f025e63e641131a6331bdc88025f3 100644 (file)
@@ -11,7 +11,6 @@ Require-Bundle: org.eclipse.core.runtime;visibility:=reexport,
  org.simantics.project;bundle-version="1.0.1";visibility:=reexport,
  org.simantics.graph.db;bundle-version="1.1.5",
  org.eclipse.equinox.p2.metadata;bundle-version="2.0.0",
- org.apache.log4j;bundle-version="1.2.15",
  org.simantics.layer0.utils;bundle-version="1.1.0",
  org.simantics.application;bundle-version="1.1.0",
  org.simantics.db.indexing;bundle-version="1.1.0",
diff --git a/bundles/org.simantics/src/org/simantics/LogManager.java b/bundles/org.simantics/src/org/simantics/LogManager.java
deleted file mode 100644 (file)
index 4274002..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
- * in Industry THTH ry.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     VTT Technical Research Centre of Finland - initial API and implementation
- *******************************************************************************/
-package org.simantics;
-
-import java.util.Properties;
-
-import org.apache.log4j.Hierarchy;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PropertyConfigurator;
-import org.apache.log4j.spi.LoggerFactory;
-import org.apache.log4j.spi.RootLogger;
-
-/**
- * This class encapsulates a Log4J Hierarchy and centralizes all Logger access.
- */
-public class LogManager {
-
-    private Hierarchy hierarchy;
-
-    /**
-     * Creates a new LogManager. Saves the log and state location.
-     * Creates a new Hierarchy and add a new EventListener to it.
-     * Configure the hierarchy with the properties passed. Add this object to
-     * the list of active log managers.
-     * 
-     * @param properties log configuration properties
-     */
-    public LogManager(Properties properties) {
-        this.hierarchy = new Hierarchy(new RootLogger(Level.DEBUG));
-        new PropertyConfigurator().doConfigure(properties, this.hierarchy);
-    }
-
-    /**
-     * Checks if this PluginLogManager is disabled for this level.
-     * 
-     * @param level level value
-     * @return boolean true if it is disabled
-     */
-    public boolean isDisabled(int level) {
-        return this.hierarchy.isDisabled(level);
-    }
-
-    /**
-     * Enable logging for logging requests with level l or higher. By default
-     * all levels are enabled.
-     * 
-     * @param level level object
-     */
-    public void setThreshold(Level level) {
-        this.hierarchy.setThreshold(level);
-    }
-
-    /**
-     * The string version of setThreshold(Level level)
-     * 
-     * @param level level string
-     */
-    public void setThreshold(String level) {
-        this.hierarchy.setThreshold(level);
-    }
-
-    /**
-     * Get the repository-wide threshold.
-     * 
-     * @return Level
-     */
-    public Level getThreshold() {
-        return this.hierarchy.getThreshold();
-    }
-
-    /**
-     * Returns a new logger instance named as the first parameter using the
-     * default factory. If a logger of that name already exists, then it will be
-     * returned. Otherwise, a new logger will be instantiated and then linked
-     * with its existing ancestors as well as children.
-     * 
-     * @param clazz the class to get the logger for
-     * @return Logger
-     */
-    public Logger getLogger(Class<?> clazz) {
-        return this.hierarchy.getLogger(clazz.getName());
-    }
-
-    /**
-     * Returns a new logger instance named as the first parameter using the
-     * default factory. If a logger of that name already exists, then it will be
-     * returned. Otherwise, a new logger will be instantiated and then linked
-     * with its existing ancestors as well as children.
-     * 
-     * @param name logger name
-     * @return Logger
-     */
-    public Logger getLogger(String name) {
-        return this.hierarchy.getLogger(name);
-    }
-
-    /**
-     * The same as getLogger(String name) but using a factory instance instead
-     * of a default factory.
-     * 
-     * @param name logger name
-     * @param factory factory instance
-     * @return Logger
-     */
-    public Logger getLogger(String name, LoggerFactory factory) {
-        return this.hierarchy.getLogger(name, factory);
-    }
-
-    /**
-     * Returns the root of this hierarchy.
-     * 
-     * @return Logger
-     */
-    public Logger getRootLogger() {
-        return this.hierarchy.getRootLogger();
-    }
-
-    /**
-     * Checks if this logger exists.
-     * 
-     * @return Logger
-     */
-    public Logger exists(String name) {
-        return this.hierarchy.exists(name);
-    }
-
-    /**
-     * Disposes the logger hierarchy
-     */
-    public void shutdown() {
-        this.hierarchy.shutdown();
-    }
-
-    /**
-     * Resets configuration values to its defaults.
-     */
-    public void resetConfiguration() {
-        this.hierarchy.resetConfiguration();
-    }
-
-}
\ No newline at end of file
index cbe17e940d9436223aa6c2b62127872963a7b769..35808bd929fa74d63f18f860bdc51680abeababf 100644 (file)
@@ -44,6 +44,7 @@ import org.simantics.db.management.SessionContextProvider;
 import org.simantics.db.management.SingleSessionContextProviderSource;
 import org.simantics.db.request.ReadInterface;
 import org.simantics.db.request.WriteInterface;
+import org.simantics.db.service.XSupport;
 import org.simantics.internal.FileServiceImpl;
 import org.simantics.layer0.Layer0;
 import org.simantics.project.IProject;
@@ -467,6 +468,14 @@ public class Simantics {
         }
     }
 
+    public static void saveQueries(Session session) {
+        try {
+            XSupport xs = session.getService(XSupport.class);
+            xs.saveQueries();
+        } catch (Exception e) {
+            LOGGER.error("Saving database queries failed.", e);
+        }
+    }
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
     public static <T> T applySCL(String module, String function, Object ... args) throws DatabaseException {
index c5ed8fd1e6374b70294bf65ecd5a4034b40b2efa..aa0b503dace880ca7c18d86dd1584f944a18260e 100644 (file)
@@ -1012,6 +1012,11 @@ public class SimanticsPlatform implements LifecycleListener {
                     } catch (Throwable t) {
                         LOGGER.error("Failed to flush index caches.", t);
                     }
+
+                    if("true".equals(System.getProperty("org.simantics.db.persistQueries"))) {
+                        progress.subTask("Saving Queries");
+                        Simantics.saveQueries(s);
+                    }
                 }
 
                 progress.subTask("Close Database Session");
index 910e199de437b4a7bebafc28a04605244606a9f8..54dd723722cfd6cddd0d97025dcd34b6747209a6 100644 (file)
@@ -479,13 +479,6 @@ This Agreement is governed by the laws of the State of New York and the intellec
          version="0.0.0"
          unpack="false"/>
 
-   <plugin
-         id="org.apache.log4j"
-         download-size="0"
-         install-size="0"
-         version="0.0.0"
-         unpack="false"/>
-
    <plugin
          id="org.eclipse.ui.browser"
          download-size="0"
index ca5692d4b4c922b2cda04f852d28eb3cae9760b9..e1133bd659bcf59effd0e26379f443ad0262a8cd 100644 (file)
          version="0.0.0"
          unpack="false"/>
 
+   <plugin
+         id="org.apache.log4j"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
 </feature>
index cac8ec5bb52684bf5b6eb25f199ec1503b64a437..3d60be4670a0cf9ce5cb98a7091002e6b7aef727 100644 (file)
@@ -105,20 +105,6 @@ worth mentioning is <a rel="nofollow" class="external text" href="http://www.ope
 <td>\r
 </td></tr>\r
 <tr>\r
-<td> <a rel="nofollow" class="external text" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ACE - Adaptive Communications Environment</a>\r
-</td>\r
-<td> <a href="#BSD_3-Clause_License">BSD 3-Clause License</a> (<a rel="nofollow" class="external free" href="http://www.cs.wustl.edu/~schmidt/ACE-copying.html">http://www.cs.wustl.edu/~schmidt/ACE-copying.html</a>)\r
-</td>\r
-<td> <pre>Copyright (c) 2000-2005 INRIA, France Telecom</pre>\r
-</td></tr>\r
-<tr>\r
-<td> <a rel="nofollow" class="external text" href="http://www.jcraft.com/jzlib/">JZlib</a>\r
-</td>\r
-<td> <a href="#BSD_3-Clause_License">BSD 3-Clause License</a> (<a rel="nofollow" class="external free" href="http://www.jcraft.com/jzlib/LICENSE.txt">http://www.jcraft.com/jzlib/LICENSE.txt</a>)\r
-</td>\r
-<td> <pre>Copyright (c) 2000,2001,2002,2003,2004 ymnk, JCraft,Inc.</pre>\r
-</td></tr>\r
-<tr>\r
 <td> <a rel="nofollow" class="external text" href="http://xmlgraphics.apache.org/batik/">Batik</a> (org.apache.batik)\r
 </td>\r
 <td> <a href="#Apache_Software_License_2.0">Apache Software License 2.0</a>\r
@@ -148,7 +134,7 @@ All rights reserved.</pre>
 <td> 1.2.3\r
 </td></tr>\r
 <tr>\r
-<td> <a rel="nofollow" class="external text" href="http://www.json.org/">JSON</a> (JSON_libraries)\r
+<td> <a rel="nofollow" class="external text" href="https://github.com/google/gson">Gson</a>\r
 </td>\r
 <td> <a href="#Apache_Software_License_2.0">Apache Software License 2.0</a>\r
 </td>\r
@@ -169,14 +155,14 @@ All rights reserved.</pre>
 <td>\r
 </td></tr>\r
 <tr>\r
-<td> <a rel="nofollow" class="external text" href="http://www.jfree.org/jcommon/">JCommon</a>, <a rel="nofollow" class="external text" href="http://www.jfree.org/jfreechart/">JFreeChart</a>\r
+<td><a rel="nofollow" class="external text" href="http://www.jfree.org/jfreechart/">JFreeChart</a>\r
 </td>\r
 <td> <a href="#LGPL">LGPL</a>\r
 </td>\r
 <td>\r
 </td></tr>\r
 <tr>\r
-<td valign="top"> <a rel="nofollow" class="external text" href="http://trove4j.sourceforge.net/">GNU Trove</a> (gnu.trove2, gnu.trove3)\r
+<td valign="top"> <a rel="nofollow" class="external text" href="http://trove4j.sourceforge.net/">GNU Trove</a> (gnu.trove3)\r
 </td>\r
 <td valign="top"> <a href="#LGPL">LGPL</a>\r
 </td>\r
@@ -254,7 +240,7 @@ Copyright (c) 2011-2016, Yann Collet</pre>
 </td>\r
 <td> <a href="#Eclipse_Public_License">EPL</a>\r
 </td>\r
-<td> 9.2.0\r
+<td> 10.2.0\r
 </td></tr>\r
 <tr>\r
 <td> <a rel="nofollow" class="external text" href="http://fastutil.di.unimi.it/">fastutil: Fast &amp; compact type-specific collections for Java</a>\r
@@ -285,11 +271,12 @@ Copyright (c) 2011-2016, Yann Collet</pre>
 <td> 21.0\r
 </td></tr>\r
 <tr>\r
-<td> <a rel="nofollow" class="external text" href="http://aries.apache.org/Apache">Aries</a>\r
+<td valign="top"> <a rel="nofollow" class="external text" href="http://www.antlr3.org/">ANTLR v3</a>\r
 </td>\r
-<td> <a href="#Apache_Software_License_2.0">Apache Software License 2.0</a>\r
+<td> <a href="#BSD_3-Clause_License">BSD 3-Clause License</a> (<a rel="nofollow" class="external free" href="http://www.antlr3.org/license.html">http://www.antlr3.org/license.html</a>)\r
 </td>\r
-<td>\r
+<td> 3.5.2\r
+<pre>Copyright (c) 2010 Terence Parr</pre>\r
 </td></tr>\r
 <tr>\r
 <td valign="top"> <a rel="nofollow" class="external text" href="http://hc.apache.org/httpclient-3.x/">Apache Commons Codec</a>\r
@@ -341,13 +328,6 @@ Copyright (c) 2011-2016, Yann Collet</pre>
 <td> 3.6.1\r
 </td></tr>\r
 <tr>\r
-<td valign="top"> <a rel="nofollow" class="external text" href="http://hc.apache.org/httpclient-3.x/">Apache HttpClient 3</a>\r
-</td>\r
-<td> <a href="#Apache_Software_License_2.0">Apache Software License 2.0</a>\r
-</td>\r
-<td> 3.1.0\r
-</td></tr>\r
-<tr>\r
 <td valign="top"> <a rel="nofollow" class="external text" href="https://poi.apache.org/">Apache POI</a>\r
 </td>\r
 <td> <a href="#Apache_Software_License_2.0">Apache Software License 2.0</a>\r
@@ -355,14 +335,6 @@ Copyright (c) 2011-2016, Yann Collet</pre>
 <td> 3.15\r
 </td></tr>\r
 <tr>\r
-<td valign="top"> <a rel="nofollow" class="external text" href="http://www.antlr3.org/">ANTLR v3</a>\r
-</td>\r
-<td> <a href="#BSD_3-Clause_License">BSD 3-Clause License</a> (<a rel="nofollow" class="external free" href="http://www.antlr3.org/license.html">http://www.antlr3.org/license.html</a>)\r
-</td>\r
-<td> 3.5.2\r
-<pre>Copyright (c) 2010 Terence Parr</pre>\r
-</td></tr>\r
-<tr>\r
 <td valign="top"> <a rel="nofollow" class="external text" href="https://lucene.apache.org/core/">Apache Lucene Core</a>\r
 </td>\r
 <td> <a href="#Apache_Software_License_2.0">Apache Software License 2.0</a>\r
@@ -384,6 +356,13 @@ Copyright (c) 2011-2016, Yann Collet</pre>
 <td> 2.6.0, only needed by Apache POI\r
 </td></tr>\r
 <tr>\r
+<td> <a rel="nofollow" class="external text" href="http://aries.apache.org/">Aries</a>\r
+</td>\r
+<td> <a href="#Apache_Software_License_2.0">Apache Software License 2.0</a>\r
+</td>\r
+<td>\r
+</td></tr>\r
+<tr>\r
 <td valign="top"> <a rel="nofollow" class="external text" href="https://github.com/virtuald/curvesapi">curvesapi</a>\r
 </td>\r
 <td> <a href="#BSD_3-Clause_License">BSD 3-Clause License</a> (<a rel="nofollow" class="external free" href="https://github.com/virtuald/curvesapi/blob/master/license.txt">https://github.com/virtuald/curvesapi/blob/master/license.txt</a>), <a href="#Apache_Software_License_2.0">Apache Software License 2.0</a>\r
index 9534f71fb89e04793f90ad84a5a2d9b8ee18efef..4d84e674f80ed65fb8998e65b8db9df61862791a 100644 (file)
@@ -42,6 +42,7 @@
         <ini4j.version>0.5.4</ini4j.version>
         <commons-collections.version>4.4</commons-collections.version>
         <commons-compress.version>1.20</commons-compress.version>
+        <commons-csv.version>1.6</commons-csv.version>
         <commons-lang.version>2.6</commons-lang.version>
         <commons-logging.version>1.2</commons-logging.version>
         <commons-io.version>1.4</commons-io.version>
                                         <Bundle-SymbolicName>org.apache.commons.compress</Bundle-SymbolicName>
                                     </instructions>
                                 </artifact>
+                                <artifact>
+                                    <id>org.apache.commons:commons-csv:${commons-csv.version}</id>
+                                    <source>true</source>
+                                </artifact>
                                 <artifact>
                                     <id>commons-lang:commons-lang:${commons-lang.version}</id>
                                     <source>true</source>
index 708e508ed9f21d1291dba93699c794f2d9adf348..6500ce550c84a4d30a4b62d8cacc05b44848dad6 100644 (file)
       <unit id="org.apache.commons.collections4.source" version="4.1.0"/>
       <unit id="org.apache.commons.compress" version="1.20.0"/>
       <unit id="org.apache.commons.compress.source" version="1.20.0"/>
+      <unit id="org.apache.commons.csv" version="1.6.0"/>
+      <unit id="org.apache.commons.csv.source" version="1.6.0"/>
       <unit id="org.apache.commons.io" version="2.4.0"/>
       <unit id="org.apache.commons.io.source" version="2.4.0"/>
       <unit id="org.apache.commons.lang" version="2.6.0"/>
index 6a0428e20586c934171ff043f0a2a125e99e7324..7494c798142049c0fbe8f943c168e766222bbb2b 100644 (file)
@@ -282,6 +282,8 @@ location "http://www.simantics.org/download/master/external-components/maven/" {
        org.apache.commons.collections4.source
        org.apache.commons.compress
        org.apache.commons.compress.source
+       org.apache.commons.csv
+       org.apache.commons.csv.source
        org.apache.commons.io
        org.apache.commons.io.source
        org.apache.commons.lang
index 10ff40e65a91788d1f415c2b2d9ec0664f28ed7f..2e8f54c2de717124ebc73e6aa1ae50d95c76245b 100644 (file)
       <unit id="org.apache.commons.collections4.source" version="4.1.0"/>
       <unit id="org.apache.commons.compress" version="1.20.0"/>
       <unit id="org.apache.commons.compress.source" version="1.20.0"/>
+      <unit id="org.apache.commons.csv" version="1.6.0"/>
+      <unit id="org.apache.commons.csv.source" version="1.6.0"/>
       <unit id="org.apache.commons.io" version="2.4.0"/>
       <unit id="org.apache.commons.io.source" version="2.4.0"/>
       <unit id="org.apache.commons.lang" version="2.6.0"/>
index 71a1b9653ddee36957cd9e8daece5dee6fb6db5f..1d23305664e38f93d743e1a49eb3790119b72455 100644 (file)
@@ -13,7 +13,6 @@ Require-Bundle: org.eclipse.core.runtime,
  org.simantics.db.management;bundle-version="0.8.0",
  gnu.trove3;bundle-version="3.0.3",
  org.simantics.fastlz;bundle-version="1.0.0",
- org.apache.log4j;bundle-version="1.2.15",
  org.simantics.db.impl;bundle-version="0.8.0",
  org.simantics.db.layer0;bundle-version="0.8.0",
  org.simantics.project;bundle-version="1.0.1",
index 05804fb8403173a2b5c57c317e3cea115ce5c1c4..80b7f7b9d61496a6e06c4461762c9423f7e84dfb 100644 (file)
        <property name="classes.dir" value="classes.dir" />
        <property name="databoard.jar" value="org.simantics.databoard_0.5.2.jar" />
        <property name="trove.jar" value="gnu.trove2_2.0.4.jar" />
-       <property name="log4j.jar" value="org.apache.log4j_1.2.15.20080201.jar" />
        <property name="db.jar" value="db-connector-${version}.jar" />
        <property name="installer.jar" value="installer.jar" />
 
-       <property name="classpath-javac" value="${installer.dir}${db.jar}:${installer.dir}${databoard.jar}:${installer.dir}${trove.jar}:${installer.dir}${log4j.jar}" />
-       <property name="classpath-manifest" value="${db.jar} ${databoard.jar} ${trove.jar} ${log4j.jar}" />
+       <property name="classpath-javac" value="${installer.dir}${db.jar}:${installer.dir}${databoard.jar}:${installer.dir}${trove.jar}" />
+       <property name="classpath-manifest" value="${db.jar} ${databoard.jar} ${trove.jar}" />
 
        <target name="clean">
                <delete dir="${classes.dir}" quiet="true" />
        <target name="trove.dir" if="plugin.dir">
                <copy file="${plugin.dir}${trove.jar}" toDir="${installer.dir}" />
        </target>
-       
-       <target name="log4j.jar" if="plugin.dir">
-               <copy file="${plugin.dir}${log4j.jar}" toDir="${installer.dir}" />
-       </target>
 
        <target name="db.jar" depends="clean">
                <property name="origin.dir" value="../"/>
index da0a86faa7699924535531d815b0debb37f0b05d..4c6a1daf9481466637d0f802fb073856af43a7ac 100644 (file)
                                <include name="eclipse/plugins/org.eclipse.osgi_*.jar" />
                                <include name="external/plugins/gnu.trove*.jar" />
                                <include name="external/plugins/org.apache.commons.collections_*.jar" />
-                               <include name="external/plugins/org.apache.log4j_*.jar" />
                                <include name="external/plugins/org.apache.commons.io_*.jar" />
                                <include name="simantics/plugins/org.simantics.databoard_*.jar" />
                                <include name="simantics/plugins/org.simantics.db.layer0_*.jar" />