Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-05-11 08:51:10 +0000
committerEike Stepper2008-05-11 08:51:10 +0000
commitb7750b38b96d2171a838496841f48786b9c85806 (patch)
tree82fb9fd3b827d0483b9bdc3941b29a414f5738b7 /plugins/org.eclipse.net4j.db
parentc4ea351383a7164db10672758584e26296f35221 (diff)
downloadcdo-b7750b38b96d2171a838496841f48786b9c85806.tar.gz
cdo-b7750b38b96d2171a838496841f48786b9c85806.tar.xz
cdo-b7750b38b96d2171a838496841f48786b9c85806.zip
Added store test framework
Diffstat (limited to 'plugins/org.eclipse.net4j.db')
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBAdapter.java5
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchema.java8
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBAdapter.java61
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBSchema.java29
4 files changed, 100 insertions, 3 deletions
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBAdapter.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBAdapter.java
index 13f126eb0c..de216e5f6b 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBAdapter.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBAdapter.java
@@ -20,6 +20,7 @@ import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.Statement;
+import java.util.Collection;
import java.util.Set;
/**
@@ -41,6 +42,10 @@ public interface IDBAdapter
public boolean createTable(IDBTable table, Statement statement) throws DBException;
+ public Collection<IDBTable> dropTables(Iterable<? extends IDBTable> tables, Connection connection) throws DBException;
+
+ public boolean dropTable(IDBTable table, Statement statement);
+
public String mangleTableName(String name, int attempt);
public String mangleFieldName(String name, int attempt);
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchema.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchema.java
index 7008f01f3c..c4b4c65ba6 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchema.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchema.java
@@ -32,7 +32,13 @@ public interface IDBSchema extends IDBSchemaElement
public Set<IDBTable> create(IDBAdapter dbAdapter, Connection connection) throws DBException;
+ public Set<IDBTable> create(IDBAdapter dbAdapter, DataSource dataSource) throws DBException;
+
public Set<IDBTable> create(IDBAdapter dbAdapter, IDBConnectionProvider connectionProvider) throws DBException;
- public Set<IDBTable> create(IDBAdapter dbAdapter, DataSource dataSource) throws DBException;
+ public void drop(IDBAdapter dbAdapter, Connection connection) throws DBException;
+
+ public void drop(IDBAdapter dbAdapter, DataSource dataSource) throws DBException;
+
+ public void drop(IDBAdapter dbAdapter, IDBConnectionProvider connectionProvider) throws DBException;
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBAdapter.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBAdapter.java
index 5a7e2e62ac..56afa34d13 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBAdapter.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBAdapter.java
@@ -28,8 +28,11 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
/**
@@ -142,6 +145,63 @@ public abstract class DBAdapter implements IDBAdapter
return created;
}
+ public Collection<IDBTable> dropTables(Iterable<? extends IDBTable> tables, Connection connection) throws DBException
+ {
+ List<IDBTable> droppedTables = new ArrayList<IDBTable>();
+ Statement statement = null;
+
+ try
+ {
+ statement = connection.createStatement();
+ for (IDBTable table : tables)
+ {
+ if (dropTable(table, statement))
+ {
+ droppedTables.add(table);
+ }
+ }
+ }
+ catch (SQLException ex)
+ {
+ OM.LOG.error(ex);
+ }
+ finally
+ {
+ DBUtil.close(statement);
+ }
+
+ return droppedTables;
+ }
+
+ public boolean dropTable(IDBTable table, Statement statement)
+ {
+ try
+ {
+ String sql = getDropTableSQL(table);
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(sql);
+ }
+
+ statement.execute(sql);
+ return true;
+ }
+ catch (SQLException ex)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(ex.getMessage());
+ }
+
+ return false;
+ }
+ }
+
+ protected String getDropTableSQL(IDBTable table)
+ {
+ return "DROP TABLE " + table;
+ }
+
public String mangleTableName(String name, int attempt)
{
return mangleName(name, getMaximumTableNameLength(), attempt);
@@ -200,6 +260,7 @@ public abstract class DBAdapter implements IDBAdapter
{
TRACER.trace(sql);
}
+
statement.execute(sql);
DBIndex[] indices = table.getIndices();
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBSchema.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBSchema.java
index ff32a4e083..d3e281ee8b 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBSchema.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBSchema.java
@@ -93,6 +93,11 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
return dbAdapter.createTables(tables.values(), connection);
}
+ public Set<IDBTable> create(IDBAdapter dbAdapter, DataSource dataSource) throws DBException
+ {
+ return create(dbAdapter, DBUtil.createConnectionProvider(dataSource));
+ }
+
public Set<IDBTable> create(IDBAdapter dbAdapter, IDBConnectionProvider connectionProvider) throws DBException
{
Connection connection = null;
@@ -108,9 +113,29 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
}
}
- public Set<IDBTable> create(IDBAdapter dbAdapter, DataSource dataSource) throws DBException
+ public void drop(IDBAdapter dbAdapter, Connection connection) throws DBException
{
- return create(dbAdapter, DBUtil.createConnectionProvider(dataSource));
+ dbAdapter.dropTables(tables.values(), connection);
+ }
+
+ public void drop(IDBAdapter dbAdapter, DataSource dataSource) throws DBException
+ {
+ drop(dbAdapter, DBUtil.createConnectionProvider(dataSource));
+ }
+
+ public void drop(IDBAdapter dbAdapter, IDBConnectionProvider connectionProvider) throws DBException
+ {
+ Connection connection = null;
+
+ try
+ {
+ connection = connectionProvider.getConnection();
+ drop(dbAdapter, connection);
+ }
+ finally
+ {
+ DBUtil.close(connection);
+ }
}
void assertUnlocked() throws DBException

Back to the top