Search in sources :

Example 11 with TypeVertex

use of com.vaticle.typedb.core.graph.vertex.TypeVertex in project grakn by graknlabs.

the class RelationTypeImpl method setRelates.

@Override
public void setRelates(String roleLabel) {
    validateIsNotDeleted();
    TypeVertex roleTypeVertex = graphMgr.schema().getType(roleLabel, vertex.label());
    if (roleTypeVertex == null) {
        if (getSupertypes().filter(t -> !t.equals(this) && t.isRelationType()).map(TypeImpl::asRelationType).flatMap(RelationType::getRelates).anyMatch(role -> role.getLabel().name().equals(roleLabel))) {
            throw exception(TypeDBException.of(RELATION_RELATES_ROLE_FROM_SUPERTYPE, roleLabel, getLabel()));
        } else {
            RoleTypeImpl roleType = RoleTypeImpl.of(graphMgr, roleLabel, vertex.label());
            assert roleType.getSupertype() != null;
            if (this.isAbstract())
                roleType.setAbstract();
            vertex.outs().put(RELATES, roleType.vertex);
            vertex.outs().edge(RELATES, roleType.vertex).overridden(((TypeImpl) roleType.getSupertype()).vertex);
        }
    }
}
Also used : TYPE_ROOT_MISMATCH(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeRead.TYPE_ROOT_MISMATCH) TypeEdge(com.vaticle.typedb.core.graph.edge.TypeEdge) RELATION_RELATES_ROLE_FROM_SUPERTYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_RELATES_ROLE_FROM_SUPERTYPE) Order(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Order) RelationImpl(com.vaticle.typedb.core.concept.thing.impl.RelationImpl) RelationType(com.vaticle.typedb.core.concept.type.RelationType) ASC(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.ASC) Forwardable.iterateSorted(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.iterateSorted) RELATION_NO_ROLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_NO_ROLE) RELATION_ABSTRACT_ROLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_ABSTRACT_ROLE) RELATES(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.RELATES) RELATION(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.Root.RELATION) ROLE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.Root.ROLE) RELATION_RELATES_ROLE_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_RELATES_ROLE_NOT_AVAILABLE) RELATION_TYPE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.RELATION_TYPE) GraphManager(com.vaticle.typedb.core.graph.GraphManager) FunctionalIterator(com.vaticle.typedb.core.common.iterator.FunctionalIterator) Forwardable(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable) RoleType(com.vaticle.typedb.core.concept.type.RoleType) ThingVertex(com.vaticle.typedb.core.graph.vertex.ThingVertex) Objects(java.util.Objects) List(java.util.List) Relation(com.vaticle.typedb.core.concept.thing.Relation) ROOT_TYPE_MUTATION(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ROOT_TYPE_MUTATION) Optional(java.util.Optional) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex) 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) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex)

Example 12 with TypeVertex

use of com.vaticle.typedb.core.graph.vertex.TypeVertex in project grakn by graknlabs.

the class ThingTypeImpl method unsetOwns.

@Override
public void unsetOwns(AttributeType attributeType) {
    validateIsNotDeleted();
    TypeEdge edge;
    TypeVertex attVertex = ((AttributeTypeImpl) attributeType).vertex;
    if (getInstances().anyMatch(thing -> thing.getHas(attributeType).first().isPresent())) {
        throw exception(TypeDBException.of(INVALID_UNDEFINE_OWNS_HAS_INSTANCES, vertex.label(), attVertex.label()));
    }
    if ((edge = vertex.outs().edge(OWNS_KEY, attVertex)) != null)
        edge.delete();
    else if ((edge = vertex.outs().edge(OWNS, attVertex)) != null)
        edge.delete();
    else if (this.getOwns().findFirst((AttributeTypeImpl) attributeType).isPresent()) {
        throw exception(TypeDBException.of(INVALID_UNDEFINE_INHERITED_OWNS, this.getLabel().toString(), attributeType.getLabel().toString()));
    } else {
        throw exception(TypeDBException.of(INVALID_UNDEFINE_NONEXISTENT_OWNS, this.getLabel().toString(), attributeType.getLabel().toString()));
    }
}
Also used : TypeEdge(com.vaticle.typedb.core.graph.edge.TypeEdge) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex)

Example 13 with TypeVertex

use of com.vaticle.typedb.core.graph.vertex.TypeVertex 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)

Example 14 with TypeVertex

use of com.vaticle.typedb.core.graph.vertex.TypeVertex in project grakn by graknlabs.

the class TypeGraph method initialise.

public void initialise() throws TypeDBException {
    TypeVertex rootThingType = create(THING_TYPE, THING.label()).isAbstract(true);
    TypeVertex rootEntityType = create(ENTITY_TYPE, ENTITY.label()).isAbstract(true);
    TypeVertex rootAttributeType = create(ATTRIBUTE_TYPE, ATTRIBUTE.label()).isAbstract(true).valueType(OBJECT);
    TypeVertex rootRelationType = create(RELATION_TYPE, RELATION.label()).isAbstract(true);
    TypeVertex rootRoleType = create(ROLE_TYPE, ROLE.label(), RELATION.label()).isAbstract(true);
    rootEntityType.outs().put(SUB, rootThingType);
    rootAttributeType.outs().put(SUB, rootThingType);
    rootRelationType.outs().put(SUB, rootThingType);
    rootRelationType.outs().put(RELATES, rootRoleType);
}
Also used : TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex)

Example 15 with TypeVertex

use of com.vaticle.typedb.core.graph.vertex.TypeVertex in project grakn by graknlabs.

the class TypeGraph method update.

public TypeVertex update(TypeVertex vertex, String oldLabel, @Nullable String oldScope, String newLabel, @Nullable String newScope) {
    assert storage.isOpen();
    if (isReadOnly)
        throw TypeDBException.of(TRANSACTION_SCHEMA_READ_VIOLATION);
    String oldScopedLabel = scopedLabel(oldLabel, oldScope);
    String newScopedLabel = scopedLabel(newLabel, newScope);
    try {
        TypeVertex type = getType(newLabel, newScope);
        multiLabelLock.writeLock().lock();
        if (type != null)
            throw TypeDBException.of(INVALID_SCHEMA_WRITE, newScopedLabel);
        typesByLabel.remove(oldScopedLabel);
        typesByLabel.put(newScopedLabel, vertex);
        cache.clear();
        return vertex;
    } finally {
        multiLabelLock.writeLock().unlock();
    }
}
Also used : TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex)

Aggregations

TypeVertex (com.vaticle.typedb.core.graph.vertex.TypeVertex)15 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)7 ASC (com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.ASC)7 Forwardable (com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable)7 Order (com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Order)7 TypeEdge (com.vaticle.typedb.core.graph.edge.TypeEdge)7 FunctionalIterator (com.vaticle.typedb.core.common.iterator.FunctionalIterator)6 Forwardable.iterateSorted (com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.iterateSorted)6 List (java.util.List)6 GraphManager (com.vaticle.typedb.core.graph.GraphManager)5 ThingVertex (com.vaticle.typedb.core.graph.vertex.ThingVertex)5 Objects (java.util.Objects)5 KeyValue (com.vaticle.typedb.core.common.collection.KeyValue)4 Encoding (com.vaticle.typedb.core.graph.common.Encoding)4 ByteArray (com.vaticle.typedb.core.common.collection.ByteArray)3 ROOT_TYPE_MUTATION (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ROOT_TYPE_MUTATION)3 TYPE_HAS_INSTANCES_SET_ABSTRACT (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_HAS_INSTANCES_SET_ABSTRACT)3 Iterators.iterate (com.vaticle.typedb.core.common.iterator.Iterators.iterate)3 Label (com.vaticle.typedb.core.common.parameters.Label)3 RelationImpl (com.vaticle.typedb.core.concept.thing.impl.RelationImpl)3