Search in sources :

Example 96 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class XMLMigratorTest method clearGraph.

@After
public void clearGraph() {
    try (GraknTx graph = session.open(GraknTxType.WRITE)) {
        AttributeType<String> nameType = graph.getAttributeType("name");
        nameType.instances().forEach(Concept::delete);
        EntityType thingType = graph.getEntityType("thingy");
        thingType.instances().forEach(Concept::delete);
        graph.commit();
    }
}
Also used : Concept(ai.grakn.concept.Concept) EntityType(ai.grakn.concept.EntityType) GraknTx(ai.grakn.GraknTx) After(org.junit.After)

Example 97 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class SampleKBLoader method tx.

public EmbeddedGraknTx<?> tx() {
    if (tx == null || tx.isClosed()) {
        // Load the graph if we need to
        if (!graphLoaded) {
            try (GraknTx graph = factory.open(GraknTxType.WRITE)) {
                load(graph);
                graph.commit();
                graphLoaded = true;
            }
        }
        tx = factory.open(GraknTxType.WRITE);
    }
    return tx;
}
Also used : GraknTx(ai.grakn.GraknTx) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx)

Example 98 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class JsonMigratorTest method whenMigratorExecutedOverMissingData_ErrorIsNotThrownAndMissingObjectsAreSkipped.

@Test
public void whenMigratorExecutedOverMissingData_ErrorIsNotThrownAndMissingObjectsAreSkipped() {
    load(factory, getFile("json", "string-or-object/schema.gql"));
    String template = "insert $thing isa the-thing has a-string <the-thing.a-string>;";
    declareAndLoad(template, "string-or-object/data");
    try (GraknTx graph = factory.open(GraknTxType.READ)) {
        EntityType theThing = graph.getEntityType("the-thing");
        assertEquals(1, theThing.instances().count());
    }
}
Also used : EntityType(ai.grakn.concept.EntityType) GraknTx(ai.grakn.GraknTx) Test(org.junit.Test)

Example 99 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class GrpcServerIT method whenGettingAConcept_TheInformationOnTheConceptIsCorrect.

@Test
public void whenGettingAConcept_TheInformationOnTheConceptIsCorrect() {
    try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
        GraknTx localTx = localSession.open(GraknTxType.READ)) {
        GetQuery query = remoteTx.graql().match(var("x")).get();
        for (Answer answer : query) {
            Concept remoteConcept = answer.get("x");
            Concept localConcept = localTx.getConcept(remoteConcept.getId());
            assertEquals(localConcept.isAttribute(), remoteConcept.isAttribute());
            assertEquals(localConcept.isAttributeType(), remoteConcept.isAttributeType());
            assertEquals(localConcept.isEntity(), remoteConcept.isEntity());
            assertEquals(localConcept.isEntityType(), remoteConcept.isEntityType());
            assertEquals(localConcept.isRelationship(), remoteConcept.isRelationship());
            assertEquals(localConcept.isRelationshipType(), remoteConcept.isRelationshipType());
            assertEquals(localConcept.isRole(), remoteConcept.isRole());
            assertEquals(localConcept.isRule(), remoteConcept.isRule());
            assertEquals(localConcept.isSchemaConcept(), remoteConcept.isSchemaConcept());
            assertEquals(localConcept.isThing(), remoteConcept.isThing());
            assertEquals(localConcept.isType(), remoteConcept.isType());
            assertEquals(localConcept.getId(), remoteConcept.getId());
            assertEquals(localConcept.isDeleted(), remoteConcept.isDeleted());
            assertEquals(localConcept.keyspace(), remoteConcept.keyspace());
        }
    }
}
Also used : Concept(ai.grakn.concept.Concept) SchemaConcept(ai.grakn.concept.SchemaConcept) GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 100 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class GrpcServerIT method whenDeletingAConcept_TheConceptIsDeleted.

@Test
public void whenDeletingAConcept_TheConceptIsDeleted() {
    Label label = Label.of("hello");
    try (GraknTx tx = localSession.open(GraknTxType.WRITE)) {
        tx.putEntityType(label);
        tx.commit();
    }
    try (GraknTx tx = remoteSession.open(GraknTxType.WRITE)) {
        SchemaConcept schemaConcept = tx.getSchemaConcept(label);
        assertFalse(schemaConcept.isDeleted());
        schemaConcept.delete();
        assertTrue(schemaConcept.isDeleted());
        tx.commit();
    }
    try (GraknTx tx = localSession.open(GraknTxType.WRITE)) {
        assertNull(tx.getSchemaConcept(label));
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Label(ai.grakn.concept.Label) SchemaConcept(ai.grakn.concept.SchemaConcept) Test(org.junit.Test)

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