use of ai.grakn.GraknTx in project grakn by graknlabs.
the class RemoteGraknTxTest method whenExecutingAQueryWithAVoidResult_GetANullBack.
@Test
public void whenExecutingAQueryWithAVoidResult_GetANullBack() {
Query<?> query = match(var("x").isa("person")).delete("x");
String queryString = query.toString();
server.setResponse(GrpcUtil.execQueryRequest(query), GrpcUtil.doneResponse());
try (GraknTx tx = RemoteGraknTx.create(session, GrpcUtil.openRequest(KEYSPACE, GraknTxType.WRITE))) {
// The open request
verify(server.requests()).onNext(any());
assertNull(tx.graql().parse(queryString).execute());
}
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class InsertQueryImpl method getSchemaConcepts.
@Override
public Set<SchemaConcept> getSchemaConcepts() {
GraknTx theGraph = getTx().orElseThrow(GraqlQueryException::noTx);
Set<SchemaConcept> types = allVarPatterns().map(VarPatternAdmin::getTypeLabel).flatMap(CommonUtil::optionalToStream).map(theGraph::<Type>getSchemaConcept).collect(Collectors.toSet());
match().ifPresent(mq -> types.addAll(mq.admin().getSchemaConcepts()));
return types;
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class GraknKeyspaceStoreTest method whenClearingGraphsUsingExternalFactory_EnsureKeyspacesAreDeletedFromSystemGraph.
@Test
public void whenClearingGraphsUsingExternalFactory_EnsureKeyspacesAreDeletedFromSystemGraph() {
String[] keyspaces = { "g1", "g2", "g3" };
// Create transactions to begin with
Set<GraknTx> txs = buildTxs(externalFactoryGraphProvider, keyspaces);
txs.forEach(GraknTx::close);
// Delete a tx entirely
GraknTx deletedGraph = txs.iterator().next();
deletedGraph.admin().delete();
txs.remove(deletedGraph);
// Get system keyspaces
Set<String> systemKeyspaces = getSystemKeyspaces();
// Check only 2 graphs have been built
for (GraknTx tx : txs) {
assertTrue("Contains correct keyspace", systemKeyspaces.contains(tx.keyspace().getValue()));
}
assertFalse(graknKeyspaceStore.containsKeyspace(deletedGraph.keyspace()));
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class GraknKeyspaceStoreTest method whenClearingGraphsUsingEngineFactory_EnsureKeyspacesAreDeletedFromSystemGraph.
@Test
public void whenClearingGraphsUsingEngineFactory_EnsureKeyspacesAreDeletedFromSystemGraph() {
String[] keyspaces = { "g4", "g5", "g6" };
// Create transactions to begin with
Set<GraknTx> txs = buildTxs(engineFactoryKBProvider, keyspaces);
txs.forEach(GraknTx::close);
// Delete a tx entirely
GraknTx deletedGraph = txs.iterator().next();
deletedGraph.admin().delete();
txs.remove(deletedGraph);
// Get system keyspaces
Set<String> systemKeyspaces = getSystemKeyspaces();
// Check only 2 graphs have been built
for (GraknTx tx : txs) {
assertTrue("Contains correct keyspace", systemKeyspaces.contains(tx.keyspace().getValue()));
}
assertFalse(graknKeyspaceStore.containsKeyspace(deletedGraph.keyspace()));
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class GrpcGraknService method delete.
@Override
public void delete(DeleteRequest request, StreamObserver<DeleteResponse> responseObserver) {
try {
runAndConvertGraknExceptions(() -> {
try (GraknTx tx = executor.execute(request.getOpen())) {
tx.admin().delete();
}
responseObserver.onNext(GrpcUtil.deleteResponse());
responseObserver.onCompleted();
});
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
}
}
Aggregations