/** * Construct a Neo4jGraph instance by specifying the directory to create the database in.. */ public static Neo4jGraph open(final String directory) { final Configuration config = new BaseConfiguration(); config.setProperty(CONFIG_DIRECTORY, directory); return open(config); }
/** * Execute the Cypher query and get the result set as a {@link GraphTraversal}. * * @param query the Cypher query to execute * @return a fluent Gremlin traversal */ public <S, E> GraphTraversal<S, E> cypher(final String query) { return cypher(query, Collections.emptyMap()); }
return IteratorUtils.filter(graph.vertices(ids), vertex -> HasContainer.testAll(vertex, hasContainers)); graph.tx().readWrite(); if (graph.getBaseGraph().hasSchemaIndex(label.get(), hasContainer.getKey())) { return IteratorUtils.stream(graph.getBaseGraph().findNodes(label.get(), hasContainer.getKey(), hasContainer.getValue())) .map(node -> (Vertex) new Neo4jVertex(node, graph)) .filter(vertex -> HasContainer.testAll(vertex, hasContainers)).iterator(); return IteratorUtils.stream(graph.getBaseGraph().findNodes(label.get())) .map(node -> (Vertex) new Neo4jVertex(node, graph)) .filter(vertex -> HasContainer.testAll(vertex, hasContainers)).iterator(); } else { return IteratorUtils.filter(graph.vertices(), vertex -> HasContainer.testAll(vertex, hasContainers));
@Override public Iterator<Vertex> vertices(final Object... vertexIds) { this.tx().readWrite(); final Predicate<Neo4jNode> nodePredicate = this.trait.getNodePredicate(); if (0 == vertexIds.length) { return IteratorUtils.stream(this.getBaseGraph().allNodes()) .filter(nodePredicate) .map(node -> (Vertex) new Neo4jVertex(node, this)).iterator();
@Override public String label() { this.graph.tx().readWrite(); return String.join(LABEL_DELIMINATOR, this.labels()); }
protected Neo4jGraphVariables(final Neo4jGraph graph) { this.graph = graph; baseGraph = graph.getBaseGraph(); }
@Override public void stop() throws Exception { LOG.info("Stopping database"); graph.close(); graphDatabase.shutdown(); LOG.info("Database stopped"); }
private Vertex nodeToVertex(final Node node) { return getNeo4jGraph().vertices(node.getId()).next(); }
@Override public Set<String> keys() { this.graph.tx().readWrite(); final Set<String> keys = new HashSet<>(); for (final String key : this.baseElement.getKeys()) { if (!Graph.Hidden.isHidden(key)) keys.add(key); } return Collections.unmodifiableSet(keys); }
@Override public Iterator<Edge> edges(final Object... edgeIds) { this.tx().readWrite(); final Predicate<Neo4jRelationship> relationshipPredicate = this.trait.getRelationshipPredicate(); if (0 == edgeIds.length) { return IteratorUtils.stream(this.getBaseGraph().allRelationships()) .filter(relationshipPredicate) .map(relationship -> (Edge) new Neo4jEdge(relationship, this)).iterator();
@Override public void doOpen() { threadLocalTx.set(getBaseGraph().tx()); }
@Override public void shutdown() { try { getNeo4jGraph().close(); } catch (Exception e) { SemanticSynchrony.getLogger().log(Level.WARNING, "failed to shut down Neo4j graph properly", e); } }
@Override public <R> Optional<R> get(final String key) { this.graph.tx().readWrite(); return this.baseGraph.hasProperty(key) ? Optional.of((R) this.baseGraph.getProperty(key)) : Optional.<R>empty(); }
private static Graph createGraph(final File dataDir) { if (!dataDir.exists()) { createAndShutdownGraphDatabaseService(dataDir); } return Neo4jGraph.open(dataDir.getAbsolutePath()); }
return IteratorUtils.filter(graph.vertices(ids), vertex -> HasContainer.testAll(vertex, hasContainers)); graph.tx().readWrite(); if (graph.getBaseGraph().hasSchemaIndex(label.get(), hasContainer.getKey())) { return Stream.concat( IteratorUtils.stream(graph.getBaseGraph().findNodes(label.get(), hasContainer.getKey(), hasContainer.getValue())) .filter(getNodePredicate()) .map(node -> (Vertex) new Neo4jVertex(node, graph)) .filter(vertex -> HasContainer.testAll(vertex, hasContainers)), IteratorUtils.stream(graph.getBaseGraph().findNodes(VERTEX_PROPERTY_LABEL, hasContainer.getKey(), hasContainer.getValue())) // look up indexed vertex property nodes .map(node -> node.relationships(Neo4jDirection.INCOMING).iterator().next().start()) .map(node -> (Vertex) new Neo4jVertex(node, graph)) return IteratorUtils.stream(graph.getBaseGraph().findNodes(label.get())) .filter(getNodePredicate()) .map(node -> (Vertex) new Neo4jVertex(node, graph)) } else { return IteratorUtils.filter(graph.vertices(), vertex -> HasContainer.testAll(vertex, hasContainers));
@Override public Iterator<Vertex> vertices(final Object... vertexIds) { this.tx().readWrite(); final Predicate<Neo4jNode> nodePredicate = this.trait.getNodePredicate(); if (0 == vertexIds.length) { return IteratorUtils.stream(this.getBaseGraph().allNodes()) .filter(nodePredicate) .map(node -> (Vertex) new Neo4jVertex(node, this)).iterator();
protected Neo4jGraphVariables(final Neo4jGraph graph) { this.graph = graph; baseGraph = graph.getBaseGraph(); }
/** * Execute the Cypher query and get the result set as a {@link GraphTraversal}. * * @param query the Cypher query to execute * @return a fluent Gremlin traversal */ public <S, E> GraphTraversal<S, E> cypher(final String query) { return cypher(query, Collections.emptyMap()); }
@Override public Set<String> keys() { this.graph.tx().readWrite(); final Set<String> keys = new HashSet<>(); for (final String key : this.baseGraph.getKeys()) { if (!Graph.Hidden.isHidden(key)) keys.add(key); } return keys; }
@Override public Graph openDatabase(String databasePath) { LOGGER.entering(getClass().getName(), "openDatabase"); g = Neo4jGraph.open(databasePath); return g; }