use of ai.grakn.GraknTx in project grakn by graknlabs.
the class PhilosophersExampleIT method setUp.
@BeforeClass
public static void setUp() throws IOException {
GraknTx tx = Grakn.session("in-memory", "mygraph").open(GraknTxType.WRITE);
qb = tx.graql();
runQueries("src/examples/philosophers.gql");
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class EngineGraknSessionTest method closeGraphWhenOnlyOneTransactionIsOpen.
@Test
public void closeGraphWhenOnlyOneTransactionIsOpen() {
// Tinker does not have any connections to close
assumeFalse(GraknTestUtil.usingTinker());
GraknSession factory = Grakn.session(sparkContext.uri(), SampleKBLoader.randomKeyspace());
GraknTx graph = factory.open(GraknTxType.WRITE);
factory.close();
expectedException.expect(GraknTxOperationException.class);
expectedException.expectMessage(ErrorMessage.SESSION_CLOSED.getMessage(graph.keyspace()));
graph.putEntityType("A thingy");
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class EngineGraknSessionTest method whenFetchingGraphsOfTheSameKeyspaceFromSessionOrEngineFactory_EnsureGraphsAreTheSame.
@Test
public void whenFetchingGraphsOfTheSameKeyspaceFromSessionOrEngineFactory_EnsureGraphsAreTheSame() {
String keyspace = "mykeyspace";
GraknTx graph1 = Grakn.session(sparkContext.uri(), keyspace).open(GraknTxType.WRITE);
graph1.close();
GraknTx graph2 = graknFactory.tx(Keyspace.of(keyspace), GraknTxType.WRITE);
assertEquals(graph1, graph2);
graph2.close();
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class RemoteGraknSessionTest method whenOpeningATransactionFromASession_ReturnATransactionWithParametersSet.
@Test
public void whenOpeningATransactionFromASession_ReturnATransactionWithParametersSet() {
try (GraknSession session = RemoteGraknSession.create(KEYSPACE, URI, server.channel())) {
try (GraknTx tx = session.open(GraknTxType.READ)) {
assertEquals(session, tx.session());
assertEquals(KEYSPACE, tx.keyspace());
assertEquals(GraknTxType.READ, tx.txType());
}
}
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class GraqlController method explainGraql.
@GET
@Path("/kb/{keyspace}/explain")
private String explainGraql(Request request, Response response) throws RetryException, ExecutionException {
Keyspace keyspace = Keyspace.of(mandatoryPathParameter(request, KEYSPACE_PARAM));
String queryString = mandatoryQueryParameter(request, QUERY);
response.status(SC_OK);
return executeFunctionWithRetrying(() -> {
try (GraknTx tx = factory.tx(keyspace, GraknTxType.WRITE);
Timer.Context context = executeExplanation.time()) {
Answer answer = tx.graql().infer(true).parser().<GetQuery>parseQuery(queryString).execute().stream().findFirst().orElse(new QueryAnswer());
return mapper.writeValueAsString(ExplanationBuilder.buildExplanation(answer));
}
});
}
Aggregations