Remove more Common.getSchemaFactory invocations to direct field uses

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2009-07-27 21:26:42 -07:00
parent 3761e8ec62
commit d058b3ebb0
7 changed files with 20 additions and 16 deletions

View File

@@ -19,6 +19,7 @@ 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.client.rpc.Common; import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.server.GerritServer;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -30,20 +31,22 @@ 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 String urlMatch; private final String urlMatch;
public PushAllProjectsOp() { public PushAllProjectsOp(final GerritServer gs) {
this(null); this(gs, null);
} }
public PushAllProjectsOp(final String urlMatch) { public PushAllProjectsOp(final GerritServer gs, final String urlMatch) {
this.server = gs;
this.urlMatch = urlMatch; this.urlMatch = urlMatch;
} }
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 = Common.getSchemaFactory().open(); final ReviewDb db = server.getSchemaFactory().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,7 +14,6 @@
package com.google.gerrit.pgm; package com.google.gerrit.pgm;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.server.GerritServer; import com.google.gerrit.server.GerritServer;
/** /**
@@ -23,8 +22,8 @@ import com.google.gerrit.server.GerritServer;
public class CreateSchema extends AbstractProgram { public class CreateSchema extends AbstractProgram {
@Override @Override
public int run() throws Exception { public int run() throws Exception {
GerritServer.getInstance(false); final GerritServer gs = GerritServer.getInstance(false);
Common.getSchemaFactory().open().close(); gs.getSchemaFactory().open().close();
System.out.println("Gerrit2 schema initialized"); System.out.println("Gerrit2 schema initialized");
return 0; return 0;
} }

View File

@@ -18,7 +18,6 @@ import com.google.gerrit.client.reviewdb.Change;
import com.google.gerrit.client.reviewdb.PatchSet; import com.google.gerrit.client.reviewdb.PatchSet;
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.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.git.PatchSetImporter; import com.google.gerrit.git.PatchSetImporter;
import com.google.gerrit.server.GerritServer; import com.google.gerrit.server.GerritServer;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
@@ -63,7 +62,7 @@ public class ReimportPatchSets extends AbstractProgram {
} }
int exitStatus = 0; int exitStatus = 0;
final ReviewDb db = Common.getSchemaFactory().open(); final ReviewDb db = gs.getSchemaFactory().open();
final ProgressMonitor pm = new TextProgressMonitor(); final ProgressMonitor pm = new TextProgressMonitor();
try { try {
pm.start(1); pm.start(1);

View File

@@ -18,7 +18,6 @@ import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.reviewdb.AccountExternalId; import com.google.gerrit.client.reviewdb.AccountExternalId;
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.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.Common;
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;
@@ -73,6 +72,7 @@ public class EncryptedContactStore implements ContactStore {
} }
} }
private final GerritServer server;
private PGPPublicKey dest; private PGPPublicKey dest;
private SecureRandom prng; private SecureRandom prng;
private URL storeUrl; private URL storeUrl;
@@ -80,6 +80,8 @@ public class EncryptedContactStore implements ContactStore {
private EncryptedContactStore(final GerritServer gs) private EncryptedContactStore(final GerritServer gs)
throws ContactInformationStoreException { throws ContactInformationStoreException {
server = gs;
if (gs.getContactStoreURL() == null) { if (gs.getContactStoreURL() == null) {
throw new ContactInformationStoreException(new IllegalStateException( throw new ContactInformationStoreException(new IllegalStateException(
"No contactStoreURL configured")); "No contactStoreURL configured"));
@@ -229,7 +231,7 @@ public class EncryptedContactStore implements ContactStore {
return buf.toByteArray(); return buf.toByteArray();
} }
private static String format(final Account account, private String format(final Account account,
final ContactInformation info) throws ContactInformationStoreException { final ContactInformation info) throws ContactInformationStoreException {
Timestamp on = account.getContactFiledOn(); Timestamp on = account.getContactFiledOn();
if (on == null) { if (on == null) {
@@ -246,7 +248,7 @@ public class EncryptedContactStore implements ContactStore {
field(b, "Preferred-Email", account.getPreferredEmail()); field(b, "Preferred-Email", account.getPreferredEmail());
try { try {
final ReviewDb db = Common.getSchemaFactory().open(); final ReviewDb db = server.getSchemaFactory().open();
try { try {
for (final AccountExternalId e : db.accountExternalIds().byAccount( for (final AccountExternalId e : db.accountExternalIds().byAccount(
account.getId())) { account.getId())) {

View File

@@ -153,7 +153,7 @@ public class GerritServer {
if (startQueues) { if (startQueues) {
impl.reloadSubmitQueue(); impl.reloadSubmitQueue();
if (PushQueue.isReplicationEnabled()) { if (PushQueue.isReplicationEnabled()) {
WorkQueue.schedule(new PushAllProjectsOp(), 30, TimeUnit.SECONDS); WorkQueue.schedule(new PushAllProjectsOp(impl), 30, TimeUnit.SECONDS);
} }
} }
} catch (OrmException e) { } catch (OrmException e) {

View File

@@ -175,7 +175,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 = Common.getSchemaFactory().open(); final ReviewDb db = server.getSchemaFactory().open();
try { try {
final ResultSet<AccountExternalId> ae = final ResultSet<AccountExternalId> ae =
db.accountExternalIds().byExternal(aReq.getIdentity()); db.accountExternalIds().byExternal(aReq.getIdentity());
@@ -329,7 +329,7 @@ class OpenIdServiceImpl implements OpenIdService {
Account account = null; Account account = null;
if (user != null) { if (user != null) {
try { try {
final ReviewDb d = Common.getSchemaFactory().open(); final ReviewDb d = server.getSchemaFactory().open();
try { try {
switch (mode) { switch (mode) {
case SIGN_IN: case SIGN_IN:

View File

@@ -51,7 +51,8 @@ class AdminReplicate extends AbstractCommand {
} }
if (all) { if (all) {
WorkQueue.schedule(new PushAllProjectsOp(urlMatch), 0, TimeUnit.SECONDS); WorkQueue.schedule(new PushAllProjectsOp(getGerritServer(), urlMatch), 0,
TimeUnit.SECONDS);
} else { } else {
for (final String name : projectNames) { for (final String name : projectNames) {