ChangeField: Add LEGACY_ID2
The LEGACY_ID field is named "_id" which cannot be used in Elasticsearch because that field name is reserved. Deprecate LEGACY_ID and add a new field LEGACY_ID2 which is named "legacy_id" instead. Add a new schema version using LEGACY_ID2 and deprecate the previous version. Change-Id: I0b89365b6af74360aeece00c61d29416951fecb4
This commit is contained in:
parent
75129a2d53
commit
5cc3023b60
@ -54,6 +54,7 @@ import com.google.gerrit.server.query.Predicate;
|
|||||||
import com.google.gerrit.server.query.QueryParseException;
|
import com.google.gerrit.server.query.QueryParseException;
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
import com.google.gerrit.server.query.change.ChangeDataSource;
|
import com.google.gerrit.server.query.change.ChangeDataSource;
|
||||||
|
import com.google.gerrit.server.query.change.LegacyChangeIdPredicate;
|
||||||
import com.google.gwtorm.protobuf.ProtobufCodec;
|
import com.google.gwtorm.protobuf.ProtobufCodec;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.gwtorm.server.ResultSet;
|
import com.google.gwtorm.server.ResultSet;
|
||||||
@ -129,9 +130,7 @@ public class LuceneChangeIndex implements ChangeIndex {
|
|||||||
private static final String APPROVAL_FIELD = ChangeField.APPROVAL.getName();
|
private static final String APPROVAL_FIELD = ChangeField.APPROVAL.getName();
|
||||||
private static final String CHANGE_FIELD = ChangeField.CHANGE.getName();
|
private static final String CHANGE_FIELD = ChangeField.CHANGE.getName();
|
||||||
private static final String DELETED_FIELD = ChangeField.DELETED.getName();
|
private static final String DELETED_FIELD = ChangeField.DELETED.getName();
|
||||||
private static final String ID_FIELD = ChangeField.LEGACY_ID.getName();
|
private static final String ID_FIELD = ChangeField.LEGACY_ID2.getName();
|
||||||
private static final String ID_SORT_FIELD =
|
|
||||||
sortFieldName(ChangeField.LEGACY_ID);
|
|
||||||
private static final String MERGEABLE_FIELD = ChangeField.MERGEABLE.getName();
|
private static final String MERGEABLE_FIELD = ChangeField.MERGEABLE.getName();
|
||||||
private static final String PATCH_SET_FIELD = ChangeField.PATCH_SET.getName();
|
private static final String PATCH_SET_FIELD = ChangeField.PATCH_SET.getName();
|
||||||
private static final String REVIEWEDBY_FIELD =
|
private static final String REVIEWEDBY_FIELD =
|
||||||
@ -211,6 +210,7 @@ public class LuceneChangeIndex implements ChangeIndex {
|
|||||||
private final QueryBuilder queryBuilder;
|
private final QueryBuilder queryBuilder;
|
||||||
private final SubIndex openIndex;
|
private final SubIndex openIndex;
|
||||||
private final SubIndex closedIndex;
|
private final SubIndex closedIndex;
|
||||||
|
private final String idSortField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to use DocValues for range/sorted numeric fields.
|
* Whether to use DocValues for range/sorted numeric fields.
|
||||||
@ -240,6 +240,7 @@ public class LuceneChangeIndex implements ChangeIndex {
|
|||||||
this.changeDataFactory = changeDataFactory;
|
this.changeDataFactory = changeDataFactory;
|
||||||
this.schema = schema;
|
this.schema = schema;
|
||||||
this.useDocValuesForSorting = schema.getVersion() >= 15;
|
this.useDocValuesForSorting = schema.getVersion() >= 15;
|
||||||
|
this.idSortField = sortFieldName(LegacyChangeIdPredicate.idField(schema));
|
||||||
|
|
||||||
CustomMappingAnalyzer analyzer =
|
CustomMappingAnalyzer analyzer =
|
||||||
new CustomMappingAnalyzer(new StandardAnalyzer(CharArraySet.EMPTY_SET),
|
new CustomMappingAnalyzer(new StandardAnalyzer(CharArraySet.EMPTY_SET),
|
||||||
@ -274,6 +275,7 @@ public class LuceneChangeIndex implements ChangeIndex {
|
|||||||
if (useDocValuesForSorting) {
|
if (useDocValuesForSorting) {
|
||||||
return new SearcherFactory();
|
return new SearcherFactory();
|
||||||
}
|
}
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
final Map<String, UninvertingReader.Type> mapping = ImmutableMap.of(
|
final Map<String, UninvertingReader.Type> mapping = ImmutableMap.of(
|
||||||
ChangeField.LEGACY_ID.getName(), UninvertingReader.Type.INTEGER,
|
ChangeField.LEGACY_ID.getName(), UninvertingReader.Type.INTEGER,
|
||||||
ChangeField.UPDATED.getName(), UninvertingReader.Type.LONG);
|
ChangeField.UPDATED.getName(), UninvertingReader.Type.LONG);
|
||||||
@ -314,7 +316,7 @@ public class LuceneChangeIndex implements ChangeIndex {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void replace(ChangeData cd) throws IOException {
|
public void replace(ChangeData cd) throws IOException {
|
||||||
Term id = QueryBuilder.idTerm(cd);
|
Term id = QueryBuilder.idTerm(schema, cd);
|
||||||
Document doc = toDocument(cd);
|
Document doc = toDocument(cd);
|
||||||
try {
|
try {
|
||||||
if (cd.change().getStatus().isOpen()) {
|
if (cd.change().getStatus().isOpen()) {
|
||||||
@ -333,7 +335,7 @@ public class LuceneChangeIndex implements ChangeIndex {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(Change.Id id) throws IOException {
|
public void delete(Change.Id id) throws IOException {
|
||||||
Term idTerm = QueryBuilder.idTerm(id);
|
Term idTerm = QueryBuilder.idTerm(schema, id);
|
||||||
try {
|
try {
|
||||||
Futures.allAsList(
|
Futures.allAsList(
|
||||||
openIndex.delete(idTerm),
|
openIndex.delete(idTerm),
|
||||||
@ -369,11 +371,12 @@ public class LuceneChangeIndex implements ChangeIndex {
|
|||||||
setReady(sitePaths, schema.getVersion(), ready);
|
setReady(sitePaths, schema.getVersion(), ready);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private Sort getSort() {
|
private Sort getSort() {
|
||||||
if (useDocValuesForSorting) {
|
if (useDocValuesForSorting) {
|
||||||
return new Sort(
|
return new Sort(
|
||||||
new SortField(UPDATED_SORT_FIELD, SortField.Type.LONG, true),
|
new SortField(UPDATED_SORT_FIELD, SortField.Type.LONG, true),
|
||||||
new SortField(ID_SORT_FIELD, SortField.Type.LONG, true));
|
new SortField(idSortField, SortField.Type.LONG, true));
|
||||||
} else {
|
} else {
|
||||||
return new Sort(
|
return new Sort(
|
||||||
new SortField(
|
new SortField(
|
||||||
@ -550,16 +553,18 @@ public class LuceneChangeIndex implements ChangeIndex {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private void add(Document doc, Values<ChangeData> values) {
|
private void add(Document doc, Values<ChangeData> values) {
|
||||||
String name = values.getField().getName();
|
String name = values.getField().getName();
|
||||||
FieldType<?> type = values.getField().getType();
|
FieldType<?> type = values.getField().getType();
|
||||||
Store store = store(values.getField());
|
Store store = store(values.getField());
|
||||||
|
|
||||||
if (useDocValuesForSorting) {
|
if (useDocValuesForSorting) {
|
||||||
if (values.getField() == ChangeField.LEGACY_ID) {
|
FieldDef<ChangeData, ?> f = values.getField();
|
||||||
|
if (f == ChangeField.LEGACY_ID || f == ChangeField.LEGACY_ID2) {
|
||||||
int v = (Integer) getOnlyElement(values.getValues());
|
int v = (Integer) getOnlyElement(values.getValues());
|
||||||
doc.add(new NumericDocValuesField(ID_SORT_FIELD, v));
|
doc.add(new NumericDocValuesField(sortFieldName(f), v));
|
||||||
} else if (values.getField() == ChangeField.UPDATED) {
|
} else if (f == ChangeField.UPDATED) {
|
||||||
long t = ((Timestamp) getOnlyElement(values.getValues())).getTime();
|
long t = ((Timestamp) getOnlyElement(values.getValues())).getTime();
|
||||||
doc.add(new NumericDocValuesField(UPDATED_SORT_FIELD, t));
|
doc.add(new NumericDocValuesField(UPDATED_SORT_FIELD, t));
|
||||||
}
|
}
|
||||||
|
@ -14,17 +14,18 @@
|
|||||||
|
|
||||||
package com.google.gerrit.lucene;
|
package com.google.gerrit.lucene;
|
||||||
|
|
||||||
|
import static com.google.gerrit.server.query.change.LegacyChangeIdPredicate.idField;
|
||||||
import static org.apache.lucene.search.BooleanClause.Occur.MUST;
|
import static org.apache.lucene.search.BooleanClause.Occur.MUST;
|
||||||
import static org.apache.lucene.search.BooleanClause.Occur.MUST_NOT;
|
import static org.apache.lucene.search.BooleanClause.Occur.MUST_NOT;
|
||||||
import static org.apache.lucene.search.BooleanClause.Occur.SHOULD;
|
import static org.apache.lucene.search.BooleanClause.Occur.SHOULD;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.server.index.ChangeField;
|
|
||||||
import com.google.gerrit.server.index.FieldType;
|
import com.google.gerrit.server.index.FieldType;
|
||||||
import com.google.gerrit.server.index.IndexPredicate;
|
import com.google.gerrit.server.index.IndexPredicate;
|
||||||
import com.google.gerrit.server.index.IntegerRangePredicate;
|
import com.google.gerrit.server.index.IntegerRangePredicate;
|
||||||
import com.google.gerrit.server.index.RegexPredicate;
|
import com.google.gerrit.server.index.RegexPredicate;
|
||||||
|
import com.google.gerrit.server.index.Schema;
|
||||||
import com.google.gerrit.server.index.TimestampRangePredicate;
|
import com.google.gerrit.server.index.TimestampRangePredicate;
|
||||||
import com.google.gerrit.server.query.AndPredicate;
|
import com.google.gerrit.server.query.AndPredicate;
|
||||||
import com.google.gerrit.server.query.NotPredicate;
|
import com.google.gerrit.server.query.NotPredicate;
|
||||||
@ -49,14 +50,13 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class QueryBuilder {
|
public class QueryBuilder {
|
||||||
private static final String ID_FIELD = ChangeField.LEGACY_ID.getName();
|
|
||||||
|
|
||||||
public static Term idTerm(ChangeData cd) {
|
public static Term idTerm(Schema<ChangeData> schema, ChangeData cd) {
|
||||||
return intTerm(ID_FIELD, cd.getId().get());
|
return intTerm(idField(schema).getName(), cd.getId().get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Term idTerm(Change.Id id) {
|
public static Term idTerm(Schema<ChangeData> schema, Change.Id id) {
|
||||||
return intTerm(ID_FIELD, id.get());
|
return intTerm(idField(schema).getName(), id.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
private final org.apache.lucene.util.QueryBuilder queryBuilder;
|
private final org.apache.lucene.util.QueryBuilder queryBuilder;
|
||||||
|
@ -62,6 +62,7 @@ import java.util.Set;
|
|||||||
* characters.
|
* characters.
|
||||||
*/
|
*/
|
||||||
public class ChangeField {
|
public class ChangeField {
|
||||||
|
@Deprecated
|
||||||
/** Legacy change ID. */
|
/** Legacy change ID. */
|
||||||
public static final FieldDef<ChangeData, Integer> LEGACY_ID =
|
public static final FieldDef<ChangeData, Integer> LEGACY_ID =
|
||||||
new FieldDef.Single<ChangeData, Integer>("_id",
|
new FieldDef.Single<ChangeData, Integer>("_id",
|
||||||
@ -72,6 +73,16 @@ public class ChangeField {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Legacy change ID without underscore prefix. */
|
||||||
|
public static final FieldDef<ChangeData, Integer> LEGACY_ID2 =
|
||||||
|
new FieldDef.Single<ChangeData, Integer>("legacy_id",
|
||||||
|
FieldType.INTEGER, true) {
|
||||||
|
@Override
|
||||||
|
public Integer get(ChangeData input, FillArgs args) {
|
||||||
|
return input.getId().get();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/** Newer style Change-Id key. */
|
/** Newer style Change-Id key. */
|
||||||
public static final FieldDef<ChangeData, String> ID =
|
public static final FieldDef<ChangeData, String> ID =
|
||||||
new FieldDef.Single<ChangeData, String>("change_id",
|
new FieldDef.Single<ChangeData, String>("change_id",
|
||||||
|
@ -241,7 +241,7 @@ public class ChangeSchemas {
|
|||||||
ChangeField.EDITBY,
|
ChangeField.EDITBY,
|
||||||
ChangeField.REVIEWEDBY);
|
ChangeField.REVIEWEDBY);
|
||||||
|
|
||||||
@Deprecated
|
@SuppressWarnings("deprecation")
|
||||||
static final Schema<ChangeData> V21 = schema(
|
static final Schema<ChangeData> V21 = schema(
|
||||||
ChangeField.LEGACY_ID,
|
ChangeField.LEGACY_ID,
|
||||||
ChangeField.ID,
|
ChangeField.ID,
|
||||||
@ -274,6 +274,7 @@ public class ChangeSchemas {
|
|||||||
ChangeField.EDITBY,
|
ChangeField.EDITBY,
|
||||||
ChangeField.REVIEWEDBY);
|
ChangeField.REVIEWEDBY);
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
static final Schema<ChangeData> V22 = schema(
|
static final Schema<ChangeData> V22 = schema(
|
||||||
ChangeField.LEGACY_ID,
|
ChangeField.LEGACY_ID,
|
||||||
ChangeField.ID,
|
ChangeField.ID,
|
||||||
@ -307,6 +308,39 @@ public class ChangeSchemas {
|
|||||||
ChangeField.REVIEWEDBY,
|
ChangeField.REVIEWEDBY,
|
||||||
ChangeField.EXACT_COMMIT);
|
ChangeField.EXACT_COMMIT);
|
||||||
|
|
||||||
|
static final Schema<ChangeData> V23 = schema(
|
||||||
|
ChangeField.LEGACY_ID2,
|
||||||
|
ChangeField.ID,
|
||||||
|
ChangeField.STATUS,
|
||||||
|
ChangeField.PROJECT,
|
||||||
|
ChangeField.PROJECTS,
|
||||||
|
ChangeField.REF,
|
||||||
|
ChangeField.EXACT_TOPIC,
|
||||||
|
ChangeField.FUZZY_TOPIC,
|
||||||
|
ChangeField.UPDATED,
|
||||||
|
ChangeField.FILE_PART,
|
||||||
|
ChangeField.PATH,
|
||||||
|
ChangeField.OWNER,
|
||||||
|
ChangeField.REVIEWER,
|
||||||
|
ChangeField.COMMIT,
|
||||||
|
ChangeField.TR,
|
||||||
|
ChangeField.LABEL,
|
||||||
|
ChangeField.COMMIT_MESSAGE,
|
||||||
|
ChangeField.COMMENT,
|
||||||
|
ChangeField.CHANGE,
|
||||||
|
ChangeField.APPROVAL,
|
||||||
|
ChangeField.MERGEABLE,
|
||||||
|
ChangeField.ADDED,
|
||||||
|
ChangeField.DELETED,
|
||||||
|
ChangeField.DELTA,
|
||||||
|
ChangeField.HASHTAG,
|
||||||
|
ChangeField.COMMENTBY,
|
||||||
|
ChangeField.PATCH_SET,
|
||||||
|
ChangeField.GROUP,
|
||||||
|
ChangeField.EDITBY,
|
||||||
|
ChangeField.REVIEWEDBY,
|
||||||
|
ChangeField.EXACT_COMMIT);
|
||||||
|
|
||||||
|
|
||||||
private static Schema<ChangeData> schema(Collection<FieldDef<ChangeData, ?>> fields) {
|
private static Schema<ChangeData> schema(Collection<FieldDef<ChangeData, ?>> fields) {
|
||||||
return new Schema<>(ImmutableList.copyOf(fields));
|
return new Schema<>(ImmutableList.copyOf(fields));
|
||||||
|
@ -341,7 +341,8 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
|||||||
@Operator
|
@Operator
|
||||||
public Predicate<ChangeData> change(String query) throws QueryParseException {
|
public Predicate<ChangeData> change(String query) throws QueryParseException {
|
||||||
if (PAT_LEGACY_ID.matcher(query).matches()) {
|
if (PAT_LEGACY_ID.matcher(query).matches()) {
|
||||||
return new LegacyChangeIdPredicate(Change.Id.parse(query));
|
return new LegacyChangeIdPredicate(
|
||||||
|
args.getSchema(), Change.Id.parse(query));
|
||||||
} else if (PAT_CHANGE_ID.matcher(query).matches()) {
|
} else if (PAT_CHANGE_ID.matcher(query).matches()) {
|
||||||
return new ChangeIdPredicate(parseChangeId(query));
|
return new ChangeIdPredicate(parseChangeId(query));
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,8 @@ class CommentPredicate extends IndexPredicate<ChangeData> {
|
|||||||
public boolean match(ChangeData object) throws OrmException {
|
public boolean match(ChangeData object) throws OrmException {
|
||||||
try {
|
try {
|
||||||
for (ChangeData cData : index.getSource(
|
for (ChangeData cData : index.getSource(
|
||||||
Predicate.and(new LegacyChangeIdPredicate(object.getId()), this), 0, 1)
|
Predicate.and(new LegacyChangeIdPredicate(
|
||||||
.read()) {
|
index.getSchema(), object.getId()), this), 0, 1).read()) {
|
||||||
if (cData.getId().equals(object.getId())) {
|
if (cData.getId().equals(object.getId())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ class ConflictsPredicate extends OrPredicate<ChangeData> {
|
|||||||
List<Predicate<ChangeData>> predicatesForOneChange =
|
List<Predicate<ChangeData>> predicatesForOneChange =
|
||||||
Lists.newArrayListWithCapacity(5);
|
Lists.newArrayListWithCapacity(5);
|
||||||
predicatesForOneChange.add(
|
predicatesForOneChange.add(
|
||||||
not(new LegacyChangeIdPredicate(c.getId())));
|
not(new LegacyChangeIdPredicate(args.getSchema(), c.getId())));
|
||||||
predicatesForOneChange.add(
|
predicatesForOneChange.add(
|
||||||
new ProjectPredicate(c.getProject().get()));
|
new ProjectPredicate(c.getProject().get()));
|
||||||
predicatesForOneChange.add(
|
predicatesForOneChange.add(
|
||||||
|
@ -55,8 +55,10 @@ class FuzzyTopicPredicate extends IndexPredicate<ChangeData> {
|
|||||||
}
|
}
|
||||||
if (getField() == FUZZY_TOPIC || getField() == LEGACY_TOPIC3) {
|
if (getField() == FUZZY_TOPIC || getField() == LEGACY_TOPIC3) {
|
||||||
try {
|
try {
|
||||||
Predicate<ChangeData> thisId = new LegacyChangeIdPredicate(cd.getId());
|
Predicate<ChangeData> thisId =
|
||||||
Iterable<ChangeData> results = index.getSource(and(thisId, this), 0, 1).read();
|
new LegacyChangeIdPredicate(index.getSchema(), cd.getId());
|
||||||
|
Iterable<ChangeData> results =
|
||||||
|
index.getSource(and(thisId, this), 0, 1).read();
|
||||||
return !Iterables.isEmpty(results);
|
return !Iterables.isEmpty(results);
|
||||||
} catch (QueryParseException e) {
|
} catch (QueryParseException e) {
|
||||||
throw new OrmException(e);
|
throw new OrmException(e);
|
||||||
|
@ -18,6 +18,7 @@ import com.google.common.collect.Lists;
|
|||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
|
import com.google.gerrit.server.index.Schema;
|
||||||
import com.google.gerrit.server.query.OrPredicate;
|
import com.google.gerrit.server.query.OrPredicate;
|
||||||
import com.google.gerrit.server.query.Predicate;
|
import com.google.gerrit.server.query.Predicate;
|
||||||
import com.google.gerrit.server.query.QueryParseException;
|
import com.google.gerrit.server.query.QueryParseException;
|
||||||
@ -37,10 +38,11 @@ class IsStarredByPredicate extends OrPredicate<ChangeData> implements
|
|||||||
return user.toString();
|
return user.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Predicate<ChangeData>> predicates(Set<Change.Id> ids) {
|
private static List<Predicate<ChangeData>> predicates(
|
||||||
|
Schema<ChangeData> schema, Set<Change.Id> ids) {
|
||||||
List<Predicate<ChangeData>> r = Lists.newArrayListWithCapacity(ids.size());
|
List<Predicate<ChangeData>> r = Lists.newArrayListWithCapacity(ids.size());
|
||||||
for (Change.Id id : ids) {
|
for (Change.Id id : ids) {
|
||||||
r.add(new LegacyChangeIdPredicate(id));
|
r.add(new LegacyChangeIdPredicate(schema, id));
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -53,7 +55,7 @@ class IsStarredByPredicate extends OrPredicate<ChangeData> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private IsStarredByPredicate(Arguments args, IdentifiedUser user) {
|
private IsStarredByPredicate(Arguments args, IdentifiedUser user) {
|
||||||
super(predicates(user.getStarredChanges()));
|
super(predicates(args.getSchema(), user.getStarredChanges()));
|
||||||
this.args = args;
|
this.args = args;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
@ -14,16 +14,32 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.query.change;
|
package com.google.gerrit.server.query.change;
|
||||||
|
|
||||||
|
import static com.google.gerrit.server.index.ChangeField.LEGACY_ID;
|
||||||
|
import static com.google.gerrit.server.index.ChangeField.LEGACY_ID2;
|
||||||
|
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.server.index.ChangeField;
|
import com.google.gerrit.server.index.ChangeField;
|
||||||
|
import com.google.gerrit.server.index.FieldDef;
|
||||||
import com.google.gerrit.server.index.IndexPredicate;
|
import com.google.gerrit.server.index.IndexPredicate;
|
||||||
|
import com.google.gerrit.server.index.Schema;
|
||||||
|
|
||||||
/** Predicate over change number (aka legacy ID or Change.Id). */
|
/** Predicate over change number (aka legacy ID or Change.Id). */
|
||||||
class LegacyChangeIdPredicate extends IndexPredicate<ChangeData> {
|
public class LegacyChangeIdPredicate extends IndexPredicate<ChangeData> {
|
||||||
private final Change.Id id;
|
private final Change.Id id;
|
||||||
|
|
||||||
LegacyChangeIdPredicate(Change.Id id) {
|
@SuppressWarnings("deprecation")
|
||||||
super(ChangeField.LEGACY_ID, ChangeQueryBuilder.FIELD_CHANGE, id.toString());
|
public static FieldDef<ChangeData, ?> idField(Schema<ChangeData> schema) {
|
||||||
|
if (schema == null) {
|
||||||
|
return ChangeField.LEGACY_ID2;
|
||||||
|
} else if (schema.hasField(LEGACY_ID2)) {
|
||||||
|
return schema.getFields().get(LEGACY_ID2.getName());
|
||||||
|
} else {
|
||||||
|
return schema.getFields().get(LEGACY_ID.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LegacyChangeIdPredicate(Schema<ChangeData> schema, Change.Id id) {
|
||||||
|
super(idField(schema), ChangeQueryBuilder.FIELD_CHANGE, id.toString());
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,8 +37,8 @@ class MessagePredicate extends IndexPredicate<ChangeData> {
|
|||||||
public boolean match(ChangeData object) throws OrmException {
|
public boolean match(ChangeData object) throws OrmException {
|
||||||
try {
|
try {
|
||||||
for (ChangeData cData : index.getSource(
|
for (ChangeData cData : index.getSource(
|
||||||
Predicate.and(new LegacyChangeIdPredicate(object.getId()), this), 0, 1)
|
Predicate.and(new LegacyChangeIdPredicate(
|
||||||
.read()) {
|
index.getSchema(), object.getId()), this), 0, 1).read()) {
|
||||||
if (cData.getId().equals(object.getId())) {
|
if (cData.getId().equals(object.getId())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user