Inject ApprovalsUtil in more places

Replace static methods taking a ReviewDb with instance methods.

Change-Id: I12d17fe122144183eeb142918a0176bc48e1705c
This commit is contained in:
Dave Borowitz
2013-12-03 10:50:51 -08:00
parent 2ede20d73d
commit 4f47ab7468
7 changed files with 22 additions and 12 deletions

View File

@@ -70,11 +70,11 @@ public class ApprovalsUtil {
* *
* @throws OrmException * @throws OrmException
*/ */
public static void copyLabels(ReviewDb db, LabelTypes labelTypes, public void copyLabels(LabelTypes labelTypes,
PatchSet.Id source, PatchSet dest, ChangeKind changeKind) throws OrmException { PatchSet.Id source, PatchSet dest, ChangeKind changeKind) throws OrmException {
Iterable<PatchSetApproval> sourceApprovals = Iterable<PatchSetApproval> sourceApprovals =
db.patchSetApprovals().byPatchSet(source); db.patchSetApprovals().byPatchSet(source);
copyLabels(db, labelTypes, sourceApprovals, source, dest, changeKind); copyLabels(labelTypes, sourceApprovals, source, dest, changeKind);
} }
/** /**
@@ -82,7 +82,7 @@ public class ApprovalsUtil {
* *
* @throws OrmException * @throws OrmException
*/ */
public static void copyLabels(ReviewDb db, LabelTypes labelTypes, public void copyLabels(LabelTypes labelTypes,
Iterable<PatchSetApproval> sourceApprovals, PatchSet.Id source, Iterable<PatchSetApproval> sourceApprovals, PatchSet.Id source,
PatchSet dest, ChangeKind changeKind) throws OrmException { PatchSet dest, ChangeKind changeKind) throws OrmException {
List<PatchSetApproval> copied = Lists.newArrayList(); List<PatchSetApproval> copied = Lists.newArrayList();
@@ -107,7 +107,7 @@ public class ApprovalsUtil {
db.patchSetApprovals().insert(copied); db.patchSetApprovals().insert(copied);
} }
public void addReviewers(ReviewDb db, LabelTypes labelTypes, Change change, public void addReviewers(LabelTypes labelTypes, Change change,
PatchSet ps, PatchSetInfo info, Set<Account.Id> wantReviewers, PatchSet ps, PatchSetInfo info, Set<Account.Id> wantReviewers,
Set<Account.Id> existingReviewers) throws OrmException { Set<Account.Id> existingReviewers) throws OrmException {
List<LabelType> allTypes = labelTypes.getLabelTypes(); List<LabelType> allTypes = labelTypes.getLabelTypes();

View File

@@ -51,6 +51,7 @@ public class Abandon implements RestModifyView<ChangeResource, AbandonInput>,
private final ChangeHooks hooks; private final ChangeHooks hooks;
private final AbandonedSender.Factory abandonedSenderFactory; private final AbandonedSender.Factory abandonedSenderFactory;
private final Provider<ReviewDb> dbProvider; private final Provider<ReviewDb> dbProvider;
private final Provider<ApprovalsUtil> approvals;
private final ChangeJson json; private final ChangeJson json;
private final ChangeIndexer indexer; private final ChangeIndexer indexer;
@@ -58,11 +59,13 @@ public class Abandon implements RestModifyView<ChangeResource, AbandonInput>,
Abandon(ChangeHooks hooks, Abandon(ChangeHooks hooks,
AbandonedSender.Factory abandonedSenderFactory, AbandonedSender.Factory abandonedSenderFactory,
Provider<ReviewDb> dbProvider, Provider<ReviewDb> dbProvider,
Provider<ApprovalsUtil> approvals,
ChangeJson json, ChangeJson json,
ChangeIndexer indexer) { ChangeIndexer indexer) {
this.hooks = hooks; this.hooks = hooks;
this.abandonedSenderFactory = abandonedSenderFactory; this.abandonedSenderFactory = abandonedSenderFactory;
this.dbProvider = dbProvider; this.dbProvider = dbProvider;
this.approvals = approvals;
this.json = json; this.json = json;
this.indexer = indexer; this.indexer = indexer;
} }
@@ -103,7 +106,7 @@ public class Abandon implements RestModifyView<ChangeResource, AbandonInput>,
} }
message = newMessage(input, caller, change); message = newMessage(input, caller, change);
db.changeMessages().insert(Collections.singleton(message)); db.changeMessages().insert(Collections.singleton(message));
new ApprovalsUtil(db).syncChangeStatus(change); approvals.get().syncChangeStatus(change);
db.commit(); db.commit();
} finally { } finally {
db.rollback(); db.rollback();

View File

@@ -75,6 +75,7 @@ public class ChangeInserter {
@Inject @Inject
ChangeInserter(Provider<ReviewDb> dbProvider, ChangeInserter(Provider<ReviewDb> dbProvider,
Provider<ApprovalsUtil> approvals,
PatchSetInfoFactory patchSetInfoFactory, PatchSetInfoFactory patchSetInfoFactory,
GitReferenceUpdated gitRefUpdated, GitReferenceUpdated gitRefUpdated,
ChangeHooks hooks, ChangeHooks hooks,
@@ -159,7 +160,7 @@ public class ChangeInserter {
db.patchSets().insert(Collections.singleton(patchSet)); db.patchSets().insert(Collections.singleton(patchSet));
db.changes().insert(Collections.singleton(change)); db.changes().insert(Collections.singleton(change));
LabelTypes labelTypes = refControl.getProjectControl().getLabelTypes(); LabelTypes labelTypes = refControl.getProjectControl().getLabelTypes();
approvalsUtil.addReviewers(db, labelTypes, change, patchSet, patchSetInfo, approvalsUtil.addReviewers(labelTypes, change, patchSet, patchSetInfo,
reviewers, Collections.<Account.Id> emptySet()); reviewers, Collections.<Account.Id> emptySet());
db.commit(); db.commit();
} finally { } finally {

View File

@@ -95,6 +95,7 @@ public class PatchSetInserter {
private final MergeabilityChecker mergeabilityChecker; private final MergeabilityChecker mergeabilityChecker;
private final ReplacePatchSetSender.Factory replacePatchSetFactory; private final ReplacePatchSetSender.Factory replacePatchSetFactory;
private final MergeUtil.Factory mergeUtilFactory; private final MergeUtil.Factory mergeUtilFactory;
private final ApprovalsUtil approvalsUtil;
private final Repository git; private final Repository git;
private final RevWalk revWalk; private final RevWalk revWalk;
@@ -120,6 +121,7 @@ public class PatchSetInserter {
MergeabilityChecker mergeabilityChecker, MergeabilityChecker mergeabilityChecker,
ReplacePatchSetSender.Factory replacePatchSetFactory, ReplacePatchSetSender.Factory replacePatchSetFactory,
MergeUtil.Factory mergeUtilFactory, MergeUtil.Factory mergeUtilFactory,
ApprovalsUtil approvalsUtil,
@Assisted Repository git, @Assisted Repository git,
@Assisted RevWalk revWalk, @Assisted RevWalk revWalk,
@Assisted RefControl refControl, @Assisted RefControl refControl,
@@ -135,6 +137,7 @@ public class PatchSetInserter {
this.mergeabilityChecker = mergeabilityChecker; this.mergeabilityChecker = mergeabilityChecker;
this.replacePatchSetFactory = replacePatchSetFactory; this.replacePatchSetFactory = replacePatchSetFactory;
this.mergeUtilFactory = mergeUtilFactory; this.mergeUtilFactory = mergeUtilFactory;
this.approvalsUtil = approvalsUtil;
this.git = git; this.git = git;
this.revWalk = revWalk; this.revWalk = revWalk;
@@ -279,7 +282,7 @@ public class PatchSetInserter {
ChangeKind changeKind = ChangeKind changeKind =
getChangeKind(mergeUtilFactory, projectState, git, priorCommit, commit); getChangeKind(mergeUtilFactory, projectState, git, priorCommit, commit);
ApprovalsUtil.copyLabels(db, refControl.getProjectControl() approvalsUtil.copyLabels(refControl.getProjectControl()
.getLabelTypes(), currentPatchSetId, patchSet, changeKind); .getLabelTypes(), currentPatchSetId, patchSet, changeKind);
} }
db.commit(); db.commit();

View File

@@ -52,6 +52,7 @@ public class Restore implements RestModifyView<ChangeResource, RestoreInput>,
private final ChangeHooks hooks; private final ChangeHooks hooks;
private final RestoredSender.Factory restoredSenderFactory; private final RestoredSender.Factory restoredSenderFactory;
private final Provider<ReviewDb> dbProvider; private final Provider<ReviewDb> dbProvider;
private final Provider<ApprovalsUtil> approvals;
private final ChangeJson json; private final ChangeJson json;
private final ChangeIndexer indexer; private final ChangeIndexer indexer;
@@ -59,11 +60,13 @@ public class Restore implements RestModifyView<ChangeResource, RestoreInput>,
Restore(ChangeHooks hooks, Restore(ChangeHooks hooks,
RestoredSender.Factory restoredSenderFactory, RestoredSender.Factory restoredSenderFactory,
Provider<ReviewDb> dbProvider, Provider<ReviewDb> dbProvider,
Provider<ApprovalsUtil> approvals,
ChangeJson json, ChangeJson json,
ChangeIndexer indexer) { ChangeIndexer indexer) {
this.hooks = hooks; this.hooks = hooks;
this.restoredSenderFactory = restoredSenderFactory; this.restoredSenderFactory = restoredSenderFactory;
this.dbProvider = dbProvider; this.dbProvider = dbProvider;
this.approvals = approvals;
this.json = json; this.json = json;
this.indexer = indexer; this.indexer = indexer;
} }
@@ -104,7 +107,7 @@ public class Restore implements RestModifyView<ChangeResource, RestoreInput>,
} }
message = newMessage(input, caller, change); message = newMessage(input, caller, change);
db.changeMessages().insert(Collections.singleton(message)); db.changeMessages().insert(Collections.singleton(message));
new ApprovalsUtil(db).syncChangeStatus(change); approvals.get().syncChangeStatus(change);
db.commit(); db.commit();
} finally { } finally {
db.rollback(); db.rollback();

View File

@@ -1856,9 +1856,9 @@ public class ReceiveCommits {
db.patchSetApprovals().byChange(change.getId()).toList(); db.patchSetApprovals().byChange(change.getId()).toList();
final MailRecipients oldRecipients = getRecipientsFromApprovals( final MailRecipients oldRecipients = getRecipientsFromApprovals(
oldChangeApprovals); oldChangeApprovals);
ApprovalsUtil.copyLabels(db, labelTypes, oldChangeApprovals, approvalsUtil.copyLabels(labelTypes, oldChangeApprovals,
priorPatchSet, newPatchSet, changeKind); priorPatchSet, newPatchSet, changeKind);
approvalsUtil.addReviewers(db, labelTypes, change, newPatchSet, info, approvalsUtil.addReviewers(labelTypes, change, newPatchSet, info,
recipients.getReviewers(), oldRecipients.getAll()); recipients.getReviewers(), oldRecipients.getAll());
recipients.add(oldRecipients); recipients.add(oldRecipients);

View File

@@ -103,7 +103,7 @@ public class PatchSetNotificationSender {
recipients.remove(me); recipients.remove(me);
if (newChange) { if (newChange) {
approvalsUtil.addReviewers(db, labelTypes, approvalsUtil.addReviewers(labelTypes,
updatedChange, updatedPatchSet, info, updatedChange, updatedPatchSet, info,
recipients.getReviewers(), Collections.<Account.Id> emptySet()); recipients.getReviewers(), Collections.<Account.Id> emptySet());
try { try {
@@ -122,7 +122,7 @@ public class PatchSetNotificationSender {
updatedChange.getId()).toList(); updatedChange.getId()).toList();
final MailRecipients oldRecipients = final MailRecipients oldRecipients =
getRecipientsFromApprovals(patchSetApprovals); getRecipientsFromApprovals(patchSetApprovals);
approvalsUtil.addReviewers(db, labelTypes, updatedChange, approvalsUtil.addReviewers(labelTypes, updatedChange,
updatedPatchSet, info, recipients.getReviewers(), updatedPatchSet, info, recipients.getReviewers(),
oldRecipients.getAll()); oldRecipients.getAll());
final ChangeMessage msg = final ChangeMessage msg =