1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.service;
14 import java.util.Collection;
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;
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
34 * See <a href="http://dev.simantics.org/index.php/Virtual_Graphs">Simantics
35 * developer wiki</a> for documentation.
37 * @author Antti Villberg
39 public interface VirtualGraphSupport {
42 * Gets previously initialized or creates new memory-persistent
43 * (session-transient) virtual graph by the specified identifier.
45 * The contents of memory-persistent graphs are lost
46 * when the session finishes.
48 * @param identifier memory-persistent virtual graph identifier
50 VirtualGraph getMemoryPersistent(String identifier);
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.
57 * The graph is automatically persisted to disk.
59 * @param identifier workspace-persistent virtual graph identifier
61 VirtualGraph getWorkspacePersistent(String identifier);
64 * Removes this graph from the set of active graphs. If the graph is
65 * workspace persistent, the contents are deleted from disk.
67 * @return <code>true</code> if the virtual graph was properly discarded
69 boolean discard(VirtualGraph graph);
72 * Transfers the contents of this virtual graph into the persistent store
74 * @return <code>true</code> if the virtual graph was properly integrated
76 boolean integrate(WriteOnlyGraph graph, VirtualGraph vg) throws DatabaseException;
79 * Lists all active virtual graphs currently attached to the owner database
82 * @return list of active virtual graphs
84 Collection<VirtualGraph> listGraphs();
87 * List all statements in the specified virtual graph.
89 * @param graph the virtual graph to get statements from
90 * @return statements in the specified virtual graph
92 Collection<Statement> listStatements(VirtualGraph graph);
95 * List all resources that contain literal values in the specified virtual
98 * @param graph the virtual graph to get resources from
99 * @return resources in the specified virtual graph containing literals
101 Collection<Resource> listValues(VirtualGraph graph);
103 VirtualGraph getGraph(ReadGraph graph, Resource subject, Resource predicate, Resource object) throws DatabaseException;
105 VirtualGraph getGraph(ReadGraph graph, Resource subject, Resource predicate) throws DatabaseException;
107 VirtualGraph getGraph(ReadGraph graph, Resource subject) throws DatabaseException;
110 * A simple method for persisting the current state of all managed virtual
111 * graphs where {@link VirtualGraph#getPersistency()} is
112 * {@link Persistency#WORKSPACE}.
114 void saveAll() throws DatabaseException;