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);
}
}
}
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()));
}
}
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);
}
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);
}
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();
}
}
Aggregations