Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-03-12 07:48:24 +0000
committerEike Stepper2013-03-12 08:11:57 +0000
commit077d8780066f74d02b2716d329ef55afbd1d41ee (patch)
tree5db9211b8ced79ded9eb6a2ae7da70800c6ab1cd /plugins/org.eclipse.net4j.db
parentf86cc1a1116425a9bc0ace0dfc1aa1b354f51cca (diff)
downloadcdo-077d8780066f74d02b2716d329ef55afbd1d41ee.tar.gz
cdo-077d8780066f74d02b2716d329ef55afbd1d41ee.tar.xz
cdo-077d8780066f74d02b2716d329ef55afbd1d41ee.zip
[401763] Make CDO Server more robust against data dictionary changes
https://bugs.eclipse.org/bugs/show_bug.cgi?id=401763
Diffstat (limited to 'plugins/org.eclipse.net4j.db')
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java133
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchema.java5
2 files changed, 82 insertions, 56 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 32f3789876..ea485c7c4b 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
@@ -171,6 +171,50 @@ public final class DBUtil
return new DBDatabase((DBAdapter)adapter, connectionProvider, schemaName);
}
+ // /**
+ // * @since 4.2
+ // */
+ // public static <T> T updateSchema(IDBConnectionProvider connectionProvider, RunnableWithConnection<T> runnable)
+ // {
+ // return execute(connectionProvider, new RunnableWithConnection<T>()
+ // {
+ // public T run(Connection connection) throws SQLException
+ // {
+ // return null;
+ // }
+ // });
+ // }
+ //
+ // /**
+ // * @since 4.2
+ // */
+ // public static <T> T updateSchema(Connection connection, RunnableWithConnection<T> runnable)
+ // {
+ // DBConnection dbConnection = null;
+ //
+ // try
+ // {
+ // if (connection instanceof DBConnection)
+ // {
+ // dbConnection = (DBConnection)connection;
+ // dbConnection.getDatabase().beginSchemaAccess(true);
+ // }
+ //
+ // return runnable.run(connection);
+ // }
+ // catch (SQLException ex)
+ // {
+ // throw new DBException(ex);
+ // }
+ // finally
+ // {
+ // if (dbConnection != null)
+ // {
+ //
+ // }
+ // }
+ // }
+
public static IDBSchema createSchema(String name)
{
return new org.eclipse.net4j.internal.db.ddl.DBSchema(name);
@@ -230,28 +274,36 @@ public final class DBUtil
}
/**
- * Can only be used when Eclipse is running. In standalone scenarios create the adapter instance by directly calling
- * the constructor of the adapter class.
+ * Retrieves an {@link IDBAdapter adapter} from the {@link IDBAdapter#REGISTRY adapter registry}.
+ * <p>
+ * If Eclipse is running adapters are automatically created from descriptors that are contributed to the extension point <code>org.eclipse.net4j.db.dbAdapters</code>.
+ * <p>
+ * In standalone scenarios the needed adapter instances must be registered with the {@link IDBAdapter#REGISTRY adapter registry} manually.
*/
public static IDBAdapter getDBAdapter(String adapterName)
{
return IDBAdapter.REGISTRY.get(adapterName);
}
- public static Exception close(Connection connection)
+ public static Exception close(ResultSet resultSet)
{
- if (connection != null)
+ if (resultSet != null)
{
try
{
- // Only for connections with autoCommit = false, we try a rollback
- // first to clear any open transactions.
- if (!connection.getAutoCommit())
+ Statement statement = resultSet.getStatement();
+ if (statement != null && statement.getMaxRows() != 0)
{
- rollback(connection);
+ statement.setMaxRows(0);
}
+ }
+ catch (Exception ignore)
+ {
+ }
- connection.close();
+ try
+ {
+ resultSet.close();
}
catch (Exception ex)
{
@@ -263,18 +315,6 @@ public final class DBUtil
return null;
}
- private static void rollback(Connection connection)
- {
- try
- {
- connection.rollback();
- }
- catch (Exception ex)
- {
- OM.LOG.error(ex);
- }
- }
-
public static Exception close(Statement statement)
{
if (statement != null)
@@ -293,25 +333,20 @@ public final class DBUtil
return null;
}
- public static Exception close(ResultSet resultSet)
+ public static Exception close(Connection connection)
{
- if (resultSet != null)
+ if (connection != null)
{
try
{
- Statement statement = resultSet.getStatement();
- if (statement != null && statement.getMaxRows() != 0)
+ // Only for connections with autoCommit = false, we try a rollback
+ // first to clear any open transactions.
+ if (!connection.getAutoCommit())
{
- statement.setMaxRows(0);
+ rollback(connection);
}
- }
- catch (Exception ignore)
- {
- }
- try
- {
- resultSet.close();
+ connection.close();
}
catch (Exception ex)
{
@@ -323,6 +358,18 @@ public final class DBUtil
return null;
}
+ private static void rollback(Connection connection)
+ {
+ try
+ {
+ connection.rollback();
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+
/**
* @since 3.0
* @deprecated As of 4.2 use {@link #getAllSchemaNames(Connection)}.
@@ -426,26 +473,6 @@ public final class DBUtil
}
/**
- * @since 4.2
- */
- public static void createSchema(DataSource dataSource, final String name, final boolean dropIfExists)
- {
- execute(createConnectionProvider(dataSource), new RunnableWithConnection<Object>()
- {
- public Object run(Connection connection) throws SQLException
- {
- if (dropIfExists)
- {
- execute(connection, "DROP SCHEMA IF EXISTS " + name);
- }
-
- execute(connection, "CREATE SCHEMA IF NOT EXISTS " + name);
- return null;
- }
- });
- }
-
- /**
* @since 4.0
*/
public static List<Exception> dropAllTables(Connection connection, String dbName)
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchema.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchema.java
index d35d963cbf..26459a0b61 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchema.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchema.java
@@ -28,9 +28,8 @@ import java.util.concurrent.ExecutorService;
/**
* @author Eike Stepper
- * @deprecated As of 4.2 call {@link DBUtil#createSchema(String)}, {@link DBUtil#createSchema(DataSource, String, boolean)},
- * {@link DBUtil#readSchema(IDBAdapter, Connection, IDBSchema)}, {@link DBUtil#readSchema(IDBAdapter, Connection, String)}
- * or {@link DBUtil#copySchema(IDBSchema)}.
+ * @deprecated As of 4.2 call {@link DBUtil#createSchema(String)}, {@link DBUtil#readSchema(IDBAdapter, Connection, IDBSchema)},
+ * {@link DBUtil#readSchema(IDBAdapter, Connection, String)} or {@link DBUtil#copySchema(IDBSchema)}.
*/
@Deprecated
public class DBSchema extends org.eclipse.net4j.internal.db.ddl.DBSchema

Back to the top