use of com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace in project grakn by graknlabs.
the class Definer method defineSub.
private ThingType defineSub(ThingType thingType, SubConstraint subConstraint, TypeVariable var) {
try (ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "define_sub")) {
LabelConstraint labelConstraint = var.label().get();
ThingType supertype = define(subConstraint.type()).asThingType();
if (supertype.isEntityType()) {
if (thingType == null)
thingType = conceptMgr.putEntityType(labelConstraint.label());
thingType.asEntityType().setSupertype(supertype.asEntityType());
} else if (supertype.isRelationType()) {
if (thingType == null)
thingType = conceptMgr.putRelationType(labelConstraint.label());
thingType.asRelationType().setSupertype(supertype.asRelationType());
} else if (supertype.isAttributeType()) {
ValueType valueType;
if (var.valueType().isPresent())
valueType = ValueType.of(var.valueType().get().valueType());
else if (!supertype.isRoot())
valueType = supertype.asAttributeType().getValueType();
else
throw TypeDBException.of(ATTRIBUTE_VALUE_TYPE_MISSING, labelConstraint.label());
if (thingType == null)
thingType = conceptMgr.putAttributeType(labelConstraint.label(), valueType);
thingType.asAttributeType().setSupertype(supertype.asAttributeType());
} else {
throw TypeDBException.of(INVALID_DEFINE_SUB, labelConstraint.scopedLabel(), supertype.getLabel());
}
return thingType;
}
}
use of com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace in project grakn by graknlabs.
the class Undefiner method sort.
private void sort(TypeVariable variable, Set<TypeVariable> sorted) {
try (ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "sort")) {
if (sorted.contains(variable))
return;
if (variable.sub().isPresent())
sort(variable.sub().get().type(), sorted);
this.variables.addFirst(variable);
sorted.add(variable);
}
}
use of com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace in project grakn by graknlabs.
the class Undefiner method undefine.
private void undefine(com.vaticle.typeql.lang.pattern.schema.Rule rule) {
try (ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "undefine_plays")) {
if (rule.when() != null || rule.then() != null) {
throw TypeDBException.of(INVALID_UNDEFINE_RULE_BODY, rule.label());
}
com.vaticle.typedb.core.logic.Rule r = logicMgr.getRule(rule.label());
if (r == null)
throw TypeDBException.of(RULE_NOT_FOUND, rule.label());
logicMgr.deleteAndInvalidateRule(r);
}
}
use of com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace in project grakn by graknlabs.
the class Undefiner method undefine.
private void undefine(TypeVariable variable) {
try (ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "undefine")) {
assert variable.label().isPresent();
LabelConstraint labelConstraint = variable.label().get();
if (labelConstraint.scope().isPresent() && variable.constraints().size() > 1) {
throw TypeDBException.of(ROLE_DEFINED_OUTSIDE_OF_RELATION, labelConstraint.scopedLabel());
} else if (!variable.is().isEmpty()) {
throw TypeDBException.of(TYPE_CONSTRAINT_UNACCEPTED, IS);
} else if (// do nothing
labelConstraint.scope().isPresent())
// do nothing
return;
else // do nothing
if (undefined.contains(variable))
return;
ThingType type = getThingType(labelConstraint);
if (!variable.plays().isEmpty())
undefinePlays(type, variable.plays());
if (!variable.owns().isEmpty())
undefineOwns(type, variable.owns());
if (!variable.relates().isEmpty())
undefineRelates(type.asRelationType(), variable.relates());
if (variable.regex().isPresent())
undefineRegex(type.asAttributeType().asString(), variable.regex().get());
if (variable.abstractConstraint().isPresent())
undefineAbstract(type);
if (variable.sub().isPresent())
undefineSub(type, variable.sub().get());
else if (variable.valueType().isPresent()) {
throw TypeDBException.of(ATTRIBUTE_VALUE_TYPE_UNDEFINED, variable.valueType().get().valueType().name(), variable.label().get().label());
}
undefined.add(variable);
}
}
use of com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace in project grakn by graknlabs.
the class Undefiner method undefineSub.
private void undefineSub(ThingType thingType, SubConstraint subConstraint) {
try (ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "undefine_sub")) {
if (thingType.isRoleType()) {
throw TypeDBException.of(ROLE_DEFINED_OUTSIDE_OF_RELATION, thingType.getLabel());
}
ThingType supertype = getThingType(subConstraint.type().label().get());
if (supertype == null) {
throw TypeDBException.of(TYPE_NOT_FOUND, subConstraint.type().label().get());
} else if (thingType.getSupertypes().noneMatch(t -> t.equals(supertype))) {
throw TypeDBException.of(INVALID_UNDEFINE_SUB, thingType.getLabel(), supertype.getLabel());
}
if (thingType.isRelationType()) {
variables.stream().filter(v -> v.label().isPresent() && v.label().get().scope().isPresent() && v.label().get().scope().get().equals(thingType.getLabel().name())).forEach(undefined::add);
}
thingType.delete();
}
}
Aggregations