public static void attachProperties(JanusGraphRelation element, Object... keyValues) { if (keyValues==null || keyValues.length==0) return; //Do nothing org.apache.tinkerpop.gremlin.structure.util.ElementHelper.legalPropertyKeyValueArray(keyValues); if (org.apache.tinkerpop.gremlin.structure.util.ElementHelper.getIdValue(keyValues).isPresent()) throw Edge.Exceptions.userSuppliedIdsNotSupported(); if (org.apache.tinkerpop.gremlin.structure.util.ElementHelper.getLabelValue(keyValues).isPresent()) throw new IllegalArgumentException("Cannot provide label as argument"); org.apache.tinkerpop.gremlin.structure.util.ElementHelper.attachProperties(element,keyValues); }
throw Edge.Exceptions.userSuppliedIdsNotSupported();
boolean userProvidedId = true; if (id != null && id instanceof String == false) { throw Edge.Exceptions.userSuppliedIdsOfThisTypeNotSupported();
throw Edge.Exceptions.userSuppliedIdsNotSupported();
throw Edge.Exceptions.userSuppliedIdsNotSupported();
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_ANY_IDS, supported = false) public void shouldSupportUserSuppliedIdsOfTypeAny() throws Exception { final Date id = new Date(); // a graph can "allow" an id without internally supporting it natively and therefore doesn't need // to throw the exception assumeFalse(graph.features().edge().willAllowId(id)); try { final Vertex v = graph.addVertex(); v.addEdge("test", v, T.id, id); fail(String.format(INVALID_FEATURE_SPECIFICATION, EdgeFeatures.class.getSimpleName(), FEATURE_ANY_IDS)); } catch (Exception e) { validateException(Edge.Exceptions.userSuppliedIdsOfThisTypeNotSupported(), e); } }
@Override public DuctileEdge addEdge(String label, Vertex inVertex, Object... keyValues) { if (null == inVertex) { throw Graph.Exceptions.argumentCanNotBeNull("inVertex"); } ElementHelper.validateLabel(label); ElementHelper.legalPropertyKeyValueArray(keyValues); if (ElementHelper.getIdValue(keyValues).isPresent()) { throw Edge.Exceptions.userSuppliedIdsNotSupported(); } graph().tx().readWrite(); DuctileDBEdge baseEdge = getBaseVertex().addEdge(label, ((DuctileVertex) inVertex).getBaseVertex(), Collections.emptyMap()); DuctileEdge edge = new DuctileEdge(baseEdge, graph()); ElementHelper.attachProperties(edge, keyValues); return edge; }
@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_NUMERIC_IDS, supported = false) public void shouldSupportUserSuppliedIdsOfTypeNumericInt() throws Exception { final int id = 123456; // a graph can "allow" an id without internally supporting it natively and therefore doesn't need // to throw the exception assumeFalse(graph.features().edge().willAllowId(id)); try { final Vertex v = graph.addVertex(); v.addEdge("test", v, T.id, id); fail(String.format(INVALID_FEATURE_SPECIFICATION, EdgeFeatures.class.getSimpleName(), FEATURE_NUMERIC_IDS)); } catch (Exception e) { validateException(Edge.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().edge().willAllowId(id)); try { final Vertex v = graph.addVertex(); v.addEdge("test", v, T.id, id); fail(String.format(INVALID_FEATURE_SPECIFICATION, EdgeFeatures.class.getSimpleName(), FEATURE_UUID_IDS)); } catch (Exception e) { validateException(Edge.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_NUMERIC_IDS, supported = false) public void shouldSupportUserSuppliedIdsOfTypeNumericLong() throws Exception { final long id = 123456l; // a graph can "allow" an id without internally supporting it natively and therefore doesn't need // to throw the exception assumeFalse(graph.features().edge().willAllowId(id)); try { final Vertex v = graph.addVertex(); v.addEdge("test", v, T.id, id); fail(String.format(INVALID_FEATURE_SPECIFICATION, EdgeFeatures.class.getSimpleName(), FEATURE_NUMERIC_IDS)); } catch (Exception e) { validateException(Edge.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_STRING_IDS, supported = false) public void shouldSupportUserSuppliedIdsOfTypeString() throws Exception { final String id = "this-is-a-valid-id"; // a graph can "allow" an id without internally supporting it natively and therefore doesn't need // to throw the exception assumeFalse(graph.features().edge().willAllowId(id)); try { final Vertex v = graph.addVertex(); v.addEdge("test", v, T.id, id); fail(String.format(INVALID_FEATURE_SPECIFICATION, EdgeFeatures.class.getSimpleName(), FEATURE_STRING_IDS)); } catch (Exception e) { validateException(Edge.Exceptions.userSuppliedIdsOfThisTypeNotSupported(), e); } }
@Test @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = EdgeFeatures.class, feature = EdgeFeatures.FEATURE_USER_SUPPLIED_IDS, supported = false) public void shouldSupportUserSuppliedIdsIfAnIdCanBeAssignedToEdge() throws Exception { try { final Vertex v = graph.addVertex(); v.addEdge("friend", v, T.id, graphProvider.convertId(99999943835l, Edge.class)); fail(String.format(INVALID_FEATURE_SPECIFICATION, EdgeFeatures.class.getSimpleName(), EdgeFeatures.FEATURE_USER_SUPPLIED_IDS)); } catch (Exception e) { validateException(Edge.Exceptions.userSuppliedIdsNotSupported(), e); } }
@Override public void remove() { throw Edge.Exceptions.edgeRemovalNotSupported(); }
@Override public void remove() { throw edgeRemovalNotSupported(); }
@Test @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_REMOVE_EDGES, supported = false) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) public void shouldSupportRemoveEdgesIfEdgeCanBeRemoved() throws Exception { try { final Vertex v = graph.addVertex(); v.addEdge("friend", v); v.remove(); fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), EdgeFeatures.FEATURE_REMOVE_EDGES)); } catch (Exception ex) { validateException(Edge.Exceptions.edgeRemovalNotSupported(), ex); } }
@Override public void remove() { if (this.baseElement instanceof Vertex) throw Vertex.Exceptions.vertexRemovalNotSupported(); else throw Edge.Exceptions.edgeRemovalNotSupported(); }
@Override public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) { if (null == inVertex) throw Graph.Exceptions.argumentCanNotBeNull("inVertex"); ElementHelper.validateLabel(label); ElementHelper.legalPropertyKeyValueArray(keyValues); if (ElementHelper.getIdValue(keyValues).isPresent()) throw Edge.Exceptions.userSuppliedIdsNotSupported(); this.graph.tx().readWrite(); final Neo4jNode node = (Neo4jNode) this.baseElement; final Neo4jEdge edge = new Neo4jEdge(node.connectTo(((Neo4jVertex) inVertex).getBaseVertex(), label), this.graph); ElementHelper.attachProperties(edge, keyValues); return edge; }
@Override public void remove() { throw Edge.Exceptions.edgeRemovalNotSupported(); }
@Test @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_USER_SUPPLIED_IDS, supported = false) public void shouldHaveExceptionConsistencyWhenIdNotSupportedForAddEdge() throws Exception { try { final Vertex v = this.graph.addVertex(); v.addEdge("self", v, T.id, ""); fail("Call to addEdge should have thrown an exception when ID was specified as it is not supported"); } catch (Exception ex) { validateException(Edge.Exceptions.userSuppliedIdsNotSupported(), ex); } }
@Override public void remove() { throw Edge.Exceptions.edgeRemovalNotSupported(); }