Search in sources :

Example 1 with OWNS

use of com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.OWNS in project grakn by graknlabs.

the class ThingTypeImpl method ownsKey.

private void ownsKey(AttributeTypeImpl attributeType) {
    validateIsNotDeleted();
    TypeVertex attVertex = attributeType.vertex;
    TypeEdge ownsEdge, ownsKeyEdge;
    if (vertex.outs().edge(OWNS_KEY, attVertex) != null)
        return;
    if (!attributeType.isKeyable()) {
        throw exception(TypeDBException.of(OWNS_KEY_VALUE_TYPE, attributeType.getLabel(), attributeType.getValueType().name()));
    } else if (link(getSupertype().getOwns(attributeType.getValueType(), true), getSupertype().overriddenOwns(false, true)).anyMatch(a -> a.equals(attributeType))) {
        throw exception(TypeDBException.of(OWNS_KEY_NOT_AVAILABLE, attributeType.getLabel()));
    }
    if ((ownsEdge = vertex.outs().edge(OWNS, attVertex)) != null) {
        // TODO: These ownership and uniqueness checks should be parallelised to scale better
        getInstances().forEachRemaining(thing -> {
            FunctionalIterator<? extends Attribute> attrs = thing.getHas(attributeType);
            if (!attrs.hasNext())
                throw exception(TypeDBException.of(OWS_KEY_PRECONDITION_OWNERSHIP_KEY_TOO_MANY, vertex.label(), attVertex.label()));
            Attribute attr = attrs.next();
            if (attrs.hasNext())
                throw exception(TypeDBException.of(OWS_KEY_PRECONDITION_OWNERSHIP_KEY_MISSING, vertex.label(), attVertex.label()));
            else if (compareSize(attr.getOwners(this), 1) != 0) {
                throw exception(TypeDBException.of(OWNS_KEY_PRECONDITION_UNIQUENESS, attVertex.label(), vertex.label()));
            }
        });
        ownsEdge.delete();
    } else if (getInstances().first().isPresent()) {
        throw exception(TypeDBException.of(OWNS_KEY_PRECONDITION_NO_INSTANCES, vertex.label(), attVertex.label()));
    }
    ownsKeyEdge = vertex.outs().put(OWNS_KEY, attVertex);
    if (getSupertype().declaredOwns(false).findFirst(attributeType).isPresent())
        ownsKeyEdge.overridden(attVertex);
}
Also used : TypeEdge(com.vaticle.typedb.core.graph.edge.TypeEdge) INVALID_UNDEFINE_NONEXISTENT_OWNS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_NONEXISTENT_OWNS) RelationImpl(com.vaticle.typedb.core.concept.thing.impl.RelationImpl) ASC(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.ASC) ThingType(com.vaticle.typedb.core.concept.type.ThingType) Iterators.loop(com.vaticle.typedb.core.common.iterator.Iterators.loop) OWNS_KEY_PRECONDITION_UNIQUENESS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_PRECONDITION_UNIQUENESS) FunctionalIterator(com.vaticle.typedb.core.common.iterator.FunctionalIterator) OWNS_KEY_PRECONDITION_NO_INSTANCES(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_PRECONDITION_NO_INSTANCES) OWNS_KEY_VALUE_TYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_VALUE_TYPE) SUB(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.SUB) EntityImpl(com.vaticle.typedb.core.concept.thing.impl.EntityImpl) INVALID_UNDEFINE_NONEXISTENT_PLAYS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_NONEXISTENT_PLAYS) Forwardable(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable) INVALID_UNDEFINE_PLAYS_HAS_INSTANCES(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_PLAYS_HAS_INSTANCES) ThingVertex(com.vaticle.typedb.core.graph.vertex.ThingVertex) Objects(java.util.Objects) List(java.util.List) ThingImpl(com.vaticle.typedb.core.concept.thing.impl.ThingImpl) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) PLAYS_ROLE_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.PLAYS_ROLE_NOT_AVAILABLE) OVERRIDDEN_NOT_SUPERTYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OVERRIDDEN_NOT_SUPERTYPE) Iterators.link(com.vaticle.typedb.core.common.iterator.Iterators.link) INVALID_UNDEFINE_INHERITED_OWNS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_INHERITED_OWNS) Order(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Order) Function(java.util.function.Function) Forwardable.iterateSorted(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.iterateSorted) INVALID_UNDEFINE_OWNS_HAS_INSTANCES(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_OWNS_HAS_INSTANCES) OWNS_ABSTRACT_ATT_TYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_ABSTRACT_ATT_TYPE) Forwardable.emptySorted(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.emptySorted) OWNS_ATT_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_ATT_NOT_AVAILABLE) OWS_KEY_PRECONDITION_OWNERSHIP_KEY_TOO_MANY(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWS_KEY_PRECONDITION_OWNERSHIP_KEY_TOO_MANY) TYPE_HAS_SUBTYPES(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_HAS_SUBTYPES) INVALID_UNDEFINE_INHERITED_PLAYS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_INHERITED_PLAYS) TYPE_HAS_INSTANCES_DELETE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_HAS_INSTANCES_DELETE) Encoding(com.vaticle.typedb.core.graph.common.Encoding) Nullable(javax.annotation.Nullable) PLAYS(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.PLAYS) GraphManager(com.vaticle.typedb.core.graph.GraphManager) UNRECOGNISED_VALUE(com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.UNRECOGNISED_VALUE) OWS_KEY_PRECONDITION_OWNERSHIP_KEY_MISSING(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWS_KEY_PRECONDITION_OWNERSHIP_KEY_MISSING) Iterators(com.vaticle.typedb.core.common.iterator.Iterators) OWNS_KEY(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.OWNS_KEY) AttributeImpl(com.vaticle.typedb.core.concept.thing.impl.AttributeImpl) RoleType(com.vaticle.typedb.core.concept.type.RoleType) OWNS_KEY_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_NOT_AVAILABLE) Attribute(com.vaticle.typedb.core.concept.thing.Attribute) Iterators.compareSize(com.vaticle.typedb.core.common.iterator.Iterators.compareSize) PLAYS_ABSTRACT_ROLE_TYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.PLAYS_ABSTRACT_ROLE_TYPE) ROOT_TYPE_MUTATION(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ROOT_TYPE_MUTATION) OWNS(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.OWNS) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex) Collections(java.util.Collections) TYPE_HAS_INSTANCES_SET_ABSTRACT(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_HAS_INSTANCES_SET_ABSTRACT) Type(com.vaticle.typedb.core.concept.type.Type) OVERRIDE_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OVERRIDE_NOT_AVAILABLE) TypeEdge(com.vaticle.typedb.core.graph.edge.TypeEdge) Attribute(com.vaticle.typedb.core.concept.thing.Attribute) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex)

Example 2 with OWNS

use of com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.OWNS in project grakn by graknlabs.

the class ThingTypeImpl method ownsAttribute.

private void ownsAttribute(AttributeTypeImpl attributeType) {
    validateIsNotDeleted();
    Forwardable<AttributeType, Order.Asc> owns = getSupertypes().filter(t -> !t.equals(this)).mergeMap(ThingType::getOwns, ASC);
    if (owns.findFirst(attributeType).isPresent()) {
        throw exception(TypeDBException.of(OWNS_ATT_NOT_AVAILABLE, attributeType.getLabel()));
    }
    TypeVertex attVertex = attributeType.vertex;
    TypeEdge keyEdge;
    if ((keyEdge = vertex.outs().edge(OWNS_KEY, attVertex)) != null)
        keyEdge.delete();
    vertex.outs().put(OWNS, attVertex);
}
Also used : TypeEdge(com.vaticle.typedb.core.graph.edge.TypeEdge) INVALID_UNDEFINE_NONEXISTENT_OWNS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_NONEXISTENT_OWNS) RelationImpl(com.vaticle.typedb.core.concept.thing.impl.RelationImpl) ASC(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.ASC) ThingType(com.vaticle.typedb.core.concept.type.ThingType) Iterators.loop(com.vaticle.typedb.core.common.iterator.Iterators.loop) OWNS_KEY_PRECONDITION_UNIQUENESS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_PRECONDITION_UNIQUENESS) FunctionalIterator(com.vaticle.typedb.core.common.iterator.FunctionalIterator) OWNS_KEY_PRECONDITION_NO_INSTANCES(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_PRECONDITION_NO_INSTANCES) OWNS_KEY_VALUE_TYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_VALUE_TYPE) SUB(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.SUB) EntityImpl(com.vaticle.typedb.core.concept.thing.impl.EntityImpl) INVALID_UNDEFINE_NONEXISTENT_PLAYS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_NONEXISTENT_PLAYS) Forwardable(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable) INVALID_UNDEFINE_PLAYS_HAS_INSTANCES(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_PLAYS_HAS_INSTANCES) ThingVertex(com.vaticle.typedb.core.graph.vertex.ThingVertex) Objects(java.util.Objects) List(java.util.List) ThingImpl(com.vaticle.typedb.core.concept.thing.impl.ThingImpl) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) PLAYS_ROLE_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.PLAYS_ROLE_NOT_AVAILABLE) OVERRIDDEN_NOT_SUPERTYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OVERRIDDEN_NOT_SUPERTYPE) Iterators.link(com.vaticle.typedb.core.common.iterator.Iterators.link) INVALID_UNDEFINE_INHERITED_OWNS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_INHERITED_OWNS) Order(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Order) Function(java.util.function.Function) Forwardable.iterateSorted(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.iterateSorted) INVALID_UNDEFINE_OWNS_HAS_INSTANCES(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_OWNS_HAS_INSTANCES) OWNS_ABSTRACT_ATT_TYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_ABSTRACT_ATT_TYPE) Forwardable.emptySorted(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.emptySorted) OWNS_ATT_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_ATT_NOT_AVAILABLE) OWS_KEY_PRECONDITION_OWNERSHIP_KEY_TOO_MANY(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWS_KEY_PRECONDITION_OWNERSHIP_KEY_TOO_MANY) TYPE_HAS_SUBTYPES(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_HAS_SUBTYPES) INVALID_UNDEFINE_INHERITED_PLAYS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_INHERITED_PLAYS) TYPE_HAS_INSTANCES_DELETE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_HAS_INSTANCES_DELETE) Encoding(com.vaticle.typedb.core.graph.common.Encoding) Nullable(javax.annotation.Nullable) PLAYS(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.PLAYS) GraphManager(com.vaticle.typedb.core.graph.GraphManager) UNRECOGNISED_VALUE(com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.UNRECOGNISED_VALUE) OWS_KEY_PRECONDITION_OWNERSHIP_KEY_MISSING(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWS_KEY_PRECONDITION_OWNERSHIP_KEY_MISSING) Iterators(com.vaticle.typedb.core.common.iterator.Iterators) OWNS_KEY(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.OWNS_KEY) AttributeImpl(com.vaticle.typedb.core.concept.thing.impl.AttributeImpl) RoleType(com.vaticle.typedb.core.concept.type.RoleType) OWNS_KEY_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_NOT_AVAILABLE) Attribute(com.vaticle.typedb.core.concept.thing.Attribute) Iterators.compareSize(com.vaticle.typedb.core.common.iterator.Iterators.compareSize) PLAYS_ABSTRACT_ROLE_TYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.PLAYS_ABSTRACT_ROLE_TYPE) ROOT_TYPE_MUTATION(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ROOT_TYPE_MUTATION) OWNS(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.OWNS) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex) Collections(java.util.Collections) TYPE_HAS_INSTANCES_SET_ABSTRACT(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_HAS_INSTANCES_SET_ABSTRACT) Type(com.vaticle.typedb.core.concept.type.Type) OVERRIDE_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OVERRIDE_NOT_AVAILABLE) TypeEdge(com.vaticle.typedb.core.graph.edge.TypeEdge) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) ThingType(com.vaticle.typedb.core.concept.type.ThingType) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex)

Aggregations

UNRECOGNISED_VALUE (com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.UNRECOGNISED_VALUE)2 INVALID_UNDEFINE_INHERITED_OWNS (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_INHERITED_OWNS)2 INVALID_UNDEFINE_INHERITED_PLAYS (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_INHERITED_PLAYS)2 INVALID_UNDEFINE_NONEXISTENT_OWNS (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_NONEXISTENT_OWNS)2 INVALID_UNDEFINE_NONEXISTENT_PLAYS (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_NONEXISTENT_PLAYS)2 INVALID_UNDEFINE_OWNS_HAS_INSTANCES (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_OWNS_HAS_INSTANCES)2 INVALID_UNDEFINE_PLAYS_HAS_INSTANCES (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_PLAYS_HAS_INSTANCES)2 OVERRIDDEN_NOT_SUPERTYPE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OVERRIDDEN_NOT_SUPERTYPE)2 OVERRIDE_NOT_AVAILABLE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OVERRIDE_NOT_AVAILABLE)2 OWNS_ABSTRACT_ATT_TYPE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_ABSTRACT_ATT_TYPE)2 OWNS_ATT_NOT_AVAILABLE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_ATT_NOT_AVAILABLE)2 OWNS_KEY_NOT_AVAILABLE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_NOT_AVAILABLE)2 OWNS_KEY_PRECONDITION_NO_INSTANCES (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_PRECONDITION_NO_INSTANCES)2 OWNS_KEY_PRECONDITION_UNIQUENESS (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_PRECONDITION_UNIQUENESS)2 OWNS_KEY_VALUE_TYPE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_VALUE_TYPE)2 OWS_KEY_PRECONDITION_OWNERSHIP_KEY_MISSING (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWS_KEY_PRECONDITION_OWNERSHIP_KEY_MISSING)2 OWS_KEY_PRECONDITION_OWNERSHIP_KEY_TOO_MANY (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWS_KEY_PRECONDITION_OWNERSHIP_KEY_TOO_MANY)2 PLAYS_ABSTRACT_ROLE_TYPE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.PLAYS_ABSTRACT_ROLE_TYPE)2 PLAYS_ROLE_NOT_AVAILABLE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.PLAYS_ROLE_NOT_AVAILABLE)2 ROOT_TYPE_MUTATION (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ROOT_TYPE_MUTATION)2