use of com.google.gerrit.index.query.DataSource in project gerrit by GerritCodeReview.
the class IndexedChangeQuery method read.
@Override
public ResultSet<ChangeData> read() {
final DataSource<ChangeData> currSource = source;
final ResultSet<ChangeData> rs = currSource.read();
return new ResultSet<>() {
@Override
public Iterator<ChangeData> iterator() {
return Iterables.transform(rs, cd -> {
fromSource.put(cd, currSource);
return cd;
}).iterator();
}
@Override
public ImmutableList<ChangeData> toList() {
ImmutableList<ChangeData> r = rs.toList();
for (ChangeData cd : r) {
fromSource.put(cd, currSource);
}
return r;
}
@Override
public void close() {
rs.close();
}
};
}
use of com.google.gerrit.index.query.DataSource in project gerrit by GerritCodeReview.
the class AbstractFakeIndex method getSource.
@Override
public DataSource<V> getSource(Predicate<V> p, QueryOptions opts) {
List<V> results;
synchronized (indexedDocuments) {
results = indexedDocuments.values().stream().map(doc -> valueFor(doc)).filter(doc -> p.asMatchable().match(doc)).sorted(sortingComparator()).skip(opts.start()).limit(opts.limit()).collect(toImmutableList());
}
return new DataSource<>() {
@Override
public int getCardinality() {
return results.size();
}
@Override
public ResultSet<V> read() {
return new ListResultSet<>(results);
}
@Override
public ResultSet<FieldBundle> readRaw() {
ImmutableList.Builder<FieldBundle> fieldBundles = ImmutableList.builder();
for (V result : results) {
ImmutableListMultimap.Builder<String, Object> fields = ImmutableListMultimap.builder();
for (FieldDef<V, ?> field : getSchema().getFields().values()) {
if (field.get(result) == null) {
continue;
}
if (field.isRepeatable()) {
fields.putAll(field.getName(), (Iterable<?>) field.get(result));
} else {
fields.put(field.getName(), field.get(result));
}
}
fieldBundles.add(new FieldBundle(fields.build()));
}
return new ListResultSet<>(fieldBundles.build());
}
};
}
Aggregations