Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-05-11 11:11:56 +0000
committerEike Stepper2008-05-11 11:11:56 +0000
commit4b0a9726955bcca76bba07bc6f30ece1ecf83720 (patch)
tree22f3e291b150a543d3ba7a2cd07f9f14dd3bf3cb /plugins/org.eclipse.net4j.db
parent56c8d531c3970c261276f98fb7ef96a4924a8113 (diff)
downloadcdo-4b0a9726955bcca76bba07bc6f30ece1ecf83720.tar.gz
cdo-4b0a9726955bcca76bba07bc6f30ece1ecf83720.tar.xz
cdo-4b0a9726955bcca76bba07bc6f30ece1ecf83720.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/ddl/IDBSchema.java7
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBSchema.java58
2 files changed, 65 insertions, 0 deletions
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 c4b4c65ba6..fc82187e34 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
@@ -16,6 +16,7 @@ import org.eclipse.net4j.db.IDBConnectionProvider;
import javax.sql.DataSource;
+import java.io.PrintStream;
import java.sql.Connection;
import java.util.Set;
@@ -41,4 +42,10 @@ public interface IDBSchema extends IDBSchemaElement
public void drop(IDBAdapter dbAdapter, DataSource dataSource) throws DBException;
public void drop(IDBAdapter dbAdapter, IDBConnectionProvider connectionProvider) throws DBException;
+
+ public void export(Connection connection, PrintStream out) throws DBException;
+
+ public void export(DataSource dataSource, PrintStream out) throws DBException;
+
+ public void export(IDBConnectionProvider connectionProvider, PrintStream out) throws DBException;
}
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 d3e281ee8b..93a0a70898 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
@@ -14,12 +14,15 @@ import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.db.IDBConnectionProvider;
+import org.eclipse.net4j.db.IDBRowHandler;
import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBTable;
import javax.sql.DataSource;
+import java.io.PrintStream;
import java.sql.Connection;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -138,6 +141,61 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
}
}
+ public void export(Connection connection, PrintStream out) throws DBException
+ {
+ for (DBTable table : getTables())
+ {
+ export(table, connection, out);
+ }
+ }
+
+ private void export(final DBTable table, Connection connection, final PrintStream out)
+ {
+ if (DBUtil.select(connection, new IDBRowHandler()
+ {
+ public boolean handle(int row, Object... values)
+ {
+ if (row == 0)
+ {
+ String tableName = table.getName();
+ out.println(tableName);
+ for (int i = 0; i < tableName.length(); i++)
+ {
+ out.print("=");
+ }
+
+ out.println();
+ }
+
+ out.println(Arrays.asList(values));
+ return true;
+ }
+ }, table.getFields()) > 0)
+ {
+ out.println();
+ }
+ }
+
+ public void export(DataSource dataSource, PrintStream out) throws DBException
+ {
+ export(DBUtil.createConnectionProvider(dataSource), out);
+ }
+
+ public void export(IDBConnectionProvider connectionProvider, PrintStream out) throws DBException
+ {
+ Connection connection = null;
+
+ try
+ {
+ connection = connectionProvider.getConnection();
+ export(connection, out);
+ }
+ finally
+ {
+ DBUtil.close(connection);
+ }
+ }
+
void assertUnlocked() throws DBException
{
if (locked)

Back to the top