com.arangodb.model.GraphCreateOptions Java Examples

The following examples show how to use com.arangodb.model.GraphCreateOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArangoDBGraphClient.java    From arangodb-tinkerpop-provider with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new graph.
 *
 * @param name 						the name of the new graph
 * @param edgeDefinitions			the edge definitions for the graph
 * @param options 					additional graph options
 * @return the arango graph
 * @throws ArangoDBGraphException 	If the graph can not be created
 */

public ArangoGraph createGraph(String name,
       List<EdgeDefinition> edgeDefinitions,
	GraphCreateOptions options)
	throws ArangoDBGraphException {
	logger.info("Creating graph {}", name);
	try {
		logger.info("Creating graph in database.");
		db.createGraph(name, edgeDefinitions, options);
	} catch (ArangoDBException e) {
           logger.info("Error creating graph in database.", e);
           throw ArangoDBExceptions.getArangoDBException(e);
       }
	ArangoGraph g = db.graph(name);
	return g;
}
 
Example #2
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Test
public void smartGraph() throws InterruptedException, ExecutionException {
    assumeTrue(isCluster());
    assumeTrue(isEnterprise());
    for (final String collection : new String[]{EDGE_COL_1, EDGE_COL_2, VERTEX_COL_1, VERTEX_COL_2,
            VERTEX_COL_3, VERTEX_COL_4}) {
        if (db.collection(collection).exists().get()) {
            db.collection(collection).drop().get();
        }
    }
    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    edgeDefinitions.add(new EdgeDefinition().collection(EDGE_COL_1).from(VERTEX_COL_1).to(VERTEX_COL_2));
    edgeDefinitions
            .add(new EdgeDefinition().collection(EDGE_COL_2).from(VERTEX_COL_2).to(VERTEX_COL_1, VERTEX_COL_3));
    final GraphEntity graph = db.createGraph(GRAPH_NAME + "_smart", edgeDefinitions,
            new GraphCreateOptions().isSmart(true).smartGraphAttribute("test").replicationFactor(REPLICATION_FACTOR)
                    .numberOfShards(NUMBER_OF_SHARDS))
            .get();
    assertThat(graph, is(notNullValue()));
    assertThat(graph.getIsSmart(), is(true));
    assertThat(graph.getSmartGraphAttribute(), is("test"));
    assertThat(graph.getNumberOfShards(), is(2));
    if (db.graph(GRAPH_NAME + "_smart").exists().get()) {
        db.graph(GRAPH_NAME + "_smart").drop().get();
    }
}
 
Example #3
Source File: ArangoGraphTest.java    From arangodb-java-driver-async with Apache License 2.0 6 votes vote down vote up
@Test
public void smartGraph() throws InterruptedException, ExecutionException {
    assumeTrue(isCluster());
    assumeTrue(isEnterprise());
    for (final String collection : new String[]{EDGE_COL_1, EDGE_COL_2, VERTEX_COL_1, VERTEX_COL_2,
            VERTEX_COL_3, VERTEX_COL_4}) {
        if (db.collection(collection).exists().get()) {
            db.collection(collection).drop().get();
        }
    }
    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    edgeDefinitions.add(new EdgeDefinition().collection(EDGE_COL_1).from(VERTEX_COL_1).to(VERTEX_COL_2));
    edgeDefinitions
            .add(new EdgeDefinition().collection(EDGE_COL_2).from(VERTEX_COL_2).to(VERTEX_COL_1, VERTEX_COL_3));
    final GraphEntity graph = db.createGraph(GRAPH_NAME + "_smart", edgeDefinitions,
            new GraphCreateOptions().isSmart(true).smartGraphAttribute("test").replicationFactor(REPLICATION_FACTOR)
                    .numberOfShards(NUMBER_OF_SHARDS))
            .get();
    assertThat(graph, is(notNullValue()));
    assertThat(graph.getIsSmart(), is(true));
    assertThat(graph.getSmartGraphAttribute(), is("test"));
    assertThat(graph.getNumberOfShards(), is(2));
    if (db.graph(GRAPH_NAME + "_smart").exists().get()) {
        db.graph(GRAPH_NAME + "_smart").drop().get();
    }
}
 
Example #4
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Test
public void smartGraph() {
    assumeTrue(isEnterprise());
    assumeTrue(isCluster());

    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    edgeDefinitions.add(new EdgeDefinition().collection("smartGraph-edge-" + rnd()).from("smartGraph-vertex-" + rnd()).to("smartGraph-vertex-" + rnd()));

    String graphId = GRAPH_NAME + rnd();
    final GraphEntity g = db.createGraph(graphId, edgeDefinitions, new GraphCreateOptions().isSmart(true).smartGraphAttribute("test").numberOfShards(2));

    assertThat(g, is(notNullValue()));
    assertThat(g.getIsSmart(), is(true));
    assertThat(g.getSmartGraphAttribute(), is("test"));
    assertThat(g.getNumberOfShards(), is(2));
}
 
Example #5
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void createWithReplicationAndMinReplicationFactor() {
    assumeTrue(isAtLeastVersion(3, 5));
    assumeTrue(isCluster());

    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    final GraphEntity graph = db.createGraph(GRAPH_NAME + "_1", edgeDefinitions, new GraphCreateOptions().isSmart(true).replicationFactor(2).minReplicationFactor(2));
    assertThat(graph, is(notNullValue()));
    assertThat(graph.getName(), is(GRAPH_NAME + "_1"));
    assertThat(graph.getMinReplicationFactor(), is(2));
    assertThat(graph.getReplicationFactor(), is(2));
    db.graph(GRAPH_NAME + "_1").drop();
}
 
Example #6
Source File: ArangoDBUtil.java    From arangodb-tinkerpop-provider with Apache License 2.0 5 votes vote down vote up
private static void checkGraphVertexCollections(List<String> verticesCollectionNames, ArangoGraph graph, GraphCreateOptions options) {
	List<String> allVertexCollections = new ArrayList<>(verticesCollectionNames);
	final Collection<String> orphanCollections = options.getOrphanCollections();
	if (orphanCollections != null) {
		allVertexCollections.addAll(orphanCollections);
	}
	if (!graph.getVertexCollections().containsAll(allVertexCollections)) {
		Set<String> avc = new HashSet<>(allVertexCollections);
		avc.removeAll(graph.getVertexCollections());
		throw new ArangoDBGraphException("Not all declared vertex names appear in the graph. Missing " + avc);
	}
}
 
Example #7
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void createWithReplicationAndMinReplicationFactor() throws ExecutionException, InterruptedException {
    assumeTrue(isAtLeastVersion(3, 5));
    assumeTrue(isCluster());
    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    final GraphEntity graph = db.createGraph(GRAPH_NAME + "_1", edgeDefinitions, new GraphCreateOptions().isSmart(true).replicationFactor(2).minReplicationFactor(2)).get();
    assertThat(graph, is(notNullValue()));
    assertThat(graph.getName(), is(GRAPH_NAME + "_1"));
    assertThat(graph.getMinReplicationFactor(), is(2));
    assertThat(graph.getReplicationFactor(), is(2));
    db.graph(GRAPH_NAME + "_1").drop();
}
 
Example #8
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws InterruptedException, ExecutionException {
    if (db.graph(GRAPH_NAME).exists().get()) {
        db.graph(GRAPH_NAME).drop().get();
    }
    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    edgeDefinitions.add(new EdgeDefinition().collection(EDGE_COL_1).from(VERTEX_COL_1).to(VERTEX_COL_2));
    edgeDefinitions
            .add(new EdgeDefinition().collection(EDGE_COL_2).from(VERTEX_COL_2).to(VERTEX_COL_1, VERTEX_COL_3));
    final GraphCreateOptions options = new GraphCreateOptions();
    if (arangoDB.getRole().get() != ServerRole.SINGLE) {
        options.replicationFactor(REPLICATION_FACTOR).numberOfShards(NUMBER_OF_SHARDS);
    }
    db.createGraph(GRAPH_NAME, edgeDefinitions, options).get();
}
 
Example #9
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void init() {
    final Collection<EdgeDefinition> edgeDefinitions = Arrays.asList(ed1, ed2);

    final GraphCreateOptions options = new GraphCreateOptions()
            .replicationFactor(REPLICATION_FACTOR)
            .numberOfShards(NUMBER_OF_SHARDS);

    BaseTest.initGraph(GRAPH_NAME, edgeDefinitions, options);
}
 
Example #10
Source File: ArangoGraphTest.java    From arangodb-java-driver-async with Apache License 2.0 5 votes vote down vote up
@Test
public void createWithReplicationAndMinReplicationFactor() throws ExecutionException, InterruptedException {
    assumeTrue(isAtLeastVersion(3, 5));
    assumeTrue(isCluster());
    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    final GraphEntity graph = db.createGraph(GRAPH_NAME + "_1", edgeDefinitions, new GraphCreateOptions().isSmart(true).replicationFactor(2).minReplicationFactor(2)).get();
    assertThat(graph, is(notNullValue()));
    assertThat(graph.getName(), is(GRAPH_NAME + "_1"));
    assertThat(graph.getMinReplicationFactor(), is(2));
    assertThat(graph.getReplicationFactor(), is(2));
    db.graph(GRAPH_NAME + "_1").drop();
}
 
Example #11
Source File: ArangoGraphTest.java    From arangodb-java-driver-async with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws InterruptedException, ExecutionException {
    if (db.graph(GRAPH_NAME).exists().get()) {
        db.graph(GRAPH_NAME).drop().get();
    }
    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    edgeDefinitions.add(new EdgeDefinition().collection(EDGE_COL_1).from(VERTEX_COL_1).to(VERTEX_COL_2));
    edgeDefinitions
            .add(new EdgeDefinition().collection(EDGE_COL_2).from(VERTEX_COL_2).to(VERTEX_COL_1, VERTEX_COL_3));
    final GraphCreateOptions options = new GraphCreateOptions();
    if (arangoDB.getRole().get() != ServerRole.SINGLE) {
        options.replicationFactor(REPLICATION_FACTOR).numberOfShards(NUMBER_OF_SHARDS);
    }
    db.createGraph(GRAPH_NAME, edgeDefinitions, options).get();
}
 
Example #12
Source File: ArangoGraphAsyncImpl.java    From arangodb-java-driver with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<GraphEntity> createGraph(
        final Collection<EdgeDefinition> edgeDefinitions,
        final GraphCreateOptions options) {
    return db().createGraph(name(), edgeDefinitions, options);
}
 
Example #13
Source File: BaseTest.java    From arangodb-java-driver with Apache License 2.0 4 votes vote down vote up
static void initGraph(String name, Collection<EdgeDefinition> edgeDefinitions, GraphCreateOptions options) {
    ArangoDatabase db = initDB();
    db.createGraph(name, edgeDefinitions, options);
}
 
Example #14
Source File: ArangoGraphImpl.java    From arangodb-java-driver with Apache License 2.0 4 votes vote down vote up
@Override
public GraphEntity create(final Collection<EdgeDefinition> edgeDefinitions, final GraphCreateOptions options)
        throws ArangoDBException {
    return db().createGraph(name(), edgeDefinitions, options);
}
 
Example #15
Source File: ArangoDBGraph.java    From arangodb-tinkerpop-provider with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a Graph (simple configuration).
 *
 * @param configuration 	the Apache Commons configuration
 */

public ArangoDBGraph(Configuration configuration) {

	logger.info("Creating new ArangoDB Graph from configuration");
	Configuration arangoConfig = configuration.subset(PROPERTY_KEY_PREFIX);
	vertexCollections = arangoConfig.getList(PROPERTY_KEY_VERTICES).stream()
			.map(String.class::cast)
			.collect(Collectors.toList());
	edgeCollections = arangoConfig.getList(PROPERTY_KEY_EDGES).stream()
			.map(String.class::cast)
			.collect(Collectors.toList());
	relations = arangoConfig.getList(PROPERTY_KEY_RELATIONS).stream()
			.map(String.class::cast)
			.collect(Collectors.toList());
	name = arangoConfig.getString(PROPERTY_KEY_GRAPH_NAME);
	checkValues(arangoConfig.getString(PROPERTY_KEY_DB_NAME), name, vertexCollections, edgeCollections, relations);
	if (CollectionUtils.isEmpty(vertexCollections)) {
		schemaless = true;
		vertexCollections.add(DEFAULT_VERTEX_COLLECTION);
	}
	if (CollectionUtils.isEmpty(edgeCollections)) {
		edgeCollections.add(DEFAULT_EDGE_COLLECTION);
	}
	shouldPrefixCollectionNames = arangoConfig.getBoolean(PROPERTY_KEY_SHOULD_PREFIX_COLLECTION_NAMES, true);

	Properties arangoProperties = ConfigurationConverter.getProperties(arangoConfig);
	int batchSize = 0;
	client = new ArangoDBGraphClient(this, arangoProperties, arangoConfig.getString(PROPERTY_KEY_DB_NAME),
			batchSize, shouldPrefixCollectionNames);

	ArangoGraph graph = client.getArangoGraph();
       GraphCreateOptions options = new  GraphCreateOptions();
       // FIXME Cant be in orphan collections because it will be deleted with graph?
       // options.orphanCollections(GRAPH_VARIABLES_COLLECTION);
	final List<String> prefVCols = vertexCollections.stream().map(this::getPrefixedCollectioName).collect(Collectors.toList());
	final List<String> prefECols = edgeCollections.stream().map(this::getPrefixedCollectioName).collect(Collectors.toList());
	final List<EdgeDefinition> edgeDefinitions = new ArrayList<>();
	if (relations.isEmpty()) {
		logger.info("No relations, creating default ones.");
		edgeDefinitions.addAll(ArangoDBUtil.createDefaultEdgeDefinitions(prefVCols, prefECols));
	} else {
		for (String value : relations) {
			EdgeDefinition ed = ArangoDBUtil.relationPropertyToEdgeDefinition(this, value);
			edgeDefinitions.add(ed);
		}
	}
	edgeDefinitions.add(ArangoDBUtil.createPropertyEdgeDefinitions(this, prefVCols, prefECols));

       if (graph.exists()) {
           ArangoDBUtil.checkGraphForErrors(prefVCols, prefECols, edgeDefinitions, graph, options);
           ArangoDBGraphVariables iter = client.getGraphVariables();
           if (iter == null) {
           	throw new ArangoDBGraphException("Existing graph does not have a Variables collection");
           }
       }
       else {
       	graph = client.createGraph(name, edgeDefinitions, options);
       	this.name = graph.name();
		ArangoDBGraphVariables variables = new ArangoDBGraphVariables(name, GRAPH_VARIABLES_COLLECTION, this);
		client.insertGraphVariables(variables);
	}
	this.configuration = configuration;
}
 
Example #16
Source File: ArangoDBUtil.java    From arangodb-tinkerpop-provider with Apache License 2.0 4 votes vote down vote up
/**
 * Validate if an existing graph is correctly configured to handle the desired vertex, edges 
 * and relations.
 *
 * @param verticesCollectionNames    The names of collections for nodes
 * @param edgesCollectionNames        The names of collections for edges
 * @param requiredDefinitions                The description of edge definitions
 * @param graph                    the graph
 * @param options                    The options used to create the graph
 * @throws ArangoDBGraphException 	If the graph settings do not match the configuration information
 */

public static void checkGraphForErrors(
	List<String> verticesCollectionNames,
	List<String> edgesCollectionNames,
	List<EdgeDefinition> requiredDefinitions,
	ArangoGraph graph,
	GraphCreateOptions options) throws ArangoDBGraphException {

	checkGraphVertexCollections(verticesCollectionNames, graph, options);

	GraphEntity ge = graph.getInfo();
       Collection<EdgeDefinition> graphEdgeDefinitions = ge.getEdgeDefinitions();
       if (CollectionUtils.isEmpty(requiredDefinitions)) {
       	// If no relations are defined, vertices and edges can only have one value
       	if ((verticesCollectionNames.size() != 1) || (edgesCollectionNames.size() != 1)) {
       		throw new ArangoDBGraphException("No relations where specified but more than one vertex/edge where defined.");
       	}
       	if (graphEdgeDefinitions.size() != 2) {		// There is always a edgeDefinition for ELEMENT_HAS_PROPERTIES
       		throw new ArangoDBGraphException("No relations where specified but the graph has more than one EdgeDefinition.");
   		}
       }
	Map<String, EdgeDefinition> eds = requiredDefinitions.stream().collect(Collectors.toMap(EdgeDefinition::getCollection, ed -> ed));

       Iterator<EdgeDefinition> it = graphEdgeDefinitions.iterator();
       while (it.hasNext()) {
       	EdgeDefinition existing = it.next();
       	if (eds.containsKey(existing.getCollection())) {
       		EdgeDefinition requiredEdgeDefinition = eds.remove(existing.getCollection());
       		HashSet<String> existingSet = new HashSet<String>(existing.getFrom());
       		HashSet<String> requiredSet = new HashSet<String>(requiredEdgeDefinition.getFrom());
       		if (!existingSet.equals(requiredSet)) {
       			throw new ArangoDBGraphException(String.format("The from collections dont match for edge definition %s", existing.getCollection()));
       		}
       		existingSet.clear();
       		existingSet.addAll(existing.getTo());
       		requiredSet.clear();
       		requiredSet.addAll(requiredEdgeDefinition.getTo());
       		if (!existingSet.equals(requiredSet)) {
       			throw new ArangoDBGraphException(String.format("The to collections dont match for edge definition %s", existing.getCollection()));
       		}
       	} else {
       		throw new ArangoDBGraphException(String.format("The graph has a surplus edge definition %s", edgeDefinitionString(existing)));
       	}
       }
}
 
Example #17
Source File: ArangoGraphAsyncImpl.java    From arangodb-java-driver-async with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<GraphEntity> createGraph(
	final Collection<EdgeDefinition> edgeDefinitions,
	final GraphCreateOptions options) {
	return db().createGraph(name(), edgeDefinitions, options);
}
 
Example #18
Source File: ArangoGraphAsync.java    From arangodb-java-driver-async with Apache License 2.0 2 votes vote down vote up
/**
 * Creates the graph in the graph module. The creation of a graph requires the name of the graph and a definition of
 * its edges.
 * 
 * @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#create-a-graph">API
 *      Documentation</a>
 * @param edgeDefinitions
 *            An array of definitions for the edge
 * @param options
 *            Additional options, can be null
 * @return information about the graph
 */
CompletableFuture<GraphEntity> createGraph(
	final Collection<EdgeDefinition> edgeDefinitions,
	final GraphCreateOptions options);
 
Example #19
Source File: ArangoGraphAsync.java    From arangodb-java-driver with Apache License 2.0 2 votes vote down vote up
/**
 * Creates the graph in the graph module. The creation of a graph requires the name of the graph and a definition of
 * its edges.
 *
 * @param edgeDefinitions An array of definitions for the edge
 * @param options         Additional options, can be null
 * @return information about the graph
 * @see <a href="https://www.arangodb.com/docs/stable/http/gharial-management.html#create-a-graph">API
 * Documentation</a>
 */
CompletableFuture<GraphEntity> createGraph(
        final Collection<EdgeDefinition> edgeDefinitions,
        final GraphCreateOptions options);
 
Example #20
Source File: ArangoGraph.java    From arangodb-java-driver with Apache License 2.0 2 votes vote down vote up
/**
 * Creates the graph in the graph module. The creation of a graph requires the name of the graph and a definition of
 * its edges.
 *
 * @param edgeDefinitions An array of definitions for the edge
 * @param options         Additional options, can be null
 * @return information about the graph
 * @throws ArangoDBException
 * @see <a href="https://www.arangodb.com/docs/stable/http/gharial-management.html#create-a-graph">API
 * Documentation</a>
 */
GraphEntity create(Collection<EdgeDefinition> edgeDefinitions, GraphCreateOptions options) throws ArangoDBException;