BatchUpdate: Key ChangeUpdates by patch set

Allow callers to create one update per patch set of the change,
looking up by patch set ID and creating as necessary. BatchUpdate will
take care of creating a BatchMetaDataUpdate and applying the updates
in order, oldest patch set to newest patch set.

Force callers to specify the patch set instead of implicitly using the
current patch set. There were some places we were forgetting to do
this, so it's good to have made it required.

We will eventually need to update multiple patch sets at once during
submit, where approvals may be copied between patch sets.

Change-Id: I35e9378d6f9b494db516f8d8c38c5b6e75c2f4c7
This commit is contained in:
Dave Borowitz
2016-01-12 13:56:04 -05:00
parent c323b5d1e8
commit 86fa7164b0
18 changed files with 109 additions and 41 deletions

View File

@@ -0,0 +1,41 @@
// Copyright (C) 2016 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.common.base.Function;
import com.google.common.collect.Ordering;
import com.google.gwtorm.client.IntKey;
/** Static utilities for ReviewDb types. */
public class ReviewDbUtil {
private static final Function<IntKey<?>, Integer> INT_KEY_FUNCTION =
new Function<IntKey<?>, Integer>() {
@Override
public Integer apply(IntKey<?> in) {
return in.get();
}
};
private static final Ordering<? extends IntKey<?>> INT_KEY_ORDERING =
Ordering.natural().onResultOf(INT_KEY_FUNCTION);
@SuppressWarnings("unchecked")
public static <K extends IntKey<?>> Ordering<K> intKeyOrdering() {
return (Ordering<K>) INT_KEY_ORDERING;
}
private ReviewDbUtil() {
}
}