Search in sources :

Example 1 with TypeVertex

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

the class EncodingTest method encoded_keys_are_correct.

@Test
public void encoded_keys_are_correct() {
    try (CoreTransaction transaction = session.transaction(WRITE)) {
        Storage.Data storage = transaction.traversal().graph().data().storage();
        assertEquals(0, vertexElements(storage).size());
        assertEquals(0, variableStartEdgeElements(storage).size());
        assertEquals(0, fixedStartEdgeElements(storage).size());
        assertEquals(0, optimisationEdgeElements(storage).size());
        transaction.query().insert(TypeQL.parseQuery("insert " + "$p isa person, has name 'Alice';" + "$c isa company, has company-id 10;" + "(employer: $c, employee: $p) isa employment;").asInsert());
        transaction.commit();
    }
    try (CoreTransaction transaction = session.transaction(WRITE)) {
        GraphManager graph = transaction.traversal().graph();
        Storage.Data storage = graph.data().storage();
        List<KeyValue<RawKey, ByteArray>> vertexKVs = vertexElements(storage);
        assertTrue(iterate(vertexKVs).allMatch(kv -> kv.value().isEmpty()));
        List<ByteArray> vertices = iterate(vertexKVs).map(kv -> kv.key().bytes()).toList();
        // we must have exactly the expected set of vertex bytes
        assertEquals(7, vertices.size());
        ByteArray personIID = expectedIID(graph, Label.of("person"), 0);
        assertTrue(vertices.contains(personIID));
        ByteArray companyIID = expectedIID(graph, Label.of("company"), 0);
        assertTrue(vertices.contains(companyIID));
        ByteArray employmentIID = expectedIID(graph, Label.of("employment"), 0);
        assertTrue(vertices.contains(employmentIID));
        ByteArray employeeRoleIID = expectedIID(graph, Label.of("employee", "employment"), 0);
        assertTrue(vertices.contains(employeeRoleIID));
        ByteArray employerRoleIID = expectedIID(graph, Label.of("employer", "employment"), 0);
        assertTrue(vertices.contains(employerRoleIID));
        ByteArray nameAliceIID = expectedAttributeIID(graph, Label.of("name"), "Alice");
        assertTrue(vertices.contains(nameAliceIID));
        ByteArray companyId10IID = expectedAttributeIID(graph, Label.of("company-id"), 10);
        assertTrue(vertices.contains(companyId10IID));
        // we must have exactly the right set of fixed length edges: relates, plays, and forward has
        List<KeyValue<RawKey, ByteArray>> fixedKVs = fixedStartEdgeElements(storage);
        assertTrue(iterate(fixedKVs).allMatch(kv -> kv.value().isEmpty()));
        List<ByteArray> fixed = iterate(fixedKVs).map(kv -> kv.key().bytes()).toList();
        assertEquals(10, fixed.size());
        assertTrue(fixed.contains(join(personIID, HAS.forward().bytes(), nameAliceIID)));
        assertTrue(fixed.contains(join(personIID, PLAYING.forward().bytes(), employeeRoleIID)));
        assertTrue(fixed.contains(join(employeeRoleIID, PLAYING.backward().bytes(), personIID)));
        assertTrue(fixed.contains(join(employeeRoleIID, RELATING.backward().bytes(), employmentIID)));
        assertTrue(fixed.contains(join(employmentIID, RELATING.forward().bytes(), employeeRoleIID)));
        assertTrue(fixed.contains(join(employmentIID, RELATING.forward().bytes(), employerRoleIID)));
        assertTrue(fixed.contains(join(employerRoleIID, RELATING.backward().bytes(), employmentIID)));
        assertTrue(fixed.contains(join(employerRoleIID, PLAYING.backward().bytes(), companyIID)));
        assertTrue(fixed.contains(join(companyIID, PLAYING.forward().bytes(), employerRoleIID)));
        assertTrue(fixed.contains(join(companyIID, HAS.forward().bytes(), companyId10IID)));
        // we must have exactly the right set of variable length edges: backward has
        List<KeyValue<RawKey, ByteArray>> variableKVs = variableStartEdgeElements(storage);
        assertTrue(iterate(variableKVs).allMatch(kv -> kv.value().isEmpty()));
        List<ByteArray> variable = iterate(variableKVs).map(kv -> kv.key().bytes()).toList();
        assertEquals(2, variable.size());
        assertTrue(variable.contains(join(nameAliceIID, HAS.backward().bytes(), personIID)));
        assertTrue(variable.contains(join(companyId10IID, HAS.backward().bytes(), companyIID)));
        // we must have exactly the right set of optimisation edges: role player
        List<KeyValue<RawKey, ByteArray>> optimisationKVs = optimisationEdgeElements(storage);
        assertTrue(iterate(optimisationKVs).allMatch(kv -> kv.value().isEmpty()));
        List<ByteArray> optimisation = iterate(optimisationKVs).map(kv -> kv.key().bytes()).toList();
        assertEquals(4, optimisation.size());
        TypeVertex employerRoleType = graph.schema().getType(Label.of("employer", "employment"));
        TypeVertex employeeRoleType = graph.schema().getType(Label.of("employee", "employment"));
        assertTrue(optimisation.contains(join(personIID, ROLEPLAYER.backward().bytes(), employeeRoleType.iid().bytes(), employmentIID, employeeRoleIID.view(1 + employeeRoleType.iid().bytes().length()))));
        assertTrue(optimisation.contains(join(employmentIID, ROLEPLAYER.forward().bytes(), employeeRoleType.iid().bytes(), personIID, employeeRoleIID.view(1 + employeeRoleType.iid().bytes().length()))));
        assertTrue(optimisation.contains(join(companyIID, ROLEPLAYER.backward().bytes(), employerRoleType.iid().bytes(), employmentIID, employerRoleIID.view(1 + employerRoleType.iid().bytes().length()))));
        assertTrue(optimisation.contains(join(employmentIID, ROLEPLAYER.forward().bytes(), employerRoleType.iid().bytes(), companyIID, employerRoleIID.view(1 + employerRoleType.iid().bytes().length()))));
    }
}
Also used : Factory(com.vaticle.typedb.core.database.Factory) MB(com.vaticle.typedb.core.common.collection.Bytes.MB) Arguments(com.vaticle.typedb.core.common.parameters.Arguments) ByteArray.encodeLong(com.vaticle.typedb.core.common.collection.ByteArray.encodeLong) VERTEX_ROLE(com.vaticle.typedb.core.graph.common.Encoding.Prefix.VERTEX_ROLE) After(org.junit.After) CoreFactory(com.vaticle.typedb.core.database.CoreFactory) ByteArray.join(com.vaticle.typedb.core.common.collection.ByteArray.join) ByteArray(com.vaticle.typedb.core.common.collection.ByteArray) Path(java.nio.file.Path) VERTEX_ENTITY(com.vaticle.typedb.core.graph.common.Encoding.Prefix.VERTEX_ENTITY) TypeQL(com.vaticle.typeql.lang.TypeQL) AfterClass(org.junit.AfterClass) CoreDatabaseManager(com.vaticle.typedb.core.database.CoreDatabaseManager) Options(com.vaticle.typedb.core.common.parameters.Options) ROLE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Thing.ROLE) ENTITY(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Thing.ENTITY) RELATING(com.vaticle.typedb.core.graph.common.Encoding.Edge.Thing.Base.RELATING) TypeDB(com.vaticle.typedb.core.TypeDB) List(java.util.List) PLAYING(com.vaticle.typedb.core.graph.common.Encoding.Edge.Thing.Base.PLAYING) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) TypeDBCheckedException(com.vaticle.typedb.core.common.exception.TypeDBCheckedException) CoreTransaction(com.vaticle.typedb.core.database.CoreTransaction) RELATION(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Thing.RELATION) ByteArray.encodeLongAsSorted(com.vaticle.typedb.core.common.collection.ByteArray.encodeLongAsSorted) BeforeClass(org.junit.BeforeClass) KeyValue(com.vaticle.typedb.core.common.collection.KeyValue) Collections.set(com.vaticle.typedb.common.collection.Collections.set) STRING_ENCODING(com.vaticle.typedb.core.graph.common.Encoding.ValueType.STRING_ENCODING) WRITE(com.vaticle.typedb.core.common.parameters.Arguments.Transaction.Type.WRITE) ByteArray.encodeStringAsSorted(com.vaticle.typedb.core.common.collection.ByteArray.encodeStringAsSorted) Storage(com.vaticle.typedb.core.graph.common.Storage) Label(com.vaticle.typedb.core.common.parameters.Label) Encoding(com.vaticle.typedb.core.graph.common.Encoding) Before(org.junit.Before) ILLEGAL_ARGUMENT(com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.ILLEGAL_ARGUMENT) HAS(com.vaticle.typedb.core.graph.common.Encoding.Edge.Thing.Base.HAS) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) CoreSession(com.vaticle.typedb.core.database.CoreSession) VERTEX_RELATION(com.vaticle.typedb.core.graph.common.Encoding.Prefix.VERTEX_RELATION) Paths(java.nio.file.Paths) ROLEPLAYER(com.vaticle.typedb.core.graph.common.Encoding.Edge.Thing.Optimised.ROLEPLAYER) Iterators.iterate(com.vaticle.typedb.core.common.iterator.Iterators.iterate) VERTEX_ATTRIBUTE(com.vaticle.typedb.core.graph.common.Encoding.Prefix.VERTEX_ATTRIBUTE) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex) ATTRIBUTE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Thing.ATTRIBUTE) Assert.assertEquals(org.junit.Assert.assertEquals) Util(com.vaticle.typedb.core.test.integration.util.Util) Storage(com.vaticle.typedb.core.graph.common.Storage) KeyValue(com.vaticle.typedb.core.common.collection.KeyValue) ByteArray(com.vaticle.typedb.core.common.collection.ByteArray) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex) CoreTransaction(com.vaticle.typedb.core.database.CoreTransaction) Test(org.junit.Test)

Example 2 with TypeVertex

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

the class TypeGraph method getType.

public TypeVertex getType(String label, @Nullable String scope) {
    assert storage.isOpen();
    String scopedLabel = scopedLabel(label, scope);
    try {
        if (!isReadOnly) {
            multiLabelLock.readLock().lock();
            singleLabelLocks.computeIfAbsent(scopedLabel, x -> newReadWriteLock()).readLock().lock();
        }
        TypeVertex vertex = typesByLabel.get(scopedLabel);
        if (vertex != null)
            return vertex;
        IndexIID.Type index = IndexIID.Type.Label.of(label, scope);
        ByteArray iid = storage.get(index);
        if (iid != null) {
            vertex = typesByIID.computeIfAbsent(VertexIID.Type.of(iid), i -> new TypeVertexImpl.Persisted(this, i, label, scope));
            typesByLabel.putIfAbsent(scopedLabel, vertex);
        }
        return vertex;
    } finally {
        if (!isReadOnly) {
            singleLabelLocks.get(scopedLabel).readLock().unlock();
            multiLabelLock.readLock().unlock();
        }
    }
}
Also used : Pair(com.vaticle.typedb.common.collection.Pair) RuleStructureImpl(com.vaticle.typedb.core.graph.structure.impl.RuleStructureImpl) ENTITY(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.Root.ENTITY) KeyGenerator(com.vaticle.typedb.core.graph.common.KeyGenerator) ASC(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.ASC) VertexIID(com.vaticle.typedb.core.graph.iid.VertexIID) RELATES(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.RELATES) RELATION(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.Root.RELATION) Map(java.util.Map) TYPE_NOT_FOUND(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeRead.TYPE_NOT_FOUND) RELATION_TYPE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.RELATION_TYPE) ATTRIBUTE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.Root.ATTRIBUTE) IndexIID(com.vaticle.typedb.core.graph.iid.IndexIID) Iterators.loop(com.vaticle.typedb.core.common.iterator.Iterators.loop) ByteArray(com.vaticle.typedb.core.common.collection.ByteArray) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) FunctionalIterator(com.vaticle.typedb.core.common.iterator.FunctionalIterator) INVALID_SCHEMA_WRITE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeGraph.INVALID_SCHEMA_WRITE) OBJECT(com.vaticle.typedb.core.graph.common.Encoding.ValueType.OBJECT) SUB(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.SUB) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) NavigableSet(java.util.NavigableSet) Pattern(com.vaticle.typeql.lang.pattern.Pattern) Forwardable(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable) ENTITY_TYPE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.ENTITY_TYPE) Objects(java.util.Objects) Stream(java.util.stream.Stream) ROLE_TYPE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.ROLE_TYPE) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) Key(com.vaticle.typedb.core.graph.common.Storage.Key) Conjunction(com.vaticle.typeql.lang.pattern.Conjunction) TRANSACTION_SCHEMA_READ_VIOLATION(com.vaticle.typedb.core.common.exception.ErrorMessage.Transaction.TRANSACTION_SCHEMA_READ_VIOLATION) Iterators.link(com.vaticle.typedb.core.common.iterator.Iterators.link) KeyValue(com.vaticle.typedb.core.common.collection.KeyValue) Collections.set(com.vaticle.typedb.common.collection.Collections.set) Order(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Order) ATTRIBUTE_TYPE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.ATTRIBUTE_TYPE) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) TreeSet(java.util.TreeSet) Forwardable.iterateSorted(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.iterateSorted) Forwardable.merge(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.merge) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) Storage(com.vaticle.typedb.core.graph.common.Storage) THING_TYPE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.THING_TYPE) Type.scopedLabel(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.scopedLabel) RuleUsage(com.vaticle.typedb.core.graph.iid.IndexIID.Type.RuleUsage) Collections.pair(com.vaticle.typedb.common.collection.Collections.pair) ROLE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.Root.ROLE) Math.toIntExact(java.lang.Math.toIntExact) Label(com.vaticle.typedb.core.common.parameters.Label) Encoding(com.vaticle.typedb.core.graph.common.Encoding) Nullable(javax.annotation.Nullable) PLAYS(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.PLAYS) Iterators.tree(com.vaticle.typedb.core.common.iterator.Iterators.tree) THING(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.Root.THING) RuleStructure(com.vaticle.typedb.core.graph.structure.RuleStructure) TypeVertexImpl(com.vaticle.typedb.core.graph.vertex.impl.TypeVertexImpl) OWNS_KEY(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.OWNS_KEY) StructureIID(com.vaticle.typedb.core.graph.iid.StructureIID) ThingVariable(com.vaticle.typeql.lang.pattern.variable.ThingVariable) Iterators.iterate(com.vaticle.typedb.core.common.iterator.Iterators.iterate) OWNS(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.OWNS) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex) StampedLock(java.util.concurrent.locks.StampedLock) ByteArray(com.vaticle.typedb.core.common.collection.ByteArray) IndexIID(com.vaticle.typedb.core.graph.iid.IndexIID) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex)

Example 3 with TypeVertex

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

the class TypeGraph method create.

public TypeVertex create(Encoding.Vertex.Type encoding, String label, @Nullable String scope) {
    assert storage.isOpen();
    if (isReadOnly)
        throw TypeDBException.of(TRANSACTION_SCHEMA_READ_VIOLATION);
    String scopedLabel = scopedLabel(label, scope);
    try {
        // we intentionally use READ on multiLabelLock, as put() only concerns one label
        multiLabelLock.readLock().lock();
        singleLabelLocks.computeIfAbsent(scopedLabel, x -> newReadWriteLock()).writeLock().lock();
        TypeVertex typeVertex = typesByLabel.computeIfAbsent(scopedLabel, i -> new TypeVertexImpl.Buffered(this, VertexIID.Type.generate(keyGenerator, encoding), label, scope));
        typesByIID.put(typeVertex.iid(), typeVertex);
        cache.clear();
        return typeVertex;
    } finally {
        singleLabelLocks.get(scopedLabel).writeLock().unlock();
        multiLabelLock.readLock().unlock();
        rules().conclusions().outdated(true);
    }
}
Also used : TypeVertexImpl(com.vaticle.typedb.core.graph.vertex.impl.TypeVertexImpl) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex)

Example 4 with TypeVertex

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

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

the class ThingTypeImpl method getOwnsOverridden.

@Override
public AttributeType getOwnsOverridden(AttributeType attributeType) {
    TypeVertex attrVertex = graphMgr.schema().getType(attributeType.getLabel());
    if (attrVertex != null) {
        TypeEdge ownsEdge = vertex.outs().edge(OWNS_KEY, attrVertex);
        if (ownsEdge != null && ownsEdge.overridden().isPresent()) {
            return AttributeTypeImpl.of(graphMgr, ownsEdge.overridden().get());
        }
        ownsEdge = vertex.outs().edge(OWNS, attrVertex);
        if (ownsEdge != null && ownsEdge.overridden().isPresent()) {
            return AttributeTypeImpl.of(graphMgr, ownsEdge.overridden().get());
        }
    }
    return null;
}
Also used : TypeEdge(com.vaticle.typedb.core.graph.edge.TypeEdge) 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