Merge branch 'dev-spearce'

* dev-spearce: (33 commits)
  Use transactions to handle comments when possible
  Avoid opening extra ReviewDb connection in PatchSetInfoFactory
  Minor ORM cleanups to support other backends
  Add command to output a Protobuf message file for the DB
  Support gwtorm 1.2
  Fix reference of Database<T> to SchemaFactory<T>
  Support Velocity 1.5
  Move replication queue binding out of GerritGlobalModule
  Remove static initialization of Velocity
  Move WorkQueue out of GerritGlobalModule
  Support auth.type = CUSTOM_EXTENSION
  Extract Git /p/ module configuration
  Make WebSession an abstract interface
  Move GitRepositoryManager setup out of SchemaModule
  Move SmtpEmailSender to its own module
  Make Address, EmailHeader visible to other EmailSenders
  Disable SSH Keys in the web UI if SSHD is disabled
  Refactor how we tie the SSH objects into the HTTP injector
  daemon: Allow httpd without sshd
  Allow sshd.listenAddress = off to disable the daemon
  ...

Conflicts:
	gerrit-httpd/src/main/java/com/google/gerrit/httpd/GitWebConfig.java
	gerrit-server/src/main/java/com/google/gerrit/server/schema/SchemaModule.java

Change-Id: If957ce2eeb9b1de4ed2b134b0db129c336900442
This commit is contained in:
Shawn O. Pearce
2011-11-01 18:18:06 -07:00
80 changed files with 1272 additions and 520 deletions

View File

@@ -25,7 +25,6 @@ import com.google.gerrit.reviewdb.UserIdentity;
import com.google.gerrit.server.account.AccountByEmailCache;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -49,15 +48,12 @@ import java.util.Set;
@Singleton
public class PatchSetInfoFactory {
private final GitRepositoryManager repoManager;
private final SchemaFactory<ReviewDb> schemaFactory;
private final AccountByEmailCache byEmailCache;
@Inject
public PatchSetInfoFactory(final GitRepositoryManager grm,
final SchemaFactory<ReviewDb> schemaFactory,
final AccountByEmailCache byEmailCache) {
this.repoManager = grm;
this.schemaFactory = schemaFactory;
this.byEmailCache = byEmailCache;
}
@@ -68,16 +64,13 @@ public class PatchSetInfoFactory {
info.setAuthor(toUserIdentity(src.getAuthorIdent()));
info.setCommitter(toUserIdentity(src.getCommitterIdent()));
info.setRevId(src.getName());
return info;
}
public PatchSetInfo get(PatchSet.Id patchSetId)
throws PatchSetInfoNotAvailableException {
ReviewDb db = null;
public PatchSetInfo get(ReviewDb db, PatchSet.Id patchSetId)
throws PatchSetInfoNotAvailableException {
Repository repo = null;
try {
db = schemaFactory.open();
final PatchSet patchSet = db.patchSets().get(patchSetId);
final Change change = db.changes().get(patchSet.getId().getParentKey());
final Project.NameKey projectKey = change.getProject();
@@ -97,9 +90,6 @@ public class PatchSetInfoFactory {
} catch (IOException e) {
throw new PatchSetInfoNotAvailableException(e);
} finally {
if (db != null) {
db.close();
}
if (repo != null) {
repo.close();
}

View File

@@ -116,18 +116,25 @@ public class PublishComments implements Callable<VoidResult> {
}
drafts = drafts();
publishDrafts();
db.changes().beginTransaction(changeId);
try {
publishDrafts();
final boolean isCurrent = patchSetId.equals(change.currentPatchSetId());
if (isCurrent && change.getStatus().isOpen()) {
publishApprovals(ctl);
} else if (! approvals.isEmpty()) {
throw new InvalidChangeOperationException("Change is closed");
} else {
publishMessageOnly();
final boolean isCurrent = patchSetId.equals(change.currentPatchSetId());
if (isCurrent && change.getStatus().isOpen()) {
publishApprovals(ctl);
} else if (!approvals.isEmpty()) {
throw new InvalidChangeOperationException("Change is closed");
} else {
publishMessageOnly();
}
touchChange();
db.commit();
} finally {
db.rollback();
}
touchChange();
email();
fireHook();
return VoidResult.INSTANCE;
@@ -280,7 +287,7 @@ public class PublishComments implements Callable<VoidResult> {
}
private List<PatchLineComment> drafts() throws OrmException {
return db.patchComments().draft(patchSetId, user.getAccountId()).toList();
return db.patchComments().draftByPatchSetAuthor(patchSetId, user.getAccountId()).toList();
}
private void email() {
@@ -288,7 +295,7 @@ public class PublishComments implements Callable<VoidResult> {
if (message != null) {
final CommentSender cm = commentSenderFactory.create(change);
cm.setFrom(user.getAccountId());
cm.setPatchSet(patchSet, patchSetInfoFactory.get(patchSetId));
cm.setPatchSet(patchSet, patchSetInfoFactory.get(db, patchSetId));
cm.setChangeMessage(message);
cm.setPatchLineComments(drafts);
cm.send();