diff options
author | Eike Stepper | 2013-05-19 16:49:46 +0000 |
---|---|---|
committer | Eike Stepper | 2013-05-19 17:07:12 +0000 |
commit | b533cfe47685b48e8c43984d04082110e5e648a3 (patch) | |
tree | 4b7ce654f420fc37fe7a8e4343d371aa7f7842a8 | |
parent | 24770a2a8333d5e18df024f1bbc851430b0e9734 (diff) | |
download | cdo-b533cfe47685b48e8c43984d04082110e5e648a3.tar.gz cdo-b533cfe47685b48e8c43984d04082110e5e648a3.tar.xz cdo-b533cfe47685b48e8c43984d04082110e5e648a3.zip |
[323006] [DB] Various PostgreSQL test failures
https://bugs.eclipse.org/bugs/show_bug.cgi?id=323006
3 files changed, 142 insertions, 166 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AbstractSetupDBConfig.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AbstractSetupDBConfig.java new file mode 100644 index 0000000000..698566303e --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AbstractSetupDBConfig.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2011, 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.emf.cdo.tests.db; + +import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation; + +import org.eclipse.net4j.db.DBUtil; + +import javax.sql.DataSource; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Victor Roldan Betancort + */ +public abstract class AbstractSetupDBConfig extends DBConfig +{ + private static final long serialVersionUID = 1L; + + private transient DataSource setupDataSource; + + private transient List<String> databases = new ArrayList<String>(); + + public AbstractSetupDBConfig(String name, boolean supportingAudits, boolean supportingBranches, boolean withRanges, + boolean copyOnBranch, IDGenerationLocation idGenerationLocation) + { + super(name, supportingAudits, supportingBranches, withRanges, copyOnBranch, idGenerationLocation); + } + + @Override + protected DataSource createDataSource(String repoName) + { + String dbName = "test_" + repoName; + initDatabase(dbName); + + return createDataSourceForDB(dbName); + } + + @Override + protected void deactivateRepositories() + { + super.deactivateRepositories(); + for (String dbName : databases) + { + dropDatabase(dbName); + } + } + + private void initDatabase(String dbName) + { + dropDatabase(dbName); + Connection connection = null; + Statement stmt = null; + + try + { + connection = getSetupDataSource().getConnection(); + stmt = connection.createStatement(); + stmt.execute("CREATE DATABASE " + dbName); + } + catch (SQLException ignore) + { + } + finally + { + DBUtil.close(stmt); + DBUtil.close(connection); + } + } + + private void dropDatabase(String dbName) + { + Connection connection = null; + Statement stmt = null; + + try + { + connection = getSetupDataSource().getConnection(); + stmt = connection.createStatement(); + stmt.execute("DROP DATABASE " + dbName); + } + catch (SQLException ignore) + { + } + finally + { + DBUtil.close(stmt); + DBUtil.close(connection); + } + } + + private DataSource getSetupDataSource() + { + if (setupDataSource == null) + { + setupDataSource = createDataSourceForDB(null); + } + + return setupDataSource; + } + + /** + * Note that <code>dbName</code> can be <code>null</code>, in which case a <i>setup</i> datasource must be returned. + * A connection form a setup< datasource can be used to create or drop other databases. + */ + protected abstract DataSource createDataSourceForDB(String dbName); +} diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/MysqlConfig.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/MysqlConfig.java index ba0c217fa2..00f9a890d6 100644 --- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/MysqlConfig.java +++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/MysqlConfig.java @@ -4,16 +4,14 @@ * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * Eike Stepper - initial API and implementation */ package org.eclipse.emf.cdo.tests.db; import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation; -import org.eclipse.emf.cdo.server.IRepository.Props; -import org.eclipse.net4j.db.DBUtil; import org.eclipse.net4j.db.IDBAdapter; import org.eclipse.net4j.db.mysql.MYSQLAdapter; @@ -21,17 +19,10 @@ import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - /** * @author Simon McDuff */ -public class MysqlConfig extends DBConfig +public class MysqlConfig extends AbstractSetupDBConfig { public static final String DB_ADAPTER_NAME = "Mysql"; @@ -48,10 +39,6 @@ public class MysqlConfig extends DBConfig private static final long serialVersionUID = 1L; - private transient DataSource setupDataSource; - - private transient List<String> databases = new ArrayList<String>(); - public MysqlConfig(boolean supportingAudits, boolean supportingBranches, IDGenerationLocation idGenerationLocation) { super(DB_ADAPTER_NAME, supportingAudits, supportingBranches, false, false, idGenerationLocation); @@ -70,98 +57,16 @@ public class MysqlConfig extends DBConfig } @Override - protected DataSource createDataSource(String repoName) - { - MysqlDataSource ds = new MysqlDataSource(); - - initDatabase("test_" + repoName); - - ds.setUrl("jdbc:mysql://" + MysqlConfig.HOST + "/test_" + repoName); - ds.setUser(MysqlConfig.USER); - if (MysqlConfig.PASS != null) - { - ds.setPassword(MysqlConfig.PASS); - } - - return ds; - } - - private void initDatabase(String dbName) - { - dropDatabase(dbName); - Connection connection = null; - Statement stmt = null; - - try - { - connection = getSetupDataSource().getConnection(); - stmt = connection.createStatement(); - stmt.execute("create database " + dbName); - } - catch (SQLException ignore) - { - } - finally - { - DBUtil.close(stmt); - DBUtil.close(connection); - } - } - - @Override - protected void deactivateRepositories() + protected DataSource createDataSourceForDB(String dbName) { - super.deactivateRepositories(); - for (String dbName : databases) + MysqlDataSource dataSource = new MysqlDataSource(); + dataSource.setUrl("jdbc:mysql://" + HOST); + dataSource.setUser(USER); + if (PASS != null) { - dropDatabase(dbName); + dataSource.setPassword(PASS); } - } - - private void dropDatabase(String dbName) - { - Connection connection = null; - Statement stmt = null; - try - { - connection = getSetupDataSource().getConnection(); - stmt = connection.createStatement(); - stmt.execute("DROP database " + dbName); - } - catch (SQLException ignore) - { - } - finally - { - DBUtil.close(stmt); - DBUtil.close(connection); - } - } - - private DataSource getSetupDataSource() - { - if (setupDataSource == null) - { - MysqlDataSource ds = new MysqlDataSource(); - ds.setUrl("jdbc:mysql://" + MysqlConfig.HOST); - ds.setUser(MysqlConfig.USER); - if (MysqlConfig.PASS != null) - { - ds.setPassword(MysqlConfig.PASS); - } - - setupDataSource = ds; - } - - return setupDataSource; - } - - @Override - protected void initRepositoryProperties(Map<String, String> props) - { - super.initRepositoryProperties(props); - props.put(Props.SUPPORTING_AUDITS, "true"); - props.put(Props.SUPPORTING_BRANCHES, "true"); + return dataSource; } } diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/PostgresqlConfig.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/PostgresqlConfig.java index c35c708403..3db45a6459 100644 --- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/PostgresqlConfig.java +++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/PostgresqlConfig.java @@ -11,35 +11,30 @@ package org.eclipse.emf.cdo.tests.db; import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation; -import org.eclipse.emf.cdo.tests.db.bundle.OM; -import org.eclipse.net4j.db.DBUtil; import org.eclipse.net4j.db.IDBAdapter; import org.eclipse.net4j.db.postgresql.PostgreSQLAdapter; -import org.eclipse.net4j.util.io.IOUtil; import org.postgresql.ds.PGSimpleDataSource; import javax.sql.DataSource; -import java.io.PrintWriter; -import java.sql.Connection; -import java.sql.SQLException; - /** * @author Victor Roldan Betancort */ -public class PostgresqlConfig extends DBConfig +public class PostgresqlConfig extends AbstractSetupDBConfig { public static final String DB_ADAPTER_NAME = "Postgresql"; - private static final long serialVersionUID = 1L; + public static final String HOST = "localhost"; - private transient PGSimpleDataSource dataSource; + public static final String USER = "postgres"; - // private transient PGSimpleDataSource setupDataSource; + public static final String PASS = "postgres"; - // private transient String currentRepositoryName; + public static final String SETUP_DATABASE_NAME = "postgres"; + + private static final long serialVersionUID = 1L; public PostgresqlConfig(boolean supportingAudits, boolean supportingBranches, IDGenerationLocation idGenerationLocation) @@ -60,60 +55,17 @@ public class PostgresqlConfig extends DBConfig } @Override - protected DataSource createDataSource(String repoName) + protected DataSource createDataSourceForDB(String dbName) { - dataSource = internalCreateDataSource(repoName); - - try - { - dataSource.setLogWriter(new PrintWriter(System.err)); - } - catch (SQLException ex) - { - OM.LOG.warn(ex.getMessage()); - } - - dropDatabase(); - - return dataSource; - } - - @Override - protected void deactivateRepositories() - { - super.deactivateRepositories(); - dropDatabase(); - dataSource = null; - } - - private void dropDatabase() - { - Connection connection = null; - - try - { - connection = dataSource.getConnection(); - String databaseName = dataSource.getDatabaseName(); - - DBUtil.dropAllTables(connection, databaseName); - } - catch (SQLException ex) - { - IOUtil.ERR().println(ex); - } - finally + PGSimpleDataSource dataSource = new PGSimpleDataSource(); + dataSource.setServerName(HOST); + dataSource.setDatabaseName(dbName == null ? SETUP_DATABASE_NAME : dbName); + dataSource.setUser(USER); + if (PASS != null) { - DBUtil.close(connection); + dataSource.setPassword(PASS); } - } - private PGSimpleDataSource internalCreateDataSource(String databaseName) - { - PGSimpleDataSource dataSource = new PGSimpleDataSource(); - dataSource.setServerName("localhost"); - dataSource.setDatabaseName(databaseName); - dataSource.setUser("postgres"); - dataSource.setPassword("postgres"); return dataSource; } } |