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();
}
}
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;
}
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());
}
}
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());
}
}
}
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));
}
}
Aggregations