Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for c8cep cursor #64

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
19 changes: 18 additions & 1 deletion src/main/java/com/c8db/C8Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,24 @@ <T> C8Cursor<T> query(String query, Map<String, Object> bindVars, C8qlQueryOptio
*/
<T> C8Cursor<T> cursor(String cursorId, Class<T> type) throws C8DBException;

/**
* Performs a database query using the given {@code query} and {@code bindVars},
* then returns a new {@code ArangoCursor} instance for the result list.
*
* @param query An AQL query string
* @param bindVars key/value pairs defining the variables to bind the query to
* @param type The type of the result (POJO class, VPackSlice, String for
* JSON, or Collection/List/Map)
* @param requestSource a placeholder that represents the source of the request
* @return cursor of the results
* @throws C8DBException
* @see <a href=
* "https://docs.arangodb.com/current/HTTP/AqlQueryCursor/AccessingCursors.html#create-cursor">API
* Documentation</a>
*/
<T> C8Cursor<T> query(final String query, final Map<String, Object> bindVars, final C8qlQueryOptions options,
final Class<T> type, String requestSource) throws C8DBException;

/**
* Explain an AQL query and return information about it
*
Expand Down Expand Up @@ -713,5 +731,4 @@ <V, E> TraversalEntity<V, E> executeTraversal(Class<V> vertexClass, Class<E> edg
* @return C8Dynamo handler
*/
C8Dynamo dynamo(final String tableName);

}
12 changes: 12 additions & 0 deletions src/main/java/com/c8db/internal/C8DatabaseImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ public <T> C8Cursor<T> query(final String query, final Map<String, Object> bindV

}

@Override
public <T> C8Cursor<T> query(final String query, final Map<String, Object> bindVars,
final C8qlQueryOptions options, final Class<T> type, String requestSource) throws C8DBException {

final Request request = queryRequest(query, bindVars, options, requestSource);
final HostHandle hostHandle = new HostHandle();
final CursorEntity result = executor.execute(request, CursorEntity.class, hostHandle);

return createCursor(result, type, options, hostHandle);

}

@Override
public <T> C8Cursor<T> query(final String query, final Map<String, Object> bindVars, final Class<T> type)
throws C8DBException {
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/c8db/internal/InternalC8Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,23 @@ protected Request userQueryRequest(final String userName, final String restqlNam
return request;
}

protected Request queryRequest(final String query, final Map<String, Object> bindVars,
final C8qlQueryOptions options, String requestSource) {
Request request;
boolean isParameterized = query.contains("@") ? true : false;
if(isParameterized) {
Map<String, Object> bindVarMap;
if (bindVars.containsKey("bindVars")) {
bindVarMap = (HashMap) bindVars.get("bindVars");
} else {
This conversation was marked as resolved.
Show resolved Hide resolved
bindVarMap = new HashMap<>();
}
request = request(tenant, name, RequestType.POST, PATH_API_CURSOR)
.setBody(util().serialize(OptionsBuilder.build(options, query, util().serialize(bindVarMap))));
} else {
request = request(tenant, name, RequestType.POST, PATH_API_CURSOR)
.setBody(util().serialize(OptionsBuilder.build(options, query, bindVars)));
}
return request;
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/c8db/model/C8qlQueryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.Serializable;
import java.util.Collection;
import java.util.Map;

import com.arangodb.velocypack.VPackSlice;

Expand All @@ -36,11 +37,23 @@ public class C8qlQueryOptions implements Serializable {
private VPackSlice bindVars;
private Long batchSize;
private Long ttl;
private Map<String, Object> bindVarMap;

public C8qlQueryOptions() {
super();
}

public C8qlQueryOptions(C8qlQueryOptions queryOptions) {
this.count = queryOptions.count;
this.query = queryOptions.query;
this.cache = queryOptions.cache;
this.options = queryOptions.options;
this.bindVars = queryOptions.bindVars;
this.batchSize = queryOptions.batchSize;
this.ttl = queryOptions.ttl;
this.bindVarMap = queryOptions.bindVarMap;
}

public Boolean getCount() {
return count;
}
Expand Down Expand Up @@ -88,6 +101,11 @@ protected C8qlQueryOptions bindVars(final VPackSlice bindVars) {
return this;
}

protected C8qlQueryOptions bindVarsMap(final Map<String, Object> bindVarMap) {
this.bindVarMap = bindVarMap;
return this;
}

protected String getQuery() {
return query;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/c8db/model/OptionsBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public static C8qlQueryOptions build(final C8qlQueryOptions options, final Strin
return options.query(query).bindVars(bindVars);
}

public static C8qlQueryOptions build(final C8qlQueryOptions options, final String query, final Map<String, Object> bindVars) {
return options.query(query).bindVarsMap(bindVars);
}

public static C8qlQueryExplainOptions build(final C8qlQueryExplainOptions options, final String query,
final VPackSlice bindVars) {
return options.query(query).bindVars(bindVars);
Expand Down