]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.db.service;\r
13 \r
14 import java.util.Collection;\r
15 \r
16 import org.simantics.db.ReadGraph;\r
17 import org.simantics.db.Resource;\r
18 import org.simantics.db.ServiceLocator;\r
19 import org.simantics.db.Session;\r
20 import org.simantics.db.Statement;\r
21 import org.simantics.db.VirtualGraph;\r
22 import org.simantics.db.VirtualGraph.Persistency;\r
23 import org.simantics.db.WriteOnlyGraph;\r
24 import org.simantics.db.exception.DatabaseException;\r
25 \r
26 \r
27 /**\r
28  * A {@link Session} service for working with virtual graphs. Virtual graphs\r
29  * offer a way to augment the persistent graph database with\r
30  * memory/workspace-persistent information. Use\r
31  * {@link ServiceLocator#getService(Class)} to retrieve this support from a\r
32  * {@link Session}.\r
33  * \r
34  * See <a href="http://dev.simantics.org/index.php/Virtual_Graphs">Simantics\r
35  * developer wiki</a> for documentation.\r
36  * \r
37  * @author Antti Villberg\r
38  */\r
39 public interface VirtualGraphSupport {\r
40 \r
41     /**\r
42      * Gets previously initialized or creates new memory-persistent\r
43      * (session-transient) virtual graph by the specified identifier.\r
44      * \r
45      * The contents of memory-persistent graphs are lost\r
46      * when the session finishes.\r
47      * \r
48      * @param identifier memory-persistent virtual graph identifier\r
49      */\r
50     VirtualGraph getMemoryPersistent(String identifier);\r
51 \r
52     /**\r
53      * First tries to return a previously loaded workspace-persistent graph by\r
54      * identifier. Then tries to restore the graph from disk by identifier.\r
55      * Finally creates a new workspace-persistent graph.\r
56      * \r
57      * The graph is automatically persisted to disk.\r
58      * \r
59      * @param identifier workspace-persistent virtual graph identifier\r
60      */\r
61     VirtualGraph getWorkspacePersistent(String identifier);\r
62 \r
63     /**\r
64      * Removes this graph from the set of active graphs. If the graph is\r
65      * workspace persistent, the contents are deleted from disk.\r
66      * \r
67      * @return <code>true</code> if the virtual graph was properly discarded\r
68      */\r
69     boolean discard(VirtualGraph graph);\r
70 \r
71     /**\r
72      * Transfers the contents of this virtual graph into the persistent store\r
73      * \r
74      * @return <code>true</code> if the virtual graph was properly integrated\r
75      */\r
76     boolean integrate(WriteOnlyGraph graph, VirtualGraph vg) throws DatabaseException;\r
77     \r
78     /**\r
79      * Lists all active virtual graphs currently attached to the owner database\r
80      * session.\r
81      * \r
82      * @return list of active virtual graphs\r
83      */\r
84     Collection<VirtualGraph> listGraphs();\r
85 \r
86     /**\r
87      * List all statements in the specified virtual graph.\r
88      * \r
89      * @param graph the virtual graph to get statements from\r
90      * @return statements in the specified virtual graph\r
91      */\r
92     Collection<Statement> listStatements(VirtualGraph graph);\r
93 \r
94     /**\r
95      * List all resources that contain literal values in the specified virtual\r
96      * graph.\r
97      * \r
98      * @param graph the virtual graph to get resources from\r
99      * @return resources in the specified virtual graph containing literals\r
100      */\r
101     Collection<Resource> listValues(VirtualGraph graph);\r
102     \r
103     VirtualGraph getGraph(ReadGraph graph, Resource subject, Resource predicate, Resource object) throws DatabaseException;\r
104 \r
105     VirtualGraph getGraph(ReadGraph graph, Resource subject, Resource predicate) throws DatabaseException;\r
106 \r
107     VirtualGraph getGraph(ReadGraph graph, Resource subject) throws DatabaseException;\r
108 \r
109     /**\r
110      * A simple method for persisting the current state of all managed virtual\r
111      * graphs where {@link VirtualGraph#getPersistency()} is\r
112      * {@link Persistency#WORKSPACE}.\r
113      */\r
114     void saveAll() throws DatabaseException;\r
115 \r
116 }\r