summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2009-07-21 07:07:08 (EDT)
committerStefan Winkler2009-07-21 07:07:08 (EDT)
commiteeda3b0d7e4654fee51b2fcb994045847846d7f8 (patch)
treee1ed78952727e0341b3ed85ab9f9abcbb227f97a
parenta671cb366a73b345f633e271f3728e71333da27d (diff)
downloadcdo-eeda3b0d7e4654fee51b2fcb994045847846d7f8.zip
cdo-eeda3b0d7e4654fee51b2fcb994045847846d7f8.tar.gz
cdo-eeda3b0d7e4654fee51b2fcb994045847846d7f8.tar.bz2
[284004] Support different store configurations for multiple repositories
https://bugs.eclipse.org/bugs/show_bug.cgi?id=284004
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBDerby.java57
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2.java73
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBHsqldb.java21
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBMysql.java40
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBStoreRepositoryConfig.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateConfig.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java18
7 files changed, 138 insertions, 81 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBDerby.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBDerby.java
index 2a05a61..2f0f0d5 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBDerby.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBDerby.java
@@ -26,6 +26,8 @@ import javax.sql.DataSource;
import java.io.File;
import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.HashMap;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -43,7 +45,7 @@ public class AllTestsDBDerby extends DBConfigs
@Override
protected void initConfigSuites(TestSuite parent)
{
- addScenario(parent, COMBINED, AllTestsDBDerby.Derby.ReusableFolder.INSTANCE, TCP, NATIVE);
+ addScenario(parent, COMBINED, AllTestsDBDerby.Derby.ReusableFolder.INSTANCE, JVM, NATIVE);
// addScenario(parent, COMBINED, AllTestsDBDerby.Derby.INSTANCE, TCP, NATIVE);
}
@@ -56,9 +58,7 @@ public class AllTestsDBDerby extends DBConfigs
public static final AllTestsDBDerby.Derby INSTANCE = new Derby("DBStore: Derby");
- protected transient File dbFolder;
-
- protected transient EmbeddedDataSource dataSource;
+ private transient ArrayList<File> dbFolders = new ArrayList<File>();
public Derby(String name)
{
@@ -78,32 +78,39 @@ public class AllTestsDBDerby extends DBConfigs
}
@Override
- protected DataSource createDataSource()
+ protected DataSource createDataSource(String repoName)
{
- dbFolder = createDBFolder();
- tearDownClean();
+ File dbFolder = createDBFolder(repoName);
+ dbFolders.add(dbFolder);
+
+ tearDownClean(dbFolder);
- dataSource = new EmbeddedDataSource();
+ EmbeddedDataSource dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName(dbFolder.getAbsolutePath());
dataSource.setCreateDatabase("create");
+
return dataSource;
}
@Override
public void tearDown() throws Exception
{
- tearDownClean();
+ for (File folder : dbFolders)
+ {
+ tearDownClean(folder);
+ }
+
super.tearDown();
}
- protected void tearDownClean()
+ protected void tearDownClean(File dbFolder)
{
IOUtil.delete(dbFolder);
}
- protected File createDBFolder()
+ protected File createDBFolder(String repo)
{
- return TMPUtil.createTempFolder("derby_", "_test", new File("/temp"));
+ return TMPUtil.createTempFolder("derby_" + repo + "_", "_test", new File("/temp"));
}
/**
@@ -115,7 +122,9 @@ public class AllTestsDBDerby extends DBConfigs
public static final ReusableFolder INSTANCE = new ReusableFolder("DBStore: Derby (Reusable Folder)");
- private static File reusableFolder;
+ private static HashMap<String, File> dbFolders = new HashMap<String, File>();
+
+ private static HashMap<File, EmbeddedDataSource> dataSources = new HashMap<File, EmbeddedDataSource>();
public ReusableFolder(String name)
{
@@ -123,27 +132,35 @@ public class AllTestsDBDerby extends DBConfigs
}
@Override
- protected DataSource createDataSource()
+ protected DataSource createDataSource(String repoName)
{
- dataSource = new EmbeddedDataSource();
+ EmbeddedDataSource dataSource = new EmbeddedDataSource();
+ File reusableFolder = dbFolders.get(repoName);
+
if (reusableFolder == null)
{
- reusableFolder = createDBFolder();
+ reusableFolder = createDBFolder(repoName);
IOUtil.delete(reusableFolder);
+ dbFolders.put(repoName, reusableFolder);
}
- dbFolder = reusableFolder;
- dataSource.setDatabaseName(dbFolder.getAbsolutePath());
+ dataSource.setDatabaseName(reusableFolder.getAbsolutePath());
dataSource.setCreateDatabase("create");
+ dataSources.put(reusableFolder, dataSource);
+
+ tearDownClean(reusableFolder);
+
return dataSource;
}
@Override
- protected void tearDownClean()
+ protected void tearDownClean(File folder)
{
- reusableFolder.deleteOnExit();
+ folder.deleteOnExit();
Connection connection = null;
+ EmbeddedDataSource dataSource = dataSources.get(folder);
+
try
{
connection = dataSource.getConnection();
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2.java
index f337f53..46ba078 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2.java
@@ -26,6 +26,8 @@ import javax.sql.DataSource;
import java.io.File;
import java.sql.Connection;
+import java.sql.Statement;
+import java.util.ArrayList;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -57,8 +59,6 @@ public class AllTestsDBH2 extends DBConfigs
protected transient File dbFolder;
- protected transient JdbcDataSource dataSource;
-
public H2(String name)
{
super(name);
@@ -77,13 +77,16 @@ public class AllTestsDBH2 extends DBConfigs
}
@Override
- protected DataSource createDataSource()
+ protected DataSource createDataSource(String repoName)
{
- dbFolder = createDBFolder();
- tearDownClean();
+ if (dbFolder == null)
+ {
+ dbFolder = createDBFolder();
+ tearDownClean();
+ }
- dataSource = new JdbcDataSource();
- dataSource.setURL("jdbc:h2:" + dbFolder.getAbsolutePath());
+ JdbcDataSource dataSource = new JdbcDataSource();
+ dataSource.setURL("jdbc:h2:" + dbFolder.getAbsolutePath() + "/h2test;SCHEMA=" + repoName);
return dataSource;
}
@@ -108,25 +111,52 @@ public class AllTestsDBH2 extends DBConfigs
private static File reusableFolder;
+ private static JdbcDataSource defaultDataSource;
+
+ private transient ArrayList<String> repoNames = new ArrayList<String>();
+
public ReusableFolder(String name)
{
super(name);
}
@Override
- protected DataSource createDataSource()
+ protected DataSource createDataSource(String repoName)
{
- dataSource = new JdbcDataSource();
if (reusableFolder == null)
{
reusableFolder = createDBFolder();
IOUtil.delete(reusableFolder);
}
-
dbFolder = reusableFolder;
- dataSource.setURL("jdbc:h2:" + dbFolder.getAbsolutePath());
- tearDownClean();
+ if (defaultDataSource == null)
+ {
+ defaultDataSource = new JdbcDataSource();
+ defaultDataSource.setURL("jdbc:h2:" + dbFolder.getAbsolutePath() + "/h2test");
+ }
+
+ Connection conn = null;
+ Statement stmt = null;
+ try
+ {
+ conn = defaultDataSource.getConnection();
+ stmt = conn.createStatement();
+ stmt.execute("DROP SCHEMA IF EXISTS " + repoName);
+ stmt.execute("CREATE SCHEMA " + repoName);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ DBUtil.close(conn);
+ DBUtil.close(stmt);
+ }
+
+ JdbcDataSource dataSource = new JdbcDataSource();
+ dataSource.setURL("jdbc:h2:" + dbFolder.getAbsolutePath() + "/h2test;SCHEMA=" + repoName);
return dataSource;
}
@@ -134,17 +164,23 @@ public class AllTestsDBH2 extends DBConfigs
@Override
protected void tearDownClean()
{
+ for (String repoName : repoNames)
+ {
+ tearDownClean(repoName);
+ }
+ }
+
+ protected void tearDownClean(String repoName)
+ {
reusableFolder.deleteOnExit();
Connection connection = null;
+ Statement stmt = null;
try
{
- connection = dataSource.getConnection();
- DBUtil.dropAllTables(connection, null); // null is the default catalog for H2.
- }
- catch (RuntimeException ex)
- {
- throw ex;
+ connection = defaultDataSource.getConnection();
+ stmt = connection.createStatement();
+ stmt.execute("DROP SCHEMA " + repoName);
}
catch (Exception ex)
{
@@ -152,6 +188,7 @@ public class AllTestsDBH2 extends DBConfigs
}
finally
{
+ DBUtil.close(stmt);
DBUtil.close(connection);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBHsqldb.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBHsqldb.java
index eedbbd1..77f6640 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBHsqldb.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBHsqldb.java
@@ -29,6 +29,7 @@ import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
+import java.util.ArrayList;
import java.util.List;
import junit.framework.Test;
@@ -47,7 +48,7 @@ public class AllTestsDBHsqldb extends DBConfigs
@Override
protected void initConfigSuites(TestSuite parent)
{
- addScenario(parent, COMBINED, AllTestsDBHsqldb.Hsqldb.INSTANCE, TCP, NATIVE);
+ addScenario(parent, COMBINED, AllTestsDBHsqldb.Hsqldb.INSTANCE, JVM, NATIVE);
}
@Override
@@ -70,7 +71,7 @@ public class AllTestsDBHsqldb extends DBConfigs
public static boolean USE_VERIFIER = false;
- private transient HSQLDBDataSource dataSource;
+ private transient ArrayList<HSQLDBDataSource> dataSources = new ArrayList<HSQLDBDataSource>();
public Hsqldb(String name)
{
@@ -90,10 +91,11 @@ public class AllTestsDBHsqldb extends DBConfigs
}
@Override
- protected DataSource createDataSource()
+ protected DataSource createDataSource(String repoName)
{
- dataSource = new HSQLDBDataSource();
- dataSource.setDatabase("jdbc:hsqldb:mem:dbtest");
+
+ HSQLDBDataSource dataSource = new HSQLDBDataSource();
+ dataSource.setDatabase("jdbc:hsqldb:mem:" + repoName);
dataSource.setUser("sa");
try
@@ -105,6 +107,8 @@ public class AllTestsDBHsqldb extends DBConfigs
OM.LOG.warn(ex.getMessage());
}
+ dataSources.add(dataSource);
+
return dataSource;
}
@@ -142,14 +146,14 @@ public class AllTestsDBHsqldb extends DBConfigs
private void shutDownHsqldb() throws SQLException
{
- if (dataSource != null)
+ for (HSQLDBDataSource ds : dataSources)
{
Connection connection = null;
Statement statement = null;
try
{
- connection = dataSource.getConnection();
+ connection = ds.getConnection();
statement = connection.createStatement();
statement.execute("SHUTDOWN");
}
@@ -157,9 +161,10 @@ public class AllTestsDBHsqldb extends DBConfigs
{
DBUtil.close(statement);
DBUtil.close(connection);
- dataSource = null;
}
}
+
+ dataSources.clear();
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBMysql.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBMysql.java
index c9a3dda..32c2a69 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBMysql.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBMysql.java
@@ -24,6 +24,8 @@ import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -41,7 +43,7 @@ public class AllTestsDBMysql extends DBConfigs
@Override
protected void initConfigSuites(TestSuite parent)
{
- addScenario(parent, COMBINED, AllTestsDBMysql.Mysql.INSTANCE, TCP, NATIVE);
+ addScenario(parent, COMBINED, AllTestsDBMysql.Mysql.INSTANCE, JVM, NATIVE);
}
/**
@@ -55,7 +57,7 @@ public class AllTestsDBMysql extends DBConfigs
private transient DataSource setupDataSource;
- private transient DataSource dataSource;
+ private transient ArrayList<String> databases = new ArrayList<String>();
public Mysql(String name)
{
@@ -75,58 +77,66 @@ public class AllTestsDBMysql extends DBConfigs
}
@Override
- protected DataSource createDataSource()
+ protected DataSource createDataSource(String repoName)
{
MysqlDataSource ds = new MysqlDataSource();
- ds.setUrl("jdbc:mysql://localhost/cdodb1");
+
+ initDatabase("test_" + repoName);
+
+ ds.setUrl("jdbc:mysql://localhost/test_" + repoName);
ds.setUser("sa");
- dataSource = ds;
- return dataSource;
+ return ds;
}
- @Override
- public void setUp() throws Exception
+ private void initDatabase(String dbName)
{
- dropDatabase();
+ dropDatabase(dbName);
Connection connection = null;
+ Statement stmt = null;
try
{
connection = getSetupDataSource().getConnection();
- connection.prepareStatement("create database cdodb1").execute();
+ stmt = connection.createStatement();
+ stmt.execute("create database " + dbName);
}
catch (SQLException ignore)
{
}
finally
{
+ DBUtil.close(stmt);
DBUtil.close(connection);
}
- super.setUp();
}
@Override
public void tearDown() throws Exception
{
super.tearDown();
- dropDatabase();
+ for (String dbName : databases)
+ {
+ dropDatabase(dbName);
+ }
}
- private void dropDatabase() throws Exception
+ private void dropDatabase(String dbName)
{
Connection connection = null;
-
+ Statement stmt = null;
try
{
connection = getSetupDataSource().getConnection();
- connection.prepareStatement("DROP database cdodb1").execute();
+ stmt = connection.createStatement();
+ stmt.execute("DROP database " + dbName);
}
catch (SQLException ignore)
{
}
finally
{
+ DBUtil.close(stmt);
DBUtil.close(connection);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBStoreRepositoryConfig.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBStoreRepositoryConfig.java
index c02e520..d3bce51 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBStoreRepositoryConfig.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBStoreRepositoryConfig.java
@@ -23,11 +23,11 @@ public abstract class DBStoreRepositoryConfig extends RepositoryConfig
}
@Override
- public IStore createStore()
+ public IStore createStore(String repoName)
{
IMappingStrategy mappingStrategy = createMappingStrategy();
IDBAdapter dbAdapter = createDBAdapter();
- DataSource dataSource = createDataSource();
+ DataSource dataSource = createDataSource(repoName);
return CDODBUtil.createStore(mappingStrategy, dbAdapter, DBUtil.createConnectionProvider(dataSource));
}
@@ -35,5 +35,5 @@ public abstract class DBStoreRepositoryConfig extends RepositoryConfig
protected abstract IDBAdapter createDBAdapter();
- protected abstract DataSource createDataSource();
+ protected abstract DataSource createDataSource(String repoName);
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateConfig.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateConfig.java
index 3bcca4e..3dfa92c 100644
--- a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateConfig.java
+++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateConfig.java
@@ -4,7 +4,7 @@
* 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
*/
@@ -61,7 +61,7 @@ public class HibernateConfig extends RepositoryConfig
}
@Override
- public IStore createStore()
+ protected IStore createStore(String repoName)
{
IHibernateMappingProvider mappingProvider = TeneoUtil.createMappingProvider();
return CDOHibernateUtil.createStore(mappingProvider);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java
index e624b9a..bf5b2b6 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java
@@ -48,8 +48,6 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
public static final String PROP_TEST_QUERY_HANDLER_PROVIDER = "test.repository.QueryHandlerProvider";
- public static final String PROP_TEST_STORE = "test.repository.Store";
-
private static final long serialVersionUID = 1L;
private transient Map<String, InternalRepository> repositories;
@@ -144,12 +142,7 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
protected InternalRepository createRepository(String name)
{
- IStore store = getTestStore();
- if (store == null)
- {
- store = createStore();
- }
-
+ IStore store = createStore(name);
Map<String, String> props = getRepositoryProperties();
InternalRepository repository = (InternalRepository)CDOServerUtil.createRepository(name, store, props);
InternalCDORevisionManager revisionManager = getTestRevisionManager();
@@ -175,7 +168,7 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
return repository;
}
- protected abstract IStore createStore();
+ protected abstract IStore createStore(String repoName);
protected InternalRepository getTestRepository()
{
@@ -197,11 +190,6 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
return (IQueryHandlerProvider)getTestProperty(PROP_TEST_QUERY_HANDLER_PROVIDER);
}
- protected IStore getTestStore()
- {
- return (IStore)getTestProperty(PROP_TEST_STORE);
- }
-
/**
* @author Eike Stepper
*/
@@ -217,7 +205,7 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
}
@Override
- protected IStore createStore()
+ protected IStore createStore(String repoName)
{
return MEMStoreUtil.createMEMStore();
}