use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.
the class SchemaConceptPropertyTest method whenASchemaElementHasADirectSuper_ItIsADirectSubOfThatSuper.
@Property
public void whenASchemaElementHasADirectSuper_ItIsADirectSubOfThatSuper(SchemaConcept schemaConcept) {
SchemaConcept superConcept = schemaConcept.sup();
assumeTrue(superConcept != null);
assertThat(PropertyUtil.directSubs(superConcept), hasItem(schemaConcept));
}
use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.
the class ValidateGlobalRules method checkRuleSideInvalid.
/**
* @param graph The graph to query against
* @param rule The rule the pattern was extracted from
* @param side The side from which the pattern was extracted
* @param pattern The pattern from which we will extract the types in the pattern
* @return A list of errors if the pattern refers to any non-existent types in the graph
*/
private static Set<String> checkRuleSideInvalid(GraknTx graph, Rule rule, Schema.VertexProperty side, Pattern pattern) {
Set<String> errors = new HashSet<>();
pattern.admin().varPatterns().stream().flatMap(v -> v.innerVarPatterns().stream()).flatMap(v -> v.getTypeLabels().stream()).forEach(typeLabel -> {
SchemaConcept schemaConcept = graph.getSchemaConcept(typeLabel);
if (schemaConcept == null) {
errors.add(ErrorMessage.VALIDATION_RULE_MISSING_ELEMENTS.getMessage(side, rule.getLabel(), typeLabel));
} else {
if (Schema.VertexProperty.RULE_WHEN.equals(side)) {
if (schemaConcept.isType()) {
RuleImpl.from(rule).addHypothesis(schemaConcept.asType());
}
} else if (Schema.VertexProperty.RULE_THEN.equals(side)) {
if (schemaConcept.isType()) {
RuleImpl.from(rule).addConclusion(schemaConcept.asType());
}
} else {
throw GraknTxOperationException.invalidPropertyUse(rule, side);
}
}
});
return errors;
}
use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.
the class GlobalCache method populateSchemaTxCache.
void populateSchemaTxCache(TxCache txCache) {
try {
lock.writeLock().lock();
Map<Label, SchemaConcept> cachedSchemaSnapshot = getCachedTypes();
Map<Label, LabelId> cachedLabelsSnapshot = getCachedLabels();
// Read central cache into txCache cloning only base concepts. Sets clones later
for (SchemaConcept type : cachedSchemaSnapshot.values()) {
txCache.cacheConcept(type);
}
// Load Labels Separately. We do this because the TypeCache may have expired.
cachedLabelsSnapshot.forEach(txCache::cacheLabel);
} finally {
lock.writeLock().unlock();
}
}
use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.
the class GraknTxTest method whenClosingReadOnlyGraph_EnsureTypesAreCached.
@Test
public void whenClosingReadOnlyGraph_EnsureTypesAreCached() {
assertCacheOnlyContainsMetaTypes();
// noinspection ResultOfMethodCallIgnored
// This loads some types into transaction cache
tx.getMetaConcept().subs();
tx.abort();
// Ensure central cache is empty
assertCacheOnlyContainsMetaTypes();
tx = EmbeddedGraknSession.create(tx.keyspace(), Grakn.IN_MEMORY).open(GraknTxType.READ);
Set<SchemaConcept> finalTypes = new HashSet<>();
finalTypes.addAll(tx.getMetaConcept().subs().collect(toSet()));
finalTypes.add(tx.getMetaRole());
finalTypes.add(tx.getMetaRule());
tx.abort();
for (SchemaConcept type : tx.getGlobalCache().getCachedTypes().values()) {
assertTrue("Type [" + type + "] is missing from central cache after closing read only graph", finalTypes.contains(type));
}
}
use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.
the class DeleteQueryTest method whenDeletingASchemaConcept_Throw.
@Test
public void whenDeletingASchemaConcept_Throw() {
SchemaConcept newType = qb.define(x.label("new-type").sub(ENTITY)).execute().get(x).asSchemaConcept();
exception.expect(GraqlQueryException.class);
exception.expectMessage(GraqlQueryException.deleteSchemaConcept(newType).getMessage());
qb.match(x.label("new-type")).delete(x).execute();
}
Aggregations