Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-04-07 13:31:57 +0000
committerEike Stepper2008-04-07 13:31:57 +0000
commitc763cd5ffa9f5941b09478c47cf836ecfcd43627 (patch)
tree641c1213e51b6655fa347e58ef07486b40071d86 /plugins/org.eclipse.net4j.db
parent1291bf4e3c6c1ba54e066925929e2929479e92dc (diff)
downloadcdo-c763cd5ffa9f5941b09478c47cf836ecfcd43627.tar.gz
cdo-c763cd5ffa9f5941b09478c47cf836ecfcd43627.tar.xz
cdo-c763cd5ffa9f5941b09478c47cf836ecfcd43627.zip
[222974] [CDO] DanglingHREFException after putEPackage() when using referencing models
https://bugs.eclipse.org/bugs/show_bug.cgi?id=222974
Diffstat (limited to 'plugins/org.eclipse.net4j.db')
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java65
1 files changed, 63 insertions, 2 deletions
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
index 97180bd51f..83c2903e47 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
@@ -23,10 +23,13 @@ import javax.sql.DataSource;
import java.sql.Clob;
import java.sql.Connection;
+import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import java.util.Map;
/**
@@ -119,7 +122,11 @@ public final class DBUtil
{
try
{
- resultSet.getStatement().setMaxRows(0);
+ Statement statement = resultSet.getStatement();
+ if (statement != null)
+ {
+ statement.setMaxRows(0);
+ }
}
catch (Exception ex)
{
@@ -140,6 +147,57 @@ public final class DBUtil
return null;
}
+ public static List<String> getAllTableNames(Connection connection, String dbName)
+ {
+ ResultSet tables = null;
+
+ try
+ {
+ List<String> names = new ArrayList<String>();
+ DatabaseMetaData metaData = connection.getMetaData();
+ tables = metaData.getTables(dbName, null, null, new String[] { "TABLE" });
+ while (tables.next())
+ {
+ String name = tables.getString(3);
+ names.add(name);
+ }
+
+ return names;
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ close(tables);
+ }
+ }
+
+ public static void dropAllTables(Connection connection, String dbName)
+ {
+ Statement statement = null;
+
+ try
+ {
+ statement = connection.createStatement();
+ for (String tableName : DBUtil.getAllTableNames(connection, dbName))
+ {
+ String sql = "DROP TABLE " + tableName;
+ DBUtil.trace(sql);
+ statement.execute(sql);
+ }
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ DBUtil.close(statement);
+ }
+ }
+
public static int selectMaximumInt(Connection connection, IDBField field) throws DBException
{
Number number = getMaximumNumber(connection, field);
@@ -383,6 +441,9 @@ public final class DBUtil
public static void trace(String sql)
{
- if (TRACER.isEnabled()) TRACER.trace(sql);
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(sql);
+ }
}
}

Back to the top