Search in sources :

Example 1 with ConflictStatus

use of com.baidu.hugegraph.entity.schema.ConflictStatus in project incubator-hugegraph-toolchain by apache.

the class EdgeLabelService method checkConflict.

public ConflictDetail checkConflict(ConflictCheckEntity entity, int connId, boolean compareEachOther) {
    ConflictDetail detail = new ConflictDetail(SchemaType.EDGE_LABEL);
    if (CollectionUtils.isEmpty(entity.getElEntities())) {
        return detail;
    }
    Map<String, EdgeLabelEntity> originElEntities = new HashMap<>();
    for (EdgeLabelEntity e : this.list(connId)) {
        originElEntities.put(e.getName(), e);
    }
    this.pkService.checkConflict(entity.getPkEntities(), detail, connId, compareEachOther);
    this.piService.checkConflict(entity.getPiEntities(), detail, connId, compareEachOther);
    this.vlService.checkConflict(entity.getVlEntities(), detail, connId, compareEachOther);
    for (EdgeLabelEntity elEntity : entity.getElEntities()) {
        // Firstly check if any properties are conflicted
        if (detail.anyPropertyKeyConflict(elEntity.getPropNames())) {
            detail.add(elEntity, ConflictStatus.DEP_CONFLICT);
            continue;
        }
        // Then check if any property indexes are conflicted
        if (detail.anyPropertyIndexConflict(elEntity.getIndexProps())) {
            detail.add(elEntity, ConflictStatus.DEP_CONFLICT);
            continue;
        }
        // Then determine if source/target vertex labels are conflicted
        if (detail.anyVertexLabelConflict(elEntity.getLinkLabels())) {
            detail.add(elEntity, ConflictStatus.DEP_CONFLICT);
            continue;
        }
        // Then check conflict of edge label itself
        EdgeLabelEntity originElEntity = originElEntities.get(elEntity.getName());
        ConflictStatus status = SchemaEntity.compare(elEntity, originElEntity);
        detail.add(elEntity, status);
    }
    if (compareEachOther) {
        compareWithEachOther(detail, SchemaType.EDGE_LABEL);
    }
    return detail;
}
Also used : ConflictDetail(com.baidu.hugegraph.entity.schema.ConflictDetail) EdgeLabelEntity(com.baidu.hugegraph.entity.schema.EdgeLabelEntity) ConflictStatus(com.baidu.hugegraph.entity.schema.ConflictStatus) HashMap(java.util.HashMap)

Example 2 with ConflictStatus

use of com.baidu.hugegraph.entity.schema.ConflictStatus in project incubator-hugegraph-toolchain by apache.

the class VertexLabelService method checkConflict.

public void checkConflict(List<VertexLabelEntity> entities, ConflictDetail detail, int connId, boolean compareEachOther) {
    if (CollectionUtils.isEmpty(entities)) {
        return;
    }
    Map<String, VertexLabelEntity> originEntities = new HashMap<>();
    for (VertexLabelEntity entity : this.list(connId)) {
        originEntities.put(entity.getName(), entity);
    }
    for (VertexLabelEntity entity : entities) {
        if (detail.anyPropertyKeyConflict(entity.getPropNames())) {
            detail.add(entity, ConflictStatus.DEP_CONFLICT);
            continue;
        }
        if (detail.anyPropertyIndexConflict(entity.getIndexProps())) {
            detail.add(entity, ConflictStatus.DEP_CONFLICT);
            continue;
        }
        VertexLabelEntity originEntity = originEntities.get(entity.getName());
        ConflictStatus status = SchemaEntity.compare(entity, originEntity);
        detail.add(entity, status);
    }
    // Compare resued entities with each other
    if (compareEachOther) {
        compareWithEachOther(detail, SchemaType.VERTEX_LABEL);
    }
}
Also used : ConflictStatus(com.baidu.hugegraph.entity.schema.ConflictStatus) HashMap(java.util.HashMap) VertexLabelEntity(com.baidu.hugegraph.entity.schema.VertexLabelEntity)

Example 3 with ConflictStatus

use of com.baidu.hugegraph.entity.schema.ConflictStatus in project incubator-hugegraph-toolchain by apache.

the class SchemaService method compareWithOthers.

public static <T extends SchemaEntity> ConflictStatus compareWithOthers(int currentIdx, List<SchemaConflict<T>> conflicts) {
    SchemaConflict<T> current = conflicts.get(currentIdx);
    T currentEntity = current.getEntity();
    // May changed
    ConflictStatus status = current.getStatus();
    for (int i = 0; i < conflicts.size(); i++) {
        if (currentIdx == i) {
            continue;
        }
        SchemaConflict<T> other = conflicts.get(i);
        T otherEntity = other.getEntity();
        if (!currentEntity.getName().equals(otherEntity.getName())) {
            continue;
        }
        if (currentEntity.equals(otherEntity)) {
            status = ConflictStatus.EXISTED;
        } else {
            status = ConflictStatus.DUPNAME;
            break;
        }
    }
    return status;
}
Also used : ConflictStatus(com.baidu.hugegraph.entity.schema.ConflictStatus)

Example 4 with ConflictStatus

use of com.baidu.hugegraph.entity.schema.ConflictStatus in project incubator-hugegraph-toolchain by apache.

the class SchemaService method compareWithEachOther.

public static <T extends SchemaEntity> void compareWithEachOther(ConflictDetail detail, SchemaType type) {
    List<SchemaConflict<T>> conflicts = detail.getConflicts(type);
    for (int i = 0; i < conflicts.size(); i++) {
        SchemaConflict<T> conflict = conflicts.get(i);
        if (conflict.getStatus().isConflicted()) {
            continue;
        }
        ConflictStatus status = compareWithOthers(i, conflicts);
        conflict.setStatus(status);
    }
}
Also used : ConflictStatus(com.baidu.hugegraph.entity.schema.ConflictStatus) SchemaConflict(com.baidu.hugegraph.entity.schema.SchemaConflict)

Example 5 with ConflictStatus

use of com.baidu.hugegraph.entity.schema.ConflictStatus in project incubator-hugegraph-toolchain by apache.

the class PropertyIndexService method checkConflict.

public void checkConflict(List<PropertyIndex> entities, ConflictDetail detail, int connId, boolean compareEachOther) {
    if (CollectionUtils.isEmpty(entities)) {
        return;
    }
    Map<String, PropertyIndex> originEntities = new HashMap<>();
    for (PropertyIndex entity : this.list(connId)) {
        originEntities.put(entity.getName(), entity);
    }
    for (PropertyIndex entity : entities) {
        if (detail.anyPropertyKeyConflict(entity.getFields())) {
            detail.add(entity, ConflictStatus.DEP_CONFLICT);
            continue;
        }
        PropertyIndex originEntity = originEntities.get(entity.getName());
        ConflictStatus status = SchemaEntity.compare(entity, originEntity);
        detail.add(entity, status);
    }
    // Compare resued entities with each other
    if (compareEachOther) {
        compareWithEachOther(detail, SchemaType.PROPERTY_INDEX);
    }
}
Also used : ConflictStatus(com.baidu.hugegraph.entity.schema.ConflictStatus) HashMap(java.util.HashMap) PropertyIndex(com.baidu.hugegraph.entity.schema.PropertyIndex)

Aggregations

ConflictStatus (com.baidu.hugegraph.entity.schema.ConflictStatus)6 HashMap (java.util.HashMap)4 ConflictDetail (com.baidu.hugegraph.entity.schema.ConflictDetail)1 EdgeLabelEntity (com.baidu.hugegraph.entity.schema.EdgeLabelEntity)1 PropertyIndex (com.baidu.hugegraph.entity.schema.PropertyIndex)1 PropertyKeyEntity (com.baidu.hugegraph.entity.schema.PropertyKeyEntity)1 SchemaConflict (com.baidu.hugegraph.entity.schema.SchemaConflict)1 VertexLabelEntity (com.baidu.hugegraph.entity.schema.VertexLabelEntity)1