@Override public String label() { this.graph.tx().readWrite(); return String.join(LABEL_DELIMINATOR, this.labels()); }
@Override public Map<String, T> next() { return this.iterator.next().entrySet().stream().collect(Collectors.toMap( Map.Entry::getKey, entry -> { final T val = entry.getValue(); if (Neo4jNode.class.isAssignableFrom(val.getClass())) { return (T) new Neo4jVertex((Neo4jNode) val, this.graph); } else if (Neo4jRelationship.class.isAssignableFrom(val.getClass())) { return (T) new Neo4jEdge((Neo4jRelationship) val, this.graph); } else { return val; } })); } }
@Override public <V> Iterator<VertexProperty<V>> getVertexProperties(final Neo4jVertex vertex, final String... keys) { return (Iterator) IteratorUtils.stream(vertex.getBaseVertex().getKeys()) .filter(key -> ElementHelper.keyExists(key, keys)) .map(key -> new Neo4jVertexProperty<>(vertex, key, (V) vertex.getBaseVertex().getProperty(key))).iterator(); }
@Override public Neo4jVertex next() { return new Neo4jVertex(this.relationshipIterator.next().other(getBaseVertex()), graph); } };
public static Vertex duplicateVertex(GraphTraversalSource traversal, Vertex vertex, IndexHandler indexHandler) { Vertex duplicate = traversal.addV().next(); for (Iterator<VertexProperty<Object>> properties = vertex.properties(); properties.hasNext(); ) { VertexProperty<Object> property = properties.next(); duplicate.property(property.key(), property.value()); } for (String label : ((Neo4jVertex) vertex).labels()) { ((Neo4jVertex) duplicate).addLabel(label); } moveIncomingEdges(vertex, duplicate, indexHandler); moveOutgoingEdges(vertex, duplicate, indexHandler); vertex.property(IS_LATEST, false); duplicate.property(IS_LATEST, true); vertex.addEdge(VERSION_OF, duplicate); return duplicate; }
final Optional<VertexProperty<V>> optionalVertexProperty = ElementHelper.stageVertexProperty(vertex, cardinality, key, value, keyValues); if (optionalVertexProperty.isPresent()) return optionalVertexProperty.get(); final Neo4jNode node = vertex.getBaseVertex(); final Neo4jGraphAPI graph = ((Neo4jGraph) vertex.graph()).getBaseGraph(); final String prefixedKey = Graph.Hidden.hide(key); if (node.hasProperty(key)) {
@Override public Object id() { // TODO: Neo4j needs a better ID system for VertexProperties return (long) (this.key.hashCode() + this.value.hashCode() + this.vertex.id().hashCode()); }
@Override public <V> VertexProperty<V> property(final String key, final V value) { return this.property(VertexProperty.Cardinality.single, key, value); }
public void handleRdfLabelRemove(Vertex vertex, String entityTypeName) { ((Neo4jVertex) vertex).removeLabel(entityTypeName); }
public void handleRdfLabelAdd(Vertex vertex, String entityTypeName) { ((Neo4jVertex) vertex).addLabel(entityTypeName); }
@Override public Neo4jVertex next() { return new Neo4jVertex(this.relationshipIterator.next().other(getBaseVertex()), graph); } };
final Optional<VertexProperty<V>> optionalVertexProperty = ElementHelper.stageVertexProperty(vertex, cardinality, key, value, keyValues); if (optionalVertexProperty.isPresent()) return optionalVertexProperty.get(); final Neo4jNode node = vertex.getBaseVertex(); final Neo4jGraphAPI graph = ((Neo4jGraph) vertex.graph()).getBaseGraph(); final String prefixedKey = Graph.Hidden.hide(key); if (node.hasProperty(key)) {
@Override public Object id() { // TODO: Neo4j needs a better ID system for VertexProperties return (long) (this.key.hashCode() + this.value.hashCode() + this.vertex.id().hashCode()); }
@Override public <V> VertexProperty<V> property(final String key, final V value) { return this.property(VertexProperty.Cardinality.single, key, value); }
@Override public void onRemoveFromCollection(Collection collection, Optional<Vertex> oldVertex, Vertex newVertex) { ((Neo4jVertex) newVertex).removeLabel(collection.getEntityTypeName()); }
@Override public void onAddToCollection(Collection collection, Optional<Vertex> oldVertex, Vertex newVertex) { ((Neo4jVertex) newVertex).addLabel(collection.getEntityTypeName()); }
public Set<String> labels() { this.graph.tx().readWrite(); final Set<String> labels = new TreeSet<>(this.getBaseVertex().labels()); return Collections.unmodifiableSet(labels); }
@Override public Vertex inVertex() { return new Neo4jVertex(this.getBaseEdge().end(), this.graph); }
@Override public String label() { this.graph.tx().readWrite(); return String.join(LABEL_DELIMINATOR, this.labels()); }
@Override public <V> Iterator<VertexProperty<V>> getVertexProperties(final Neo4jVertex vertex, final String... keys) { if (Neo4jHelper.isDeleted(vertex.getBaseVertex())) return Collections.emptyIterator(); // TODO: I believe its because the vertex property is deleted, but then seen again in the iterator. ? return IteratorUtils.stream(vertex.getBaseVertex().getKeys()) .filter(key -> ElementHelper.keyExists(key, keys)) .flatMap(key -> { if (vertex.getBaseVertex().getProperty(key).equals(VERTEX_PROPERTY_TOKEN)) return IteratorUtils.stream(vertex.getBaseVertex().relationships(Neo4jDirection.OUTGOING, Graph.Hidden.hide(key))) .map(relationship -> (VertexProperty<V>) new Neo4jVertexProperty<>(vertex, relationship.end())); else return Stream.of(new Neo4jVertexProperty<>(vertex, key, (V) vertex.getBaseVertex().getProperty(key))); }).iterator(); }