Search in sources :

Example 26 with HugeType

use of com.baidu.hugegraph.type.HugeType 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 27 with HugeType

use of com.baidu.hugegraph.type.HugeType 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 28 with HugeType

use of com.baidu.hugegraph.type.HugeType 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)

Example 29 with HugeType

use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.

the class MysqlEntryIterator method row2Entry.

private MysqlBackendEntry row2Entry(ResultSet result) throws SQLException {
    HugeType type = this.query.resultType();
    MysqlBackendEntry entry = new MysqlBackendEntry(type);
    ResultSetMetaData metaData = result.getMetaData();
    for (int i = 1; i <= metaData.getColumnCount(); i++) {
        String name = metaData.getColumnLabel(i);
        HugeKeys key = MysqlTable.parseKey(name);
        Object value = result.getObject(i);
        if (value == null) {
            assert key == HugeKeys.EXPIRED_TIME;
            continue;
        }
        entry.column(key, value);
    }
    return entry;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys) HugeType(com.baidu.hugegraph.type.HugeType)

Example 30 with HugeType

use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.

the class RocksDBStore method queryNumber.

@Override
public Number queryNumber(Query query) {
    Lock readLock = this.storeLock.readLock();
    readLock.lock();
    try {
        this.checkOpened();
        HugeType tableType = RocksDBTable.tableType(query);
        RocksDBTable table = this.table(tableType);
        return table.queryNumber(this.session(tableType), query);
    } finally {
        readLock.unlock();
    }
}
Also used : HugeType(com.baidu.hugegraph.type.HugeType) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

HugeType (com.baidu.hugegraph.type.HugeType)34 Id (com.baidu.hugegraph.backend.id.Id)16 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)5 Query (com.baidu.hugegraph.backend.query.Query)4 ExistedException (com.baidu.hugegraph.exception.ExistedException)4 SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)4 ArrayList (java.util.ArrayList)4 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)3 Condition (com.baidu.hugegraph.backend.query.Condition)3 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)3 BinaryBackendEntry (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry)3 BinaryId (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId)3 BackendAction (com.baidu.hugegraph.backend.store.BackendAction)3 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)3 Lock (java.util.concurrent.locks.Lock)3 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)3 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)3 HugeException (com.baidu.hugegraph.HugeException)2 BackendException (com.baidu.hugegraph.backend.BackendException)2 BinaryEntryIterator (com.baidu.hugegraph.backend.serializer.BinaryEntryIterator)2