Search in sources :

Example 1 with ExistedException

use of com.baidu.hugegraph.exception.ExistedException in project incubator-hugegraph by apache.

the class IndexLabelBuilder method createWithTask.

/**
 * Create index label with async mode
 */
@Override
public SchemaElement.TaskWithSchema createWithTask() {
    HugeType type = HugeType.INDEX_LABEL;
    this.checkSchemaName(this.name);
    return this.lockCheckAndCreateSchema(type, this.name, name -> {
        IndexLabel indexLabel = this.indexLabelOrNull(name);
        if (indexLabel != null) {
            if (this.checkExist || !hasSameProperties(indexLabel)) {
                throw new ExistedException(type, name);
            }
            return new SchemaElement.TaskWithSchema(indexLabel, IdGenerator.ZERO);
        }
        this.checkSchemaIdIfRestoringMode(type, this.id);
        this.checkBaseType();
        this.checkIndexType();
        if (VertexLabel.OLAP_VL.name().equals(this.baseValue)) {
            return new SchemaElement.TaskWithSchema(this.build(), IdGenerator.ZERO);
        }
        SchemaLabel schemaLabel = this.loadBaseLabel();
        /*
             * If new index label is prefix of existed index label, or has
             * the same fields, fail to create new index label.
             */
        this.checkFields(schemaLabel.properties());
        this.checkRepeatIndex(schemaLabel);
        Userdata.check(this.userdata, Action.INSERT);
        // Async delete index label which is prefix of the new index label
        // TODO: use event to replace direct call
        Set<Id> removeTasks = this.removeSubIndex(schemaLabel);
        indexLabel = this.build();
        assert indexLabel.name().equals(name);
        /*
             * If not rebuild, just create index label and return.
             * The actual indexes may be rebuilt later as needed
             */
        if (!this.rebuild) {
            indexLabel.status(SchemaStatus.CREATED);
            this.graph().addIndexLabel(schemaLabel, indexLabel);
            return new SchemaElement.TaskWithSchema(indexLabel, IdGenerator.ZERO);
        }
        // Create index label (just schema)
        indexLabel.status(SchemaStatus.CREATING);
        this.graph().addIndexLabel(schemaLabel, indexLabel);
        try {
            // Async rebuild index
            Id rebuildTask = this.rebuildIndex(indexLabel, removeTasks);
            E.checkNotNull(rebuildTask, "rebuild-index task");
            return new SchemaElement.TaskWithSchema(indexLabel, rebuildTask);
        } catch (Throwable e) {
            this.updateSchemaStatus(indexLabel, SchemaStatus.INVALID);
            throw e;
        }
    });
}
Also used : ExistedException(com.baidu.hugegraph.exception.ExistedException) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) SchemaLabel(com.baidu.hugegraph.schema.SchemaLabel) Id(com.baidu.hugegraph.backend.id.Id) HugeType(com.baidu.hugegraph.type.HugeType)

Example 2 with ExistedException

use of com.baidu.hugegraph.exception.ExistedException in project incubator-hugegraph by apache.

the class EdgeLabelBuilder method create.

@Override
public EdgeLabel create() {
    HugeType type = HugeType.EDGE_LABEL;
    this.checkSchemaName(this.name);
    return this.lockCheckAndCreateSchema(type, this.name, name -> {
        EdgeLabel edgeLabel = this.edgeLabelOrNull(this.name);
        if (edgeLabel != null) {
            if (this.checkExist || !hasSameProperties(edgeLabel)) {
                throw new ExistedException(type, this.name);
            }
            return edgeLabel;
        }
        this.checkSchemaIdIfRestoringMode(type, this.id);
        // These methods will check params and fill to member variables
        this.checkRelation();
        this.checkProperties(Action.INSERT);
        this.checkSortKeys();
        this.checkNullableKeys(Action.INSERT);
        Userdata.check(this.userdata, Action.INSERT);
        this.checkTtl();
        this.checkUserdata(Action.INSERT);
        edgeLabel = this.build();
        assert edgeLabel.name().equals(name);
        this.graph().addEdgeLabel(edgeLabel);
        return edgeLabel;
    });
}
Also used : ExistedException(com.baidu.hugegraph.exception.ExistedException) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeType(com.baidu.hugegraph.type.HugeType)

Example 3 with ExistedException

use of com.baidu.hugegraph.exception.ExistedException in project incubator-hugegraph by apache.

the class PropertyKeyBuilder method createWithTask.

@Override
public SchemaElement.TaskWithSchema createWithTask() {
    HugeType type = HugeType.PROPERTY_KEY;
    this.checkSchemaName(this.name);
    return this.lockCheckAndCreateSchema(type, this.name, name -> {
        PropertyKey propertyKey = this.propertyKeyOrNull(name);
        if (propertyKey != null) {
            if (this.checkExist || !hasSameProperties(propertyKey)) {
                throw new ExistedException(type, name);
            }
            return new SchemaElement.TaskWithSchema(propertyKey, IdGenerator.ZERO);
        }
        this.checkSchemaIdIfRestoringMode(type, this.id);
        Userdata.check(this.userdata, Action.INSERT);
        this.checkAggregateType();
        this.checkOlap();
        propertyKey = this.build();
        assert propertyKey.name().equals(name);
        Id id = this.graph().addPropertyKey(propertyKey);
        return new SchemaElement.TaskWithSchema(propertyKey, id);
    });
}
Also used : ExistedException(com.baidu.hugegraph.exception.ExistedException) Id(com.baidu.hugegraph.backend.id.Id) HugeType(com.baidu.hugegraph.type.HugeType) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 4 with ExistedException

use of com.baidu.hugegraph.exception.ExistedException in project incubator-hugegraph by apache.

the class VertexLabelBuilder method create.

@Override
public VertexLabel create() {
    HugeType type = HugeType.VERTEX_LABEL;
    this.checkSchemaName(this.name);
    return this.lockCheckAndCreateSchema(type, this.name, name -> {
        VertexLabel vertexLabel = this.vertexLabelOrNull(name);
        if (vertexLabel != null) {
            if (this.checkExist || !hasSameProperties(vertexLabel)) {
                throw new ExistedException(type, name);
            }
            return vertexLabel;
        }
        this.checkSchemaIdIfRestoringMode(type, this.id);
        this.checkProperties(Action.INSERT);
        this.checkIdStrategy();
        this.checkNullableKeys(Action.INSERT);
        Userdata.check(this.userdata, Action.INSERT);
        this.checkTtl();
        this.checkUserdata(Action.INSERT);
        vertexLabel = this.build();
        assert vertexLabel.name().equals(name);
        this.graph().addVertexLabel(vertexLabel);
        return vertexLabel;
    });
}
Also used : ExistedException(com.baidu.hugegraph.exception.ExistedException) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) HugeType(com.baidu.hugegraph.type.HugeType)

Aggregations

ExistedException (com.baidu.hugegraph.exception.ExistedException)4 HugeType (com.baidu.hugegraph.type.HugeType)4 Id (com.baidu.hugegraph.backend.id.Id)2 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)1 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)1 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)1 SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)1 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)1