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:
@@ -37,6 +37,7 @@ import com.google.gwtjsonrpc.server.ValidToken;
|
||||
import com.google.gwtjsonrpc.server.XsrfException;
|
||||
import com.google.gwtorm.client.OrmDuplicateKeyException;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.gwtorm.client.Transaction;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@@ -61,11 +62,14 @@ import javax.servlet.http.HttpServletRequest;
|
||||
class AccountSecurityImpl extends BaseServiceImplementation implements
|
||||
AccountSecurity {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final GerritServer server;
|
||||
private final ContactStore contactStore;
|
||||
|
||||
@Inject
|
||||
AccountSecurityImpl(final GerritServer gs, final ContactStore cs) {
|
||||
super(gs);
|
||||
AccountSecurityImpl(final SchemaFactory<ReviewDb> sf, final GerritServer gs,
|
||||
final ContactStore cs) {
|
||||
super(sf);
|
||||
server = gs;
|
||||
contactStore = cs;
|
||||
}
|
||||
|
||||
|
@@ -28,6 +28,7 @@ import com.google.gerrit.client.rpc.NoSuchEntityException;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwtjsonrpc.client.VoidResult;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.gwtorm.client.Transaction;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@@ -40,8 +41,8 @@ import java.util.Set;
|
||||
class AccountServiceImpl extends BaseServiceImplementation implements
|
||||
AccountService {
|
||||
@Inject
|
||||
AccountServiceImpl(final GerritServer gs) {
|
||||
super(gs);
|
||||
AccountServiceImpl(final SchemaFactory<ReviewDb> sf) {
|
||||
super(sf);
|
||||
}
|
||||
|
||||
public void myAccount(final AsyncCallback<Account> callback) {
|
||||
|
@@ -27,15 +27,16 @@ import com.google.gerrit.client.rpc.CorruptEntityException;
|
||||
import com.google.gerrit.client.rpc.NoSuchEntityException;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/** Support for services which require a {@link ReviewDb} instance. */
|
||||
public class BaseServiceImplementation {
|
||||
protected final GerritServer server;
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
|
||||
protected BaseServiceImplementation(final GerritServer gs) {
|
||||
server = gs;
|
||||
protected BaseServiceImplementation(final SchemaFactory<ReviewDb> sf) {
|
||||
schema = sf;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,7 +52,7 @@ public class BaseServiceImplementation {
|
||||
*/
|
||||
protected <T> void run(final AsyncCallback<T> callback, final Action<T> action) {
|
||||
try {
|
||||
final ReviewDb db = server.getSchemaFactory().open();
|
||||
final ReviewDb db = schema.open();
|
||||
final T r;
|
||||
try {
|
||||
r = action.run(db);
|
||||
@@ -116,7 +117,8 @@ public class BaseServiceImplementation {
|
||||
public static boolean canPerform(final Account.Id who,
|
||||
final ProjectCache.Entry e, final ApprovalCategory.Id actionId,
|
||||
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);
|
||||
}
|
||||
|
||||
|
@@ -17,8 +17,8 @@ package com.google.gerrit.server;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.reviewdb.Account;
|
||||
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.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@@ -44,10 +44,13 @@ public class BecomeAnyAccountLoginServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
private final boolean allowed;
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
private final GerritServer server;
|
||||
|
||||
@Inject
|
||||
BecomeAnyAccountLoginServlet(final GerritServer gs) {
|
||||
BecomeAnyAccountLoginServlet(final SchemaFactory<ReviewDb> sf,
|
||||
final GerritServer gs) {
|
||||
schema = sf;
|
||||
server = gs;
|
||||
allowed = isAllowed();
|
||||
}
|
||||
@@ -109,7 +112,7 @@ public class BecomeAnyAccountLoginServlet extends HttpServlet {
|
||||
private List<Account> bySshUserName(final HttpServletResponse rsp,
|
||||
final String userName) {
|
||||
try {
|
||||
final ReviewDb db = server.getSchemaFactory().open();
|
||||
final ReviewDb db = schema.open();
|
||||
try {
|
||||
return db.accounts().bySshUserName(userName).toList();
|
||||
} finally {
|
||||
@@ -124,7 +127,7 @@ public class BecomeAnyAccountLoginServlet extends HttpServlet {
|
||||
private List<Account> byPreferredEmail(final HttpServletResponse rsp,
|
||||
final String email) {
|
||||
try {
|
||||
final ReviewDb db = server.getSchemaFactory().open();
|
||||
final ReviewDb db = schema.open();
|
||||
try {
|
||||
return db.accounts().byPreferredEmail(email).toList();
|
||||
} finally {
|
||||
@@ -145,7 +148,7 @@ public class BecomeAnyAccountLoginServlet extends HttpServlet {
|
||||
return Collections.<Account> emptyList();
|
||||
}
|
||||
try {
|
||||
final ReviewDb db = server.getSchemaFactory().open();
|
||||
final ReviewDb db = schema.open();
|
||||
try {
|
||||
final Account account = db.accounts().get(id);
|
||||
return account != null ? Collections.<Account> singletonList(account)
|
||||
|
@@ -25,6 +25,7 @@ import com.google.gerrit.client.reviewdb.Project;
|
||||
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.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@@ -65,12 +66,15 @@ import javax.servlet.http.HttpServletResponse;
|
||||
public class CatServlet extends HttpServlet {
|
||||
private static final MimeType ZIP = new MimeType("application/zip");
|
||||
private final GerritServer server;
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
private final SecureRandom rng;
|
||||
private final FileTypeRegistry registry;
|
||||
|
||||
@Inject
|
||||
CatServlet(final GerritServer gs, final FileTypeRegistry ftr) {
|
||||
CatServlet(final GerritServer gs, final SchemaFactory<ReviewDb> sf,
|
||||
final FileTypeRegistry ftr) {
|
||||
server = gs;
|
||||
schema = sf;
|
||||
rng = new SecureRandom();
|
||||
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 Project project;
|
||||
final Change change;
|
||||
final PatchSet patchSet;
|
||||
final Patch patch;
|
||||
try {
|
||||
final ReviewDb db = server.getSchemaFactory().open();
|
||||
final ReviewDb db = schema.open();
|
||||
try {
|
||||
change = db.changes().get(changeId);
|
||||
if (change == null) {
|
||||
|
@@ -24,13 +24,14 @@ import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.client.rpc.NoSuchEntityException;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
class ChangeDetailServiceImpl extends BaseServiceImplementation implements
|
||||
ChangeDetailService {
|
||||
@Inject
|
||||
ChangeDetailServiceImpl(final GerritServer gs) {
|
||||
super(gs);
|
||||
ChangeDetailServiceImpl(final SchemaFactory<ReviewDb> sf) {
|
||||
super(sf);
|
||||
}
|
||||
|
||||
public void changeDetail(final Change.Id id,
|
||||
|
@@ -38,6 +38,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwtjsonrpc.client.VoidResult;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.ResultSet;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.gwtorm.client.Transaction;
|
||||
import com.google.gwtorm.client.impl.ListResultSet;
|
||||
import com.google.inject.Inject;
|
||||
@@ -83,8 +84,8 @@ class ChangeListServiceImpl extends BaseServiceImplementation implements
|
||||
}
|
||||
|
||||
@Inject
|
||||
ChangeListServiceImpl(final GerritServer gs) {
|
||||
super(gs);
|
||||
ChangeListServiceImpl(final SchemaFactory<ReviewDb> sf) {
|
||||
super(sf);
|
||||
}
|
||||
|
||||
public void allOpenPrev(final String pos, final int pageSize,
|
||||
|
@@ -31,6 +31,7 @@ import com.google.gerrit.server.workflow.FunctionState;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwtjsonrpc.client.VoidResult;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.gwtorm.client.Transaction;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@@ -41,10 +42,10 @@ import java.util.List;
|
||||
class ChangeManageServiceImpl extends BaseServiceImplementation implements
|
||||
ChangeManageService {
|
||||
private final MergeQueue merger;
|
||||
|
||||
|
||||
@Inject
|
||||
ChangeManageServiceImpl(final GerritServer gs, final MergeQueue mq) {
|
||||
super(gs);
|
||||
ChangeManageServiceImpl(final SchemaFactory<ReviewDb> sf, final MergeQueue mq) {
|
||||
super(sf);
|
||||
merger = mq;
|
||||
}
|
||||
|
||||
|
@@ -20,6 +20,7 @@ import com.google.gerrit.client.reviewdb.ContactInformation;
|
||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.client.rpc.ContactInformationStoreException;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
|
||||
import org.apache.sshd.common.util.SecurityUtils;
|
||||
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||
@@ -59,14 +60,16 @@ class EncryptedContactStore implements ContactStore {
|
||||
private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
|
||||
|
||||
private final GerritServer server;
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
private PGPPublicKey dest;
|
||||
private SecureRandom prng;
|
||||
private URL storeUrl;
|
||||
private String storeAPPSEC;
|
||||
|
||||
EncryptedContactStore(final GerritServer gs)
|
||||
EncryptedContactStore(final GerritServer gs, final SchemaFactory<ReviewDb> sf)
|
||||
throws ContactInformationStoreException {
|
||||
server = gs;
|
||||
schema = sf;
|
||||
|
||||
if (gs.getContactStoreURL() == null) {
|
||||
throw new ContactInformationStoreException(new IllegalStateException(
|
||||
@@ -90,12 +93,12 @@ class EncryptedContactStore implements ContactStore {
|
||||
throw new ContactInformationStoreException(e);
|
||||
}
|
||||
|
||||
dest = selectKey(readPubRing(gs));
|
||||
dest = selectKey(readPubRing());
|
||||
}
|
||||
|
||||
private PGPPublicKeyRingCollection readPubRing(final GerritServer gs)
|
||||
private PGPPublicKeyRingCollection readPubRing()
|
||||
throws ContactInformationStoreException {
|
||||
final File pub = new File(gs.getSitePath(), "contact_information.pub");
|
||||
final File pub = new File(server.getSitePath(), "contact_information.pub");
|
||||
try {
|
||||
InputStream in = new FileInputStream(pub);
|
||||
try {
|
||||
@@ -234,7 +237,7 @@ class EncryptedContactStore implements ContactStore {
|
||||
field(b, "Preferred-Email", account.getPreferredEmail());
|
||||
|
||||
try {
|
||||
final ReviewDb db = server.getSchemaFactory().open();
|
||||
final ReviewDb db = schema.open();
|
||||
try {
|
||||
for (final AccountExternalId e : db.accountExternalIds().byAccount(
|
||||
account.getId())) {
|
||||
|
@@ -16,18 +16,22 @@ package com.google.gerrit.server;
|
||||
|
||||
import com.google.gerrit.client.reviewdb.Account;
|
||||
import com.google.gerrit.client.reviewdb.ContactInformation;
|
||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.client.rpc.ContactInformationStoreException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
class EncryptedContactStoreProvider implements Provider<ContactStore> {
|
||||
@Inject
|
||||
private GerritServer server;
|
||||
@Inject
|
||||
private SchemaFactory<ReviewDb> schema;
|
||||
|
||||
@Override
|
||||
public ContactStore get() {
|
||||
try {
|
||||
return new EncryptedContactStore(server);
|
||||
return new EncryptedContactStore(server, schema);
|
||||
} catch (final ContactInformationStoreException initError) {
|
||||
return new ContactStore() {
|
||||
@Override
|
||||
|
@@ -24,6 +24,7 @@ import com.google.gwtjsonrpc.server.ActiveCall;
|
||||
import com.google.gwtjsonrpc.server.ValidToken;
|
||||
import com.google.gwtjsonrpc.server.XsrfException;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.gwtorm.client.Transaction;
|
||||
|
||||
import org.spearce.jgit.util.Base64;
|
||||
@@ -46,13 +47,15 @@ public class GerritCall extends ActiveCall {
|
||||
}
|
||||
|
||||
private final GerritServer server;
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
private boolean accountRead;
|
||||
private Account.Id accountId;
|
||||
private boolean rememberAccount;
|
||||
|
||||
public GerritCall(final GerritServer gs, final HttpServletRequest i,
|
||||
final HttpServletResponse o) {
|
||||
public GerritCall(final GerritServer gs, final SchemaFactory<ReviewDb> sf,
|
||||
final HttpServletRequest i, final HttpServletResponse o) {
|
||||
super(i, o);
|
||||
schema = sf;
|
||||
server = gs;
|
||||
}
|
||||
|
||||
@@ -158,7 +161,7 @@ public class GerritCall extends ActiveCall {
|
||||
}
|
||||
|
||||
try {
|
||||
final ReviewDb db = server.getSchemaFactory().open();
|
||||
final ReviewDb db = schema.open();
|
||||
try {
|
||||
final String eid = "gerrit:" + user;
|
||||
final List<AccountExternalId> matches =
|
||||
|
@@ -44,9 +44,9 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
||||
private GerritSshDaemon sshd;
|
||||
|
||||
@Inject
|
||||
GerritConfigProvider(final GerritServer gs) {
|
||||
GerritConfigProvider(final GerritServer gs, final SchemaFactory<ReviewDb> sf) {
|
||||
server = gs;
|
||||
schema = gs.getSchemaFactory();
|
||||
schema = sf;
|
||||
}
|
||||
|
||||
@Inject(optional = true)
|
||||
|
@@ -14,12 +14,14 @@
|
||||
|
||||
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.SignInRequired;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gwtjsonrpc.client.RemoteJsonService;
|
||||
import com.google.gwtjsonrpc.server.JsonServlet;
|
||||
import com.google.gwtjsonrpc.server.SignedToken;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -35,12 +37,15 @@ public final class GerritJsonServlet extends JsonServlet<GerritCall> {
|
||||
return JsonServlet.<GerritCall> getCurrentCall();
|
||||
}
|
||||
|
||||
protected GerritServer server;
|
||||
private RemoteJsonService service;
|
||||
private final GerritServer server;
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
private final RemoteJsonService service;
|
||||
|
||||
@Inject
|
||||
GerritJsonServlet(final GerritServer gs, final RemoteJsonService s) {
|
||||
GerritJsonServlet(final GerritServer gs, final SchemaFactory<ReviewDb> sf,
|
||||
final RemoteJsonService s) {
|
||||
server = gs;
|
||||
schema = sf;
|
||||
service = s;
|
||||
}
|
||||
|
||||
@@ -52,7 +57,7 @@ public final class GerritJsonServlet extends JsonServlet<GerritCall> {
|
||||
@Override
|
||||
protected GerritCall createActiveCall(final HttpServletRequest req,
|
||||
final HttpServletResponse resp) {
|
||||
return new GerritCall(server, req, resp);
|
||||
return new GerritCall(server, schema, req, resp);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -36,7 +36,6 @@ import com.google.gerrit.server.workflow.SubmitFunction;
|
||||
import com.google.gwtjsonrpc.server.SignedToken;
|
||||
import com.google.gwtjsonrpc.server.XsrfException;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.gwtorm.client.Transaction;
|
||||
import com.google.gwtorm.jdbc.Database;
|
||||
import com.google.inject.Inject;
|
||||
@@ -297,7 +296,7 @@ public class GerritServer {
|
||||
final Cache dc = cacheMgr.getCache("sshkeys");
|
||||
final SelfPopulatingCache r;
|
||||
|
||||
r = new SelfPopulatingCache(dc, new SshKeyCacheEntryFactory(this));
|
||||
r = new SelfPopulatingCache(dc, new SshKeyCacheEntryFactory(db));
|
||||
cacheMgr.replaceCacheWithDecoratedCache(dc, r);
|
||||
return r;
|
||||
}
|
||||
@@ -708,11 +707,6 @@ public class GerritServer {
|
||||
return gerritConfigFile;
|
||||
}
|
||||
|
||||
/** Get the schema factory for this instance. */
|
||||
public SchemaFactory<ReviewDb> getSchemaFactory() {
|
||||
return db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get (or open) a repository by name.
|
||||
*
|
||||
|
@@ -22,6 +22,7 @@ import com.google.gerrit.git.ChangeMergeQueue;
|
||||
import com.google.gerrit.git.MergeQueue;
|
||||
import com.google.gerrit.git.PushReplication;
|
||||
import com.google.gerrit.git.ReplicationQueue;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.gwtorm.jdbc.Database;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Key;
|
||||
@@ -38,6 +39,8 @@ public class GerritServerModule extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DS).toProvider(ReviewDbDataSourceProvider.class).in(SINGLETON);
|
||||
bind(new TypeLiteral<SchemaFactory<ReviewDb>>() {}).to(
|
||||
new TypeLiteral<Database<ReviewDb>>() {});
|
||||
bind(new TypeLiteral<Database<ReviewDb>>() {}).toProvider(
|
||||
ReviewDbProvider.class).in(SINGLETON);
|
||||
|
||||
|
@@ -28,6 +28,7 @@ import com.google.gerrit.server.ssh.SshServlet;
|
||||
import com.google.gwtexpui.server.CacheControlFilter;
|
||||
import com.google.gwtjsonrpc.client.RemoteJsonService;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.inject.BindingAnnotation;
|
||||
import com.google.inject.ConfigurationException;
|
||||
import com.google.inject.Guice;
|
||||
@@ -35,6 +36,7 @@ import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
|
||||
@@ -182,19 +184,23 @@ public class GerritServletConfig extends GuiceServletContextListener {
|
||||
private void startReplication() {
|
||||
final ReplicationQueue rq = injector.getInstance(ReplicationQueue.class);
|
||||
if (rq.isEnabled()) {
|
||||
final GerritServer gs = injector.getInstance(GerritServer.class);
|
||||
WorkQueue.schedule(new PushAllProjectsOp(gs, rq), 30, TimeUnit.SECONDS);
|
||||
final SchemaFactory<ReviewDb> sf =
|
||||
injector.getInstance(Key
|
||||
.get(new TypeLiteral<SchemaFactory<ReviewDb>>() {}));
|
||||
WorkQueue.schedule(new PushAllProjectsOp(sf, rq), 30, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
private void restartPendingMerges() {
|
||||
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() {
|
||||
public void run() {
|
||||
final HashSet<Branch.NameKey> pending = new HashSet<Branch.NameKey>();
|
||||
try {
|
||||
final ReviewDb c = gs.getSchemaFactory().open();
|
||||
final ReviewDb c = sf.open();
|
||||
try {
|
||||
for (final Change change : c.changes().allSubmitted()) {
|
||||
pending.add(change.getDest());
|
||||
|
@@ -29,6 +29,7 @@ import com.google.gerrit.client.rpc.NoSuchEntityException;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwtjsonrpc.client.VoidResult;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.gwtorm.client.Transaction;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@@ -43,8 +44,8 @@ import java.util.Set;
|
||||
class GroupAdminServiceImpl extends BaseServiceImplementation implements
|
||||
GroupAdminService {
|
||||
@Inject
|
||||
GroupAdminServiceImpl(final GerritServer gs) {
|
||||
super(gs);
|
||||
GroupAdminServiceImpl(final SchemaFactory<ReviewDb> sf) {
|
||||
super(sf);
|
||||
}
|
||||
|
||||
public void ownedGroups(final AsyncCallback<List<AccountGroup>> callback) {
|
||||
|
@@ -16,8 +16,10 @@ package com.google.gerrit.server;
|
||||
|
||||
import com.google.gerrit.client.data.GerritConfig;
|
||||
import com.google.gerrit.client.reviewdb.Account;
|
||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.client.rpc.Common;
|
||||
import com.google.gwt.user.server.rpc.RPCServletUtils;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@@ -44,6 +46,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
@Singleton
|
||||
public class HostPageServlet extends HttpServlet {
|
||||
private final GerritServer server;
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
private final GerritConfig config;
|
||||
|
||||
private String canonicalUrl;
|
||||
@@ -51,8 +54,10 @@ public class HostPageServlet extends HttpServlet {
|
||||
private Document hostDoc;
|
||||
|
||||
@Inject
|
||||
HostPageServlet(final GerritServer gs, final GerritConfig gc) {
|
||||
HostPageServlet(final GerritServer gs, final SchemaFactory<ReviewDb> sf,
|
||||
final GerritConfig gc) {
|
||||
server = gs;
|
||||
schema = sf;
|
||||
config = gc;
|
||||
}
|
||||
|
||||
@@ -220,7 +225,8 @@ public class HostPageServlet extends HttpServlet {
|
||||
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 Document peruser = HtmlDomUtil.clone(hostDoc);
|
||||
|
@@ -32,6 +32,7 @@ import com.google.gwtjsonrpc.server.XsrfException;
|
||||
import com.google.gwtorm.client.KeyUtil;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.ResultSet;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.gwtorm.client.Transaction;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -95,12 +96,15 @@ class OpenIdServiceImpl implements OpenIdService {
|
||||
}
|
||||
|
||||
private final GerritServer server;
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
private final ConsumerManager manager;
|
||||
private final SelfPopulatingCache discoveryCache;
|
||||
|
||||
@Inject
|
||||
OpenIdServiceImpl(final GerritServer gs) throws ConsumerException {
|
||||
OpenIdServiceImpl(final GerritServer gs, final SchemaFactory<ReviewDb> sf)
|
||||
throws ConsumerException {
|
||||
server = gs;
|
||||
schema = sf;
|
||||
manager = new ConsumerManager();
|
||||
if (useOpenID()) {
|
||||
discoveryCache =
|
||||
@@ -179,7 +183,7 @@ class OpenIdServiceImpl implements OpenIdService {
|
||||
// We might already have this account on file. Look for it.
|
||||
//
|
||||
try {
|
||||
final ReviewDb db = server.getSchemaFactory().open();
|
||||
final ReviewDb db = schema.open();
|
||||
try {
|
||||
final ResultSet<AccountExternalId> ae =
|
||||
db.accountExternalIds().byExternal(aReq.getIdentity());
|
||||
@@ -333,7 +337,7 @@ class OpenIdServiceImpl implements OpenIdService {
|
||||
Account account = null;
|
||||
if (user != null) {
|
||||
try {
|
||||
final ReviewDb d = server.getSchemaFactory().open();
|
||||
final ReviewDb d = schema.open();
|
||||
try {
|
||||
switch (mode) {
|
||||
case SIGN_IN:
|
||||
|
@@ -34,6 +34,7 @@ import com.google.gerrit.git.ReplicationQueue;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwtjsonrpc.client.VoidResult;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -66,12 +67,14 @@ import javax.servlet.http.HttpServletRequest;
|
||||
class ProjectAdminServiceImpl extends BaseServiceImplementation implements
|
||||
ProjectAdminService {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private final GerritServer server;
|
||||
private final ReplicationQueue replication;
|
||||
|
||||
@Inject
|
||||
ProjectAdminServiceImpl(final GerritServer gs, final ReplicationQueue rq) {
|
||||
super(gs);
|
||||
ProjectAdminServiceImpl(final SchemaFactory<ReviewDb> sf,
|
||||
final GerritServer gs, final ReplicationQueue rq) {
|
||||
super(sf);
|
||||
server = gs;
|
||||
replication = rq;
|
||||
}
|
||||
|
||||
|
@@ -25,6 +25,7 @@ import com.google.gerrit.client.rpc.Common;
|
||||
import com.google.gerrit.client.ui.SuggestService;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -36,8 +37,8 @@ class SuggestServiceImpl extends BaseServiceImplementation implements
|
||||
private static final String MAX_SUFFIX = "\u9fa5";
|
||||
|
||||
@Inject
|
||||
SuggestServiceImpl(final GerritServer gs) {
|
||||
super(gs);
|
||||
SuggestServiceImpl(final SchemaFactory<ReviewDb> sf) {
|
||||
super(sf);
|
||||
}
|
||||
|
||||
public void suggestProjectNameKey(final String query, final int limit,
|
||||
|
@@ -22,6 +22,7 @@ import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.server.ssh.GerritSshDaemon;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import com.jcraft.jsch.HostKey;
|
||||
@@ -51,15 +52,15 @@ class SystemInfoServiceImpl implements SystemInfoService {
|
||||
LoggerFactory.getLogger(SystemInfoServiceImpl.class);
|
||||
private static final JSch JSCH = new JSch();
|
||||
|
||||
private final GerritServer server;
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
private final GerritSshDaemon sshd;
|
||||
private final GerritConfig config;
|
||||
private final List<PublicKey> hostKeys;
|
||||
|
||||
@Inject
|
||||
SystemInfoServiceImpl(final GerritServer gs, final GerritSshDaemon daemon,
|
||||
final GerritConfig gc) {
|
||||
server = gs;
|
||||
SystemInfoServiceImpl(final SchemaFactory<ReviewDb> sf,
|
||||
final GerritSshDaemon daemon, final GerritConfig gc) {
|
||||
schema = sf;
|
||||
sshd = daemon;
|
||||
config = gc;
|
||||
hostKeys = sortHostKeys();
|
||||
@@ -77,7 +78,7 @@ class SystemInfoServiceImpl implements SystemInfoService {
|
||||
public void contributorAgreements(
|
||||
final AsyncCallback<List<ContributorAgreement>> callback) {
|
||||
try {
|
||||
final ReviewDb db = server.getSchemaFactory().open();
|
||||
final ReviewDb db = schema.open();
|
||||
try {
|
||||
callback.onSuccess(db.contributorAgreements().active().toList());
|
||||
} finally {
|
||||
|
@@ -20,6 +20,7 @@ import com.google.gerrit.client.reviewdb.Change;
|
||||
import com.google.gerrit.client.reviewdb.RevId;
|
||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@@ -69,12 +70,12 @@ public class UrlRewriteFilter implements Filter {
|
||||
staticExtensions.add(".png");
|
||||
}
|
||||
|
||||
private final GerritServer server;
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
private FilterConfig config;
|
||||
|
||||
@Inject
|
||||
UrlRewriteFilter(final GerritServer gs) {
|
||||
server = gs;
|
||||
UrlRewriteFilter(final SchemaFactory<ReviewDb> sf) {
|
||||
schema = sf;
|
||||
}
|
||||
|
||||
public void init(final FilterConfig config) {
|
||||
@@ -194,7 +195,7 @@ public class UrlRewriteFilter implements Filter {
|
||||
final String email = cleanEmail(m.group(1));
|
||||
final List<Account> people;
|
||||
try {
|
||||
final ReviewDb db = server.getSchemaFactory().open();
|
||||
final ReviewDb db = schema.open();
|
||||
try {
|
||||
people = db.accounts().byPreferredEmail(email).toList();
|
||||
} finally {
|
||||
|
@@ -51,6 +51,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwtjsonrpc.client.VoidResult;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.OrmRunnable;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.gwtorm.client.Transaction;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@@ -67,11 +68,14 @@ import java.util.Set;
|
||||
public class PatchDetailServiceImpl extends BaseServiceImplementation implements
|
||||
PatchDetailService {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final GerritServer server;
|
||||
private final FileTypeRegistry registry;
|
||||
|
||||
@Inject
|
||||
PatchDetailServiceImpl(final GerritServer gs, final FileTypeRegistry ftr) {
|
||||
super(gs);
|
||||
PatchDetailServiceImpl(final SchemaFactory<ReviewDb> sf,
|
||||
final GerritServer gs, final FileTypeRegistry ftr) {
|
||||
super(sf);
|
||||
server = gs;
|
||||
registry = ftr;
|
||||
}
|
||||
|
||||
|
@@ -23,6 +23,7 @@ import com.google.gerrit.client.rpc.Common;
|
||||
import com.google.gerrit.server.BaseServiceImplementation;
|
||||
import com.google.gerrit.server.GerritServer;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.servlet.RequestScoped;
|
||||
|
||||
@@ -62,8 +63,12 @@ abstract class AbstractCommand implements Command, SessionAware {
|
||||
protected OutputStream err;
|
||||
protected ExitCallback exit;
|
||||
protected ServerSession session;
|
||||
|
||||
@Inject
|
||||
protected GerritServer server;
|
||||
|
||||
@Inject
|
||||
protected SchemaFactory<ReviewDb> schema;
|
||||
protected ReviewDb db;
|
||||
|
||||
private String name;
|
||||
@@ -105,7 +110,7 @@ abstract class AbstractCommand implements Command, SessionAware {
|
||||
protected ReviewDb openReviewDb() throws Failure {
|
||||
if (db == null) {
|
||||
try {
|
||||
db = getGerritServer().getSchemaFactory().open();
|
||||
db = schema.open();
|
||||
} catch (OrmException e) {
|
||||
throw new Failure(1, "fatal: Gerrit database is offline", e);
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ class AdminReplicate extends AbstractCommand {
|
||||
}
|
||||
|
||||
if (all) {
|
||||
WorkQueue.schedule(new PushAllProjectsOp(server, replication, urlMatch),
|
||||
WorkQueue.schedule(new PushAllProjectsOp(schema, replication, urlMatch),
|
||||
0, TimeUnit.SECONDS);
|
||||
|
||||
} else {
|
||||
|
@@ -15,7 +15,11 @@
|
||||
package com.google.gerrit.server.ssh;
|
||||
|
||||
import com.google.gerrit.client.reviewdb.AccountSshKey;
|
||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||
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.constructs.blocking.SelfPopulatingCache;
|
||||
@@ -35,14 +39,16 @@ import java.util.Collections;
|
||||
* address, as listed in their Account entity. Only keys listed under that
|
||||
* account as authorized keys are permitted to access the account.
|
||||
*/
|
||||
@Singleton
|
||||
class DatabasePubKeyAuth implements PublickeyAuthenticator {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
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();
|
||||
server = gs;
|
||||
schema = sf;
|
||||
}
|
||||
|
||||
public boolean hasKey(final String username, final PublicKey inkey,
|
||||
@@ -67,7 +73,7 @@ class DatabasePubKeyAuth implements PublickeyAuthenticator {
|
||||
}
|
||||
|
||||
if (matched != null) {
|
||||
matched.updateLastUsed(server);
|
||||
matched.updateLastUsed(schema);
|
||||
session.setAttribute(SshUtil.CURRENT_ACCOUNT, matched.getAccount());
|
||||
return true;
|
||||
}
|
||||
|
@@ -49,6 +49,7 @@ import org.apache.sshd.common.signature.SignatureDSA;
|
||||
import org.apache.sshd.common.signature.SignatureRSA;
|
||||
import org.apache.sshd.common.util.SecurityUtils;
|
||||
import org.apache.sshd.server.CommandFactory;
|
||||
import org.apache.sshd.server.PublickeyAuthenticator;
|
||||
import org.apache.sshd.server.ServerChannel;
|
||||
import org.apache.sshd.server.SessionFactory;
|
||||
import org.apache.sshd.server.UserAuth;
|
||||
@@ -126,7 +127,7 @@ public class GerritSshDaemon extends SshServer {
|
||||
|
||||
@Inject
|
||||
public GerritSshDaemon(final GerritServer srv,
|
||||
final CommandFactory commandFactory) {
|
||||
final CommandFactory commandFactory, final PublickeyAuthenticator userAuth) {
|
||||
setPort(22/* never used */);
|
||||
|
||||
final RepositoryConfig cfg = srv.getGerritConfig();
|
||||
@@ -144,7 +145,7 @@ public class GerritSshDaemon extends SshServer {
|
||||
initSignatures();
|
||||
initChannels();
|
||||
initCompression();
|
||||
initUserAuth(srv);
|
||||
initUserAuth(userAuth);
|
||||
setKeyPairProvider(initHostKey(srv));
|
||||
setCommandFactory(commandFactory);
|
||||
setShellFactory(new NoShell());
|
||||
@@ -467,10 +468,10 @@ public class GerritSshDaemon extends SshServer {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void initUserAuth(final GerritServer srv) {
|
||||
private void initUserAuth(final PublickeyAuthenticator pubkey) {
|
||||
setUserAuthFactories(Arrays
|
||||
.<NamedFactory<UserAuth>> asList(new UserAuthPublicKey.Factory()));
|
||||
setPublickeyAuthenticator(new DatabasePubKeyAuth(srv));
|
||||
setPublickeyAuthenticator(pubkey);
|
||||
}
|
||||
|
||||
private KeyPairProvider initHostKey(final GerritServer srv) {
|
||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.server.ssh;
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
import org.apache.sshd.server.CommandFactory;
|
||||
import org.apache.sshd.server.PublickeyAuthenticator;
|
||||
|
||||
/** Configures standard dependencies for {@link GerritSshDaemon}. */
|
||||
public class SshDaemonModule extends AbstractModule {
|
||||
@@ -24,5 +25,6 @@ public class SshDaemonModule extends AbstractModule {
|
||||
protected void configure() {
|
||||
bind(GerritSshDaemon.class);
|
||||
bind(CommandFactory.class).to(GerritCommandFactory.class);
|
||||
bind(PublickeyAuthenticator.class).to(DatabasePubKeyAuth.class);
|
||||
}
|
||||
}
|
||||
|
@@ -17,8 +17,8 @@ package com.google.gerrit.server.ssh;
|
||||
import com.google.gerrit.client.reviewdb.Account;
|
||||
import com.google.gerrit.client.reviewdb.AccountSshKey;
|
||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.server.GerritServer;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -46,9 +46,9 @@ class SshKeyCacheEntry {
|
||||
return publicKey.equals(inkey);
|
||||
}
|
||||
|
||||
void updateLastUsed(final GerritServer server) {
|
||||
void updateLastUsed(final SchemaFactory<ReviewDb> schema) {
|
||||
try {
|
||||
final ReviewDb db = server.getSchemaFactory().open();
|
||||
final ReviewDb db = schema.open();
|
||||
try {
|
||||
final AccountSshKey k = db.accountSshKeys().get(id);
|
||||
if (k != null) {
|
||||
|
@@ -17,8 +17,8 @@ package com.google.gerrit.server.ssh;
|
||||
import com.google.gerrit.client.reviewdb.Account;
|
||||
import com.google.gerrit.client.reviewdb.AccountSshKey;
|
||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.server.GerritServer;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
|
||||
import net.sf.ehcache.constructs.blocking.CacheEntryFactory;
|
||||
|
||||
@@ -32,15 +32,15 @@ import java.util.List;
|
||||
public class SshKeyCacheEntryFactory implements CacheEntryFactory {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private final GerritServer server;
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
|
||||
public SshKeyCacheEntryFactory(final GerritServer gs) {
|
||||
server = gs;
|
||||
public SshKeyCacheEntryFactory(final SchemaFactory<ReviewDb> sf) {
|
||||
schema = sf;
|
||||
}
|
||||
|
||||
public Object createEntry(final Object genericKey) throws Exception {
|
||||
final String username = (String) genericKey;
|
||||
final ReviewDb db = server.getSchemaFactory().open();
|
||||
final ReviewDb db = schema.open();
|
||||
try {
|
||||
final List<Account> matches =
|
||||
db.accounts().bySshUserName(username).toList();
|
||||
|
Reference in New Issue
Block a user