InternalChangeQuery: Add a noFields builder method

Allows to build a query that does not request any stored fields,
without the caller explicitly having to call setRequestedFields
with an empty set.

Change-Id: I1d2be6e9c3947ef79901bd269f33475677863482
This commit is contained in:
David Pursehouse
2016-02-12 09:28:34 +09:00
parent 9aa8e27c1a
commit 72ca253ec2
2 changed files with 8 additions and 5 deletions

View File

@@ -15,7 +15,6 @@
package com.google.gerrit.server;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
import com.google.common.primitives.Ints;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.change.ChangeTriplet;
@@ -55,8 +54,7 @@ public class ChangeFinder {
throws OrmException {
// Use the index to search for changes, but don't return any stored fields,
// to force rereading in case the index is stale.
InternalChangeQuery query = queryProvider.get()
.setRequestedFields(ImmutableSet.<String> of());
InternalChangeQuery query = queryProvider.get().noFields();
// Try legacy id
if (!id.isEmpty() && id.charAt(0) != '0') {
@@ -96,8 +94,7 @@ public class ChangeFinder {
throws OrmException {
// Use the index to search for changes, but don't return any stored fields,
// to force rereading in case the index is stale.
InternalChangeQuery query = queryProvider.get()
.setRequestedFields(ImmutableSet.<String> of());
InternalChangeQuery query = queryProvider.get().noFields();
return asChangeControls(query.byLegacyChangeId(id), user);
}

View File

@@ -23,6 +23,7 @@ import static com.google.gerrit.server.query.change.ChangeStatusPredicate.open;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.reviewdb.client.Branch;
@@ -110,6 +111,11 @@ public class InternalChangeQuery {
return this;
}
public InternalChangeQuery noFields() {
qp.setRequestedFields(ImmutableSet.<String> of());
return this;
}
public List<ChangeData> byKey(Change.Key key) throws OrmException {
return byKeyPrefix(key.get());
}