@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> getProperty(final Neo4jVertexProperty vertexProperty, final String key) { final Neo4jNode vertexPropertyNode = Neo4jHelper.getVertexPropertyNode(vertexProperty); if (null != vertexPropertyNode && vertexPropertyNode.hasProperty(key)) return new Neo4jProperty<>(vertexProperty, key, (V) vertexPropertyNode.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); } } }
@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> 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<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> getProperty(final Neo4jVertexProperty vertexProperty, final String key) { final Neo4jNode vertexPropertyNode = Neo4jHelper.getVertexPropertyNode(vertexProperty); if (null != vertexPropertyNode && vertexPropertyNode.hasProperty(key)) return new Neo4jProperty<>(vertexProperty, key, (V) vertexPropertyNode.getProperty(key)); else return Property.empty(); }
@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); } } }
@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); } }