use of com.baidu.hugegraph.driver.HugeClient in project incubator-hugegraph-toolchain by apache.
the class EdgeLabelService method reuse.
public void reuse(ConflictDetail detail, int connId) {
Ex.check(!detail.hasConflict(), "schema.cannot-reuse-conflict");
HugeClient client = this.client(connId);
List<PropertyKey> propertyKeys = this.pkService.filter(detail, client);
if (!propertyKeys.isEmpty()) {
try {
this.pkService.addBatch(propertyKeys, client);
} catch (Exception e) {
throw new ExternalException("schema.propertykey.reuse.failed", e);
}
}
List<VertexLabel> vertexLabels = this.vlService.filter(detail, client);
if (!vertexLabels.isEmpty()) {
try {
this.vlService.addBatch(vertexLabels, client);
} catch (Exception e) {
this.pkService.removeBatch(propertyKeys, client);
throw new ExternalException("schema.vertexlabel.reuse.failed", e);
}
}
List<EdgeLabel> edgeLabels = this.filter(detail, client);
if (!edgeLabels.isEmpty()) {
try {
this.addBatch(edgeLabels, client);
} catch (Exception e) {
this.vlService.removeBatch(vertexLabels, client);
this.pkService.removeBatch(propertyKeys, client);
throw new ExternalException("schema.edgelabel.reuse.failed", e);
}
}
List<IndexLabel> indexLabels = this.piService.filter(detail, client);
if (!indexLabels.isEmpty()) {
try {
this.piService.addBatch(indexLabels, client);
} catch (Exception e) {
this.removeBatch(edgeLabels, client);
this.vlService.removeBatch(vertexLabels, client);
this.pkService.removeBatch(propertyKeys, client);
throw new ExternalException("schema.propertyindex.reuse.failed", e);
}
}
}
use of com.baidu.hugegraph.driver.HugeClient in project incubator-hugegraph-toolchain by apache.
the class EdgeLabelService method add.
public void add(EdgeLabelEntity entity, int connId) {
HugeClient client = this.client(connId);
EdgeLabel edgeLabel = convert(entity, client);
try {
client.schema().addEdgeLabel(edgeLabel);
} catch (Exception e) {
throw new ExternalException("schema.edgelabel.create.failed", e, entity.getName());
}
List<IndexLabel> indexLabels = collectIndexLabels(entity, client);
this.piService.addBatch(indexLabels, client);
}
use of com.baidu.hugegraph.driver.HugeClient in project incubator-hugegraph-toolchain by apache.
the class EdgeLabelService method update.
public void update(EdgeLabelUpdateEntity entity, int connId) {
HugeClient client = this.client(connId);
EdgeLabel edgeLabel = convert(entity, client);
// All existed indexlabels
List<IndexLabel> existedIndexLabels = client.schema().getIndexLabels();
List<String> existedIndexLabelNames = collectNames(existedIndexLabels);
List<String> addedIndexLabelNames = entity.getAppendPropertyIndexNames();
List<IndexLabel> addedIndexLabels = convertIndexLabels(entity.getAppendPropertyIndexes(), client, false, entity.getName());
List<String> removedIndexLabelNames = entity.getRemovePropertyIndexes();
if (addedIndexLabelNames != null) {
for (String name : addedIndexLabelNames) {
if (existedIndexLabelNames.contains(name)) {
throw new ExternalException("schema.edgelabel.update.append-index-existed", entity.getName(), name);
}
}
}
if (removedIndexLabelNames != null) {
for (String name : removedIndexLabelNames) {
if (!existedIndexLabelNames.contains(name)) {
throw new ExternalException("schema.edgelabel.update.remove-index-unexisted", entity.getName(), name);
}
}
}
try {
// NOTE: property can append but doesn't support eliminate now
client.schema().appendEdgeLabel(edgeLabel);
} catch (Exception e) {
throw new ExternalException("schema.edgelabel.update.failed", e, entity.getName());
}
this.piService.addBatch(addedIndexLabels, client);
this.piService.removeBatch(removedIndexLabelNames, client);
}
use of com.baidu.hugegraph.driver.HugeClient in project incubator-hugegraph-toolchain by apache.
the class EdgeLabelService method remove.
public void remove(String name, int connId) {
HugeClient client = this.client(connId);
client.schema().removeEdgeLabelAsync(name);
}
use of com.baidu.hugegraph.driver.HugeClient in project incubator-hugegraph-toolchain by apache.
the class PropertyKeyService method reuse.
public void reuse(ConflictDetail detail, int connId) {
// Assume that the conflict detail is valid
Ex.check(!detail.hasConflict(), "schema.cannot-reuse-conflict");
HugeClient client = this.client(connId);
List<PropertyKey> propertyKeys = this.filter(detail, client);
if (propertyKeys.isEmpty()) {
return;
}
try {
this.addBatch(propertyKeys, client);
} catch (Exception e) {
throw new ExternalException("schema.propertykey.reuse.failed", e);
}
}
Aggregations