Remove ReviewDb DataSource from WebAppInitializer
Change-Id: I5c5eba110b3fe6cfb9763f38ede71228e6da07f5
This commit is contained in:
		| @@ -1,21 +0,0 @@ | |||||||
| // Copyright (C) 2014 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.extensions.persistence; |  | ||||||
|  |  | ||||||
| import javax.sql.DataSource; |  | ||||||
|  |  | ||||||
| public interface DataSourceInterceptor { |  | ||||||
|   DataSource intercept(String name, DataSource dataSource); |  | ||||||
| } |  | ||||||
| @@ -1,77 +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.httpd.init; |  | ||||||
|  |  | ||||||
| import com.google.gerrit.extensions.events.LifecycleListener; |  | ||||||
| import com.google.inject.Provider; |  | ||||||
| import com.google.inject.ProvisionException; |  | ||||||
| import com.google.inject.Singleton; |  | ||||||
| import javax.naming.InitialContext; |  | ||||||
| import javax.naming.NamingException; |  | ||||||
| import javax.sql.DataSource; |  | ||||||
|  |  | ||||||
| /** Provides access to the {@code ReviewDb} DataSource. */ |  | ||||||
| @Singleton |  | ||||||
| final class ReviewDbDataSourceProvider implements Provider<DataSource>, LifecycleListener { |  | ||||||
|   private DataSource ds; |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public synchronized DataSource get() { |  | ||||||
|     if (ds == null) { |  | ||||||
|       ds = open(); |  | ||||||
|     } |  | ||||||
|     return ds; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public void start() {} |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public synchronized void stop() { |  | ||||||
|     if (ds != null) { |  | ||||||
|       closeDataSource(ds); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   private DataSource open() { |  | ||||||
|     final String dsName = "java:comp/env/jdbc/ReviewDb"; |  | ||||||
|     try { |  | ||||||
|       return (DataSource) new InitialContext().lookup(dsName); |  | ||||||
|     } catch (NamingException namingErr) { |  | ||||||
|       throw new ProvisionException("No DataSource " + dsName, namingErr); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   private void closeDataSource(DataSource ds) { |  | ||||||
|     try { |  | ||||||
|       Class<?> type = Class.forName("org.apache.commons.dbcp.BasicDataSource"); |  | ||||||
|       if (type.isInstance(ds)) { |  | ||||||
|         type.getMethod("close").invoke(ds); |  | ||||||
|         return; |  | ||||||
|       } |  | ||||||
|     } catch (Throwable bad) { |  | ||||||
|       // Oh well, its not a Commons DBCP pooled connection. |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     try { |  | ||||||
|       Class<?> type = Class.forName("com.mchange.v2.c3p0.DataSources"); |  | ||||||
|       if (type.isInstance(ds)) { |  | ||||||
|         type.getMethod("destroy", DataSource.class).invoke(null, ds); |  | ||||||
|       } |  | ||||||
|     } catch (Throwable bad) { |  | ||||||
|       // Oh well, its not a c3p0 pooled connection. |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -14,7 +14,6 @@ | |||||||
|  |  | ||||||
| package com.google.gerrit.httpd.init; | package com.google.gerrit.httpd.init; | ||||||
|  |  | ||||||
| import static com.google.inject.Scopes.SINGLETON; |  | ||||||
| import static com.google.inject.Stage.PRODUCTION; | import static com.google.inject.Stage.PRODUCTION; | ||||||
|  |  | ||||||
| import com.google.common.base.Splitter; | import com.google.common.base.Splitter; | ||||||
| @@ -38,7 +37,6 @@ import com.google.gerrit.httpd.auth.openid.OpenIdModule; | |||||||
| import com.google.gerrit.httpd.plugins.HttpPluginModule; | import com.google.gerrit.httpd.plugins.HttpPluginModule; | ||||||
| import com.google.gerrit.httpd.raw.StaticModule; | import com.google.gerrit.httpd.raw.StaticModule; | ||||||
| import com.google.gerrit.lifecycle.LifecycleManager; | import com.google.gerrit.lifecycle.LifecycleManager; | ||||||
| import com.google.gerrit.lifecycle.LifecycleModule; |  | ||||||
| import com.google.gerrit.lucene.LuceneIndexModule; | import com.google.gerrit.lucene.LuceneIndexModule; | ||||||
| import com.google.gerrit.metrics.dropwizard.DropWizardMetricMaker; | import com.google.gerrit.metrics.dropwizard.DropWizardMetricMaker; | ||||||
| import com.google.gerrit.pgm.util.LogFileCompressor; | import com.google.gerrit.pgm.util.LogFileCompressor; | ||||||
| @@ -105,7 +103,6 @@ import com.google.inject.Key; | |||||||
| import com.google.inject.Module; | import com.google.inject.Module; | ||||||
| import com.google.inject.Provider; | import com.google.inject.Provider; | ||||||
| import com.google.inject.ProvisionException; | import com.google.inject.ProvisionException; | ||||||
| import com.google.inject.name.Names; |  | ||||||
| import com.google.inject.servlet.GuiceFilter; | import com.google.inject.servlet.GuiceFilter; | ||||||
| import com.google.inject.servlet.GuiceServletContextListener; | import com.google.inject.servlet.GuiceServletContextListener; | ||||||
| import com.google.inject.spi.Message; | import com.google.inject.spi.Message; | ||||||
| @@ -125,7 +122,6 @@ import javax.servlet.ServletException; | |||||||
| import javax.servlet.ServletRequest; | import javax.servlet.ServletRequest; | ||||||
| import javax.servlet.ServletResponse; | import javax.servlet.ServletResponse; | ||||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||||
| import javax.sql.DataSource; |  | ||||||
| import org.eclipse.jgit.lib.Config; | import org.eclipse.jgit.lib.Config; | ||||||
|  |  | ||||||
| /** Configures the web application environment for Gerrit Code Review. */ | /** Configures the web application environment for Gerrit Code Review. */ | ||||||
| @@ -262,16 +258,6 @@ public class WebAppInitializer extends GuiceServletContextListener implements Fi | |||||||
|       Module configModule = new GerritServerConfigModule(); |       Module configModule = new GerritServerConfigModule(); | ||||||
|       modules.add(configModule); |       modules.add(configModule); | ||||||
|     } else { |     } else { | ||||||
|       modules.add( |  | ||||||
|           new LifecycleModule() { |  | ||||||
|             @Override |  | ||||||
|             protected void configure() { |  | ||||||
|               bind(Key.get(DataSource.class, Names.named("ReviewDb"))) |  | ||||||
|                   .toProvider(ReviewDbDataSourceProvider.class) |  | ||||||
|                   .in(SINGLETON); |  | ||||||
|               listener().to(ReviewDbDataSourceProvider.class); |  | ||||||
|             } |  | ||||||
|           }); |  | ||||||
|       modules.add(new GerritServerConfigModule()); |       modules.add(new GerritServerConfigModule()); | ||||||
|     } |     } | ||||||
|     modules.add(new DropWizardMetricMaker.ApiModule()); |     modules.add(new DropWizardMetricMaker.ApiModule()); | ||||||
|   | |||||||
| @@ -1,11 +1,5 @@ | |||||||
| <?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||||
| <web-app> | <web-app> | ||||||
|   <resource-ref> |  | ||||||
|     <res-ref-name>jdbc/ReviewDb</res-ref-name> |  | ||||||
|     <res-type>javax.sql.DataSource</res-type> |  | ||||||
|     <res-auth>Container</res-auth> |  | ||||||
|   </resource-ref> |  | ||||||
|  |  | ||||||
|   <filter> |   <filter> | ||||||
|     <filter-name>guiceFilter</filter-name> |     <filter-name>guiceFilter</filter-name> | ||||||
|     <filter-class>com.google.gerrit.httpd.init.WebAppInitializer</filter-class> |     <filter-class>com.google.gerrit.httpd.init.WebAppInitializer</filter-class> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Dave Borowitz
					Dave Borowitz