Search in sources :

Example 1 with ValueType

use of com.vaticle.typedb.core.concept.type.AttributeType.ValueType 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)

Aggregations

ThreadTrace (com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace)1 ValueType (com.vaticle.typedb.core.concept.type.AttributeType.ValueType)1 ThingType (com.vaticle.typedb.core.concept.type.ThingType)1 LabelConstraint (com.vaticle.typedb.core.pattern.constraint.type.LabelConstraint)1