use of com.baidu.hugegraph.iterator.MapperIterator in project incubator-hugegraph by apache.
the class GraphTransaction method queryEdgesByIds.
protected Iterator<Edge> queryEdgesByIds(Object[] edgeIds, boolean verifyId) {
Query.checkForceCapacity(edgeIds.length);
// NOTE: allowed duplicated edges if query by duplicated ids
List<Id> ids = InsertionOrderUtil.newList();
Map<Id, HugeEdge> edges = new HashMap<>(edgeIds.length);
IdQuery query = new IdQuery(HugeType.EDGE);
for (Object edgeId : edgeIds) {
HugeEdge edge;
EdgeId id = HugeEdge.getIdValue(edgeId, !verifyId);
if (id == null) {
continue;
}
if (id.direction() == Directions.IN) {
id = id.switchDirection();
}
if (this.removedEdges.containsKey(id)) {
// The record has been deleted
continue;
} else if ((edge = this.addedEdges.get(id)) != null || (edge = this.updatedEdges.get(id)) != null) {
if (edge.expired()) {
continue;
}
// Found from local tx
edges.put(edge.id(), edge);
} else {
// Prepare to query from backend store
query.query(id);
}
ids.add(id);
}
if (!query.empty()) {
// Query from backend store
if (edges.isEmpty() && query.idsSize() == ids.size()) {
/*
* Sort at the lower layer and return directly if there is no
* local vertex and duplicated id.
*/
Iterator<HugeEdge> it = this.queryEdgesFromBackend(query);
@SuppressWarnings({ "unchecked", "rawtypes" }) Iterator<Edge> r = (Iterator) it;
return r;
}
query.mustSortByInput(false);
Iterator<HugeEdge> it = this.queryEdgesFromBackend(query);
QueryResults.fillMap(it, edges);
}
return new MapperIterator<>(ids.iterator(), id -> {
Edge edge = edges.get(id);
return edge;
});
}
Aggregations