Search in sources :

Example 1 with DataSource

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();
        }
    };
}
Also used : Iterables(com.google.common.collect.Iterables) ImmutableSet(com.google.common.collect.ImmutableSet) IndexConfig(com.google.gerrit.index.IndexConfig) Iterator(java.util.Iterator) QueryOptions(com.google.gerrit.index.QueryOptions) Set(java.util.Set) HashMap(java.util.HashMap) ResultSet(com.google.gerrit.index.query.ResultSet) Preconditions.checkState(com.google.common.base.Preconditions.checkState) IndexedQuery(com.google.gerrit.index.query.IndexedQuery) HashSet(java.util.HashSet) ChangeData(com.google.gerrit.server.query.change.ChangeData) CHANGE(com.google.gerrit.server.index.change.ChangeField.CHANGE) ImmutableList(com.google.common.collect.ImmutableList) PROJECT(com.google.gerrit.server.index.change.ChangeField.PROJECT) QueryParseException(com.google.gerrit.index.query.QueryParseException) Map(java.util.Map) IndexPredicate(com.google.gerrit.index.query.IndexPredicate) Change(com.google.gerrit.entities.Change) DataSource(com.google.gerrit.index.query.DataSource) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ChangeDataSource(com.google.gerrit.server.query.change.ChangeDataSource) Predicate(com.google.gerrit.index.query.Predicate) Matchable(com.google.gerrit.index.query.Matchable) ResultSet(com.google.gerrit.index.query.ResultSet) ChangeData(com.google.gerrit.server.query.change.ChangeData)

Example 2 with DataSource

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());
        }
    };
}
Also used : InternalGroup(com.google.gerrit.entities.InternalGroup) MergeabilityComputationBehavior(com.google.gerrit.server.change.MergeabilityComputationBehavior) IndexUtils(com.google.gerrit.server.index.IndexUtils) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) ProjectData(com.google.gerrit.index.project.ProjectData) ResultSet(com.google.gerrit.index.query.ResultSet) Assisted(com.google.inject.assistedinject.Assisted) Config(org.eclipse.jgit.lib.Config) ProjectIndex(com.google.gerrit.index.project.ProjectIndex) ListResultSet(com.google.gerrit.index.query.ListResultSet) ImmutableList(com.google.common.collect.ImmutableList) AccountIndex(com.google.gerrit.server.index.account.AccountIndex) Map(java.util.Map) FieldBundle(com.google.gerrit.index.query.FieldBundle) Change(com.google.gerrit.entities.Change) Predicate(com.google.gerrit.index.query.Predicate) AccountGroup(com.google.gerrit.entities.AccountGroup) FieldDef(com.google.gerrit.index.FieldDef) Schema(com.google.gerrit.index.Schema) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Account(com.google.gerrit.entities.Account) QueryOptions(com.google.gerrit.index.QueryOptions) Instant(java.time.Instant) Index(com.google.gerrit.index.Index) ChangeField(com.google.gerrit.server.index.change.ChangeField) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) SitePaths(com.google.gerrit.server.config.SitePaths) Project(com.google.gerrit.entities.Project) DataSource(com.google.gerrit.index.query.DataSource) GroupIndex(com.google.gerrit.server.index.group.GroupIndex) AccountState(com.google.gerrit.server.account.AccountState) Comparator(java.util.Comparator) ChangeIndex(com.google.gerrit.server.index.change.ChangeIndex) ListResultSet(com.google.gerrit.index.query.ListResultSet) FieldBundle(com.google.gerrit.index.query.FieldBundle) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) DataSource(com.google.gerrit.index.query.DataSource) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 Change (com.google.gerrit.entities.Change)2 QueryOptions (com.google.gerrit.index.QueryOptions)2 DataSource (com.google.gerrit.index.query.DataSource)2 Predicate (com.google.gerrit.index.query.Predicate)2 ResultSet (com.google.gerrit.index.query.ResultSet)2 ChangeData (com.google.gerrit.server.query.change.ChangeData)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Account (com.google.gerrit.entities.Account)1 AccountGroup (com.google.gerrit.entities.AccountGroup)1 InternalGroup (com.google.gerrit.entities.InternalGroup)1 Project (com.google.gerrit.entities.Project)1