use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class GraphTransaction method removeVertices.
public void removeVertices(VertexLabel vertexLabel) {
if (this.hasUpdate()) {
throw new HugeException("There are still changes to commit");
}
boolean autoCommit = this.autoCommit();
this.autoCommit(false);
// Commit data already in tx firstly
this.commit();
try {
this.traverseVerticesByLabel(vertexLabel, vertex -> {
this.removeVertex((HugeVertex) vertex);
this.commitIfGtSize(COMMIT_BATCH);
}, true);
this.commit();
} catch (Exception e) {
LOG.error("Failed to remove vertices", e);
throw new HugeException("Failed to remove vertices", e);
} finally {
this.autoCommit(autoCommit);
}
}
use of com.baidu.hugegraph.HugeException 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.HugeException in project incubator-hugegraph by apache.
the class GraphTransaction method verifyEdgesConditionQuery.
private static void verifyEdgesConditionQuery(ConditionQuery query) {
assert query.resultType().isEdge();
int total = query.conditionsSize();
if (total == 1) {
/*
* Supported query:
* 1.query just by edge label
* 2.query just by PROPERTIES (like containsKey,containsValue)
* 3.query with scan
*/
if (query.containsCondition(HugeKeys.LABEL) || query.containsCondition(HugeKeys.PROPERTIES) || query.containsScanRelation()) {
return;
}
}
int matched = 0;
for (HugeKeys key : EdgeId.KEYS) {
Object value = query.condition(key);
if (value == null) {
break;
}
matched++;
}
int count = matched;
if (query.containsCondition(HugeKeys.PROPERTIES)) {
matched++;
if (count < 3 && query.containsCondition(HugeKeys.LABEL)) {
matched++;
}
}
if (matched != total) {
throw new HugeException("Not supported querying edges by %s, expect %s", query.conditions(), EdgeId.KEYS[count]);
}
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class RamTable method reload.
public void reload(boolean loadFromFile, String file) {
if (this.loading) {
throw new HugeException("There is one loading task, " + "please wait for it to complete");
}
this.loading = true;
try {
this.reset();
if (loadFromFile) {
this.loadFromFile(file);
} else {
this.loadFromDB();
if (file != null) {
LOG.info("Export graph to file '{}'", file);
if (!this.exportToFile(file)) {
LOG.warn("Can't export graph to file '{}'", file);
}
}
}
LOG.info("Loaded {} edges", this.edgesSize());
} catch (Throwable e) {
this.reset();
throw new HugeException("Failed to load ramtable", e);
} finally {
this.loading = false;
}
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class API method commit.
public static <R> R commit(HugeGraph g, Callable<R> callable) {
Consumer<Throwable> rollback = (error) -> {
if (error != null) {
LOG.error("Failed to commit", error);
}
try {
g.tx().rollback();
} catch (Throwable e) {
LOG.error("Failed to rollback", e);
}
};
try {
R result = callable.call();
g.tx().commit();
SUCCEED_METER.mark();
return result;
} catch (IllegalArgumentException | NotFoundException | ForbiddenException e) {
ILLEGAL_ARG_ERROR_METER.mark();
rollback.accept(null);
throw e;
} catch (RuntimeException e) {
EXPECTED_ERROR_METER.mark();
rollback.accept(e);
throw e;
} catch (Throwable e) {
UNKNOWN_ERROR_METER.mark();
rollback.accept(e);
// TODO: throw the origin exception 'e'
throw new HugeException("Failed to commit", e);
}
}
Aggregations