Search in sources :

Example 6 with ThreadTrace

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;
    }
}
Also used : LabelConstraint(com.vaticle.typedb.core.pattern.constraint.type.LabelConstraint) ValueType(com.vaticle.typedb.core.concept.type.AttributeType.ValueType) ThreadTrace(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace) ThingType(com.vaticle.typedb.core.concept.type.ThingType)

Example 7 with ThreadTrace

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);
    }
}
Also used : ThreadTrace(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace)

Example 8 with ThreadTrace

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);
    }
}
Also used : ThreadTrace(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace)

Example 9 with ThreadTrace

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);
    }
}
Also used : LabelConstraint(com.vaticle.typedb.core.pattern.constraint.type.LabelConstraint) ThreadTrace(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace) ThingType(com.vaticle.typedb.core.concept.type.ThingType)

Example 10 with ThreadTrace

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();
    }
}
Also used : ConceptManager(com.vaticle.typedb.core.concept.ConceptManager) Context(com.vaticle.typedb.core.common.parameters.Context) LabelConstraint(com.vaticle.typedb.core.pattern.constraint.type.LabelConstraint) TypeQLUndefine(com.vaticle.typeql.lang.query.TypeQLUndefine) RelationType(com.vaticle.typedb.core.concept.type.RelationType) INVALID_UNDEFINE_SUB(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_SUB) LogicManager(com.vaticle.typedb.core.logic.LogicManager) HashSet(java.util.HashSet) PlaysConstraint(com.vaticle.typedb.core.pattern.constraint.type.PlaysConstraint) TYPE_CONSTRAINT_UNACCEPTED(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_CONSTRAINT_UNACCEPTED) INVALID_UNDEFINE_OWNS_KEY(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_OWNS_KEY) ThingType(com.vaticle.typedb.core.concept.type.ThingType) RelatesConstraint(com.vaticle.typedb.core.pattern.constraint.type.RelatesConstraint) TYPE_NOT_FOUND(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeRead.TYPE_NOT_FOUND) INVALID_UNDEFINE_RELATES_OVERRIDE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_RELATES_OVERRIDE) OwnsConstraint(com.vaticle.typedb.core.pattern.constraint.type.OwnsConstraint) LinkedList(java.util.LinkedList) IS(com.vaticle.typeql.lang.common.TypeQLToken.Constraint.IS) ROLE_DEFINED_OUTSIDE_OF_RELATION(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ROLE_DEFINED_OUTSIDE_OF_RELATION) SubConstraint(com.vaticle.typedb.core.pattern.constraint.type.SubConstraint) Set(java.util.Set) RegexConstraint(com.vaticle.typedb.core.pattern.constraint.type.RegexConstraint) ATTRIBUTE_VALUE_TYPE_UNDEFINED(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ATTRIBUTE_VALUE_TYPE_UNDEFINED) RoleType(com.vaticle.typedb.core.concept.type.RoleType) FactoryTracingThreadStatic.traceOnThread(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.traceOnThread) RULE_NOT_FOUND(com.vaticle.typedb.core.common.exception.ErrorMessage.RuleRead.RULE_NOT_FOUND) INVALID_UNDEFINE_OWNS_OVERRIDE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_OWNS_OVERRIDE) INVALID_UNDEFINE_RULE_BODY(com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.INVALID_UNDEFINE_RULE_BODY) List(java.util.List) TypeVariable(com.vaticle.typedb.core.pattern.variable.TypeVariable) VariableRegistry(com.vaticle.typedb.core.pattern.variable.VariableRegistry) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) ThreadTrace(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace) INVALID_UNDEFINE_PLAYS_OVERRIDE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_PLAYS_OVERRIDE) Type(com.vaticle.typedb.core.concept.type.Type) ThreadTrace(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace) ThingType(com.vaticle.typedb.core.concept.type.ThingType)

Aggregations

ThreadTrace (com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace)14 ThingType (com.vaticle.typedb.core.concept.type.ThingType)6 LabelConstraint (com.vaticle.typedb.core.pattern.constraint.type.LabelConstraint)5 AttributeType (com.vaticle.typedb.core.concept.type.AttributeType)3 RoleType (com.vaticle.typedb.core.concept.type.RoleType)3 VariableRegistry (com.vaticle.typedb.core.pattern.variable.VariableRegistry)3 FactoryTracingThreadStatic.traceOnThread (com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.traceOnThread)2 TYPE_NOT_FOUND (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeRead.TYPE_NOT_FOUND)2 ROLE_DEFINED_OUTSIDE_OF_RELATION (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ROLE_DEFINED_OUTSIDE_OF_RELATION)2 TYPE_CONSTRAINT_UNACCEPTED (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_CONSTRAINT_UNACCEPTED)2 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)2 Context (com.vaticle.typedb.core.common.parameters.Context)2 ConceptManager (com.vaticle.typedb.core.concept.ConceptManager)2 ValueType (com.vaticle.typedb.core.concept.type.AttributeType.ValueType)2 RelationType (com.vaticle.typedb.core.concept.type.RelationType)2 LogicManager (com.vaticle.typedb.core.logic.LogicManager)2 OwnsConstraint (com.vaticle.typedb.core.pattern.constraint.type.OwnsConstraint)2 PlaysConstraint (com.vaticle.typedb.core.pattern.constraint.type.PlaysConstraint)2 RegexConstraint (com.vaticle.typedb.core.pattern.constraint.type.RegexConstraint)2 RelatesConstraint (com.vaticle.typedb.core.pattern.constraint.type.RelatesConstraint)2