@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 <V> Property<V> setProperty(final Neo4jVertexProperty vertexProperty, final String key, final V value) { final Neo4jNode vertexPropertyNode = Neo4jHelper.getVertexPropertyNode(vertexProperty); if (null != vertexPropertyNode) { vertexPropertyNode.setProperty(key, value); return new Neo4jProperty<>(vertexProperty, key, value); } else { final Neo4jNode vertexNode = ((Neo4jVertex) vertexProperty.element()).getBaseVertex(); final Neo4jNode newVertexPropertyNode = ((WrappedGraph<Neo4jGraphAPI>) vertexProperty.element().graph()).getBaseGraph().createNode(VERTEX_PROPERTY_LABEL, vertexProperty.label()); newVertexPropertyNode.setProperty(T.key.getAccessor(), vertexProperty.key()); newVertexPropertyNode.setProperty(T.value.getAccessor(), vertexProperty.value()); newVertexPropertyNode.setProperty(vertexProperty.key(), vertexProperty.value()); newVertexPropertyNode.setProperty(key, value); vertexNode.connectTo(newVertexPropertyNode, Graph.Hidden.hide(vertexProperty.key())); vertexNode.setProperty(vertexProperty.key(), VERTEX_PROPERTY_TOKEN); Neo4jHelper.setVertexPropertyNode(vertexProperty, newVertexPropertyNode); return new Neo4jProperty<>(vertexProperty, key, value); } }
public Neo4jProperty(final Element element, final String key, final V value) { this.element = element; this.key = key; this.value = value; this.graph = element instanceof Neo4jVertexProperty ? ((Neo4jVertex) (((Neo4jVertexProperty) element).element())).graph : ((Neo4jElement) element).graph; }
@Override public <V> Iterator<Property<V>> getProperties(final Neo4jVertexProperty vertexProperty, final String... keys) { final Neo4jNode vertexPropertyNode = Neo4jHelper.getVertexPropertyNode(vertexProperty); if (null == vertexPropertyNode) return Collections.emptyIterator(); else return IteratorUtils.stream(vertexPropertyNode.getKeys()) .filter(key -> ElementHelper.keyExists(key, keys)) .filter(key -> !key.equals(vertexProperty.key())) .map(key -> (Property<V>) new Neo4jProperty<>(vertexProperty, key, (V) vertexPropertyNode.getProperty(key))).iterator(); }
@Override public void removeVertexProperty(final Neo4jVertexProperty vertexProperty) { final Neo4jNode vertexPropertyNode = Neo4jHelper.getVertexPropertyNode(vertexProperty); final Neo4jNode vertexNode = ((Neo4jVertex) vertexProperty.element()).getBaseVertex(); if (null == vertexPropertyNode) { if (vertexNode.degree(Neo4jDirection.OUTGOING, Graph.Hidden.hide(vertexProperty.key())) == 0) { if (vertexNode.hasProperty(vertexProperty.key())) vertexNode.removeProperty(vertexProperty.key()); } } else { vertexPropertyNode.relationships(Neo4jDirection.BOTH).forEach(Neo4jRelationship::delete); vertexPropertyNode.delete(); if (vertexNode.degree(Neo4jDirection.OUTGOING, Graph.Hidden.hide(vertexProperty.key())) == 0) { if (vertexNode.hasProperty(vertexProperty.key())) vertexNode.removeProperty(vertexProperty.key()); } } }
public Neo4jProperty(final Element element, final String key, final V value) { this.element = element; this.key = key; this.value = value; this.graph = element instanceof Neo4jVertexProperty ? ((Neo4jVertex) (((Neo4jVertexProperty) element).element())).graph : ((Neo4jElement) element).graph; }
@Override public <V> Iterator<Property<V>> getProperties(final Neo4jVertexProperty vertexProperty, final String... keys) { final Neo4jNode vertexPropertyNode = Neo4jHelper.getVertexPropertyNode(vertexProperty); if (null == vertexPropertyNode) return Collections.emptyIterator(); else return IteratorUtils.stream(vertexPropertyNode.getKeys()) .filter(key -> ElementHelper.keyExists(key, keys)) .filter(key -> !key.equals(vertexProperty.key())) .map(key -> (Property<V>) new Neo4jProperty<>(vertexProperty, key, (V) vertexPropertyNode.getProperty(key))).iterator(); }
@Override public <V> Property<V> setProperty(final Neo4jVertexProperty vertexProperty, final String key, final V value) { final Neo4jNode vertexPropertyNode = Neo4jHelper.getVertexPropertyNode(vertexProperty); if (null != vertexPropertyNode) { vertexPropertyNode.setProperty(key, value); return new Neo4jProperty<>(vertexProperty, key, value); } else { final Neo4jNode vertexNode = ((Neo4jVertex) vertexProperty.element()).getBaseVertex(); final Neo4jNode newVertexPropertyNode = ((WrappedGraph<Neo4jGraphAPI>) vertexProperty.element().graph()).getBaseGraph().createNode(VERTEX_PROPERTY_LABEL, vertexProperty.label()); newVertexPropertyNode.setProperty(T.key.getAccessor(), vertexProperty.key()); newVertexPropertyNode.setProperty(T.value.getAccessor(), vertexProperty.value()); newVertexPropertyNode.setProperty(vertexProperty.key(), vertexProperty.value()); newVertexPropertyNode.setProperty(key, value); vertexNode.connectTo(newVertexPropertyNode, Graph.Hidden.hide(vertexProperty.key())); vertexNode.setProperty(vertexProperty.key(), VERTEX_PROPERTY_TOKEN); Neo4jHelper.setVertexPropertyNode(vertexProperty, newVertexPropertyNode); return new Neo4jProperty<>(vertexProperty, key, value); } }
@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(); }
@Override public void removeVertexProperty(final Neo4jVertexProperty vertexProperty) { final Neo4jNode vertexPropertyNode = Neo4jHelper.getVertexPropertyNode(vertexProperty); final Neo4jNode vertexNode = ((Neo4jVertex) vertexProperty.element()).getBaseVertex(); if (null == vertexPropertyNode) { if (vertexNode.degree(Neo4jDirection.OUTGOING, Graph.Hidden.hide(vertexProperty.key())) == 0) { if (vertexNode.hasProperty(vertexProperty.key())) vertexNode.removeProperty(vertexProperty.key()); } } else { vertexPropertyNode.relationships(Neo4jDirection.BOTH).forEach(Neo4jRelationship::delete); vertexPropertyNode.delete(); if (vertexNode.degree(Neo4jDirection.OUTGOING, Graph.Hidden.hide(vertexProperty.key())) == 0) { if (vertexNode.hasProperty(vertexProperty.key())) vertexNode.removeProperty(vertexProperty.key()); } } }
@Override public <V> VertexProperty<V> getVertexProperty(final Neo4jVertex vertex, final String key) { final Neo4jNode node = vertex.getBaseVertex(); if (node.hasProperty(key)) { if (node.getProperty(key).equals(VERTEX_PROPERTY_TOKEN)) { if (node.degree(Neo4jDirection.OUTGOING, Graph.Hidden.hide(key)) > 1) throw Vertex.Exceptions.multiplePropertiesExistForProvidedKey(key); else { return (VertexProperty<V>) new Neo4jVertexProperty<>(vertex, node.relationships(Neo4jDirection.OUTGOING, Graph.Hidden.hide(key)).iterator().next().end()); } } else { return new Neo4jVertexProperty<>(vertex, key, (V) node.getProperty(key)); } } else return VertexProperty.<V>empty(); }
@Override public <V> VertexProperty<V> setVertexProperty(final Neo4jVertex vertex, final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) { if (cardinality != VertexProperty.Cardinality.single) throw VertexProperty.Exceptions.multiPropertiesNotSupported(); if (keyValues.length > 0) throw VertexProperty.Exceptions.metaPropertiesNotSupported(); try { vertex.getBaseVertex().setProperty(key, value); return new Neo4jVertexProperty<>(vertex, key, value); } catch (final IllegalArgumentException iae) { throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value, iae); } }
@Override public <V> VertexProperty<V> getVertexProperty(final Neo4jVertex vertex, final String key) { return vertex.getBaseVertex().hasProperty(key) ? new Neo4jVertexProperty<>(vertex, key, (V) vertex.getBaseVertex().getProperty(key)) : VertexProperty.<V>empty(); }
vertexPropertyNode.setProperty(key, value); node.connectTo(vertexPropertyNode, prefixedKey); final Neo4jVertexProperty<V> property = new Neo4jVertexProperty<>(vertex, key, value, vertexPropertyNode); vertexPropertyNode.setProperty(key, value); node.connectTo(vertexPropertyNode, prefixedKey); final Neo4jVertexProperty<V> property = new Neo4jVertexProperty<>(vertex, key, value, vertexPropertyNode); final Neo4jVertexProperty<V> property = new Neo4jVertexProperty<>(vertex, key, value);
@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 <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(); }
@Override public <V> VertexProperty<V> getVertexProperty(final Neo4jVertex vertex, final String key) { final Neo4jNode node = vertex.getBaseVertex(); if (node.hasProperty(key)) { if (node.getProperty(key).equals(VERTEX_PROPERTY_TOKEN)) { if (node.degree(Neo4jDirection.OUTGOING, Graph.Hidden.hide(key)) > 1) throw Vertex.Exceptions.multiplePropertiesExistForProvidedKey(key); else { return (VertexProperty<V>) new Neo4jVertexProperty<>(vertex, node.relationships(Neo4jDirection.OUTGOING, Graph.Hidden.hide(key)).iterator().next().end()); } } else { return new Neo4jVertexProperty<>(vertex, key, (V) node.getProperty(key)); } } else return VertexProperty.<V>empty(); }
@Override public <V> VertexProperty<V> setVertexProperty(final Neo4jVertex vertex, final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) { if (cardinality != VertexProperty.Cardinality.single) throw VertexProperty.Exceptions.multiPropertiesNotSupported(); if (keyValues.length > 0) throw VertexProperty.Exceptions.metaPropertiesNotSupported(); try { vertex.getBaseVertex().setProperty(key, value); return new Neo4jVertexProperty<>(vertex, key, value); } catch (final IllegalArgumentException iae) { throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value, iae); } }