@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; }
/** * Get the {@link VertexProperty} for the provided key. If the property does not exist, return * {@link VertexProperty#empty}. If there are more than one vertex properties for the provided * key, then throw {@link Vertex.Exceptions#multiplePropertiesExistForProvidedKey}. * * @param key the key of the vertex property to get * @param <V> the expected type of the vertex property value * @return the retrieved vertex property */ @Override public default <V> VertexProperty<V> property(final String key) { final Iterator<VertexProperty<V>> iterator = this.properties(key); if (iterator.hasNext()) { final VertexProperty<V> property = iterator.next(); if (iterator.hasNext()) throw Vertex.Exceptions.multiplePropertiesExistForProvidedKey(key); else return property; } else { return VertexProperty.<V>empty(); } }
@Test @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES, supported = false) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) public void shouldSupportAddEdgesIfEdgeCanBeAdded() throws Exception { try { final Vertex v = graph.addVertex(); v.addEdge("friend", v); fail(String.format(INVALID_FEATURE_SPECIFICATION, EdgeFeatures.class.getSimpleName(), EdgeFeatures.FEATURE_ADD_EDGES)); } catch (Exception e) { validateException(Vertex.Exceptions.edgeAdditionsNotSupported(), e); } }
fail("This should throw a: " + Vertex.Exceptions.multiplePropertiesExistForProvidedKey("name")); } catch (final Exception e) { validateException(Vertex.Exceptions.multiplePropertiesExistForProvidedKey("name"), e);
throw Vertex.Exceptions.userSuppliedIdsOfThisTypeNotSupported();
throw Vertex.Exceptions.userSuppliedIdsOfThisTypeNotSupported();
throw Vertex.Exceptions.userSuppliedIdsNotSupported();
throw Vertex.Exceptions.userSuppliedIdsNotSupported();
throw Vertex.Exceptions.userSuppliedIdsNotSupported();
public TitanVertex addVertex(Object... keyValues) { ElementHelper.legalPropertyKeyValueArray(keyValues); if (ElementHelper.getIdValue(keyValues).isPresent()) throw Vertex.Exceptions.userSuppliedIdsNotSupported(); Object labelValue = null; for (int i = 0; i < keyValues.length; i = i + 2) {
boolean userProvidedId = true; if (id != null && id instanceof String == false) { throw Vertex.Exceptions.userSuppliedIdsOfThisTypeNotSupported();
throw Vertex.Exceptions.userSuppliedIdsNotSupported();
@Override public <V> DuctileVertexProperty<V> property(Cardinality cardinality, String key, V value, Object... keyValues) { if (cardinality != VertexProperty.Cardinality.single) { throw VertexProperty.Exceptions.multiPropertiesNotSupported(); } if (keyValues.length > 0) { throw VertexProperty.Exceptions.metaPropertiesNotSupported(); } ElementHelper.validateProperty(key, value); if (ElementHelper.getIdValue(keyValues).isPresent()) throw Vertex.Exceptions.userSuppliedIdsNotSupported(); graph().tx().readWrite(); try { if (value == null) { getBaseVertex().removeProperty(key); } else { getBaseVertex().setProperty(key, value); } return new DuctileVertexProperty<V>(this, key, value); } catch (final IllegalArgumentException iae) { throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value); } }
@Override public <V> VertexProperty<V> property(final String key) { if (this.removed) return VertexProperty.empty(); if (TinkerHelper.inComputerMode(this.graph)) { final List<VertexProperty> list = (List) this.graph.graphComputerView.getProperty(this, key); if (list.size() == 0) return VertexProperty.<V>empty(); else if (list.size() == 1) return list.get(0); else throw Vertex.Exceptions.multiplePropertiesExistForProvidedKey(key); } else { if (this.properties != null && this.properties.containsKey(key)) { final List<VertexProperty> list = (List) this.properties.get(key); if (list.size() > 1) throw Vertex.Exceptions.multiplePropertiesExistForProvidedKey(key); else return list.get(0); } else return VertexProperty.<V>empty(); } }
/** * Get the {@link VertexProperty} for the provided key. If the property does not exist, return * {@link VertexProperty#empty}. If there are more than one vertex properties for the provided * key, then throw {@link Vertex.Exceptions#multiplePropertiesExistForProvidedKey}. * * @param key the key of the vertex property to get * @param <V> the expected type of the vertex property value * @return the retrieved vertex property */ @Override public default <V> VertexProperty<V> property(final String key) { final Iterator<VertexProperty<V>> iterator = this.properties(key); if (iterator.hasNext()) { final VertexProperty<V> property = iterator.next(); if (iterator.hasNext()) throw Vertex.Exceptions.multiplePropertiesExistForProvidedKey(key); else return property; } else { return VertexProperty.<V>empty(); } }
@Override public <V> VertexProperty<V> property(final String key) { if (this.removed) return VertexProperty.empty(); if (TinkerHelper.inComputerMode(this.graph)) { final List<VertexProperty> list = (List) this.graph.graphComputerView.getProperty(this, key); if (list.size() == 0) return VertexProperty.<V>empty(); else if (list.size() == 1) return list.get(0); else throw Vertex.Exceptions.multiplePropertiesExistForProvidedKey(key); } else { if (this.properties != null && this.properties.containsKey(key)) { final List<VertexProperty> list = (List) this.properties.get(key); if (list.size() > 1) throw Vertex.Exceptions.multiplePropertiesExistForProvidedKey(key); else return list.get(0); } else return VertexProperty.<V>empty(); } }
@Override public Edge addEdge(String label, Vertex inVertex, Object... keyValues) { if (inVertex == null) throw new IllegalArgumentException("destination vertex is null"); checkArgument(!isNullOrEmpty(label), "label is invalid"); ElementHelper.legalPropertyKeyValueArray(keyValues); if (ElementHelper.getIdValue(keyValues).isPresent()) throw Vertex.Exceptions.userSuppliedIdsNotSupported(); if (Graph.Hidden.isHidden(label)) throw Element.Exceptions.labelCanNotBeAHiddenKey(label); graph.createEdgeClass(label); this.graph.tx().readWrite(); OEdge oEdge = getRawElement().addEdge(((OrientVertex) inVertex).getRawElement(), label); final OrientEdge edge = graph.elementFactory().wrapEdge(oEdge); edge.property(keyValues); edge.save(); return edge; }
@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(); }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_ANY_IDS, supported = false) public void shouldSupportUserSuppliedIdsOfTypeAny() throws Exception { try { final Date id = new Date(); graph.addVertex(T.id, id); // a graph can "allow" an id without internally supporting it natively and therefore doesn't need // to throw the exception if (!graph.features().vertex().willAllowId(id)) fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), FEATURE_ANY_IDS)); } catch (Exception e) { validateException(Vertex.Exceptions.userSuppliedIdsOfThisTypeNotSupported(), e); } }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_UUID_IDS, supported = false) public void shouldSupportUserSuppliedIdsOfTypeUuid() throws Exception { final UUID id = UUID.randomUUID(); // a graph can "allow" an id without internally supporting it natively and therefore doesn't need // to throw the exception assumeFalse(graph.features().vertex().willAllowId(id)); try { graph.addVertex(T.id, id); fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), FEATURE_UUID_IDS)); } catch (Exception e) { validateException(Vertex.Exceptions.userSuppliedIdsOfThisTypeNotSupported(), e); } }