Remove ReviewDb DataSource from WebAppInitializer

Change-Id: I5c5eba110b3fe6cfb9763f38ede71228e6da07f5
This commit is contained in:
Dave Borowitz
2018-12-17 09:26:39 -08:00
parent b6106e86a8
commit 1ff45113b5
4 changed files with 0 additions and 118 deletions

View File

@@ -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);
}

View File

@@ -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.
}
}
}

View File

@@ -14,7 +14,6 @@
package com.google.gerrit.httpd.init;
import static com.google.inject.Scopes.SINGLETON;
import static com.google.inject.Stage.PRODUCTION;
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.raw.StaticModule;
import com.google.gerrit.lifecycle.LifecycleManager;
import com.google.gerrit.lifecycle.LifecycleModule;
import com.google.gerrit.lucene.LuceneIndexModule;
import com.google.gerrit.metrics.dropwizard.DropWizardMetricMaker;
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.Provider;
import com.google.inject.ProvisionException;
import com.google.inject.name.Names;
import com.google.inject.servlet.GuiceFilter;
import com.google.inject.servlet.GuiceServletContextListener;
import com.google.inject.spi.Message;
@@ -125,7 +122,6 @@ import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.sql.DataSource;
import org.eclipse.jgit.lib.Config;
/** Configures the web application environment for Gerrit Code Review. */
@@ -262,16 +258,6 @@ public class WebAppInitializer extends GuiceServletContextListener implements Fi
Module configModule = new GerritServerConfigModule();
modules.add(configModule);
} 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 DropWizardMetricMaker.ApiModule());