Provide SchemFactory<ReviewDb> by Guice and not GerritServer

This makes it easier to replace the dependency, by letting Guice
manage the registration of the SchemaFactory.  In some cases we
were able to reduce our dependency entirely and drop the server
object out of the dependency set.

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2009-07-28 15:06:12 -07:00
parent 5fbee29514
commit e66e89020b
36 changed files with 204 additions and 111 deletions

View File

@@ -16,7 +16,9 @@ package com.google.gerrit.git;
import com.google.gerrit.client.reviewdb.Branch; import com.google.gerrit.client.reviewdb.Branch;
import com.google.gerrit.client.reviewdb.Project; import com.google.gerrit.client.reviewdb.Project;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.server.GerritServer; import com.google.gerrit.server.GerritServer;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Inject; import com.google.inject.Inject;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -34,11 +36,14 @@ public class ChangeMergeQueue implements MergeQueue {
new HashMap<Branch.NameKey, MergeEntry>(); new HashMap<Branch.NameKey, MergeEntry>();
private final GerritServer server; private final GerritServer server;
private final SchemaFactory<ReviewDb> schema;
private final ReplicationQueue replication; private final ReplicationQueue replication;
@Inject @Inject
ChangeMergeQueue(final GerritServer gs, final ReplicationQueue rq) { ChangeMergeQueue(final GerritServer gs, final SchemaFactory<ReviewDb> sf,
final ReplicationQueue rq) {
server = gs; server = gs;
schema = sf;
replication = rq; replication = rq;
} }
@@ -131,7 +136,7 @@ public class ChangeMergeQueue implements MergeQueue {
private void mergeImpl(final Branch.NameKey branch) { private void mergeImpl(final Branch.NameKey branch) {
try { try {
new MergeOp(server, replication, branch).merge(); new MergeOp(server, schema, replication, branch).merge();
} catch (Throwable e) { } catch (Throwable e) {
log.error("Merge attempt for " + branch + " failed", e); log.error("Merge attempt for " + branch + " failed", e);
} }

View File

@@ -34,6 +34,7 @@ import com.google.gerrit.server.mail.MergedSender;
import com.google.gerrit.server.workflow.CategoryFunction; import com.google.gerrit.server.workflow.CategoryFunction;
import com.google.gerrit.server.workflow.FunctionState; import com.google.gerrit.server.workflow.FunctionState;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.gwtorm.client.Transaction; import com.google.gwtorm.client.Transaction;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -96,6 +97,7 @@ public class MergeOp {
private static final FooterKey REVIEWED_ON = new FooterKey("Reviewed-on"); private static final FooterKey REVIEWED_ON = new FooterKey("Reviewed-on");
private final GerritServer server; private final GerritServer server;
private final SchemaFactory<ReviewDb> schemaFactory;
private final ReplicationQueue replication; private final ReplicationQueue replication;
private final PersonIdent myIdent; private final PersonIdent myIdent;
private final Branch.NameKey destBranch; private final Branch.NameKey destBranch;
@@ -111,9 +113,10 @@ public class MergeOp {
private CodeReviewCommit mergeTip; private CodeReviewCommit mergeTip;
private RefUpdate branchUpdate; private RefUpdate branchUpdate;
public MergeOp(final GerritServer gs, final ReplicationQueue rq, public MergeOp(final GerritServer gs, final SchemaFactory<ReviewDb> sf,
final Branch.NameKey branch) { final ReplicationQueue rq, final Branch.NameKey branch) {
server = gs; server = gs;
schemaFactory = sf;
replication = rq; replication = rq;
myIdent = server.newGerritPersonIdent(); myIdent = server.newGerritPersonIdent();
destBranch = branch; destBranch = branch;
@@ -131,7 +134,7 @@ public class MergeOp {
destProject = pe.getProject(); destProject = pe.getProject();
try { try {
schema = server.getSchemaFactory().open(); schema = schemaFactory.open();
} catch (OrmException e) { } catch (OrmException e) {
throw new MergeException("Cannot open database", e); throw new MergeException("Cannot open database", e);
} }

View File

@@ -18,8 +18,8 @@ import com.google.gerrit.client.reviewdb.Branch;
import com.google.gerrit.client.reviewdb.Project; import com.google.gerrit.client.reviewdb.Project;
import com.google.gerrit.client.reviewdb.ProjectRight; import com.google.gerrit.client.reviewdb.ProjectRight;
import com.google.gerrit.client.reviewdb.ReviewDb; import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.server.GerritServer;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -30,17 +30,18 @@ public class PushAllProjectsOp implements Runnable {
private static final Logger log = private static final Logger log =
LoggerFactory.getLogger(PushAllProjectsOp.class); LoggerFactory.getLogger(PushAllProjectsOp.class);
private final GerritServer server; private final SchemaFactory<ReviewDb> schema;
private final ReplicationQueue replication; private final ReplicationQueue replication;
private final String urlMatch; private final String urlMatch;
public PushAllProjectsOp(final GerritServer gs, final ReplicationQueue rq) { public PushAllProjectsOp(final SchemaFactory<ReviewDb> sf,
this(gs, rq, null); final ReplicationQueue rq) {
this(sf, rq, null);
} }
public PushAllProjectsOp(final GerritServer gs, final ReplicationQueue rq, public PushAllProjectsOp(final SchemaFactory<ReviewDb> sf,
final String urlMatch) { final ReplicationQueue rq, final String urlMatch) {
this.server = gs; this.schema = sf;
this.replication = rq; this.replication = rq;
this.urlMatch = urlMatch; this.urlMatch = urlMatch;
} }
@@ -48,7 +49,7 @@ public class PushAllProjectsOp implements Runnable {
public void run() { public void run() {
final HashSet<Branch.NameKey> pending = new HashSet<Branch.NameKey>(); final HashSet<Branch.NameKey> pending = new HashSet<Branch.NameKey>();
try { try {
final ReviewDb db = server.getSchemaFactory().open(); final ReviewDb db = schema.open();
try { try {
for (final Project project : db.projects().all()) { for (final Project project : db.projects().all()) {
if (!ProjectRight.WILD_PROJECT.equals(project.getId())) { if (!ProjectRight.WILD_PROJECT.equals(project.getId())) {

View File

@@ -14,20 +14,27 @@
package com.google.gerrit.pgm; package com.google.gerrit.pgm;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.server.GerritServer; import com.google.gerrit.server.GerritServer;
import com.google.gerrit.server.GerritServerModule; import com.google.gerrit.server.GerritServerModule;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector; import com.google.inject.Injector;
/** /**
* Creates the Gerrit 2 database schema. * Creates the Gerrit 2 database schema.
*/ */
public class CreateSchema extends AbstractProgram { public class CreateSchema extends AbstractProgram {
@Inject
private SchemaFactory<ReviewDb> schema;
@Override @Override
public int run() throws Exception { public int run() throws Exception {
final Injector injector = Guice.createInjector(new GerritServerModule()); final Injector injector = Guice.createInjector(new GerritServerModule());
final GerritServer gs = injector.getInstance(GerritServer.class); injector.injectMembers(this);
gs.getSchemaFactory().open().close(); injector.getInstance(GerritServer.class);
schema.open().close();
System.out.println("Gerrit2 schema initialized"); System.out.println("Gerrit2 schema initialized");
return 0; return 0;
} }

View File

@@ -22,8 +22,9 @@ import com.google.gerrit.git.PatchSetImporter;
import com.google.gerrit.server.GerritServer; import com.google.gerrit.server.GerritServer;
import com.google.gerrit.server.GerritServerModule; import com.google.gerrit.server.GerritServerModule;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Inject;
import org.spearce.jgit.errors.RepositoryNotFoundException; import org.spearce.jgit.errors.RepositoryNotFoundException;
import org.spearce.jgit.lib.ObjectId; import org.spearce.jgit.lib.ObjectId;
@@ -53,10 +54,15 @@ import java.util.ArrayList;
* based on the data stored in Git. * based on the data stored in Git.
*/ */
public class ReimportPatchSets extends AbstractProgram { public class ReimportPatchSets extends AbstractProgram {
@Inject
private SchemaFactory<ReviewDb> schema;
@Inject
private GerritServer gs;
@Override @Override
public int run() throws Exception { public int run() throws Exception {
final Injector injector = Guice.createInjector(new GerritServerModule()); Guice.createInjector(new GerritServerModule()).injectMembers(this);
final GerritServer gs = injector.getInstance(GerritServer.class);
final ArrayList<PatchSet.Id> todo = new ArrayList<PatchSet.Id>(); final ArrayList<PatchSet.Id> todo = new ArrayList<PatchSet.Id>();
final BufferedReader br = final BufferedReader br =
@@ -67,7 +73,7 @@ public class ReimportPatchSets extends AbstractProgram {
} }
int exitStatus = 0; int exitStatus = 0;
final ReviewDb db = gs.getSchemaFactory().open(); final ReviewDb db = schema.open();
final ProgressMonitor pm = new TextProgressMonitor(); final ProgressMonitor pm = new TextProgressMonitor();
try { try {
pm.start(1); pm.start(1);

View File

@@ -37,6 +37,7 @@ import com.google.gwtjsonrpc.server.ValidToken;
import com.google.gwtjsonrpc.server.XsrfException; import com.google.gwtjsonrpc.server.XsrfException;
import com.google.gwtorm.client.OrmDuplicateKeyException; import com.google.gwtorm.client.OrmDuplicateKeyException;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.gwtorm.client.Transaction; import com.google.gwtorm.client.Transaction;
import com.google.inject.Inject; import com.google.inject.Inject;
@@ -61,11 +62,14 @@ import javax.servlet.http.HttpServletRequest;
class AccountSecurityImpl extends BaseServiceImplementation implements class AccountSecurityImpl extends BaseServiceImplementation implements
AccountSecurity { AccountSecurity {
private final Logger log = LoggerFactory.getLogger(getClass()); private final Logger log = LoggerFactory.getLogger(getClass());
private final GerritServer server;
private final ContactStore contactStore; private final ContactStore contactStore;
@Inject @Inject
AccountSecurityImpl(final GerritServer gs, final ContactStore cs) { AccountSecurityImpl(final SchemaFactory<ReviewDb> sf, final GerritServer gs,
super(gs); final ContactStore cs) {
super(sf);
server = gs;
contactStore = cs; contactStore = cs;
} }

View File

@@ -28,6 +28,7 @@ import com.google.gerrit.client.rpc.NoSuchEntityException;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwtjsonrpc.client.VoidResult; import com.google.gwtjsonrpc.client.VoidResult;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.gwtorm.client.Transaction; import com.google.gwtorm.client.Transaction;
import com.google.inject.Inject; import com.google.inject.Inject;
@@ -40,8 +41,8 @@ import java.util.Set;
class AccountServiceImpl extends BaseServiceImplementation implements class AccountServiceImpl extends BaseServiceImplementation implements
AccountService { AccountService {
@Inject @Inject
AccountServiceImpl(final GerritServer gs) { AccountServiceImpl(final SchemaFactory<ReviewDb> sf) {
super(gs); super(sf);
} }
public void myAccount(final AsyncCallback<Account> callback) { public void myAccount(final AsyncCallback<Account> callback) {

View File

@@ -27,15 +27,16 @@ import com.google.gerrit.client.rpc.CorruptEntityException;
import com.google.gerrit.client.rpc.NoSuchEntityException; import com.google.gerrit.client.rpc.NoSuchEntityException;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import java.util.Set; import java.util.Set;
/** Support for services which require a {@link ReviewDb} instance. */ /** Support for services which require a {@link ReviewDb} instance. */
public class BaseServiceImplementation { public class BaseServiceImplementation {
protected final GerritServer server; private final SchemaFactory<ReviewDb> schema;
protected BaseServiceImplementation(final GerritServer gs) { protected BaseServiceImplementation(final SchemaFactory<ReviewDb> sf) {
server = gs; schema = sf;
} }
/** /**
@@ -51,7 +52,7 @@ public class BaseServiceImplementation {
*/ */
protected <T> void run(final AsyncCallback<T> callback, final Action<T> action) { protected <T> void run(final AsyncCallback<T> callback, final Action<T> action) {
try { try {
final ReviewDb db = server.getSchemaFactory().open(); final ReviewDb db = schema.open();
final T r; final T r;
try { try {
r = action.run(db); r = action.run(db);
@@ -116,7 +117,8 @@ public class BaseServiceImplementation {
public static boolean canPerform(final Account.Id who, public static boolean canPerform(final Account.Id who,
final ProjectCache.Entry e, final ApprovalCategory.Id actionId, final ProjectCache.Entry e, final ApprovalCategory.Id actionId,
final short requireValue) { final short requireValue) {
Set<AccountGroup.Id> groups = Common.getGroupCache().getEffectiveGroups(who); Set<AccountGroup.Id> groups =
Common.getGroupCache().getEffectiveGroups(who);
return canPerform(groups, e, actionId, requireValue); return canPerform(groups, e, actionId, requireValue);
} }

View File

@@ -17,8 +17,8 @@ package com.google.gerrit.server;
import com.google.gerrit.client.Gerrit; import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.reviewdb.Account; import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.reviewdb.ReviewDb; import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.Common;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@@ -44,10 +44,13 @@ public class BecomeAnyAccountLoginServlet extends HttpServlet {
} }
private final boolean allowed; private final boolean allowed;
private final SchemaFactory<ReviewDb> schema;
private final GerritServer server; private final GerritServer server;
@Inject @Inject
BecomeAnyAccountLoginServlet(final GerritServer gs) { BecomeAnyAccountLoginServlet(final SchemaFactory<ReviewDb> sf,
final GerritServer gs) {
schema = sf;
server = gs; server = gs;
allowed = isAllowed(); allowed = isAllowed();
} }
@@ -109,7 +112,7 @@ public class BecomeAnyAccountLoginServlet extends HttpServlet {
private List<Account> bySshUserName(final HttpServletResponse rsp, private List<Account> bySshUserName(final HttpServletResponse rsp,
final String userName) { final String userName) {
try { try {
final ReviewDb db = server.getSchemaFactory().open(); final ReviewDb db = schema.open();
try { try {
return db.accounts().bySshUserName(userName).toList(); return db.accounts().bySshUserName(userName).toList();
} finally { } finally {
@@ -124,7 +127,7 @@ public class BecomeAnyAccountLoginServlet extends HttpServlet {
private List<Account> byPreferredEmail(final HttpServletResponse rsp, private List<Account> byPreferredEmail(final HttpServletResponse rsp,
final String email) { final String email) {
try { try {
final ReviewDb db = server.getSchemaFactory().open(); final ReviewDb db = schema.open();
try { try {
return db.accounts().byPreferredEmail(email).toList(); return db.accounts().byPreferredEmail(email).toList();
} finally { } finally {
@@ -145,7 +148,7 @@ public class BecomeAnyAccountLoginServlet extends HttpServlet {
return Collections.<Account> emptyList(); return Collections.<Account> emptyList();
} }
try { try {
final ReviewDb db = server.getSchemaFactory().open(); final ReviewDb db = schema.open();
try { try {
final Account account = db.accounts().get(id); final Account account = db.accounts().get(id);
return account != null ? Collections.<Account> singletonList(account) return account != null ? Collections.<Account> singletonList(account)

View File

@@ -25,6 +25,7 @@ import com.google.gerrit.client.reviewdb.Project;
import com.google.gerrit.client.reviewdb.ReviewDb; import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.Common; import com.google.gerrit.client.rpc.Common;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@@ -65,12 +66,15 @@ import javax.servlet.http.HttpServletResponse;
public class CatServlet extends HttpServlet { public class CatServlet extends HttpServlet {
private static final MimeType ZIP = new MimeType("application/zip"); private static final MimeType ZIP = new MimeType("application/zip");
private final GerritServer server; private final GerritServer server;
private final SchemaFactory<ReviewDb> schema;
private final SecureRandom rng; private final SecureRandom rng;
private final FileTypeRegistry registry; private final FileTypeRegistry registry;
@Inject @Inject
CatServlet(final GerritServer gs, final FileTypeRegistry ftr) { CatServlet(final GerritServer gs, final SchemaFactory<ReviewDb> sf,
final FileTypeRegistry ftr) {
server = gs; server = gs;
schema = sf;
rng = new SecureRandom(); rng = new SecureRandom();
registry = ftr; registry = ftr;
} }
@@ -115,14 +119,15 @@ public class CatServlet extends HttpServlet {
} }
} }
final Account.Id me = new GerritCall(server, req, rsp).getAccountId(); final Account.Id me =
new GerritCall(server, schema, req, rsp).getAccountId();
final Change.Id changeId = patchKey.getParentKey().getParentKey(); final Change.Id changeId = patchKey.getParentKey().getParentKey();
final Project project; final Project project;
final Change change; final Change change;
final PatchSet patchSet; final PatchSet patchSet;
final Patch patch; final Patch patch;
try { try {
final ReviewDb db = server.getSchemaFactory().open(); final ReviewDb db = schema.open();
try { try {
change = db.changes().get(changeId); change = db.changes().get(changeId);
if (change == null) { if (change == null) {

View File

@@ -24,13 +24,14 @@ import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.NoSuchEntityException; import com.google.gerrit.client.rpc.NoSuchEntityException;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Inject; import com.google.inject.Inject;
class ChangeDetailServiceImpl extends BaseServiceImplementation implements class ChangeDetailServiceImpl extends BaseServiceImplementation implements
ChangeDetailService { ChangeDetailService {
@Inject @Inject
ChangeDetailServiceImpl(final GerritServer gs) { ChangeDetailServiceImpl(final SchemaFactory<ReviewDb> sf) {
super(gs); super(sf);
} }
public void changeDetail(final Change.Id id, public void changeDetail(final Change.Id id,

View File

@@ -38,6 +38,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwtjsonrpc.client.VoidResult; import com.google.gwtjsonrpc.client.VoidResult;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.ResultSet; import com.google.gwtorm.client.ResultSet;
import com.google.gwtorm.client.SchemaFactory;
import com.google.gwtorm.client.Transaction; import com.google.gwtorm.client.Transaction;
import com.google.gwtorm.client.impl.ListResultSet; import com.google.gwtorm.client.impl.ListResultSet;
import com.google.inject.Inject; import com.google.inject.Inject;
@@ -83,8 +84,8 @@ class ChangeListServiceImpl extends BaseServiceImplementation implements
} }
@Inject @Inject
ChangeListServiceImpl(final GerritServer gs) { ChangeListServiceImpl(final SchemaFactory<ReviewDb> sf) {
super(gs); super(sf);
} }
public void allOpenPrev(final String pos, final int pageSize, public void allOpenPrev(final String pos, final int pageSize,

View File

@@ -31,6 +31,7 @@ import com.google.gerrit.server.workflow.FunctionState;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwtjsonrpc.client.VoidResult; import com.google.gwtjsonrpc.client.VoidResult;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.gwtorm.client.Transaction; import com.google.gwtorm.client.Transaction;
import com.google.inject.Inject; import com.google.inject.Inject;
@@ -41,10 +42,10 @@ import java.util.List;
class ChangeManageServiceImpl extends BaseServiceImplementation implements class ChangeManageServiceImpl extends BaseServiceImplementation implements
ChangeManageService { ChangeManageService {
private final MergeQueue merger; private final MergeQueue merger;
@Inject @Inject
ChangeManageServiceImpl(final GerritServer gs, final MergeQueue mq) { ChangeManageServiceImpl(final SchemaFactory<ReviewDb> sf, final MergeQueue mq) {
super(gs); super(sf);
merger = mq; merger = mq;
} }

View File

@@ -20,6 +20,7 @@ import com.google.gerrit.client.reviewdb.ContactInformation;
import com.google.gerrit.client.reviewdb.ReviewDb; import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.ContactInformationStoreException; import com.google.gerrit.client.rpc.ContactInformationStoreException;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import org.apache.sshd.common.util.SecurityUtils; import org.apache.sshd.common.util.SecurityUtils;
import org.bouncycastle.bcpg.ArmoredOutputStream; import org.bouncycastle.bcpg.ArmoredOutputStream;
@@ -59,14 +60,16 @@ class EncryptedContactStore implements ContactStore {
private static final TimeZone UTC = TimeZone.getTimeZone("UTC"); private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
private final GerritServer server; private final GerritServer server;
private final SchemaFactory<ReviewDb> schema;
private PGPPublicKey dest; private PGPPublicKey dest;
private SecureRandom prng; private SecureRandom prng;
private URL storeUrl; private URL storeUrl;
private String storeAPPSEC; private String storeAPPSEC;
EncryptedContactStore(final GerritServer gs) EncryptedContactStore(final GerritServer gs, final SchemaFactory<ReviewDb> sf)
throws ContactInformationStoreException { throws ContactInformationStoreException {
server = gs; server = gs;
schema = sf;
if (gs.getContactStoreURL() == null) { if (gs.getContactStoreURL() == null) {
throw new ContactInformationStoreException(new IllegalStateException( throw new ContactInformationStoreException(new IllegalStateException(
@@ -90,12 +93,12 @@ class EncryptedContactStore implements ContactStore {
throw new ContactInformationStoreException(e); throw new ContactInformationStoreException(e);
} }
dest = selectKey(readPubRing(gs)); dest = selectKey(readPubRing());
} }
private PGPPublicKeyRingCollection readPubRing(final GerritServer gs) private PGPPublicKeyRingCollection readPubRing()
throws ContactInformationStoreException { throws ContactInformationStoreException {
final File pub = new File(gs.getSitePath(), "contact_information.pub"); final File pub = new File(server.getSitePath(), "contact_information.pub");
try { try {
InputStream in = new FileInputStream(pub); InputStream in = new FileInputStream(pub);
try { try {
@@ -234,7 +237,7 @@ class EncryptedContactStore implements ContactStore {
field(b, "Preferred-Email", account.getPreferredEmail()); field(b, "Preferred-Email", account.getPreferredEmail());
try { try {
final ReviewDb db = server.getSchemaFactory().open(); final ReviewDb db = schema.open();
try { try {
for (final AccountExternalId e : db.accountExternalIds().byAccount( for (final AccountExternalId e : db.accountExternalIds().byAccount(
account.getId())) { account.getId())) {

View File

@@ -16,18 +16,22 @@ package com.google.gerrit.server;
import com.google.gerrit.client.reviewdb.Account; import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.reviewdb.ContactInformation; import com.google.gerrit.client.reviewdb.ContactInformation;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.ContactInformationStoreException; import com.google.gerrit.client.rpc.ContactInformationStoreException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
class EncryptedContactStoreProvider implements Provider<ContactStore> { class EncryptedContactStoreProvider implements Provider<ContactStore> {
@Inject @Inject
private GerritServer server; private GerritServer server;
@Inject
private SchemaFactory<ReviewDb> schema;
@Override @Override
public ContactStore get() { public ContactStore get() {
try { try {
return new EncryptedContactStore(server); return new EncryptedContactStore(server, schema);
} catch (final ContactInformationStoreException initError) { } catch (final ContactInformationStoreException initError) {
return new ContactStore() { return new ContactStore() {
@Override @Override

View File

@@ -24,6 +24,7 @@ import com.google.gwtjsonrpc.server.ActiveCall;
import com.google.gwtjsonrpc.server.ValidToken; import com.google.gwtjsonrpc.server.ValidToken;
import com.google.gwtjsonrpc.server.XsrfException; import com.google.gwtjsonrpc.server.XsrfException;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.gwtorm.client.Transaction; import com.google.gwtorm.client.Transaction;
import org.spearce.jgit.util.Base64; import org.spearce.jgit.util.Base64;
@@ -46,13 +47,15 @@ public class GerritCall extends ActiveCall {
} }
private final GerritServer server; private final GerritServer server;
private final SchemaFactory<ReviewDb> schema;
private boolean accountRead; private boolean accountRead;
private Account.Id accountId; private Account.Id accountId;
private boolean rememberAccount; private boolean rememberAccount;
public GerritCall(final GerritServer gs, final HttpServletRequest i, public GerritCall(final GerritServer gs, final SchemaFactory<ReviewDb> sf,
final HttpServletResponse o) { final HttpServletRequest i, final HttpServletResponse o) {
super(i, o); super(i, o);
schema = sf;
server = gs; server = gs;
} }
@@ -158,7 +161,7 @@ public class GerritCall extends ActiveCall {
} }
try { try {
final ReviewDb db = server.getSchemaFactory().open(); final ReviewDb db = schema.open();
try { try {
final String eid = "gerrit:" + user; final String eid = "gerrit:" + user;
final List<AccountExternalId> matches = final List<AccountExternalId> matches =

View File

@@ -44,9 +44,9 @@ class GerritConfigProvider implements Provider<GerritConfig> {
private GerritSshDaemon sshd; private GerritSshDaemon sshd;
@Inject @Inject
GerritConfigProvider(final GerritServer gs) { GerritConfigProvider(final GerritServer gs, final SchemaFactory<ReviewDb> sf) {
server = gs; server = gs;
schema = gs.getSchemaFactory(); schema = sf;
} }
@Inject(optional = true) @Inject(optional = true)

View File

@@ -14,12 +14,14 @@
package com.google.gerrit.server; package com.google.gerrit.server;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.NotSignedInException; import com.google.gerrit.client.rpc.NotSignedInException;
import com.google.gerrit.client.rpc.SignInRequired; import com.google.gerrit.client.rpc.SignInRequired;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gwtjsonrpc.client.RemoteJsonService; import com.google.gwtjsonrpc.client.RemoteJsonService;
import com.google.gwtjsonrpc.server.JsonServlet; import com.google.gwtjsonrpc.server.JsonServlet;
import com.google.gwtjsonrpc.server.SignedToken; import com.google.gwtjsonrpc.server.SignedToken;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Inject; import com.google.inject.Inject;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@@ -35,12 +37,15 @@ public final class GerritJsonServlet extends JsonServlet<GerritCall> {
return JsonServlet.<GerritCall> getCurrentCall(); return JsonServlet.<GerritCall> getCurrentCall();
} }
protected GerritServer server; private final GerritServer server;
private RemoteJsonService service; private final SchemaFactory<ReviewDb> schema;
private final RemoteJsonService service;
@Inject @Inject
GerritJsonServlet(final GerritServer gs, final RemoteJsonService s) { GerritJsonServlet(final GerritServer gs, final SchemaFactory<ReviewDb> sf,
final RemoteJsonService s) {
server = gs; server = gs;
schema = sf;
service = s; service = s;
} }
@@ -52,7 +57,7 @@ public final class GerritJsonServlet extends JsonServlet<GerritCall> {
@Override @Override
protected GerritCall createActiveCall(final HttpServletRequest req, protected GerritCall createActiveCall(final HttpServletRequest req,
final HttpServletResponse resp) { final HttpServletResponse resp) {
return new GerritCall(server, req, resp); return new GerritCall(server, schema, req, resp);
} }
@Override @Override

View File

@@ -36,7 +36,6 @@ import com.google.gerrit.server.workflow.SubmitFunction;
import com.google.gwtjsonrpc.server.SignedToken; import com.google.gwtjsonrpc.server.SignedToken;
import com.google.gwtjsonrpc.server.XsrfException; import com.google.gwtjsonrpc.server.XsrfException;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.gwtorm.client.Transaction; import com.google.gwtorm.client.Transaction;
import com.google.gwtorm.jdbc.Database; import com.google.gwtorm.jdbc.Database;
import com.google.inject.Inject; import com.google.inject.Inject;
@@ -297,7 +296,7 @@ public class GerritServer {
final Cache dc = cacheMgr.getCache("sshkeys"); final Cache dc = cacheMgr.getCache("sshkeys");
final SelfPopulatingCache r; final SelfPopulatingCache r;
r = new SelfPopulatingCache(dc, new SshKeyCacheEntryFactory(this)); r = new SelfPopulatingCache(dc, new SshKeyCacheEntryFactory(db));
cacheMgr.replaceCacheWithDecoratedCache(dc, r); cacheMgr.replaceCacheWithDecoratedCache(dc, r);
return r; return r;
} }
@@ -708,11 +707,6 @@ public class GerritServer {
return gerritConfigFile; return gerritConfigFile;
} }
/** Get the schema factory for this instance. */
public SchemaFactory<ReviewDb> getSchemaFactory() {
return db;
}
/** /**
* Get (or open) a repository by name. * Get (or open) a repository by name.
* *

View File

@@ -22,6 +22,7 @@ import com.google.gerrit.git.ChangeMergeQueue;
import com.google.gerrit.git.MergeQueue; import com.google.gerrit.git.MergeQueue;
import com.google.gerrit.git.PushReplication; import com.google.gerrit.git.PushReplication;
import com.google.gerrit.git.ReplicationQueue; import com.google.gerrit.git.ReplicationQueue;
import com.google.gwtorm.client.SchemaFactory;
import com.google.gwtorm.jdbc.Database; import com.google.gwtorm.jdbc.Database;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Key; import com.google.inject.Key;
@@ -38,6 +39,8 @@ public class GerritServerModule extends AbstractModule {
@Override @Override
protected void configure() { protected void configure() {
bind(DS).toProvider(ReviewDbDataSourceProvider.class).in(SINGLETON); bind(DS).toProvider(ReviewDbDataSourceProvider.class).in(SINGLETON);
bind(new TypeLiteral<SchemaFactory<ReviewDb>>() {}).to(
new TypeLiteral<Database<ReviewDb>>() {});
bind(new TypeLiteral<Database<ReviewDb>>() {}).toProvider( bind(new TypeLiteral<Database<ReviewDb>>() {}).toProvider(
ReviewDbProvider.class).in(SINGLETON); ReviewDbProvider.class).in(SINGLETON);

View File

@@ -28,6 +28,7 @@ import com.google.gerrit.server.ssh.SshServlet;
import com.google.gwtexpui.server.CacheControlFilter; import com.google.gwtexpui.server.CacheControlFilter;
import com.google.gwtjsonrpc.client.RemoteJsonService; import com.google.gwtjsonrpc.client.RemoteJsonService;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.BindingAnnotation; import com.google.inject.BindingAnnotation;
import com.google.inject.ConfigurationException; import com.google.inject.ConfigurationException;
import com.google.inject.Guice; import com.google.inject.Guice;
@@ -35,6 +36,7 @@ import com.google.inject.Injector;
import com.google.inject.Key; import com.google.inject.Key;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.Scopes; import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.servlet.GuiceServletContextListener; import com.google.inject.servlet.GuiceServletContextListener;
import com.google.inject.servlet.ServletModule; import com.google.inject.servlet.ServletModule;
@@ -182,19 +184,23 @@ public class GerritServletConfig extends GuiceServletContextListener {
private void startReplication() { private void startReplication() {
final ReplicationQueue rq = injector.getInstance(ReplicationQueue.class); final ReplicationQueue rq = injector.getInstance(ReplicationQueue.class);
if (rq.isEnabled()) { if (rq.isEnabled()) {
final GerritServer gs = injector.getInstance(GerritServer.class); final SchemaFactory<ReviewDb> sf =
WorkQueue.schedule(new PushAllProjectsOp(gs, rq), 30, TimeUnit.SECONDS); injector.getInstance(Key
.get(new TypeLiteral<SchemaFactory<ReviewDb>>() {}));
WorkQueue.schedule(new PushAllProjectsOp(sf, rq), 30, TimeUnit.SECONDS);
} }
} }
private void restartPendingMerges() { private void restartPendingMerges() {
final MergeQueue mq = injector.getInstance(MergeQueue.class); final MergeQueue mq = injector.getInstance(MergeQueue.class);
final GerritServer gs = injector.getInstance(GerritServer.class); final SchemaFactory<ReviewDb> sf =
injector.getInstance(Key
.get(new TypeLiteral<SchemaFactory<ReviewDb>>() {}));
WorkQueue.schedule(new Runnable() { WorkQueue.schedule(new Runnable() {
public void run() { public void run() {
final HashSet<Branch.NameKey> pending = new HashSet<Branch.NameKey>(); final HashSet<Branch.NameKey> pending = new HashSet<Branch.NameKey>();
try { try {
final ReviewDb c = gs.getSchemaFactory().open(); final ReviewDb c = sf.open();
try { try {
for (final Change change : c.changes().allSubmitted()) { for (final Change change : c.changes().allSubmitted()) {
pending.add(change.getDest()); pending.add(change.getDest());

View File

@@ -29,6 +29,7 @@ import com.google.gerrit.client.rpc.NoSuchEntityException;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwtjsonrpc.client.VoidResult; import com.google.gwtjsonrpc.client.VoidResult;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.gwtorm.client.Transaction; import com.google.gwtorm.client.Transaction;
import com.google.inject.Inject; import com.google.inject.Inject;
@@ -43,8 +44,8 @@ import java.util.Set;
class GroupAdminServiceImpl extends BaseServiceImplementation implements class GroupAdminServiceImpl extends BaseServiceImplementation implements
GroupAdminService { GroupAdminService {
@Inject @Inject
GroupAdminServiceImpl(final GerritServer gs) { GroupAdminServiceImpl(final SchemaFactory<ReviewDb> sf) {
super(gs); super(sf);
} }
public void ownedGroups(final AsyncCallback<List<AccountGroup>> callback) { public void ownedGroups(final AsyncCallback<List<AccountGroup>> callback) {

View File

@@ -16,8 +16,10 @@ package com.google.gerrit.server;
import com.google.gerrit.client.data.GerritConfig; import com.google.gerrit.client.data.GerritConfig;
import com.google.gerrit.client.reviewdb.Account; import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.Common; import com.google.gerrit.client.rpc.Common;
import com.google.gwt.user.server.rpc.RPCServletUtils; import com.google.gwt.user.server.rpc.RPCServletUtils;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@@ -44,6 +46,7 @@ import javax.servlet.http.HttpServletResponse;
@Singleton @Singleton
public class HostPageServlet extends HttpServlet { public class HostPageServlet extends HttpServlet {
private final GerritServer server; private final GerritServer server;
private final SchemaFactory<ReviewDb> schema;
private final GerritConfig config; private final GerritConfig config;
private String canonicalUrl; private String canonicalUrl;
@@ -51,8 +54,10 @@ public class HostPageServlet extends HttpServlet {
private Document hostDoc; private Document hostDoc;
@Inject @Inject
HostPageServlet(final GerritServer gs, final GerritConfig gc) { HostPageServlet(final GerritServer gs, final SchemaFactory<ReviewDb> sf,
final GerritConfig gc) {
server = gs; server = gs;
schema = sf;
config = gc; config = gc;
} }
@@ -220,7 +225,8 @@ public class HostPageServlet extends HttpServlet {
return; return;
} }
final Account.Id me = new GerritCall(server, req, rsp).getAccountId(); final Account.Id me =
new GerritCall(server, schema, req, rsp).getAccountId();
final Account account = Common.getAccountCache().get(me); final Account account = Common.getAccountCache().get(me);
final Document peruser = HtmlDomUtil.clone(hostDoc); final Document peruser = HtmlDomUtil.clone(hostDoc);

View File

@@ -32,6 +32,7 @@ import com.google.gwtjsonrpc.server.XsrfException;
import com.google.gwtorm.client.KeyUtil; import com.google.gwtorm.client.KeyUtil;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.ResultSet; import com.google.gwtorm.client.ResultSet;
import com.google.gwtorm.client.SchemaFactory;
import com.google.gwtorm.client.Transaction; import com.google.gwtorm.client.Transaction;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@@ -95,12 +96,15 @@ class OpenIdServiceImpl implements OpenIdService {
} }
private final GerritServer server; private final GerritServer server;
private final SchemaFactory<ReviewDb> schema;
private final ConsumerManager manager; private final ConsumerManager manager;
private final SelfPopulatingCache discoveryCache; private final SelfPopulatingCache discoveryCache;
@Inject @Inject
OpenIdServiceImpl(final GerritServer gs) throws ConsumerException { OpenIdServiceImpl(final GerritServer gs, final SchemaFactory<ReviewDb> sf)
throws ConsumerException {
server = gs; server = gs;
schema = sf;
manager = new ConsumerManager(); manager = new ConsumerManager();
if (useOpenID()) { if (useOpenID()) {
discoveryCache = discoveryCache =
@@ -179,7 +183,7 @@ class OpenIdServiceImpl implements OpenIdService {
// We might already have this account on file. Look for it. // We might already have this account on file. Look for it.
// //
try { try {
final ReviewDb db = server.getSchemaFactory().open(); final ReviewDb db = schema.open();
try { try {
final ResultSet<AccountExternalId> ae = final ResultSet<AccountExternalId> ae =
db.accountExternalIds().byExternal(aReq.getIdentity()); db.accountExternalIds().byExternal(aReq.getIdentity());
@@ -333,7 +337,7 @@ class OpenIdServiceImpl implements OpenIdService {
Account account = null; Account account = null;
if (user != null) { if (user != null) {
try { try {
final ReviewDb d = server.getSchemaFactory().open(); final ReviewDb d = schema.open();
try { try {
switch (mode) { switch (mode) {
case SIGN_IN: case SIGN_IN:

View File

@@ -34,6 +34,7 @@ import com.google.gerrit.git.ReplicationQueue;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwtjsonrpc.client.VoidResult; import com.google.gwtjsonrpc.client.VoidResult;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Inject; import com.google.inject.Inject;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -66,12 +67,14 @@ import javax.servlet.http.HttpServletRequest;
class ProjectAdminServiceImpl extends BaseServiceImplementation implements class ProjectAdminServiceImpl extends BaseServiceImplementation implements
ProjectAdminService { ProjectAdminService {
private final Logger log = LoggerFactory.getLogger(getClass()); private final Logger log = LoggerFactory.getLogger(getClass());
private final GerritServer server;
private final ReplicationQueue replication; private final ReplicationQueue replication;
@Inject @Inject
ProjectAdminServiceImpl(final GerritServer gs, final ReplicationQueue rq) { ProjectAdminServiceImpl(final SchemaFactory<ReviewDb> sf,
super(gs); final GerritServer gs, final ReplicationQueue rq) {
super(sf);
server = gs;
replication = rq; replication = rq;
} }

View File

@@ -25,6 +25,7 @@ import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.client.ui.SuggestService; import com.google.gerrit.client.ui.SuggestService;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Inject; import com.google.inject.Inject;
import java.util.ArrayList; import java.util.ArrayList;
@@ -36,8 +37,8 @@ class SuggestServiceImpl extends BaseServiceImplementation implements
private static final String MAX_SUFFIX = "\u9fa5"; private static final String MAX_SUFFIX = "\u9fa5";
@Inject @Inject
SuggestServiceImpl(final GerritServer gs) { SuggestServiceImpl(final SchemaFactory<ReviewDb> sf) {
super(gs); super(sf);
} }
public void suggestProjectNameKey(final String query, final int limit, public void suggestProjectNameKey(final String query, final int limit,

View File

@@ -22,6 +22,7 @@ import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.server.ssh.GerritSshDaemon; import com.google.gerrit.server.ssh.GerritSshDaemon;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.jcraft.jsch.HostKey; import com.jcraft.jsch.HostKey;
@@ -51,15 +52,15 @@ class SystemInfoServiceImpl implements SystemInfoService {
LoggerFactory.getLogger(SystemInfoServiceImpl.class); LoggerFactory.getLogger(SystemInfoServiceImpl.class);
private static final JSch JSCH = new JSch(); private static final JSch JSCH = new JSch();
private final GerritServer server; private final SchemaFactory<ReviewDb> schema;
private final GerritSshDaemon sshd; private final GerritSshDaemon sshd;
private final GerritConfig config; private final GerritConfig config;
private final List<PublicKey> hostKeys; private final List<PublicKey> hostKeys;
@Inject @Inject
SystemInfoServiceImpl(final GerritServer gs, final GerritSshDaemon daemon, SystemInfoServiceImpl(final SchemaFactory<ReviewDb> sf,
final GerritConfig gc) { final GerritSshDaemon daemon, final GerritConfig gc) {
server = gs; schema = sf;
sshd = daemon; sshd = daemon;
config = gc; config = gc;
hostKeys = sortHostKeys(); hostKeys = sortHostKeys();
@@ -77,7 +78,7 @@ class SystemInfoServiceImpl implements SystemInfoService {
public void contributorAgreements( public void contributorAgreements(
final AsyncCallback<List<ContributorAgreement>> callback) { final AsyncCallback<List<ContributorAgreement>> callback) {
try { try {
final ReviewDb db = server.getSchemaFactory().open(); final ReviewDb db = schema.open();
try { try {
callback.onSuccess(db.contributorAgreements().active().toList()); callback.onSuccess(db.contributorAgreements().active().toList());
} finally { } finally {

View File

@@ -20,6 +20,7 @@ import com.google.gerrit.client.reviewdb.Change;
import com.google.gerrit.client.reviewdb.RevId; import com.google.gerrit.client.reviewdb.RevId;
import com.google.gerrit.client.reviewdb.ReviewDb; import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@@ -69,12 +70,12 @@ public class UrlRewriteFilter implements Filter {
staticExtensions.add(".png"); staticExtensions.add(".png");
} }
private final GerritServer server; private final SchemaFactory<ReviewDb> schema;
private FilterConfig config; private FilterConfig config;
@Inject @Inject
UrlRewriteFilter(final GerritServer gs) { UrlRewriteFilter(final SchemaFactory<ReviewDb> sf) {
server = gs; schema = sf;
} }
public void init(final FilterConfig config) { public void init(final FilterConfig config) {
@@ -194,7 +195,7 @@ public class UrlRewriteFilter implements Filter {
final String email = cleanEmail(m.group(1)); final String email = cleanEmail(m.group(1));
final List<Account> people; final List<Account> people;
try { try {
final ReviewDb db = server.getSchemaFactory().open(); final ReviewDb db = schema.open();
try { try {
people = db.accounts().byPreferredEmail(email).toList(); people = db.accounts().byPreferredEmail(email).toList();
} finally { } finally {

View File

@@ -51,6 +51,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwtjsonrpc.client.VoidResult; import com.google.gwtjsonrpc.client.VoidResult;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.OrmRunnable; import com.google.gwtorm.client.OrmRunnable;
import com.google.gwtorm.client.SchemaFactory;
import com.google.gwtorm.client.Transaction; import com.google.gwtorm.client.Transaction;
import com.google.inject.Inject; import com.google.inject.Inject;
@@ -67,11 +68,14 @@ import java.util.Set;
public class PatchDetailServiceImpl extends BaseServiceImplementation implements public class PatchDetailServiceImpl extends BaseServiceImplementation implements
PatchDetailService { PatchDetailService {
private final Logger log = LoggerFactory.getLogger(getClass()); private final Logger log = LoggerFactory.getLogger(getClass());
private final GerritServer server;
private final FileTypeRegistry registry; private final FileTypeRegistry registry;
@Inject @Inject
PatchDetailServiceImpl(final GerritServer gs, final FileTypeRegistry ftr) { PatchDetailServiceImpl(final SchemaFactory<ReviewDb> sf,
super(gs); final GerritServer gs, final FileTypeRegistry ftr) {
super(sf);
server = gs;
registry = ftr; registry = ftr;
} }

View File

@@ -23,6 +23,7 @@ import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.server.BaseServiceImplementation; import com.google.gerrit.server.BaseServiceImplementation;
import com.google.gerrit.server.GerritServer; import com.google.gerrit.server.GerritServer;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.servlet.RequestScoped; import com.google.inject.servlet.RequestScoped;
@@ -62,8 +63,12 @@ abstract class AbstractCommand implements Command, SessionAware {
protected OutputStream err; protected OutputStream err;
protected ExitCallback exit; protected ExitCallback exit;
protected ServerSession session; protected ServerSession session;
@Inject @Inject
protected GerritServer server; protected GerritServer server;
@Inject
protected SchemaFactory<ReviewDb> schema;
protected ReviewDb db; protected ReviewDb db;
private String name; private String name;
@@ -105,7 +110,7 @@ abstract class AbstractCommand implements Command, SessionAware {
protected ReviewDb openReviewDb() throws Failure { protected ReviewDb openReviewDb() throws Failure {
if (db == null) { if (db == null) {
try { try {
db = getGerritServer().getSchemaFactory().open(); db = schema.open();
} catch (OrmException e) { } catch (OrmException e) {
throw new Failure(1, "fatal: Gerrit database is offline", e); throw new Failure(1, "fatal: Gerrit database is offline", e);
} }

View File

@@ -55,7 +55,7 @@ class AdminReplicate extends AbstractCommand {
} }
if (all) { if (all) {
WorkQueue.schedule(new PushAllProjectsOp(server, replication, urlMatch), WorkQueue.schedule(new PushAllProjectsOp(schema, replication, urlMatch),
0, TimeUnit.SECONDS); 0, TimeUnit.SECONDS);
} else { } else {

View File

@@ -15,7 +15,11 @@
package com.google.gerrit.server.ssh; package com.google.gerrit.server.ssh;
import com.google.gerrit.client.reviewdb.AccountSshKey; import com.google.gerrit.client.reviewdb.AccountSshKey;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.server.GerritServer; import com.google.gerrit.server.GerritServer;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import net.sf.ehcache.Element; import net.sf.ehcache.Element;
import net.sf.ehcache.constructs.blocking.SelfPopulatingCache; import net.sf.ehcache.constructs.blocking.SelfPopulatingCache;
@@ -35,14 +39,16 @@ import java.util.Collections;
* address, as listed in their Account entity. Only keys listed under that * address, as listed in their Account entity. Only keys listed under that
* account as authorized keys are permitted to access the account. * account as authorized keys are permitted to access the account.
*/ */
@Singleton
class DatabasePubKeyAuth implements PublickeyAuthenticator { class DatabasePubKeyAuth implements PublickeyAuthenticator {
private final Logger log = LoggerFactory.getLogger(getClass()); private final Logger log = LoggerFactory.getLogger(getClass());
private final SelfPopulatingCache sshKeysCache; private final SelfPopulatingCache sshKeysCache;
private final GerritServer server; private final SchemaFactory<ReviewDb> schema;
DatabasePubKeyAuth(final GerritServer gs) { @Inject
DatabasePubKeyAuth(final GerritServer gs, final SchemaFactory<ReviewDb> sf) {
sshKeysCache = gs.getSshKeysCache(); sshKeysCache = gs.getSshKeysCache();
server = gs; schema = sf;
} }
public boolean hasKey(final String username, final PublicKey inkey, public boolean hasKey(final String username, final PublicKey inkey,
@@ -67,7 +73,7 @@ class DatabasePubKeyAuth implements PublickeyAuthenticator {
} }
if (matched != null) { if (matched != null) {
matched.updateLastUsed(server); matched.updateLastUsed(schema);
session.setAttribute(SshUtil.CURRENT_ACCOUNT, matched.getAccount()); session.setAttribute(SshUtil.CURRENT_ACCOUNT, matched.getAccount());
return true; return true;
} }

View File

@@ -49,6 +49,7 @@ import org.apache.sshd.common.signature.SignatureDSA;
import org.apache.sshd.common.signature.SignatureRSA; import org.apache.sshd.common.signature.SignatureRSA;
import org.apache.sshd.common.util.SecurityUtils; import org.apache.sshd.common.util.SecurityUtils;
import org.apache.sshd.server.CommandFactory; import org.apache.sshd.server.CommandFactory;
import org.apache.sshd.server.PublickeyAuthenticator;
import org.apache.sshd.server.ServerChannel; import org.apache.sshd.server.ServerChannel;
import org.apache.sshd.server.SessionFactory; import org.apache.sshd.server.SessionFactory;
import org.apache.sshd.server.UserAuth; import org.apache.sshd.server.UserAuth;
@@ -126,7 +127,7 @@ public class GerritSshDaemon extends SshServer {
@Inject @Inject
public GerritSshDaemon(final GerritServer srv, public GerritSshDaemon(final GerritServer srv,
final CommandFactory commandFactory) { final CommandFactory commandFactory, final PublickeyAuthenticator userAuth) {
setPort(22/* never used */); setPort(22/* never used */);
final RepositoryConfig cfg = srv.getGerritConfig(); final RepositoryConfig cfg = srv.getGerritConfig();
@@ -144,7 +145,7 @@ public class GerritSshDaemon extends SshServer {
initSignatures(); initSignatures();
initChannels(); initChannels();
initCompression(); initCompression();
initUserAuth(srv); initUserAuth(userAuth);
setKeyPairProvider(initHostKey(srv)); setKeyPairProvider(initHostKey(srv));
setCommandFactory(commandFactory); setCommandFactory(commandFactory);
setShellFactory(new NoShell()); setShellFactory(new NoShell());
@@ -467,10 +468,10 @@ public class GerritSshDaemon extends SshServer {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void initUserAuth(final GerritServer srv) { private void initUserAuth(final PublickeyAuthenticator pubkey) {
setUserAuthFactories(Arrays setUserAuthFactories(Arrays
.<NamedFactory<UserAuth>> asList(new UserAuthPublicKey.Factory())); .<NamedFactory<UserAuth>> asList(new UserAuthPublicKey.Factory()));
setPublickeyAuthenticator(new DatabasePubKeyAuth(srv)); setPublickeyAuthenticator(pubkey);
} }
private KeyPairProvider initHostKey(final GerritServer srv) { private KeyPairProvider initHostKey(final GerritServer srv) {

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.server.ssh;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import org.apache.sshd.server.CommandFactory; import org.apache.sshd.server.CommandFactory;
import org.apache.sshd.server.PublickeyAuthenticator;
/** Configures standard dependencies for {@link GerritSshDaemon}. */ /** Configures standard dependencies for {@link GerritSshDaemon}. */
public class SshDaemonModule extends AbstractModule { public class SshDaemonModule extends AbstractModule {
@@ -24,5 +25,6 @@ public class SshDaemonModule extends AbstractModule {
protected void configure() { protected void configure() {
bind(GerritSshDaemon.class); bind(GerritSshDaemon.class);
bind(CommandFactory.class).to(GerritCommandFactory.class); bind(CommandFactory.class).to(GerritCommandFactory.class);
bind(PublickeyAuthenticator.class).to(DatabasePubKeyAuth.class);
} }
} }

View File

@@ -17,8 +17,8 @@ package com.google.gerrit.server.ssh;
import com.google.gerrit.client.reviewdb.Account; import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.reviewdb.AccountSshKey; import com.google.gerrit.client.reviewdb.AccountSshKey;
import com.google.gerrit.client.reviewdb.ReviewDb; import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.server.GerritServer;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -46,9 +46,9 @@ class SshKeyCacheEntry {
return publicKey.equals(inkey); return publicKey.equals(inkey);
} }
void updateLastUsed(final GerritServer server) { void updateLastUsed(final SchemaFactory<ReviewDb> schema) {
try { try {
final ReviewDb db = server.getSchemaFactory().open(); final ReviewDb db = schema.open();
try { try {
final AccountSshKey k = db.accountSshKeys().get(id); final AccountSshKey k = db.accountSshKeys().get(id);
if (k != null) { if (k != null) {

View File

@@ -17,8 +17,8 @@ package com.google.gerrit.server.ssh;
import com.google.gerrit.client.reviewdb.Account; import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.reviewdb.AccountSshKey; import com.google.gerrit.client.reviewdb.AccountSshKey;
import com.google.gerrit.client.reviewdb.ReviewDb; import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.server.GerritServer;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import net.sf.ehcache.constructs.blocking.CacheEntryFactory; import net.sf.ehcache.constructs.blocking.CacheEntryFactory;
@@ -32,15 +32,15 @@ import java.util.List;
public class SshKeyCacheEntryFactory implements CacheEntryFactory { public class SshKeyCacheEntryFactory implements CacheEntryFactory {
private final Logger log = LoggerFactory.getLogger(getClass()); private final Logger log = LoggerFactory.getLogger(getClass());
private final GerritServer server; private final SchemaFactory<ReviewDb> schema;
public SshKeyCacheEntryFactory(final GerritServer gs) { public SshKeyCacheEntryFactory(final SchemaFactory<ReviewDb> sf) {
server = gs; schema = sf;
} }
public Object createEntry(final Object genericKey) throws Exception { public Object createEntry(final Object genericKey) throws Exception {
final String username = (String) genericKey; final String username = (String) genericKey;
final ReviewDb db = server.getSchemaFactory().open(); final ReviewDb db = schema.open();
try { try {
final List<Account> matches = final List<Account> matches =
db.accounts().bySshUserName(username).toList(); db.accounts().bySshUserName(username).toList();