Search in sources :

Example 71 with GraknTx

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");
}
Also used : GraknTx(ai.grakn.GraknTx) BeforeClass(org.junit.BeforeClass)

Example 72 with GraknTx

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");
}
Also used : GraknTx(ai.grakn.GraknTx) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) GraknSession(ai.grakn.GraknSession) Test(org.junit.Test)

Example 73 with GraknTx

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();
}
Also used : GraknTx(ai.grakn.GraknTx) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) Test(org.junit.Test)

Example 74 with GraknTx

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());
        }
    }
}
Also used : GraknTx(ai.grakn.GraknTx) GraknSession(ai.grakn.GraknSession) Test(org.junit.Test)

Example 75 with GraknTx

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));
        }
    });
}
Also used : GraknTx(ai.grakn.GraknTx) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) Answer(ai.grakn.graql.admin.Answer) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) Timer(com.codahale.metrics.Timer) GetQuery(ai.grakn.graql.GetQuery) Keyspace(ai.grakn.Keyspace) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

GraknTx (ai.grakn.GraknTx)243 Test (org.junit.Test)189 EntityType (ai.grakn.concept.EntityType)54 GetQuery (ai.grakn.graql.GetQuery)52 Entity (ai.grakn.concept.Entity)51 QueryBuilder (ai.grakn.graql.QueryBuilder)49 Role (ai.grakn.concept.Role)48 RelationshipType (ai.grakn.concept.RelationshipType)46 Answer (ai.grakn.graql.admin.Answer)44 Set (java.util.Set)44 EmbeddedGraknTx (ai.grakn.kb.internal.EmbeddedGraknTx)33 Label (ai.grakn.concept.Label)28 Attribute (ai.grakn.concept.Attribute)27 Concept (ai.grakn.concept.Concept)27 HashSet (java.util.HashSet)26 GraknSession (ai.grakn.GraknSession)22 AttributeType (ai.grakn.concept.AttributeType)22 ConceptId (ai.grakn.concept.ConceptId)22 List (java.util.List)19 GraknTxType (ai.grakn.GraknTxType)17