Accept Dates in PatchSetApproval

The goal is to avoid calling TimeUtil.nowTs() in ApprovalsUtil, but
that method only has a Date available. Accept these from
PatchSetApproval methods. We have to do a bit of type checking to not
unnecessarily truncate Timestamps when available.

Change-Id: I1853719ce187f28f7a3553cdf4834e2093d172d5
This commit is contained in:
Dave Borowitz
2016-03-07 15:10:30 -05:00
parent 7a28e61bb2
commit 0e54fb3dcb
2 changed files with 11 additions and 6 deletions

View File

@@ -18,6 +18,7 @@ import com.google.gwtorm.client.Column;
import com.google.gwtorm.client.CompoundKey;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Objects;
/** An approval (or negative approval) on a patch set. */
@@ -95,7 +96,7 @@ public final class PatchSetApproval {
protected PatchSetApproval() {
}
public PatchSetApproval(PatchSetApproval.Key k, short v, Timestamp ts) {
public PatchSetApproval(PatchSetApproval.Key k, short v, Date ts) {
key = k;
setValue(v);
setGranted(ts);
@@ -136,8 +137,12 @@ public final class PatchSetApproval {
return granted;
}
public void setGranted(Timestamp ts) {
granted = ts;
public void setGranted(Date when) {
if (when instanceof Timestamp) {
granted = (Timestamp) when;
} else {
granted = new Timestamp(when.getTime());
}
}
public String getLabel() {

View File

@@ -31,7 +31,6 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;
import com.google.common.collect.SetMultimap;
import com.google.common.collect.Sets;
import com.google.gerrit.common.TimeUtil;
import com.google.gerrit.common.data.LabelType;
import com.google.gerrit.common.data.LabelTypes;
import com.google.gerrit.common.data.Permission;
@@ -56,6 +55,7 @@ import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -216,7 +216,7 @@ public class ApprovalsUtil {
for (Account.Id account : need) {
cells.add(new PatchSetApproval(
new PatchSetApproval.Key(psId, account, labelId),
(short) 0, TimeUtil.nowTs()));
(short) 0, update.getWhen()));
update.putReviewer(account, REVIEWER);
}
db.patchSetApprovals().insert(cells);
@@ -229,7 +229,7 @@ public class ApprovalsUtil {
if (!approvals.isEmpty()) {
checkApprovals(approvals, changeCtl);
List<PatchSetApproval> cells = new ArrayList<>(approvals.size());
Timestamp ts = TimeUtil.nowTs();
Date ts = update.getWhen();
for (Map.Entry<String, Short> vote : approvals.entrySet()) {
LabelType lt = labelTypes.byLabel(vote.getKey());
cells.add(new PatchSetApproval(new PatchSetApproval.Key(