Search in sources :

Example 1 with IdStrategy

use of com.baidu.hugegraph.structure.constant.IdStrategy in project incubator-hugegraph-toolchain by apache.

the class ElementBuilder method customizeId.

private void customizeId(VertexLabel vertexLabel, Vertex vertex, String idField, Object idValue) {
    E.checkArgumentNotNull(idField, "The vertex id field can't be null");
    E.checkArgumentNotNull(idValue, "The vertex id value can't be null");
    IdStrategy idStrategy = vertexLabel.idStrategy();
    if (idStrategy.isCustomizeString()) {
        String id = (String) idValue;
        this.checkVertexIdLength(id);
        vertex.id(id);
    } else if (idStrategy.isCustomizeNumber()) {
        Long id = DataTypeUtil.parseNumber(idField, idValue);
        vertex.id(id);
    } else {
        assert idStrategy.isCustomizeUuid();
        UUID id = DataTypeUtil.parseUUID(idField, idValue);
        vertex.id(id);
    }
}
Also used : IdStrategy(com.baidu.hugegraph.structure.constant.IdStrategy) UUID(java.util.UUID)

Example 2 with IdStrategy

use of com.baidu.hugegraph.structure.constant.IdStrategy in project incubator-hugegraph-toolchain by apache.

the class VertexLabelController method checkPrimaryKeys.

private void checkPrimaryKeys(VertexLabelEntity entity) {
    IdStrategy idStrategy = entity.getIdStrategy();
    Ex.check(idStrategy != null, "common.param.cannot-be-null", "id_strategy");
    List<String> primaryKeys = entity.getPrimaryKeys();
    if (idStrategy.isPrimaryKey()) {
        Ex.check(!CollectionUtils.isEmpty(entity.getProperties()), "schema.vertexlabel.property.cannot-be-null-or-empty", entity.getName());
        Ex.check(!CollectionUtils.isEmpty(primaryKeys), "schema.vertexlabel.primarykey.cannot-be-null-or-empty", entity.getName());
        // All primary keys must belong to properties
        Set<String> propNames = entity.getPropNames();
        Ex.check(propNames.containsAll(primaryKeys), "schema.vertexlabel.primarykey.must-belong-to.property", entity.getName(), primaryKeys, propNames);
        // Any primary key can't be nullable
        Ex.check(!CollectionUtil.hasIntersection(primaryKeys, entity.getNullableProps()), "schmea.vertexlabel.primarykey.cannot-be-nullable", entity.getName());
    } else {
        Ex.check(CollectionUtils.isEmpty(primaryKeys), "schema.vertexlabel.primarykey.should-be-null-or-empty", entity.getName(), idStrategy);
    }
}
Also used : IdStrategy(com.baidu.hugegraph.structure.constant.IdStrategy)

Example 3 with IdStrategy

use of com.baidu.hugegraph.structure.constant.IdStrategy in project incubator-hugegraph-toolchain by apache.

the class GremlinQueryService method getRealVertexId.

private Object getRealVertexId(int connId, AdjacentQuery query) {
    VertexLabelEntity entity = this.vlService.get(query.getVertexLabel(), connId);
    IdStrategy idStrategy = entity.getIdStrategy();
    String rawVertexId = query.getVertexId();
    try {
        if (idStrategy == IdStrategy.AUTOMATIC || idStrategy == IdStrategy.CUSTOMIZE_NUMBER) {
            return Long.parseLong(rawVertexId);
        } else if (idStrategy == IdStrategy.CUSTOMIZE_UUID) {
            return UUID.fromString(rawVertexId);
        }
    } catch (Exception e) {
        throw new ExternalException("gremlin.convert-vertex-id.failed", e, rawVertexId, idStrategy);
    }
    assert idStrategy == IdStrategy.PRIMARY_KEY || idStrategy == IdStrategy.CUSTOMIZE_STRING;
    return rawVertexId;
}
Also used : IdStrategy(com.baidu.hugegraph.structure.constant.IdStrategy) ExternalException(com.baidu.hugegraph.exception.ExternalException) VertexLabelEntity(com.baidu.hugegraph.entity.schema.VertexLabelEntity) ServerException(com.baidu.hugegraph.exception.ServerException) ExternalException(com.baidu.hugegraph.exception.ExternalException) ClientException(com.baidu.hugegraph.rest.ClientException) IllegalGremlinException(com.baidu.hugegraph.exception.IllegalGremlinException) InternalException(com.baidu.hugegraph.exception.InternalException)

Example 4 with IdStrategy

use of com.baidu.hugegraph.structure.constant.IdStrategy in project incubator-hugegraph-toolchain by apache.

the class GraphController method checkParamsValid.

private void checkParamsValid(int connId, VertexEntity entity, boolean create) {
    Ex.check(!StringUtils.isEmpty(entity.getLabel()), "common.param.cannot-be-null-or-empty", "label");
    // If schema doesn't exist, it will throw exception
    VertexLabelEntity vlEntity = this.vlService.get(entity.getLabel(), connId);
    IdStrategy idStrategy = vlEntity.getIdStrategy();
    if (create) {
        Ex.check(idStrategy.isCustomize(), () -> entity.getId() != null, "common.param.cannot-be-null", "id");
    } else {
        Ex.check(entity.getId() != null, "common.param.cannot-be-null", "id");
    }
    Set<String> nonNullableProps = vlEntity.getNonNullableProps();
    Map<String, Object> properties = entity.getProperties();
    Ex.check(properties.keySet().containsAll(nonNullableProps), "graph.vertex.all-nonnullable-prop.should-be-setted");
}
Also used : IdStrategy(com.baidu.hugegraph.structure.constant.IdStrategy) VertexLabelEntity(com.baidu.hugegraph.entity.schema.VertexLabelEntity)

Aggregations

IdStrategy (com.baidu.hugegraph.structure.constant.IdStrategy)4 VertexLabelEntity (com.baidu.hugegraph.entity.schema.VertexLabelEntity)2 ExternalException (com.baidu.hugegraph.exception.ExternalException)1 IllegalGremlinException (com.baidu.hugegraph.exception.IllegalGremlinException)1 InternalException (com.baidu.hugegraph.exception.InternalException)1 ServerException (com.baidu.hugegraph.exception.ServerException)1 ClientException (com.baidu.hugegraph.rest.ClientException)1 UUID (java.util.UUID)1