/** * 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]); } }
/** * 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 void createKeyIndex(final String key) { if (null == key) throw Graph.Exceptions.argumentCanNotBeNull("key"); if (key.isEmpty()) throw new IllegalArgumentException("The key for the index cannot be an empty string"); if (this.indexedKeys.contains(key)) return; this.indexedKeys.add(key); (Vertex.class.isAssignableFrom(this.indexClass) ? this.graph.vertices.values().<T>parallelStream() : this.graph.edges.values().<T>parallelStream()) .map(e -> new Object[]{((T) e).property(key), e}) .filter(a -> ((Property) a[0]).isPresent()) .forEach(a -> this.put(key, ((Property) a[0]).value(), (T) a[1])); }
/** * Open a graph. See each {@link Graph} instance for its configuration options. * * @param configuration A configuration object that specifies the minimally required properties for a I * {@link Graph} instance. This minimum is determined by the * {@link Graph} instance itself. * @return A {@link org.apache.tinkerpop.gremlin.structure.Graph} instance. * @throws IllegalArgumentException if {@code configuration} */ public static Graph open(final Configuration configuration) { if (null == configuration) throw Graph.Exceptions.argumentCanNotBeNull("configuration"); final String clazz = configuration.getString(Graph.GRAPH, null); if (null == clazz) throw new RuntimeException(String.format("Configuration must contain a valid '%s' setting", Graph.GRAPH)); final Class<?> graphClass; try { graphClass = Class.forName(clazz); } catch (final ClassNotFoundException e) { throw new RuntimeException(String.format("GraphFactory could not find [%s] - Ensure that the jar is in the classpath", clazz)); } // If the graph class specifies a factory class then use that instead of the specified class. final GraphFactoryClass factoryAnnotation = graphClass.getAnnotation(GraphFactoryClass.class); final Class<?> factoryClass = factoryAnnotation != null ? factoryAnnotation.value() : graphClass; return open(configuration, factoryClass); }
/** * Open a graph. See each {@link Graph} instance for its configuration options. This file may be XML, YAML, * or a standard properties file. How the configuration is used (and which kind is required) is dependent on * the implementation. * <p/> * If using XML, ensure that the appropriate version of Apache {@code commons-collections} is available on the * classpath as it is an optional dependency of Apache {@code commons-configuration}, the library that * {@code GraphFactory} depends on. * * @param configurationFile The location of a configuration file that specifies the minimally required properties * for a {@link org.apache.tinkerpop.gremlin.structure.Graph} instance. This minimum is determined by the {@link org.apache.tinkerpop.gremlin.structure.Graph} instance * itself. * @return A {@link org.apache.tinkerpop.gremlin.structure.Graph} instance. * @throws IllegalArgumentException if {@code configurationFile} is null */ public static Graph open(final String configurationFile) { if (null == configurationFile) throw Graph.Exceptions.argumentCanNotBeNull("configurationFile"); return open(getConfiguration(new File(configurationFile))); }
/** * 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]); } }
/** * Assign key/value pairs as properties to a {@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. * * @param vertex the vertex to attach the properties to * @param cardinality the cardinality of the key value pair settings * @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 VertexProperty.Cardinality cardinality, 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(cardinality, (String) propertyKeyValues[i], propertyKeyValues[i + 1]); } }
/** * Assign key/value pairs as properties to an {@link org.apache.tinkerpop.gremlin.structure.Element}. If the value of {@link T#id} or * {@link T#label} is in the set of pairs, then they are ignored. * * @param element the graph element 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 Element element, final Object... propertyKeyValues) { if (null == element) throw Graph.Exceptions.argumentCanNotBeNull("element"); for (int i = 0; i < propertyKeyValues.length; i = i + 2) { if (!propertyKeyValues[i].equals(T.id) && !propertyKeyValues[i].equals(T.label)) element.property((String) propertyKeyValues[i], propertyKeyValues[i + 1]); } }
public static HadoopGraph open(final String configurationFile) throws ConfigurationException { if (null == configurationFile) throw Graph.Exceptions.argumentCanNotBeNull("configurationFile"); return open(new PropertiesConfiguration(configurationFile)); }
public Builder edgeDirection(final Direction direction) { if (null == direction) throw Graph.Exceptions.argumentCanNotBeNull("direction"); return edgeTraversal(__.toE(direction)); }
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; }
public static boolean areEqual(final MapReduce a, final Object b) { if (null == a) throw Graph.Exceptions.argumentCanNotBeNull("a"); if (null == b) throw Graph.Exceptions.argumentCanNotBeNull("b"); if (!(b instanceof MapReduce)) return false; return a.getClass().equals(b.getClass()) && a.getMemoryKey().equals(((MapReduce) b).getMemoryKey()); }
public Builder distanceTraversal(final Traversal<Edge, Number> distanceTraversal) { if (null == distanceTraversal) throw Graph.Exceptions.argumentCanNotBeNull("distanceTraversal"); PureTraversal.storeState(this.configuration, DISTANCE_TRAVERSAL, distanceTraversal.asAdmin()); return this; }
public Builder target(final Traversal<Vertex, ?> targetVertexFilter) { if (null == targetVertexFilter) throw Graph.Exceptions.argumentCanNotBeNull("targetVertexFilter"); PureTraversal.storeState(this.configuration, TARGET_VERTEX_FILTER, targetVertexFilter.asAdmin()); return this; }
@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) public void shouldHaveExceptionConsistencyWhenUsingNullVertex() { final Vertex v = graph.addVertex(); try { v.addEdge("tonothing", null); fail("Call to Vertex.addEdge() should throw an exception when vertex is null"); } catch (Exception ex) { validateException(Graph.Exceptions.argumentCanNotBeNull("vertex"), ex); } }
/** * Open a graph. See each {@link org.apache.tinkerpop.gremlin.structure.Graph} instance for its configuration options. * * @param configuration A {@link java.util.Map} based configuration that will be converted to an {@link org.apache.commons.configuration.Configuration} object * via {@link org.apache.commons.configuration.MapConfiguration} and passed to the appropriate overload. * @return A Graph instance. */ public static Graph open(final Map configuration) { if (null == configuration) throw Graph.Exceptions.argumentCanNotBeNull("configuration"); return open(new MapConfiguration(configuration)); }
@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 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); }
/** * 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); }
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; }