Refine search
/** * Assign key/value pairs as properties to an {@link org.apache.tinkerpop.gremlin.structure.Vertex}. If the value of {@link T#id} or * {@link T#label} is in the set of pairs, then they are ignored. * The {@link org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality} of the key is determined from the {@link org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexFeatures}. * * @param vertex the graph vertex to assign the {@code propertyKeyValues} * @param propertyKeyValues the key/value pairs to assign to the {@code element} * @throws ClassCastException if the value of the key is not a {@link String} * @throws IllegalArgumentException if the value of {@code element} is null */ public static void attachProperties(final Vertex vertex, final Object... propertyKeyValues) { if (null == vertex) throw Graph.Exceptions.argumentCanNotBeNull("vertex"); for (int i = 0; i < propertyKeyValues.length; i = i + 2) { if (!propertyKeyValues[i].equals(T.id) && !propertyKeyValues[i].equals(T.label)) vertex.property(vertex.graph().features().vertex().getCardinality((String) propertyKeyValues[i]), (String) propertyKeyValues[i], propertyKeyValues[i + 1]); } }
/** * A {@link org.apache.tinkerpop.gremlin.structure.Graph} that does not support {@link org.apache.tinkerpop.gremlin.structure.Graph.Features.GraphFeatures#FEATURE_COMPUTER} must call * {@link org.apache.tinkerpop.gremlin.structure.Graph.Exceptions#graphComputerNotSupported()}. */ @Test @FeatureRequirement(featureClass = GraphFeatures.class, feature = FEATURE_COMPUTER, supported = false) public void shouldSupportComputerIfAGraphCanCompute() throws Exception { try { graph.compute(); fail(String.format(INVALID_FEATURE_SPECIFICATION, GraphFeatures.class.getSimpleName(), FEATURE_COMPUTER)); } catch (Exception e) { validateException(Graph.Exceptions.graphComputerNotSupported(), e); } }
/** * A {@link org.apache.tinkerpop.gremlin.structure.Graph} that does not support {@link org.apache.tinkerpop.gremlin.structure.Graph.Features.GraphFeatures#FEATURE_TRANSACTIONS} must call * {@link org.apache.tinkerpop.gremlin.structure.Graph.Exceptions#transactionsNotSupported()}. */ @Test @FeatureRequirement(featureClass = GraphFeatures.class, feature = FEATURE_TRANSACTIONS, supported = false) public void shouldSupportTransactionsIfAGraphConstructsATx() throws Exception { try { graph.tx(); fail(String.format(INVALID_FEATURE_SPECIFICATION, GraphFeatures.class.getSimpleName(), FEATURE_TRANSACTIONS)); } catch (Exception e) { validateException(Graph.Exceptions.transactionsNotSupported(), e); } }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_UPSERT, supported = false) public void shouldHaveExceptionConsistencyWhenAssigningSameIdOnVertex() { final Object o = graphProvider.convertId("1", Vertex.class); graph.addVertex(T.id, o, "name", "marko"); try { graph.addVertex(T.id, o, "name", "stephen"); fail("Assigning the same ID to an Element should throw an exception"); } catch (Exception ex) { assertThat(ex, instanceOf(Graph.Exceptions.vertexWithIdAlreadyExists(0).getClass())); } }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ANY_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_STRING_IDS) public void shouldNotMixTypesForGettingSpecificVerticesWithStringFirst() { final Vertex v1 = graph.addVertex(); try { graph.vertices(graphProvider.convertId("1", Vertex.class), v1); fail("Should have thrown an exception because id arguments were mixed."); } catch (Exception ex) { final Exception expected = Graph.Exceptions.idArgsMustBeEitherIdOrElement(); assertEquals(expected.getClass(), ex.getClass()); assertEquals(expected.getMessage(), ex.getMessage()); } }
@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 = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ANY_IDS) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_STRING_IDS) public void shouldNotMixTypesForGettingSpecificEdgesWithEdgeFirst() { final Vertex v = graph.addVertex(); final Edge e1 = v.addEdge("self", v); try { graph.edges(e1, graphProvider.convertId("1", Edge.class)); fail("Should have thrown an exception because id arguments were mixed."); } catch (Exception ex) { final Exception expected = Graph.Exceptions.idArgsMustBeEitherIdOrElement(); assertEquals(expected.getClass(), ex.getClass()); assertEquals(expected.getMessage(), ex.getMessage()); } }
/** * A {@link org.apache.tinkerpop.gremlin.structure.Graph} that does not support {@link org.apache.tinkerpop.gremlin.structure.Graph.Features.VariableFeatures#FEATURE_VARIABLES} must call * {@link org.apache.tinkerpop.gremlin.structure.Graph.Exceptions#variablesNotSupported()}. */ @Test @FeatureRequirement(featureClass = Graph.Features.VariableFeatures.class, feature = FEATURE_VARIABLES, supported = false) public void shouldSupportMemoryIfAGraphAcceptsMemory() throws Exception { try { graph.variables(); fail(String.format(INVALID_FEATURE_SPECIFICATION, Graph.Features.VariableFeatures.class.getSimpleName(), FEATURE_VARIABLES)); } catch (Exception e) { validateException(Graph.Exceptions.variablesNotSupported(), e); } }
@Override public <C extends GraphComputer> C compute(Class<C> graphComputerClass) throws IllegalArgumentException { if (!graphComputerClass.equals(FulgoraGraphComputer.class)) { throw Graph.Exceptions.graphDoesNotSupportProvidedGraphComputer(graphComputerClass); } else { return (C)compute(); } }
public static void verifyArgsMustBeEitherIdorElement(Object... ids) { assert ids.length>0; int numElements = 0; for (int i = 0; i < ids.length; i++) { if (ids[i] instanceof Element) numElements++; } if (numElements>0 && numElements<ids.length) throw Graph.Exceptions.idArgsMustBeEitherIdOrElement(); } }
/** * This is essentially an adjusted copy&paste from TinkerPop's ElementHelper class. * The reason for copying it is so that we can determine the cardinality of a property key based on * Titan's schema which is tied to this particular transaction and not the graph. * * @param vertex * @param propertyKeyValues */ public static void attachProperties(final TitanVertex vertex, final Object... propertyKeyValues) { if (null == vertex) throw Graph.Exceptions.argumentCanNotBeNull("vertex"); for (int i = 0; i < propertyKeyValues.length; i = i + 2) { if (!propertyKeyValues[i].equals(T.id) && !propertyKeyValues[i].equals(T.label)) vertex.property((String) propertyKeyValues[i], propertyKeyValues[i + 1]); } }
@Override public <C extends GraphComputer> C compute(Class<C> graphComputerClass) throws IllegalArgumentException { if (!graphComputerClass.equals(FulgoraGraphComputer.class)) { throw Graph.Exceptions.graphDoesNotSupportProvidedGraphComputer(graphComputerClass); } else { return (C)compute(); } }
public static void verifyArgsMustBeEitherIdOrElement(Object... ids) { assert ids.length>0; int numElements = 0; for (Object id : ids) { if (id instanceof Element) numElements++; } if (numElements>0 && numElements<ids.length) throw Graph.Exceptions.idArgsMustBeEitherIdOrElement(); } }
/** * This is essentially an adjusted copy&paste from TinkerPop's ElementHelper class. * The reason for copying it is so that we can determine the cardinality of a property key based on * JanusGraph's schema which is tied to this particular transaction and not the graph. * * @param vertex * @param propertyKeyValues */ public static void attachProperties(final JanusGraphVertex vertex, final Object... propertyKeyValues) { if (null == vertex) throw Graph.Exceptions.argumentCanNotBeNull("vertex"); for (int i = 0; i < propertyKeyValues.length; i = i + 2) { if (!propertyKeyValues[i].equals(T.id) && !propertyKeyValues[i].equals(T.label)) vertex.property((String) propertyKeyValues[i], propertyKeyValues[i + 1]); } }
public Builder source(final Traversal<Vertex, ?> sourceVertexFilter) { if (null == sourceVertexFilter) throw Graph.Exceptions.argumentCanNotBeNull("sourceVertexFilter"); PureTraversal.storeState(this.configuration, SOURCE_VERTEX_FILTER, sourceVertexFilter.asAdmin()); return this; }
/** * Open a new {@link Neo4jGraph} instance. * * @param configuration the configuration for the instance * @return a newly opened {@link org.apache.tinkerpop.gremlin.structure.Graph} */ public static Neo4jGraph open(final Configuration configuration) { if (null == configuration) throw Graph.Exceptions.argumentCanNotBeNull("configuration"); if (!configuration.containsKey(CONFIG_DIRECTORY)) throw new IllegalArgumentException(String.format("Neo4j configuration requires that the %s be set", CONFIG_DIRECTORY)); return new Neo4jGraph(configuration); }
@Override public <C extends GraphComputer> C compute(final Class<C> graphComputerClass) { if (!graphComputerClass.equals(TinkerGraphComputer.class)) throw Graph.Exceptions.graphDoesNotSupportProvidedGraphComputer(graphComputerClass); return (C) new TinkerGraphComputer(this); }
@Override public Edge addEdge(final String label, final Vertex vertex, final Object... keyValues) { if (null == vertex) throw Graph.Exceptions.argumentCanNotBeNull("vertex"); if (this.removed) throw elementAlreadyRemoved(Vertex.class, this.id); return TinkerHelper.addEdge(this.graph, this, (TinkerVertex) vertex, label, keyValues); }
@Test @LoadGraphWith(MODERN) public void shouldThrowExceptionWhenIdsMixed() { final List<Vertex> vertices = g.V().toList(); try { g.V(vertices.get(0), vertices.get(1).id()).toList(); } catch (Exception ex) { validateException(Graph.Exceptions.idArgsMustBeEitherIdOrElement(), ex); } }
private void validateHomogenousIds(final List<Object> ids) { final Iterator<Object> iterator = ids.iterator(); Object id = iterator.next(); if (id == null) throw Graph.Exceptions.idArgsMustBeEitherIdOrElement(); final Class firstClass = id.getClass(); while (iterator.hasNext()) { id = iterator.next(); if (id == null || !id.getClass().equals(firstClass)) throw Graph.Exceptions.idArgsMustBeEitherIdOrElement(); } }
public Builder edgeTraversal(final Traversal<Vertex, Edge> edgeTraversal) { if (null == edgeTraversal) throw Graph.Exceptions.argumentCanNotBeNull("edgeTraversal"); PureTraversal.storeState(this.configuration, EDGE_TRAVERSAL, edgeTraversal.asAdmin()); return this; }