@Override public String label() { this.graph.tx().readWrite(); return String.join(LABEL_DELIMINATOR, this.labels()); }
@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 <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(); }
@Override public <U> Iterator<Property<U>> properties(final String... propertyKeys) { this.vertex.graph.tx().readWrite(); return this.vertex.graph.trait.getProperties(this, propertyKeys); }
@Override public void remove() { this.vertex.graph.tx().readWrite(); this.vertex.graph.trait.removeVertexProperty(this); this.vertexPropertyNode= null; }
@Override public void remove() { this.graph.tx().readWrite(); this.graph.trait.removeVertex(this); }
@Override public <V> VertexProperty<V> property(final String key) { this.graph.tx().readWrite(); return this.graph.trait.getVertexProperty(this, key); }
/** * This implementation of {@code close} will also close the current transaction on the thread, but it * is up to the caller to deal with dangling transactions in other threads prior to calling this method. */ @Override public void close() throws Exception { this.tx().close(); if (this.baseGraph != null) this.baseGraph.shutdown(); }
@Override public <U> Property<U> property(final String key, final U value) { this.vertex.graph.tx().readWrite(); ElementHelper.validateProperty(key, value); return this.vertex.graph.trait.setProperty(this, key, value); }
@Override public String label() { this.graph.tx().readWrite(); return this.getBaseEdge().type(); }
public void removeLabel(final String label) { this.graph.tx().readWrite(); this.getBaseVertex().removeLabel(label); } //////////////////////////////////////////////////////////////////////////////////////
public void addLabel(final String label) { this.graph.tx().readWrite(); this.getBaseVertex().addLabel(label); }
@Override public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) { ElementHelper.validateProperty(key, value); if (ElementHelper.getIdValue(keyValues).isPresent()) throw Vertex.Exceptions.userSuppliedIdsNotSupported(); this.graph.tx().readWrite(); return this.graph.trait.setVertexProperty(this, cardinality, key, value, keyValues); }
@Override public Vertex addVertex(final Object... keyValues) { ElementHelper.legalPropertyKeyValueArray(keyValues); if (ElementHelper.getIdValue(keyValues).isPresent()) throw Vertex.Exceptions.userSuppliedIdsNotSupported(); this.tx().readWrite(); final Neo4jVertex vertex = new Neo4jVertex(this.baseGraph.createNode(ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL).split(Neo4jVertex.LABEL_DELIMINATOR)), this); ElementHelper.attachProperties(vertex, keyValues); return vertex; }
@Override public void remove() { if (this.removed) return; this.removed = true; this.graph.tx().readWrite(); final Neo4jEntity entity = this.element instanceof Neo4jVertexProperty ? ((Neo4jVertexProperty) this.element).vertexPropertyNode : ((Neo4jElement) this.element).getBaseElement(); if (entity.hasProperty(this.key)) { entity.removeProperty(this.key); } }
@Override public <V> Property<V> property(final String key) { this.graph.tx().readWrite(); if (this.baseElement.hasProperty(key)) return new Neo4jProperty<>(this, key, (V) this.baseElement.getProperty(key)); else return Property.empty(); }
@Override public <V> Iterator<Property<V>> properties(final String... propertyKeys) { this.graph.tx().readWrite(); Iterable<String> keys = this.baseElement.getKeys(); Iterator<String> filter = IteratorUtils.filter(keys.iterator(), key -> ElementHelper.keyExists(key, propertyKeys)); return IteratorUtils.map(filter, key -> new Neo4jProperty<>(this, key, (V) this.baseElement.getProperty(key))); }
@Override public <V> Property<V> property(final String key, final V value) { ElementHelper.validateProperty(key, value); this.graph.tx().readWrite(); try { this.baseElement.setProperty(key, value); return new Neo4jProperty<>(this, key, value); } catch (final IllegalArgumentException e) { throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value, e); } } }
/** * Execute the Cypher query with provided parameters and get the result set as a {@link GraphTraversal}. * * @param query the Cypher query to execute * @param parameters the parameters of the Cypher query * @return a fluent Gremlin traversal */ public <S, E> GraphTraversal<S, E> cypher(final String query, final Map<String, Object> parameters) { this.tx().readWrite(); final GraphTraversal.Admin<S, E> traversal = new DefaultGraphTraversal<>(this); traversal.addStep(new CypherStartStep(traversal, query, new Neo4jCypherIterator<>((Iterator) this.baseGraph.execute(query, parameters), this))); return traversal; }
@Override public Iterator<Vertex> vertices(final Direction direction) { this.graph.tx().readWrite(); switch (direction) { case OUT: return IteratorUtils.of(new Neo4jVertex(this.getBaseEdge().start(), this.graph)); case IN: return IteratorUtils.of(new Neo4jVertex(this.getBaseEdge().end(), this.graph)); default: return IteratorUtils.of(new Neo4jVertex(this.getBaseEdge().start(), this.graph), new Neo4jVertex(this.getBaseEdge().end(), this.graph)); } }