Remove getReviewDbProvider() from RequestContext interface
This method was the source of lots of complexity in reopening ReviewDbs in background threads and Guice request scopes. Thankfully we don't need it anymore. Change-Id: Ifd76484bcf308362c24ca7df38b07f604476c932
This commit is contained in:
		| @@ -35,11 +35,7 @@ import com.google.gerrit.server.patch.PatchSetInfoFactory; | ||||
| import com.google.gerrit.server.util.LabelVote; | ||||
| import com.google.gerrit.server.util.RequestContext; | ||||
| import com.google.gerrit.server.util.ThreadLocalRequestContext; | ||||
| import com.google.gwtorm.server.OrmException; | ||||
| import com.google.gwtorm.server.SchemaFactory; | ||||
| import com.google.inject.Inject; | ||||
| import com.google.inject.Provider; | ||||
| import com.google.inject.ProvisionException; | ||||
| import com.google.inject.assistedinject.Assisted; | ||||
| import java.util.List; | ||||
| import java.util.concurrent.ExecutorService; | ||||
| @@ -82,7 +78,6 @@ public class EmailReviewComments implements Runnable, RequestContext { | ||||
|   private final ExecutorService sendEmailsExecutor; | ||||
|   private final PatchSetInfoFactory patchSetInfoFactory; | ||||
|   private final CommentSender.Factory commentSenderFactory; | ||||
|   private final SchemaFactory<ReviewDb> schemaFactory; | ||||
|   private final ThreadLocalRequestContext requestContext; | ||||
|  | ||||
|   private final NotifyHandling notify; | ||||
| @@ -101,7 +96,6 @@ public class EmailReviewComments implements Runnable, RequestContext { | ||||
|       @SendEmailExecutor ExecutorService executor, | ||||
|       PatchSetInfoFactory patchSetInfoFactory, | ||||
|       CommentSender.Factory commentSenderFactory, | ||||
|       SchemaFactory<ReviewDb> schemaFactory, | ||||
|       ThreadLocalRequestContext requestContext, | ||||
|       @Assisted NotifyHandling notify, | ||||
|       @Assisted ListMultimap<RecipientType, Account.Id> accountsToNotify, | ||||
| @@ -115,7 +109,6 @@ public class EmailReviewComments implements Runnable, RequestContext { | ||||
|     this.sendEmailsExecutor = executor; | ||||
|     this.patchSetInfoFactory = patchSetInfoFactory; | ||||
|     this.commentSenderFactory = commentSenderFactory; | ||||
|     this.schemaFactory = schemaFactory; | ||||
|     this.requestContext = requestContext; | ||||
|     this.notify = notify; | ||||
|     this.accountsToNotify = accountsToNotify; | ||||
| @@ -168,21 +161,4 @@ public class EmailReviewComments implements Runnable, RequestContext { | ||||
|   public CurrentUser getUser() { | ||||
|     return user.getRealUser(); | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public Provider<ReviewDb> getReviewDbProvider() { | ||||
|     return new Provider<ReviewDb>() { | ||||
|       @Override | ||||
|       public ReviewDb get() { | ||||
|         if (db == null) { | ||||
|           try { | ||||
|             db = schemaFactory.open(); | ||||
|           } catch (OrmException e) { | ||||
|             throw new ProvisionException("Cannot open ReviewDb", e); | ||||
|           } | ||||
|         } | ||||
|         return db; | ||||
|       } | ||||
|     }; | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -26,7 +26,6 @@ public class GerritRequestModule extends FactoryModule { | ||||
|   @Override | ||||
|   protected void configure() { | ||||
|     bind(RequestCleanup.class).in(RequestScoped.class); | ||||
|     bind(RequestScopedReviewDbProvider.class); | ||||
|     bind(IdentifiedUser.RequestFactory.class).in(SINGLETON); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -1,66 +0,0 @@ | ||||
| // Copyright (C) 2009 The Android Open Source Project | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| package com.google.gerrit.server.config; | ||||
|  | ||||
| import com.google.gerrit.reviewdb.server.ReviewDb; | ||||
| import com.google.gerrit.server.RequestCleanup; | ||||
| import com.google.gwtorm.server.OrmException; | ||||
| import com.google.gwtorm.server.SchemaFactory; | ||||
| import com.google.inject.Inject; | ||||
| import com.google.inject.Provider; | ||||
| import com.google.inject.ProvisionException; | ||||
| import com.google.inject.servlet.RequestScoped; | ||||
|  | ||||
| /** Provides {@link ReviewDb} database handle live only for this request. */ | ||||
| @RequestScoped | ||||
| public class RequestScopedReviewDbProvider implements Provider<ReviewDb> { | ||||
|   private final SchemaFactory<ReviewDb> schema; | ||||
|   private final Provider<RequestCleanup> cleanup; | ||||
|   private ReviewDb db; | ||||
|  | ||||
|   @Inject | ||||
|   public RequestScopedReviewDbProvider( | ||||
|       final SchemaFactory<ReviewDb> schema, Provider<RequestCleanup> cleanup) { | ||||
|     this.schema = schema; | ||||
|     this.cleanup = cleanup; | ||||
|   } | ||||
|  | ||||
|   @SuppressWarnings("resource") | ||||
|   @Override | ||||
|   public ReviewDb get() { | ||||
|     if (db == null) { | ||||
|       ReviewDb c; | ||||
|       try { | ||||
|         c = schema.open(); | ||||
|       } catch (OrmException e) { | ||||
|         throw new ProvisionException("Cannot open ReviewDb", e); | ||||
|       } | ||||
|       try { | ||||
|         cleanup | ||||
|             .get() | ||||
|             .add( | ||||
|                 () -> { | ||||
|                   c.close(); | ||||
|                   db = null; | ||||
|                 }); | ||||
|       } catch (Throwable e) { | ||||
|         c.close(); | ||||
|         throw new ProvisionException("Cannot defer cleanup of ReviewDb", e); | ||||
|       } | ||||
|       db = c; | ||||
|     } | ||||
|     return db; | ||||
|   } | ||||
| } | ||||
| @@ -14,7 +14,6 @@ | ||||
|  | ||||
| package com.google.gerrit.server.git; | ||||
|  | ||||
| import com.google.gerrit.server.config.RequestScopedReviewDbProvider; | ||||
| import com.google.gerrit.server.util.RequestContext; | ||||
| import com.google.gerrit.server.util.ThreadLocalRequestContext; | ||||
| import com.google.gerrit.server.util.ThreadLocalRequestScopePropagator; | ||||
| @@ -52,10 +51,8 @@ public class PerThreadRequestScope { | ||||
|  | ||||
|   public static class Propagator extends ThreadLocalRequestScopePropagator<Context> { | ||||
|     @Inject | ||||
|     Propagator( | ||||
|         ThreadLocalRequestContext local, | ||||
|         Provider<RequestScopedReviewDbProvider> dbProviderProvider) { | ||||
|       super(REQUEST, current, local, dbProviderProvider); | ||||
|     Propagator(ThreadLocalRequestContext local) { | ||||
|       super(REQUEST, current, local); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -87,7 +87,6 @@ import com.google.gerrit.reviewdb.client.PatchSetInfo; | ||||
| import com.google.gerrit.reviewdb.client.Project; | ||||
| import com.google.gerrit.reviewdb.client.RefNames; | ||||
| import com.google.gerrit.reviewdb.client.RevId; | ||||
| import com.google.gerrit.reviewdb.server.ReviewDb; | ||||
| import com.google.gerrit.server.ApprovalsUtil; | ||||
| import com.google.gerrit.server.ChangeUtil; | ||||
| import com.google.gerrit.server.CreateGroupPermissionSyncer; | ||||
| @@ -315,7 +314,6 @@ class ReceiveCommits { | ||||
|   private final ReplaceOp.Factory replaceOpFactory; | ||||
|   private final RetryHelper retryHelper; | ||||
|   private final RequestScopePropagator requestScopePropagator; | ||||
|   private final ReviewDb db; | ||||
|   private final Sequences seq; | ||||
|   private final SetHashtagsOp.Factory hashtagsFactory; | ||||
|   private final SubmoduleOp.Factory subOpFactory; | ||||
| @@ -391,7 +389,6 @@ class ReceiveCommits { | ||||
|       ReplaceOp.Factory replaceOpFactory, | ||||
|       RetryHelper retryHelper, | ||||
|       RequestScopePropagator requestScopePropagator, | ||||
|       ReviewDb db, | ||||
|       Sequences seq, | ||||
|       SetHashtagsOp.Factory hashtagsFactory, | ||||
|       SubmoduleOp.Factory subOpFactory, | ||||
| @@ -412,7 +409,6 @@ class ReceiveCommits { | ||||
|     this.commitValidatorFactory = commitValidatorFactory; | ||||
|     this.createRefControl = createRefControl; | ||||
|     this.createGroupPermissionSyncer = createGroupPermissionSyncer; | ||||
|     this.db = db; | ||||
|     this.editUtil = editUtil; | ||||
|     this.hashtagsFactory = hashtagsFactory; | ||||
|     this.indexer = indexer; | ||||
|   | ||||
| @@ -37,14 +37,10 @@ import com.google.gerrit.server.plugincontext.PluginSetContext; | ||||
| import com.google.gerrit.server.query.change.ChangeData; | ||||
| import com.google.gerrit.server.util.RequestContext; | ||||
| import com.google.gerrit.server.util.ThreadLocalRequestContext; | ||||
| import com.google.gwtorm.server.OrmException; | ||||
| import com.google.gwtorm.server.SchemaFactory; | ||||
| import com.google.inject.OutOfScopeException; | ||||
| import com.google.inject.Provider; | ||||
| import com.google.inject.ProvisionException; | ||||
| import com.google.inject.assistedinject.Assisted; | ||||
| import com.google.inject.assistedinject.AssistedInject; | ||||
| import com.google.inject.util.Providers; | ||||
| import java.io.IOException; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| @@ -83,7 +79,6 @@ public class ChangeIndexer { | ||||
|  | ||||
|   @Nullable private final ChangeIndexCollection indexes; | ||||
|   @Nullable private final ChangeIndex index; | ||||
|   private final SchemaFactory<ReviewDb> schemaFactory; | ||||
|   private final ChangeData.Factory changeDataFactory; | ||||
|   private final ThreadLocalRequestContext context; | ||||
|   private final ListeningExecutorService batchExecutor; | ||||
| @@ -95,7 +90,6 @@ public class ChangeIndexer { | ||||
|   @AssistedInject | ||||
|   ChangeIndexer( | ||||
|       @GerritServerConfig Config cfg, | ||||
|       SchemaFactory<ReviewDb> schemaFactory, | ||||
|       ChangeData.Factory changeDataFactory, | ||||
|       ThreadLocalRequestContext context, | ||||
|       PluginSetContext<ChangeIndexedListener> indexedListeners, | ||||
| @@ -104,7 +98,6 @@ public class ChangeIndexer { | ||||
|       @Assisted ListeningExecutorService executor, | ||||
|       @Assisted ChangeIndex index) { | ||||
|     this.executor = executor; | ||||
|     this.schemaFactory = schemaFactory; | ||||
|     this.changeDataFactory = changeDataFactory; | ||||
|     this.context = context; | ||||
|     this.indexedListeners = indexedListeners; | ||||
| @@ -117,7 +110,6 @@ public class ChangeIndexer { | ||||
|  | ||||
|   @AssistedInject | ||||
|   ChangeIndexer( | ||||
|       SchemaFactory<ReviewDb> schemaFactory, | ||||
|       @GerritServerConfig Config cfg, | ||||
|       ChangeData.Factory changeDataFactory, | ||||
|       ThreadLocalRequestContext context, | ||||
| @@ -127,7 +119,6 @@ public class ChangeIndexer { | ||||
|       @Assisted ListeningExecutorService executor, | ||||
|       @Assisted ChangeIndexCollection indexes) { | ||||
|     this.executor = executor; | ||||
|     this.schemaFactory = schemaFactory; | ||||
|     this.changeDataFactory = changeDataFactory; | ||||
|     this.context = context; | ||||
|     this.indexedListeners = indexedListeners; | ||||
| @@ -313,7 +304,7 @@ public class ChangeIndexer { | ||||
|       this.id = id; | ||||
|     } | ||||
|  | ||||
|     protected abstract T callImpl(Provider<ReviewDb> db) throws Exception; | ||||
|     protected abstract T callImpl() throws Exception; | ||||
|  | ||||
|     @Override | ||||
|     public abstract String toString(); | ||||
| @@ -324,20 +315,6 @@ public class ChangeIndexer { | ||||
|         final AtomicReference<Provider<ReviewDb>> dbRef = Atomics.newReference(); | ||||
|         RequestContext newCtx = | ||||
|             new RequestContext() { | ||||
|               @Override | ||||
|               public Provider<ReviewDb> getReviewDbProvider() { | ||||
|                 Provider<ReviewDb> db = dbRef.get(); | ||||
|                 if (db == null) { | ||||
|                   try { | ||||
|                     db = Providers.of(schemaFactory.open()); | ||||
|                   } catch (OrmException e) { | ||||
|                     throw new ProvisionException("error opening ReviewDb", e); | ||||
|                   } | ||||
|                   dbRef.set(db); | ||||
|                 } | ||||
|                 return db; | ||||
|               } | ||||
|  | ||||
|               @Override | ||||
|               public CurrentUser getUser() { | ||||
|                 throw new OutOfScopeException("No user during ChangeIndexer"); | ||||
| @@ -345,7 +322,7 @@ public class ChangeIndexer { | ||||
|             }; | ||||
|         RequestContext oldCtx = context.setContext(newCtx); | ||||
|         try { | ||||
|           return callImpl(newCtx.getReviewDbProvider()); | ||||
|           return callImpl(); | ||||
|         } finally { | ||||
|           context.setContext(oldCtx); | ||||
|           Provider<ReviewDb> db = dbRef.get(); | ||||
| @@ -366,7 +343,7 @@ public class ChangeIndexer { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Void callImpl(Provider<ReviewDb> db) throws Exception { | ||||
|     public Void callImpl() throws Exception { | ||||
|       ChangeData cd = changeDataFactory.create(project, id); | ||||
|       index(cd); | ||||
|       return null; | ||||
| @@ -410,7 +387,7 @@ public class ChangeIndexer { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Boolean callImpl(Provider<ReviewDb> db) throws Exception { | ||||
|     public Boolean callImpl() throws Exception { | ||||
|       try { | ||||
|         if (stalenessChecker.isStale(id)) { | ||||
|           indexImpl(changeDataFactory.create(project, id)); | ||||
|   | ||||
| @@ -29,12 +29,8 @@ import com.google.gerrit.server.config.SendEmailExecutor; | ||||
| import com.google.gerrit.server.mail.send.MergedSender; | ||||
| import com.google.gerrit.server.util.RequestContext; | ||||
| import com.google.gerrit.server.util.ThreadLocalRequestContext; | ||||
| import com.google.gwtorm.server.OrmException; | ||||
| import com.google.gwtorm.server.SchemaFactory; | ||||
| import com.google.inject.Inject; | ||||
| import com.google.inject.OutOfScopeException; | ||||
| import com.google.inject.Provider; | ||||
| import com.google.inject.ProvisionException; | ||||
| import com.google.inject.assistedinject.Assisted; | ||||
| import java.util.concurrent.ExecutorService; | ||||
| import java.util.concurrent.Future; | ||||
| @@ -53,7 +49,6 @@ class EmailMerge implements Runnable, RequestContext { | ||||
|  | ||||
|   private final ExecutorService sendEmailsExecutor; | ||||
|   private final MergedSender.Factory mergedSenderFactory; | ||||
|   private final SchemaFactory<ReviewDb> schemaFactory; | ||||
|   private final ThreadLocalRequestContext requestContext; | ||||
|   private final IdentifiedUser.GenericFactory identifiedUserFactory; | ||||
|  | ||||
| @@ -69,7 +64,6 @@ class EmailMerge implements Runnable, RequestContext { | ||||
|   EmailMerge( | ||||
|       @SendEmailExecutor ExecutorService executor, | ||||
|       MergedSender.Factory mergedSenderFactory, | ||||
|       SchemaFactory<ReviewDb> schemaFactory, | ||||
|       ThreadLocalRequestContext requestContext, | ||||
|       IdentifiedUser.GenericFactory identifiedUserFactory, | ||||
|       @Assisted Project.NameKey project, | ||||
| @@ -79,7 +73,6 @@ class EmailMerge implements Runnable, RequestContext { | ||||
|       @Assisted ListMultimap<RecipientType, Account.Id> accountsToNotify) { | ||||
|     this.sendEmailsExecutor = executor; | ||||
|     this.mergedSenderFactory = mergedSenderFactory; | ||||
|     this.schemaFactory = schemaFactory; | ||||
|     this.requestContext = requestContext; | ||||
|     this.identifiedUserFactory = identifiedUserFactory; | ||||
|     this.project = project; | ||||
| @@ -128,21 +121,4 @@ class EmailMerge implements Runnable, RequestContext { | ||||
|     } | ||||
|     throw new OutOfScopeException("No user on email thread"); | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public Provider<ReviewDb> getReviewDbProvider() { | ||||
|     return new Provider<ReviewDb>() { | ||||
|       @Override | ||||
|       public ReviewDb get() { | ||||
|         if (db == null) { | ||||
|           try { | ||||
|             db = schemaFactory.open(); | ||||
|           } catch (OrmException e) { | ||||
|             throw new ProvisionException("Cannot open ReviewDb", e); | ||||
|           } | ||||
|         } | ||||
|         return db; | ||||
|       } | ||||
|     }; | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -14,12 +14,9 @@ | ||||
|  | ||||
| package com.google.gerrit.server.util; | ||||
|  | ||||
| import com.google.gerrit.reviewdb.server.ReviewDb; | ||||
| import com.google.gerrit.server.AnonymousUser; | ||||
| import com.google.gerrit.server.CurrentUser; | ||||
| import com.google.inject.Inject; | ||||
| import com.google.inject.Provider; | ||||
| import com.google.inject.ProvisionException; | ||||
| import com.google.inject.Singleton; | ||||
|  | ||||
| /** | ||||
| @@ -40,14 +37,4 @@ public class FallbackRequestContext implements RequestContext { | ||||
|   public CurrentUser getUser() { | ||||
|     return user; | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public Provider<ReviewDb> getReviewDbProvider() { | ||||
|     return new Provider<ReviewDb>() { | ||||
|       @Override | ||||
|       public ReviewDb get() { | ||||
|         throw new ProvisionException("Automatic ReviewDb only available in request scope"); | ||||
|       } | ||||
|     }; | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -17,7 +17,6 @@ package com.google.gerrit.server.util; | ||||
| import com.google.gerrit.common.Nullable; | ||||
| import com.google.gerrit.server.RemotePeer; | ||||
| import com.google.gerrit.server.config.CanonicalWebUrl; | ||||
| import com.google.gerrit.server.config.RequestScopedReviewDbProvider; | ||||
| import com.google.inject.Inject; | ||||
| import com.google.inject.Key; | ||||
| import com.google.inject.Provider; | ||||
| @@ -41,9 +40,8 @@ public class GuiceRequestScopePropagator extends RequestScopePropagator { | ||||
|   GuiceRequestScopePropagator( | ||||
|       @CanonicalWebUrl @Nullable Provider<String> urlProvider, | ||||
|       @RemotePeer Provider<SocketAddress> remotePeerProvider, | ||||
|       ThreadLocalRequestContext local, | ||||
|       Provider<RequestScopedReviewDbProvider> dbProviderProvider) { | ||||
|     super(ServletScopes.REQUEST, local, dbProviderProvider); | ||||
|       ThreadLocalRequestContext local) { | ||||
|     super(ServletScopes.REQUEST, local); | ||||
|     this.url = urlProvider != null ? urlProvider.get() : null; | ||||
|     this.peer = remotePeerProvider.get(); | ||||
|   } | ||||
|   | ||||
| @@ -52,11 +52,6 @@ public class ManualRequestContext implements RequestContext, AutoCloseable { | ||||
|     return userProvider.get(); | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public Provider<ReviewDb> getReviewDbProvider() { | ||||
|     return db; | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public void close() { | ||||
|     requestContext.setContext(old); | ||||
|   | ||||
| @@ -14,11 +14,8 @@ | ||||
|  | ||||
| package com.google.gerrit.server.util; | ||||
|  | ||||
| import com.google.gerrit.reviewdb.server.ReviewDb; | ||||
| import com.google.gerrit.server.CurrentUser; | ||||
| import com.google.gerrit.server.PluginUser; | ||||
| import com.google.inject.Provider; | ||||
| import com.google.inject.ProvisionException; | ||||
|  | ||||
| /** RequestContext active while plugins load or unload. */ | ||||
| public class PluginRequestContext implements RequestContext { | ||||
| @@ -32,14 +29,4 @@ public class PluginRequestContext implements RequestContext { | ||||
|   public CurrentUser getUser() { | ||||
|     return user; | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public Provider<ReviewDb> getReviewDbProvider() { | ||||
|     return new Provider<ReviewDb>() { | ||||
|       @Override | ||||
|       public ReviewDb get() { | ||||
|         throw new ProvisionException("Automatic ReviewDb only available in request scope"); | ||||
|       } | ||||
|     }; | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -14,9 +14,7 @@ | ||||
|  | ||||
| package com.google.gerrit.server.util; | ||||
|  | ||||
| import com.google.gerrit.reviewdb.server.ReviewDb; | ||||
| import com.google.gerrit.server.CurrentUser; | ||||
| import com.google.inject.Provider; | ||||
|  | ||||
| /** | ||||
|  * The RequestContext is an interface exposing the fields that are needed by the GerritGlobalModule | ||||
| @@ -24,6 +22,4 @@ import com.google.inject.Provider; | ||||
|  */ | ||||
| public interface RequestContext { | ||||
|   CurrentUser getUser(); | ||||
|  | ||||
|   Provider<ReviewDb> getReviewDbProvider(); | ||||
| } | ||||
|   | ||||
| @@ -18,10 +18,8 @@ import static java.util.Objects.requireNonNull; | ||||
|  | ||||
| import com.google.common.base.Throwables; | ||||
| import com.google.gerrit.reviewdb.client.Project; | ||||
| import com.google.gerrit.reviewdb.server.ReviewDb; | ||||
| import com.google.gerrit.server.CurrentUser; | ||||
| import com.google.gerrit.server.RequestCleanup; | ||||
| import com.google.gerrit.server.config.RequestScopedReviewDbProvider; | ||||
| import com.google.gerrit.server.git.ProjectRunnable; | ||||
| import com.google.inject.Key; | ||||
| import com.google.inject.Provider; | ||||
| @@ -47,15 +45,10 @@ public abstract class RequestScopePropagator { | ||||
|  | ||||
|   private final Scope scope; | ||||
|   private final ThreadLocalRequestContext local; | ||||
|   private final Provider<RequestScopedReviewDbProvider> dbProviderProvider; | ||||
|  | ||||
|   protected RequestScopePropagator( | ||||
|       Scope scope, | ||||
|       ThreadLocalRequestContext local, | ||||
|       Provider<RequestScopedReviewDbProvider> dbProviderProvider) { | ||||
|   protected RequestScopePropagator(Scope scope, ThreadLocalRequestContext local) { | ||||
|     this.scope = scope; | ||||
|     this.local = local; | ||||
|     this.dbProviderProvider = dbProviderProvider; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
| @@ -181,11 +174,6 @@ public abstract class RequestScopePropagator { | ||||
|                 public CurrentUser getUser() { | ||||
|                   return context.getUser(); | ||||
|                 } | ||||
|  | ||||
|                 @Override | ||||
|                 public Provider<ReviewDb> getReviewDbProvider() { | ||||
|                   return dbProviderProvider.get(); | ||||
|                 } | ||||
|               }); | ||||
|       try { | ||||
|         return callable.call(); | ||||
|   | ||||
| @@ -14,12 +14,9 @@ | ||||
|  | ||||
| package com.google.gerrit.server.util; | ||||
|  | ||||
| import com.google.gerrit.reviewdb.server.ReviewDb; | ||||
| import com.google.gerrit.server.CurrentUser; | ||||
| import com.google.gerrit.server.InternalUser; | ||||
| import com.google.inject.Inject; | ||||
| import com.google.inject.Provider; | ||||
| import com.google.inject.ProvisionException; | ||||
|  | ||||
| /** RequestContext with an InternalUser making the internals visible. */ | ||||
| public class ServerRequestContext implements RequestContext { | ||||
| @@ -34,14 +31,4 @@ public class ServerRequestContext implements RequestContext { | ||||
|   public CurrentUser getUser() { | ||||
|     return user; | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public Provider<ReviewDb> getReviewDbProvider() { | ||||
|     return new Provider<ReviewDb>() { | ||||
|       @Override | ||||
|       public ReviewDb get() { | ||||
|         throw new ProvisionException("Automatic ReviewDb only available in request scope"); | ||||
|       } | ||||
|     }; | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -17,7 +17,6 @@ package com.google.gerrit.server.util; | ||||
| import com.google.common.base.MoreObjects; | ||||
| import com.google.gerrit.common.Nullable; | ||||
| import com.google.gerrit.common.errors.NotSignedInException; | ||||
| import com.google.gerrit.reviewdb.server.ReviewDb; | ||||
| import com.google.gerrit.server.CurrentUser; | ||||
| import com.google.gerrit.server.IdentifiedUser; | ||||
| import com.google.inject.AbstractModule; | ||||
| @@ -63,11 +62,6 @@ public class ThreadLocalRequestContext { | ||||
|         } | ||||
|         throw new ProvisionException(NotSignedInException.MESSAGE, new NotSignedInException()); | ||||
|       } | ||||
|  | ||||
|       @Provides | ||||
|       ReviewDb provideReviewDb(RequestContext ctx) { | ||||
|         return ctx.getReviewDbProvider().get(); | ||||
|       } | ||||
|     }; | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -14,9 +14,7 @@ | ||||
|  | ||||
| package com.google.gerrit.server.util; | ||||
|  | ||||
| import com.google.gerrit.server.config.RequestScopedReviewDbProvider; | ||||
| import com.google.inject.OutOfScopeException; | ||||
| import com.google.inject.Provider; | ||||
| import com.google.inject.Scope; | ||||
| import java.util.concurrent.Callable; | ||||
|  | ||||
| @@ -31,11 +29,8 @@ public abstract class ThreadLocalRequestScopePropagator<C> extends RequestScopeP | ||||
|   private final ThreadLocal<C> threadLocal; | ||||
|  | ||||
|   protected ThreadLocalRequestScopePropagator( | ||||
|       Scope scope, | ||||
|       ThreadLocal<C> threadLocal, | ||||
|       ThreadLocalRequestContext local, | ||||
|       Provider<RequestScopedReviewDbProvider> dbProviderProvider) { | ||||
|     super(scope, local, dbProviderProvider); | ||||
|       Scope scope, ThreadLocal<C> threadLocal, ThreadLocalRequestContext local) { | ||||
|     super(scope, local); | ||||
|     this.threadLocal = threadLocal; | ||||
|   } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Dave Borowitz
					Dave Borowitz