Search in sources :

Example 1 with SubConstraint

use of com.vaticle.typedb.core.pattern.constraint.type.SubConstraint 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)

Example 2 with SubConstraint

use of com.vaticle.typedb.core.pattern.constraint.type.SubConstraint in project grakn by graknlabs.

the class TypeVariable method sub.

public SubConstraint sub(TypeVariable type, boolean isExplicit) {
    SubConstraint subConstraint = new SubConstraint(this, type, isExplicit);
    constrain(subConstraint);
    return subConstraint;
}
Also used : SubConstraint(com.vaticle.typedb.core.pattern.constraint.type.SubConstraint)

Aggregations

SubConstraint (com.vaticle.typedb.core.pattern.constraint.type.SubConstraint)2 ThreadTrace (com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace)1 FactoryTracingThreadStatic.traceOnThread (com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.traceOnThread)1 RULE_NOT_FOUND (com.vaticle.typedb.core.common.exception.ErrorMessage.RuleRead.RULE_NOT_FOUND)1 INVALID_UNDEFINE_RULE_BODY (com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.INVALID_UNDEFINE_RULE_BODY)1 TYPE_NOT_FOUND (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeRead.TYPE_NOT_FOUND)1 ATTRIBUTE_VALUE_TYPE_UNDEFINED (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ATTRIBUTE_VALUE_TYPE_UNDEFINED)1 INVALID_UNDEFINE_OWNS_KEY (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_OWNS_KEY)1 INVALID_UNDEFINE_OWNS_OVERRIDE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_OWNS_OVERRIDE)1 INVALID_UNDEFINE_PLAYS_OVERRIDE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_PLAYS_OVERRIDE)1 INVALID_UNDEFINE_RELATES_OVERRIDE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_RELATES_OVERRIDE)1 INVALID_UNDEFINE_SUB (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_SUB)1 ROLE_DEFINED_OUTSIDE_OF_RELATION (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ROLE_DEFINED_OUTSIDE_OF_RELATION)1 TYPE_CONSTRAINT_UNACCEPTED (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_CONSTRAINT_UNACCEPTED)1 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)1 Context (com.vaticle.typedb.core.common.parameters.Context)1 ConceptManager (com.vaticle.typedb.core.concept.ConceptManager)1 AttributeType (com.vaticle.typedb.core.concept.type.AttributeType)1 RelationType (com.vaticle.typedb.core.concept.type.RelationType)1 RoleType (com.vaticle.typedb.core.concept.type.RoleType)1