Move ReviewDb ProtobufCodecs to a common class
Change-Id: I617181fb4273ca0767ec68957efddbfff7190e65
This commit is contained in:
parent
3f0779e9bc
commit
475c110a8b
java/com/google/gerrit
elasticsearch
lucene
reviewdb/server
server/index/change
@ -15,9 +15,9 @@
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.gerrit.server.index.change.ChangeField.APPROVAL_CODEC;
|
||||
import static com.google.gerrit.server.index.change.ChangeField.CHANGE_CODEC;
|
||||
import static com.google.gerrit.server.index.change.ChangeField.PATCH_SET_CODEC;
|
||||
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.APPROVAL_CODEC;
|
||||
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.CHANGE_CODEC;
|
||||
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.PATCH_SET_CODEC;
|
||||
import static com.google.gerrit.server.index.change.ChangeIndexRewriter.CLOSED_STATUSES;
|
||||
import static com.google.gerrit.server.index.change.ChangeIndexRewriter.OPEN_STATUSES;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
@ -16,11 +16,11 @@ package com.google.gerrit.lucene;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.gerrit.lucene.AbstractLuceneIndex.sortFieldName;
|
||||
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.APPROVAL_CODEC;
|
||||
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.CHANGE_CODEC;
|
||||
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.PATCH_SET_CODEC;
|
||||
import static com.google.gerrit.server.git.QueueProvider.QueueType.INTERACTIVE;
|
||||
import static com.google.gerrit.server.index.change.ChangeField.APPROVAL_CODEC;
|
||||
import static com.google.gerrit.server.index.change.ChangeField.CHANGE_CODEC;
|
||||
import static com.google.gerrit.server.index.change.ChangeField.LEGACY_ID;
|
||||
import static com.google.gerrit.server.index.change.ChangeField.PATCH_SET_CODEC;
|
||||
import static com.google.gerrit.server.index.change.ChangeField.PROJECT;
|
||||
import static com.google.gerrit.server.index.change.ChangeIndexRewriter.CLOSED_STATUSES;
|
||||
import static com.google.gerrit.server.index.change.ChangeIndexRewriter.OPEN_STATUSES;
|
||||
|
34
java/com/google/gerrit/reviewdb/server/ReviewDbCodecs.java
Normal file
34
java/com/google/gerrit/reviewdb/server/ReviewDbCodecs.java
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2018 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.reviewdb.server;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
import com.google.gwtorm.protobuf.CodecFactory;
|
||||
import com.google.gwtorm.protobuf.ProtobufCodec;
|
||||
|
||||
/** {@link ProtobufCodec} instances for ReviewDb types. */
|
||||
public class ReviewDbCodecs {
|
||||
public static final ProtobufCodec<PatchSetApproval> APPROVAL_CODEC =
|
||||
CodecFactory.encoder(PatchSetApproval.class);
|
||||
|
||||
public static final ProtobufCodec<Change> CHANGE_CODEC = CodecFactory.encoder(Change.class);
|
||||
|
||||
public static final ProtobufCodec<PatchSet> PATCH_SET_CODEC =
|
||||
CodecFactory.encoder(PatchSet.class);
|
||||
|
||||
private ReviewDbCodecs() {}
|
||||
}
|
@ -22,6 +22,9 @@ import static com.google.gerrit.index.FieldDef.integer;
|
||||
import static com.google.gerrit.index.FieldDef.prefix;
|
||||
import static com.google.gerrit.index.FieldDef.storedOnly;
|
||||
import static com.google.gerrit.index.FieldDef.timestamp;
|
||||
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.APPROVAL_CODEC;
|
||||
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.CHANGE_CODEC;
|
||||
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.PATCH_SET_CODEC;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
@ -64,7 +67,6 @@ import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gerrit.server.query.change.ChangeQueryBuilder;
|
||||
import com.google.gerrit.server.query.change.ChangeStatusPredicate;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gwtorm.protobuf.CodecFactory;
|
||||
import com.google.gwtorm.protobuf.ProtobufCodec;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.protobuf.CodedOutputStream;
|
||||
@ -468,15 +470,10 @@ public class ChangeField {
|
||||
exact(ChangeQueryBuilder.FIELD_EXACTCOMMITTER)
|
||||
.buildRepeatable(ChangeField::getCommitterNameAndEmail);
|
||||
|
||||
public static final ProtobufCodec<Change> CHANGE_CODEC = CodecFactory.encoder(Change.class);
|
||||
|
||||
/** Serialized change object, used for pre-populating results. */
|
||||
public static final FieldDef<ChangeData, byte[]> CHANGE =
|
||||
storedOnly("_change").build(changeGetter(CHANGE_CODEC::encodeToByteArray));
|
||||
|
||||
public static final ProtobufCodec<PatchSetApproval> APPROVAL_CODEC =
|
||||
CodecFactory.encoder(PatchSetApproval.class);
|
||||
|
||||
/** Serialized approvals for the current patch set, used for pre-populating results. */
|
||||
public static final FieldDef<ChangeData, Iterable<byte[]>> APPROVAL =
|
||||
storedOnly("_approval")
|
||||
@ -596,9 +593,6 @@ public class ChangeField {
|
||||
cd ->
|
||||
cd.patchSets().stream().flatMap(ps -> ps.getGroups().stream()).collect(toSet()));
|
||||
|
||||
public static final ProtobufCodec<PatchSet> PATCH_SET_CODEC =
|
||||
CodecFactory.encoder(PatchSet.class);
|
||||
|
||||
/** Serialized patch set object, used for pre-populating results. */
|
||||
public static final FieldDef<ChangeData, Iterable<byte[]>> PATCH_SET =
|
||||
storedOnly("_patch_set").buildRepeatable(cd -> toProtos(PATCH_SET_CODEC, cd.patchSets()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user