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