use of org.janusgraph.graphdb.management.JanusGraphManager in project janusgraph by JanusGraph.
the class ConfiguredGraphFactory method open.
/**
* Open a {@link JanusGraph} using a previously created Configuration using the
* {@link ConfigurationManagementGraph} API. A corresponding configuration must exist.
*
* <p>NOTE: If your configuration corresponding to this graph does not contain information about
* the backend's keyspace/table/storage directory, then we set the keyspace/table to the
* graphName or set the storage directory to the storage_root + /graphName.</p>
*
* @param graphName
*
* @return JanusGraph
*/
public static JanusGraph open(String graphName) {
final ConfigurationManagementGraph configManagementGraph = getConfigGraphManagementInstance();
final Map<String, Object> graphConfigMap = configManagementGraph.getConfiguration(graphName);
Preconditions.checkNotNull(graphConfigMap, "Please create configuration for this graph using the ConfigurationManagementGraph#createConfiguration API.");
final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance();
Preconditions.checkNotNull(jgm, JANUS_GRAPH_MANAGER_EXPECTED_STATE_MSG);
final CommonsConfiguration config = new CommonsConfiguration(ConfigurationUtil.loadMapConfiguration(graphConfigMap));
return (JanusGraph) jgm.openGraph(graphName, (String gName) -> new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(config)));
}
use of org.janusgraph.graphdb.management.JanusGraphManager in project janusgraph by JanusGraph.
the class JanusGraphFactory method drop.
/**
* Drop graph database, deleting all data in storage and indexing backends. Graph can be open or closed (will be
* closed as part of the drop operation). The graph is also removed from the {@link JanusGraphManager}
* graph reference tracker, if there.
*
* <p><b>WARNING: This is an irreversible operation that will delete all graph and index data.</b></p>
* @param graph JanusGraph graph database. Can be open or closed.
* @throws BackendException If an error occurs during deletion
*/
public static void drop(JanusGraph graph) throws BackendException {
Preconditions.checkNotNull(graph);
Preconditions.checkArgument(graph instanceof StandardJanusGraph, "Invalid graph instance detected: %s", graph.getClass());
final StandardJanusGraph g = (StandardJanusGraph) graph;
final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance();
if (jgm != null) {
jgm.removeGraph(g.getGraphName());
jgm.removeTraversalSource(ConfiguredGraphFactory.toTraversalSourceName(g.getGraphName()));
}
if (graph.isOpen()) {
graph.close();
}
final GraphDatabaseConfiguration config = g.getConfiguration();
final Backend backend = config.getBackend();
try {
backend.clearStorage();
} finally {
IOUtils.closeQuietly(backend);
}
}
Aggregations