]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db/src/org/simantics/db/service/VirtualGraphSupport.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / service / VirtualGraphSupport.java
diff --git a/bundles/org.simantics.db/src/org/simantics/db/service/VirtualGraphSupport.java b/bundles/org.simantics.db/src/org/simantics/db/service/VirtualGraphSupport.java
new file mode 100644 (file)
index 0000000..a1512ec
--- /dev/null
@@ -0,0 +1,116 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.db.service;\r
+\r
+import java.util.Collection;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.ServiceLocator;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.Statement;\r
+import org.simantics.db.VirtualGraph;\r
+import org.simantics.db.VirtualGraph.Persistency;\r
+import org.simantics.db.WriteOnlyGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+\r
+/**\r
+ * A {@link Session} service for working with virtual graphs. Virtual graphs\r
+ * offer a way to augment the persistent graph database with\r
+ * memory/workspace-persistent information. Use\r
+ * {@link ServiceLocator#getService(Class)} to retrieve this support from a\r
+ * {@link Session}.\r
+ * \r
+ * See <a href="http://dev.simantics.org/index.php/Virtual_Graphs">Simantics\r
+ * developer wiki</a> for documentation.\r
+ * \r
+ * @author Antti Villberg\r
+ */\r
+public interface VirtualGraphSupport {\r
+\r
+    /**\r
+     * Gets previously initialized or creates new memory-persistent\r
+     * (session-transient) virtual graph by the specified identifier.\r
+     * \r
+     * The contents of memory-persistent graphs are lost\r
+     * when the session finishes.\r
+     * \r
+     * @param identifier memory-persistent virtual graph identifier\r
+     */\r
+    VirtualGraph getMemoryPersistent(String identifier);\r
+\r
+    /**\r
+     * First tries to return a previously loaded workspace-persistent graph by\r
+     * identifier. Then tries to restore the graph from disk by identifier.\r
+     * Finally creates a new workspace-persistent graph.\r
+     * \r
+     * The graph is automatically persisted to disk.\r
+     * \r
+     * @param identifier workspace-persistent virtual graph identifier\r
+     */\r
+    VirtualGraph getWorkspacePersistent(String identifier);\r
+\r
+    /**\r
+     * Removes this graph from the set of active graphs. If the graph is\r
+     * workspace persistent, the contents are deleted from disk.\r
+     * \r
+     * @return <code>true</code> if the virtual graph was properly discarded\r
+     */\r
+    boolean discard(VirtualGraph graph);\r
+\r
+    /**\r
+     * Transfers the contents of this virtual graph into the persistent store\r
+     * \r
+     * @return <code>true</code> if the virtual graph was properly integrated\r
+     */\r
+    boolean integrate(WriteOnlyGraph graph, VirtualGraph vg) throws DatabaseException;\r
+    \r
+    /**\r
+     * Lists all active virtual graphs currently attached to the owner database\r
+     * session.\r
+     * \r
+     * @return list of active virtual graphs\r
+     */\r
+    Collection<VirtualGraph> listGraphs();\r
+\r
+    /**\r
+     * List all statements in the specified virtual graph.\r
+     * \r
+     * @param graph the virtual graph to get statements from\r
+     * @return statements in the specified virtual graph\r
+     */\r
+    Collection<Statement> listStatements(VirtualGraph graph);\r
+\r
+    /**\r
+     * List all resources that contain literal values in the specified virtual\r
+     * graph.\r
+     * \r
+     * @param graph the virtual graph to get resources from\r
+     * @return resources in the specified virtual graph containing literals\r
+     */\r
+    Collection<Resource> listValues(VirtualGraph graph);\r
+    \r
+    VirtualGraph getGraph(ReadGraph graph, Resource subject, Resource predicate, Resource object) throws DatabaseException;\r
+\r
+    VirtualGraph getGraph(ReadGraph graph, Resource subject, Resource predicate) throws DatabaseException;\r
+\r
+    VirtualGraph getGraph(ReadGraph graph, Resource subject) throws DatabaseException;\r
+\r
+    /**\r
+     * A simple method for persisting the current state of all managed virtual\r
+     * graphs where {@link VirtualGraph#getPersistency()} is\r
+     * {@link Persistency#WORKSPACE}.\r
+     */\r
+    void saveAll() throws DatabaseException;\r
+\r
+}\r