com.arangodb.model.AqlQueryOptions Java Examples
The following examples show how to use
com.arangodb.model.AqlQueryOptions.
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 |
/** * Execute AQL query. * * @param <T> the generic type of the returned values * @param query the query string * @param bindVars the value of the bind parameters * @param aqlQueryOptions the aql query options * @param type the type of the result (POJO class, VPackSlice, String for Json, or Collection/List/Map) * @return the cursor result * @throws ArangoDBGraphException if executing the query raised an exception */ public <T> ArangoCursor<T> executeAqlQuery( String query, Map<String, Object> bindVars, AqlQueryOptions aqlQueryOptions, final Class<T> type) throws ArangoDBGraphException { logger.debug("Executing AQL query ({}) against db, with bind vars: {}", query, bindVars); try { return db.query(query, bindVars, aqlQueryOptions, type); } catch (ArangoDBException e) { logger.error("Error executing query", e); throw ArangoDBExceptions.getArangoDBException(e); } }
Example #2
Source File: UserAuthTest.java From arangodb-java-driver with Apache License 2.0 | 6 votes |
@Test public void readDocumentByAql() { try { arangoDBRoot.db(DB_NAME).collection(COLLECTION_NAME).insertDocument(new BaseDocument("123")); if ((Permissions.RW.equals(param.dbPermission) || Permissions.RO.equals(param.dbPermission)) && (Permissions.RW.equals(param.colPermission) || Permissions.RO.equals(param.colPermission))) { assertThat(details, arangoDB.db(DB_NAME).query("FOR i IN @@col RETURN i", new MapBuilder().put("@col", COLLECTION_NAME).get(), new AqlQueryOptions(), BaseDocument.class) .asListRemaining().size(), is(1)); } else { assertThat(details, arangoDB.db(DB_NAME).collection(COLLECTION_NAME).getDocument("123", BaseDocument.class), is(nullValue())); } } finally { try { arangoDBRoot.db(DB_NAME).collection(COLLECTION_NAME).deleteDocument("123"); } catch (final ArangoDBException e) { } } }
Example #3
Source File: DerivedQueryCreatorTest.java From spring-data with Apache License 2.0 | 6 votes |
@Test public void pageableTest() { final List<Customer> toBeRetrieved = new LinkedList<>(); repository.save(new Customer("", "", 0)); repository.save(new Customer("", "", 1)); toBeRetrieved.add(new Customer("", "", 2)); repository.save(new Customer("-", "", 3)); toBeRetrieved.add(new Customer("", "", 4)); repository.save(new Customer("", "", 5)); repository.saveAll(toBeRetrieved); final Pageable pageable = PageRequest.of(1, 2, Sort.by("age")); final Page<Customer> retrieved = repository.readByNameAndSurname(pageable, "", new AqlQueryOptions().fullCount(false), ""); assertEquals(5, retrieved.getTotalElements()); assertEquals(3, retrieved.getTotalPages()); assertTrue(equals(toBeRetrieved, retrieved, cmp, eq, true)); assertTrue(equals(toBeRetrieved, retrieved, cmp, eq, true)); }
Example #4
Source File: ArangoTemplateTest.java From spring-data with Apache License 2.0 | 5 votes |
@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 #5
Source File: ArangoTemplateTest.java From spring-data with Apache License 2.0 | 5 votes |
@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 #6
Source File: ArangoTemplateTest.java From spring-data with Apache License 2.0 | 5 votes |
@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: StringBasedArangoQuery.java From spring-data with Apache License 2.0 | 5 votes |
@Override protected String createQuery( final ArangoParameterAccessor accessor, final Map<String, Object> bindVars, final AqlQueryOptions options) { extractBindVars(accessor, bindVars); return prepareQuery(accessor); }
Example #8
Source File: SimpleArangoRepository.java From spring-data with Apache License 2.0 | 5 votes |
private <S extends T> ArangoCursor<T> findAllInternal( final Pageable pageable, @Nullable final Example<S> example, final Map<String, Object> bindVars) { final String query = String.format("FOR e IN %s %s %s RETURN e", getCollectionName(), buildFilterClause(example, bindVars), buildPageableClause(pageable, "e")); return arangoOperations.query(query, bindVars, pageable != null && pageable.isPaged() ? new AqlQueryOptions().fullCount(true) : null, domainClass); }
Example #9
Source File: ArangoTemplateTest.java From spring-data with Apache License 2.0 | 5 votes |
@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 #10
Source File: ArangoTemplateTest.java From spring-data with Apache License 2.0 | 5 votes |
@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 #11
Source File: GeneralMappingTest.java From spring-data with Apache License 2.0 | 5 votes |
@Test public void supplementKey() { final OnlyIdTestEntity value = new OnlyIdTestEntity(); template.insert(value); final List<BasicTestEntity> result = template.query("RETURN @doc", new MapBuilder().put("doc", value).get(), new AqlQueryOptions(), BasicTestEntity.class).asListRemaining(); assertThat(result.size(), is(1)); assertThat(result.get(0).getId(), is(value.id)); assertThat(result.get(0).getRev(), is(nullValue())); }
Example #12
Source File: DerivedArangoQuery.java From spring-data with Apache License 2.0 | 5 votes |
@Override protected String createQuery( final ArangoParameterAccessor accessor, final Map<String, Object> bindVars, final AqlQueryOptions options) { return new DerivedQueryCreator(context, domainClass, tree, accessor, new BindParameterBinding(bindVars), geoFields).createQuery(); }
Example #13
Source File: ArangoQueryMethod.java From spring-data with Apache License 2.0 | 5 votes |
public AqlQueryOptions getAnnotatedQueryOptions() { final QueryOptions queryOptions = getQueryOptionsAnnotation(); if (queryOptions == null) { return null; } final AqlQueryOptions options = new AqlQueryOptions(); final int batchSize = queryOptions.batchSize(); if (batchSize != -1) { options.batchSize(batchSize); } final int maxPlans = queryOptions.maxPlans(); if (maxPlans != -1) { options.maxPlans(maxPlans); } final int ttl = queryOptions.ttl(); if (ttl != -1) { options.ttl(ttl); } options.cache(queryOptions.cache()); options.count(queryOptions.count()); options.fullCount(queryOptions.fullCount()); options.profile(queryOptions.profile()); options.rules(Arrays.asList(queryOptions.rules())); final boolean stream = queryOptions.stream(); if (stream) { options.stream(stream); } final long memoryLimit = queryOptions.memoryLimit(); if (memoryLimit != -1) { options.memoryLimit(memoryLimit); } final boolean allowDirtyRead = queryOptions.allowDirtyRead(); if (allowDirtyRead) { options.allowDirtyRead(allowDirtyRead); } return options; }
Example #14
Source File: ArangoAqlQueryTest.java From spring-data with Apache License 2.0 | 5 votes |
@Test public void findOneByIdAqlWithNamedParameterTest() { repository.saveAll(customers); final Map<String, Object> retrieved = repository.findOneByIdAqlWithNamedParameter(john.getId(), new AqlQueryOptions()); assertThat(retrieved, hasEntry("_key", john.getId())); assertThat(retrieved, hasEntry("_rev", john.getRev())); assertThat(retrieved, hasEntry("name", john.getName())); assertThat(retrieved, hasEntry("surname", john.getSurname())); assertThat(retrieved, hasEntry("age", (long) john.getAge())); assertThat(retrieved, hasEntry("alive", john.isAlive())); }
Example #15
Source File: ArangoAqlQueryTest.java From spring-data with Apache License 2.0 | 5 votes |
@Test public void findOneByBindVarsAqlTest() { repository.saveAll(customers); final Map<String, Object> bindVars = new HashMap<>(); bindVars.put("id", john.getId()); bindVars.put("name", john.getName()); final ArangoCursor<Customer> retrieved = repository .findOneByBindVarsAql(new AqlQueryOptions().ttl(127).cache(true), bindVars); assertEquals(john, retrieved.next()); }
Example #16
Source File: ArangoParameters.java From spring-data with Apache License 2.0 | 4 votes |
public boolean isQueryOptions() { return AqlQueryOptions.class.isAssignableFrom(parameter.getParameterType()); }
Example #17
Source File: CustomerRepository.java From spring-data with Apache License 2.0 | 4 votes |
@QueryOptions(maxPlans = 1000, ttl = 128) @Query("FOR c IN #collection FILTER c._key == @id AND c.name == @name RETURN c") ArangoCursor<Customer> findOneByBindVarsAql(AqlQueryOptions options, @BindVars Map<String, Object> bindVars);
Example #18
Source File: CustomerRepository.java From spring-data with Apache License 2.0 | 4 votes |
@Query("FOR c IN customer FILTER c._key == @id RETURN c") Map<String, Object> findOneByIdAqlWithNamedParameter(@Param("id") String idString, AqlQueryOptions options);
Example #19
Source File: DocumentToResolver.java From spring-data with Apache License 2.0 | 4 votes |
private ArangoCursor<?> _resolve(final String id, final Class<?> type, final boolean limit) { final String query = String.format("FOR e IN @@edge FILTER e._to == @id RETURN e", limit ? "LIMIT 1" : ""); return template.query(query, new MapBuilder().put("@edge", type).put("id", id).get(), new AqlQueryOptions(), type); }
Example #20
Source File: DocumentFromResolver.java From spring-data with Apache License 2.0 | 4 votes |
private ArangoCursor<?> _resolve(final String id, final Class<?> type, final boolean limit) { final String query = String.format("FOR e IN @@edge FILTER e._from == @id %s RETURN e", limit ? "LIMIT 1" : ""); return template.query(query, new MapBuilder().put("@edge", type).put("id", id).get(), new AqlQueryOptions(), type); }
Example #21
Source File: AbstractArangoQuery.java From spring-data with Apache License 2.0 | 4 votes |
/** * Merges AqlQueryOptions derived from @QueryOptions with dynamically passed AqlQueryOptions which takes priority * * @param oldStatic * @param newDynamic * @return */ protected AqlQueryOptions mergeQueryOptions(final AqlQueryOptions oldStatic, final AqlQueryOptions newDynamic) { if (oldStatic == null) { return newDynamic; } if (newDynamic == null) { return oldStatic; } final Integer batchSize = newDynamic.getBatchSize(); if (batchSize != null) { oldStatic.batchSize(batchSize); } final Integer maxPlans = newDynamic.getMaxPlans(); if (maxPlans != null) { oldStatic.maxPlans(maxPlans); } final Integer ttl = newDynamic.getTtl(); if (ttl != null) { oldStatic.ttl(ttl); } final Boolean cache = newDynamic.getCache(); if (cache != null) { oldStatic.cache(cache); } final Boolean count = newDynamic.getCount(); if (count != null) { oldStatic.count(count); } final Boolean fullCount = newDynamic.getFullCount(); if (fullCount != null) { oldStatic.fullCount(fullCount); } final Boolean profile = newDynamic.getProfile(); if (profile != null) { oldStatic.profile(profile); } final Collection<String> rules = newDynamic.getRules(); if (rules != null) { oldStatic.rules(rules); } return oldStatic; }
Example #22
Source File: ArangoParametersParameterAccessor.java From spring-data with Apache License 2.0 | 4 votes |
@Override public AqlQueryOptions getQueryOptions() { final int optionsIndex = parameters.getQueryOptionsIndex(); return optionsIndex == -1 ? null : getValue(optionsIndex); }
Example #23
Source File: ArangoCursorTest.java From arangodb-java-driver with Apache License 2.0 | 3 votes |
@Test public void next() { final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", new AqlQueryOptions().batchSize(5), VPackSlice.class); while (cursor.hasNext()) { cursor.next(); } }
Example #24
Source File: AbstractArangoQuery.java From spring-data with Apache License 2.0 | 2 votes |
/** * Implementations should create an AQL query with the given * {@link com.arangodb.springframework.repository.query.ArangoParameterAccessor} and set necessary binding * parameters and query options. * * @param accessor * provides access to the actual arguments * @param bindVars * the binding parameter map * @param options * contains the merged {@link com.arangodb.model.AqlQueryOptions} * @return the created AQL query */ protected abstract String createQuery( ArangoParameterAccessor accessor, Map<String, Object> bindVars, AqlQueryOptions options);
Example #25
Source File: CustomerRepository.java From spring-data with Apache License 2.0 | votes |
Page<Customer> readByNameAndSurname(Pageable pageable, String name, AqlQueryOptions options, String surname);
Example #26
Source File: ArangoParameterAccessor.java From spring-data with Apache License 2.0 | votes |
AqlQueryOptions getQueryOptions();