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