Java Code Examples for com.arangodb.ArangoCursor#asListRemaining()

The following examples show how to use com.arangodb.ArangoCursor#asListRemaining() . 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: PolymorphicTemplate.java    From spring-data with Apache License 2.0 6 votes vote down vote up
@Test
public void query() {
	Dog dog = new Dog();
	dog.setId("1");
	dog.setName("dog");
	dog.setTeeths(11);

	Eagle eagle = new Eagle();
	dog.setId("2");
	eagle.setName("eagle");
	eagle.setWingspan(2.5);

	template.insert(dog);
	template.insert(eagle);

	final ArangoCursor<Animal> cursor = template.query("FOR a IN animals RETURN a", Animal.class);
	Assert.assertThat(cursor, is(notNullValue()));
	final List<Animal> animals = cursor.asListRemaining();
	Assert.assertThat(animals.size(), is(2));
	Assert.assertThat(animals.stream().anyMatch(it -> it.equals(eagle)), is(true));
	Assert.assertThat(animals.stream().anyMatch(it -> it.equals(dog)), is(true));
}
 
Example 2
Source File: GraphTraversalsInAQLExample.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Test
public void queryOutboundInbound() throws ArangoDBException {
	String queryString = "FOR v IN 1..3 OUTBOUND 'circles/E' GRAPH 'traversalGraph' return v._key";
	ArangoCursor<String> cursor = db.query(queryString, null, null, String.class);
	Collection<String> result = cursor.asListRemaining();
	assertThat(result.size(), is(1));
	assertThat(result, hasItems("F"));

	queryString = "FOR v IN 1..3 INBOUND 'circles/E' GRAPH 'traversalGraph' return v._key";
	cursor = db.query(queryString, null, null, String.class);
	result = cursor.asListRemaining();
	assertThat(result.size(), is(2));
	assertThat(result, hasItems("B", "A"));

	queryString = "FOR v IN 1..3 ANY 'circles/E' GRAPH 'traversalGraph' return v._key";
	cursor = db.query(queryString, null, null, String.class);

	result = cursor.asListRemaining();
	assertThat(result.size(), is(6));
	assertThat(result, hasItems("F", "B", "C", "D", "A", "G"));
}
 
Example 3
Source File: SimpleArangoRepository.java    From spring-data with Apache License 2.0 5 votes vote down vote up
/**
 * Gets all documents in the collection for the class type of this repository, with pagination
 *
 * @param pageable
 *            the pageable object to use for pagination of the results
 * @return an iterable with all the documents in the collection
 */
@Override
public Page<T> findAll(final Pageable pageable) {
	if (pageable == null) {
		LOGGER.debug("Pageable in findAll(Pageable) is null");
	}

	final ArangoCursor<T> result = findAllInternal(pageable, null, new HashMap<>());
	final List<T> content = result.asListRemaining();
	return new PageImpl<>(content, pageable, result.getStats().getFullCount());
}
 
Example 4
Source File: ArangoTemplateTest.java    From spring-data with Apache License 2.0 5 votes vote down vote up
@Test
public void query() {
	template.insert(new Customer("John", "Doe", 30));
	final ArangoCursor<Customer> cursor = template.query("FOR c IN @@coll FILTER c.name == @name RETURN c",
		new MapBuilder().put("@coll", "customer").put("name", "John").get(), new AqlQueryOptions(), Customer.class);
	assertThat(cursor, is(notNullValue()));
	final List<Customer> customers = cursor.asListRemaining();
	assertThat(customers.size(), is(1));
	assertThat(customers.get(0).getName(), is("John"));
	assertThat(customers.get(0).getSurname(), is("Doe"));
	assertThat(customers.get(0).getAge(), is(30));
}
 
Example 5
Source File: ArangoTemplateTest.java    From spring-data with Apache License 2.0 5 votes vote down vote up
@Test
public void queryWithoutBindParams() {
	template.insert(new Customer("John", "Doe", 30));
	final ArangoCursor<Customer> cursor = template.query("FOR c IN customer FILTER c.name == 'John' RETURN c", null,
		new AqlQueryOptions(), Customer.class);
	assertThat(cursor, is(notNullValue()));
	final List<Customer> customers = cursor.asListRemaining();
	assertThat(customers.size(), is(1));
	assertThat(customers.get(0).getName(), is("John"));
	assertThat(customers.get(0).getSurname(), is("Doe"));
	assertThat(customers.get(0).getAge(), is(30));
}
 
Example 6
Source File: ArangoTemplateTest.java    From spring-data with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Test
public void queryMap() {
	template.insert(new Customer("John", "Doe", 30));
	final ArangoCursor<Map> cursor = template.query("FOR c IN @@coll FILTER c.name == @name RETURN c",
		new MapBuilder().put("@coll", "customer").put("name", "John").get(), new AqlQueryOptions(), Map.class);
	assertThat(cursor, is(notNullValue()));
	final List<Map> customers = cursor.asListRemaining();
	assertThat(customers.size(), is(1));
	assertThat(customers.get(0).get("name"), is("John"));
	assertThat(customers.get(0).get("surname"), is("Doe"));
	assertThat(customers.get(0).get("age"), is(30L));
}
 
Example 7
Source File: ArangoTemplateTest.java    From spring-data with Apache License 2.0 5 votes vote down vote up
@Test
public void queryBaseDocument() {
	template.insert(new Customer("John", "Doe", 30));
	final ArangoCursor<BaseDocument> cursor = template.query("FOR c IN @@coll FILTER c.name == @name RETURN c",
		new MapBuilder().put("@coll", "customer").put("name", "John").get(), new AqlQueryOptions(),
		BaseDocument.class);
	assertThat(cursor, is(notNullValue()));
	final List<BaseDocument> customers = cursor.asListRemaining();
	assertThat(customers.size(), is(1));
	assertThat(customers.get(0).getAttribute("name"), is("John"));
	assertThat(customers.get(0).getAttribute("surname"), is("Doe"));
	assertThat(customers.get(0).getAttribute("age"), is(30L));
}
 
Example 8
Source File: ArangoTemplateTest.java    From spring-data with Apache License 2.0 5 votes vote down vote up
@Test
public void queryVPackSlice() {
	template.insert(new Customer("John", "Doe", 30));
	final ArangoCursor<VPackSlice> cursor = template.query("FOR c IN @@coll FILTER c.name == @name RETURN c",
		new MapBuilder().put("@coll", "customer").put("name", "John").get(), new AqlQueryOptions(),
		VPackSlice.class);
	assertThat(cursor, is(notNullValue()));
	final List<VPackSlice> customers = cursor.asListRemaining();
	assertThat(customers.size(), is(1));
	assertThat(customers.get(0).get("name").getAsString(), is("John"));
	assertThat(customers.get(0).get("surname").getAsString(), is("Doe"));
	assertThat(customers.get(0).get("age").getAsInt(), is(30));
}
 
Example 9
Source File: GraphTraversalsInAQLExample.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void queryAllVertices() throws ArangoDBException {
	String queryString = "FOR v IN 1..3 OUTBOUND 'circles/A' GRAPH 'traversalGraph' RETURN v._key";
	ArangoCursor<String> cursor = db.query(queryString, null, null, String.class);
	Collection<String> result = cursor.asListRemaining();
	assertThat(result.size(), is(10));

	queryString = "WITH circles FOR v IN 1..3 OUTBOUND 'circles/A' edges RETURN v._key";
	cursor = db.query(queryString, null, null, String.class);
	result = cursor.asListRemaining();
	assertThat(result.size(), is(10));
}
 
Example 10
Source File: GraphTraversalsInAQLExample.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void queryDepthTwo() throws ArangoDBException {
	String queryString = "FOR v IN 2..2 OUTBOUND 'circles/A' GRAPH 'traversalGraph' return v._key";
	ArangoCursor<String> cursor = db.query(queryString, null, null, String.class);
	Collection<String> result = cursor.asListRemaining();
	assertThat(result.size(), is(4));
	assertThat(result, hasItems("C", "E", "H", "J"));

	queryString = "FOR v IN 2 OUTBOUND 'circles/A' GRAPH 'traversalGraph' return v._key";
	cursor = db.query(queryString, null, null, String.class);
	result = cursor.asListRemaining();
	assertThat(result.size(), is(4));
	assertThat(result, hasItems("C", "E", "H", "J"));
}
 
Example 11
Source File: GraphTraversalsInAQLExample.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void queryWithFilter() throws ArangoDBException {
	String queryString = "FOR v, e, p IN 1..3 OUTBOUND 'circles/A' GRAPH 'traversalGraph' FILTER p.vertices[1]._key != 'G' RETURN v._key";
	ArangoCursor<String> cursor = db.query(queryString, null, null, String.class);
	Collection<String> result = cursor.asListRemaining();
	assertThat(result.size(), is(5));
	assertThat(result, hasItems("B", "C", "D", "E", "F"));

	queryString = "FOR v, e, p IN 1..3 OUTBOUND 'circles/A' GRAPH 'traversalGraph' FILTER p.edges[0].label != 'right_foo' RETURN v._key";
	cursor = db.query(queryString, null, null, String.class);
	result = cursor.asListRemaining();
	assertThat(result.size(), is(5));
	assertThat(result, hasItems("B", "C", "D", "E", "F"));

	queryString = "FOR v,e,p IN 1..3 OUTBOUND 'circles/A' GRAPH 'traversalGraph' FILTER p.vertices[1]._key != 'G' FILTER p.edges[1].label != 'left_blub' return v._key";
	cursor = db.query(queryString, null, null, String.class);

	result = cursor.asListRemaining();
	assertThat(result.size(), is(3));
	assertThat(result, hasItems("B", "C", "D"));

	queryString = "FOR v,e,p IN 1..3 OUTBOUND 'circles/A' GRAPH 'traversalGraph' FILTER p.vertices[1]._key != 'G' AND    p.edges[1].label != 'left_blub' return v._key";
	cursor = db.query(queryString, null, null, String.class);
	result = cursor.asListRemaining();
	assertThat(result.size(), is(3));
	assertThat(result, hasItems("B", "C", "D"));
}
 
Example 12
Source File: SimpleArangoRepository.java    From spring-data with Apache License 2.0 3 votes vote down vote up
/**
 * Finds all documents which match with the given example, with pagination
 *
 * @param example
 *            example object to construct query with
 * @param pageable
 *            pageable object to apply pagination with
 * @param <S>
 * @return iterable of all matching documents, with pagination
 */
@Override
public <S extends T> Page<S> findAll(final Example<S> example, final Pageable pageable) {
	final ArangoCursor cursor = findAllInternal(pageable, example, new HashMap());
	final List<T> content = cursor.asListRemaining();
	return new PageImpl<>((List<S>) content, pageable, cursor.getStats().getFullCount());
}