use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class GraphTransaction method checkVertexExistIfCustomizedId.
private void checkVertexExistIfCustomizedId(Map<Id, HugeVertex> vertices) {
Set<Id> ids = new HashSet<>();
for (HugeVertex vertex : vertices.values()) {
VertexLabel vl = vertex.schemaLabel();
if (!vl.hidden() && vl.idStrategy().isCustomized()) {
ids.add(vertex.id());
}
}
if (ids.isEmpty()) {
return;
}
IdQuery idQuery = new IdQuery(HugeType.VERTEX, ids);
Iterator<HugeVertex> results = this.queryVerticesFromBackend(idQuery);
try {
if (!results.hasNext()) {
return;
}
HugeVertex existedVertex = results.next();
HugeVertex newVertex = vertices.get(existedVertex.id());
if (!existedVertex.label().equals(newVertex.label())) {
throw new HugeException("The newly added vertex with id:'%s' label:'%s' " + "is not allowed to insert, because already exist " + "a vertex with same id and different label:'%s'", newVertex.id(), newVertex.label(), existedVertex.label());
}
} finally {
CloseableIterator.closeIterator(results);
}
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class SchemaTransaction method removePropertyKey.
@Watched(prefix = "schema")
public Id removePropertyKey(Id id) {
LOG.debug("SchemaTransaction remove property key '{}'", id);
PropertyKey propertyKey = this.getPropertyKey(id);
// If the property key does not exist, return directly
if (propertyKey == null) {
return null;
}
List<VertexLabel> vertexLabels = this.getVertexLabels();
for (VertexLabel vertexLabel : vertexLabels) {
if (vertexLabel.properties().contains(id)) {
throw new NotAllowException("Not allowed to remove property key: '%s' " + "because the vertex label '%s' is still using it.", propertyKey, vertexLabel.name());
}
}
List<EdgeLabel> edgeLabels = this.getEdgeLabels();
for (EdgeLabel edgeLabel : edgeLabels) {
if (edgeLabel.properties().contains(id)) {
throw new NotAllowException("Not allowed to remove property key: '%s' " + "because the edge label '%s' is still using it.", propertyKey, edgeLabel.name());
}
}
if (propertyKey.oltp()) {
this.removeSchema(propertyKey);
return IdGenerator.ZERO;
} else {
return this.removeOlapPk(propertyKey);
}
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class SchemaTransaction method removeVertexLabel.
@Watched(prefix = "schema")
public Id removeVertexLabel(Id id) {
LOG.debug("SchemaTransaction remove vertex label '{}'", id);
SchemaJob callable = new VertexLabelRemoveJob();
VertexLabel schema = this.getVertexLabel(id);
return asyncRun(this.graph(), schema, callable);
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class EdgeAPI method newVertex.
private static Vertex newVertex(HugeGraph g, Object id, String label) {
VertexLabel vl = vertexLabel(g, label, "Invalid vertex label '%s'");
Id idValue = HugeVertex.getIdValue(id);
return new HugeVertex(g, idValue, vl);
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexAPI method getVertexId.
private static Id getVertexId(HugeGraph g, JsonVertex vertex) {
VertexLabel vertexLabel = g.vertexLabel(vertex.label);
String labelId = vertexLabel.id().asString();
IdStrategy idStrategy = vertexLabel.idStrategy();
E.checkArgument(idStrategy != IdStrategy.AUTOMATIC, "Automatic Id strategy is not supported now");
if (idStrategy == IdStrategy.PRIMARY_KEY) {
List<Id> pkIds = vertexLabel.primaryKeys();
List<Object> pkValues = new ArrayList<>(pkIds.size());
for (Id pkId : pkIds) {
String propertyKey = g.propertyKey(pkId).name();
Object propertyValue = vertex.properties.get(propertyKey);
E.checkArgument(propertyValue != null, "The value of primary key '%s' can't be null", propertyKey);
pkValues.add(propertyValue);
}
String value = ConditionQuery.concatValues(pkValues);
return SplicingIdGenerator.splicing(labelId, value);
} else if (idStrategy == IdStrategy.CUSTOMIZE_UUID) {
return Text.uuid(String.valueOf(vertex.id));
} else {
assert idStrategy == IdStrategy.CUSTOMIZE_NUMBER || idStrategy == IdStrategy.CUSTOMIZE_STRING;
return HugeVertex.getIdValue(vertex.id);
}
}
Aggregations