Search in sources :

Example 1 with EXECUTE_WITH_INFERENCE

use of ai.grakn.util.REST.Request.Graql.EXECUTE_WITH_INFERENCE in project grakn by graknlabs.

the class GraknClientImpl method graqlExecute.

@Override
public List<QueryResponse> graqlExecute(List<Query<?>> queryList, Keyspace keyspace) throws GraknClientException {
    LOG.debug("Sending query list size {} to keyspace {}", queryList.size(), keyspace);
    String body = queryList.stream().map(Object::toString).reduce("; ", String::concat).substring(2);
    URI fullURI = UriBuilder.fromUri(uri.toURI()).path(REST.resolveTemplate(REST.WebPath.KEYSPACE_GRAQL, keyspace.getValue())).queryParam(ALLOW_MULTIPLE_QUERIES, true).queryParam(EXECUTE_WITH_INFERENCE, // Making inference true could lead to non-deterministic loading of data
    false).queryParam(LOADING_DATA, // Skip serialising responses for the sake of efficiency
    true).queryParam(TX_TYPE, GraknTxType.BATCH).build();
    ClientResponse response = client.resource(fullURI).accept(APPLICATION_JSON).post(ClientResponse.class, body);
    try {
        Response.StatusType status = response.getStatusInfo();
        String entity = response.getEntity(String.class);
        if (!status.getFamily().equals(Family.SUCCESSFUL)) {
            String queries = queryList.stream().map(Object::toString).collect(Collectors.joining("\n"));
            throw new GraknClientException("Failed graqlExecute. Error status: " + status.getStatusCode() + ", error info: " + entity + "\nqueries: " + queries, response.getStatusInfo());
        }
        LOG.debug("Received {}", status.getStatusCode());
        return queryList.stream().map(q -> QueryResponse.INSTANCE).collect(Collectors.toList());
    } finally {
        response.close();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ClientResponse(com.sun.jersey.api.client.ClientResponse) Response(javax.ws.rs.core.Response) GraknTxType(ai.grakn.GraknTxType) Logger(org.slf4j.Logger) ALLOW_MULTIPLE_QUERIES(ai.grakn.util.REST.Request.Graql.ALLOW_MULTIPLE_QUERIES) Keyspace(ai.grakn.Keyspace) ClientResponse(com.sun.jersey.api.client.ClientResponse) LoggerFactory(org.slf4j.LoggerFactory) LOADING_DATA(ai.grakn.util.REST.Request.Graql.LOADING_DATA) APPLICATION_JSON(ai.grakn.util.REST.Response.ContentType.APPLICATION_JSON) REST(ai.grakn.util.REST) Collectors(java.util.stream.Collectors) TX_TYPE(ai.grakn.util.REST.Request.Graql.TX_TYPE) Query(ai.grakn.graql.Query) Family(javax.ws.rs.core.Response.Status.Family) List(java.util.List) Response(javax.ws.rs.core.Response) Client(com.sun.jersey.api.client.Client) Optional(java.util.Optional) UriBuilder(javax.ws.rs.core.UriBuilder) EXECUTE_WITH_INFERENCE(ai.grakn.util.REST.Request.Graql.EXECUTE_WITH_INFERENCE) URI(java.net.URI) Status(javax.ws.rs.core.Response.Status) SimpleURI(ai.grakn.util.SimpleURI) URI(java.net.URI) SimpleURI(ai.grakn.util.SimpleURI)

Aggregations

GraknTxType (ai.grakn.GraknTxType)1 Keyspace (ai.grakn.Keyspace)1 Query (ai.grakn.graql.Query)1 REST (ai.grakn.util.REST)1 ALLOW_MULTIPLE_QUERIES (ai.grakn.util.REST.Request.Graql.ALLOW_MULTIPLE_QUERIES)1 EXECUTE_WITH_INFERENCE (ai.grakn.util.REST.Request.Graql.EXECUTE_WITH_INFERENCE)1 LOADING_DATA (ai.grakn.util.REST.Request.Graql.LOADING_DATA)1 TX_TYPE (ai.grakn.util.REST.Request.Graql.TX_TYPE)1 APPLICATION_JSON (ai.grakn.util.REST.Response.ContentType.APPLICATION_JSON)1 SimpleURI (ai.grakn.util.SimpleURI)1 Client (com.sun.jersey.api.client.Client)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 URI (java.net.URI)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Response (javax.ws.rs.core.Response)1 Status (javax.ws.rs.core.Response.Status)1 Family (javax.ws.rs.core.Response.Status.Family)1 UriBuilder (javax.ws.rs.core.UriBuilder)1