Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-03-10 03:54:00 -0400
committerEike Stepper2013-03-11 06:26:17 -0400
commite281dd0e6474ce8d294459f1a7ae2d118591317b (patch)
treefa3ce9ac9065ad04e52d01649c0cb8b59f9c2b85
parent35f2316585607417e99e5dd5fe93541e1b9089d1 (diff)
downloadcdo-e281dd0e6474ce8d294459f1a7ae2d118591317b.tar.gz
cdo-e281dd0e6474ce8d294459f1a7ae2d118591317b.tar.xz
cdo-e281dd0e6474ce8d294459f1a7ae2d118591317b.zip
[401763] Make CDO Server more robust against data dictionary changes
https://bugs.eclipse.org/bugs/show_bug.cgi?id=401763
-rw-r--r--plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/internal/db/cache/DBRevisionCacheSchema.java17
-rw-r--r--plugins/org.eclipse.emf.cdo.server.lissome/src/org/eclipse/emf/cdo/server/internal/lissome/db/Index.java20
-rw-r--r--plugins/org.eclipse.emf.cdo.server.lissome/src/org/eclipse/emf/cdo/server/internal/lissome/db/Table.java2
-rw-r--r--plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/TestSchema.java17
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBDatabase.java25
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchemaElement.java5
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBDelta.java4
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBDatabase.java78
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBSchemaTransaction.java7
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBField.java7
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBIndex.java6
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBIndexField.java7
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBNamedElement.java4
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBSchema.java6
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBSchemaElement.java29
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBTable.java7
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBField.java114
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBIndex.java143
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBIndexField.java64
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBSchema.java191
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBSchemaElement.java284
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBTable.java206
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBField.java2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBIndex.java2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBIndexField.java2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBSchema.java2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBSchemaElement.java3
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBTable.java2
-rw-r--r--plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms.server.jdbc/src/org/eclipse/net4j/jms/server/internal/jdbc/JMSSchema.java17
-rw-r--r--plugins/org.eclipse.net4j.jms.server.jdbc/src/org/eclipse/net4j/jms/server/internal/jdbc/JMSSchema.java17
30 files changed, 1134 insertions, 156 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/internal/db/cache/DBRevisionCacheSchema.java b/plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/internal/db/cache/DBRevisionCacheSchema.java
index 8126370e4b..8c604e6c93 100644
--- a/plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/internal/db/cache/DBRevisionCacheSchema.java
+++ b/plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/internal/db/cache/DBRevisionCacheSchema.java
@@ -12,19 +12,19 @@
package org.eclipse.emf.cdo.common.internal.db.cache;
import org.eclipse.net4j.db.DBType;
+import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBIndex;
+import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBTable;
-import org.eclipse.net4j.spi.db.DBSchema;
+import org.eclipse.net4j.spi.db.ddl.InternalDBSchema;
/**
* @author Andre Dietisheim
*/
-public class DBRevisionCacheSchema extends DBSchema
+public class DBRevisionCacheSchema
{
- public static final DBRevisionCacheSchema INSTANCE = new DBRevisionCacheSchema();
-
- private static final long serialVersionUID = 1L;
+ public static final IDBSchema INSTANCE = DBUtil.createSchema("DBRevisionCache");
/**
* DBTable dbrevisioncache_revisions.
@@ -69,13 +69,8 @@ public class DBRevisionCacheSchema extends DBSchema
public static final IDBIndex INDEX_REVISIONS_CONTAINERID = //
REVISIONS.addIndex(IDBIndex.Type.NON_UNIQUE, REVISIONS_CONTAINERID);
- private DBRevisionCacheSchema()
- {
- super("DBRevisionCache");
- }
-
static
{
- INSTANCE.lock();
+ ((InternalDBSchema)INSTANCE).lock();
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.lissome/src/org/eclipse/emf/cdo/server/internal/lissome/db/Index.java b/plugins/org.eclipse.emf.cdo.server.lissome/src/org/eclipse/emf/cdo/server/internal/lissome/db/Index.java
index 5719c214c0..57f2854c7c 100644
--- a/plugins/org.eclipse.emf.cdo.server.lissome/src/org/eclipse/emf/cdo/server/internal/lissome/db/Index.java
+++ b/plugins/org.eclipse.emf.cdo.server.lissome/src/org/eclipse/emf/cdo/server/internal/lissome/db/Index.java
@@ -17,11 +17,13 @@ import org.eclipse.emf.cdo.server.internal.lissome.LissomeStore;
import org.eclipse.emf.cdo.spi.server.InternalRepository;
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.ddl.IDBSchema;
import org.eclipse.net4j.db.h2.H2Adapter;
import org.eclipse.net4j.spi.db.DBAdapter;
-import org.eclipse.net4j.spi.db.DBSchema;
+import org.eclipse.net4j.spi.db.ddl.InternalDBSchema;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.net4j.util.om.trace.ContextTracer;
@@ -38,7 +40,7 @@ import java.sql.SQLException;
/**
* @author Eike Stepper
*/
-public class Index extends DBSchema implements IDBConnectionProvider
+public class Index implements IDBConnectionProvider
{
public static final long NULL_POINTER = 0; // A pointer value that has no meaning in the vob.
@@ -46,10 +48,10 @@ public class Index extends DBSchema implements IDBConnectionProvider
private static final String INDENT = " ";
- private static final long serialVersionUID = 1L;
-
private LissomeStore store;
+ private IDBSchema schema = DBUtil.createSchema(LissomeStore.TYPE);
+
private IDBAdapter adapter;
private DataSource dataSource;
@@ -64,7 +66,6 @@ public class Index extends DBSchema implements IDBConnectionProvider
public Index(LissomeStore store)
{
- super(LissomeStore.TYPE);
this.store = store;
adapter = createAdapter();
@@ -78,7 +79,7 @@ public class Index extends DBSchema implements IDBConnectionProvider
branches = new BranchesTable(this);
}
- lock();
+ ((InternalDBSchema)schema).lock();
}
public LissomeStore getStore()
@@ -161,7 +162,12 @@ public class Index extends DBSchema implements IDBConnectionProvider
public void createTables()
{
Connection connection = writer.getConnection();
- create(adapter, connection);
+ schema.create(adapter, connection);
+ }
+
+ public IDBSchema getSchema()
+ {
+ return schema;
}
public Connection getConnection()
diff --git a/plugins/org.eclipse.emf.cdo.server.lissome/src/org/eclipse/emf/cdo/server/internal/lissome/db/Table.java b/plugins/org.eclipse.emf.cdo.server.lissome/src/org/eclipse/emf/cdo/server/internal/lissome/db/Table.java
index 55654dc21e..051c78d0ed 100644
--- a/plugins/org.eclipse.emf.cdo.server.lissome/src/org/eclipse/emf/cdo/server/internal/lissome/db/Table.java
+++ b/plugins/org.eclipse.emf.cdo.server.lissome/src/org/eclipse/emf/cdo/server/internal/lissome/db/Table.java
@@ -30,7 +30,7 @@ public class Table
public Table(Index index, String name)
{
this.index = index;
- table = index.addTable(name);
+ table = index.getSchema().addTable(name);
}
public Index getIndex()
diff --git a/plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/TestSchema.java b/plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/TestSchema.java
index f62eb9bf55..4f93f5a193 100644
--- a/plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/TestSchema.java
+++ b/plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/TestSchema.java
@@ -11,19 +11,19 @@
package org.eclipse.net4j.db.tests;
import org.eclipse.net4j.db.DBType;
+import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBIndex;
+import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBTable;
-import org.eclipse.net4j.spi.db.DBSchema;
+import org.eclipse.net4j.spi.db.ddl.InternalDBSchema;
/**
* @author Eike Stepper
*/
-public class TestSchema extends DBSchema
+public class TestSchema
{
- public static final TestSchema INSTANCE = new TestSchema();
-
- private static final long serialVersionUID = 1L;
+ public static final IDBSchema INSTANCE = DBUtil.createSchema("CDO");
/**
* DBTable cdo_repository
@@ -195,13 +195,8 @@ public class TestSchema extends DBSchema
public static final String REFERENCES_TARGET = "cdo_target";
- private TestSchema()
- {
- super("CDO");
- }
-
static
{
- INSTANCE.lock();
+ ((InternalDBSchema)INSTANCE).lock();
}
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBDatabase.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBDatabase.java
index 928180ccea..3b0448d1cc 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBDatabase.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBDatabase.java
@@ -11,8 +11,6 @@
package org.eclipse.net4j.db;
import org.eclipse.net4j.db.ddl.IDBSchema;
-import org.eclipse.net4j.db.ddl.IDBSchemaElement;
-import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.db.ddl.delta.IDBSchemaDelta;
import org.eclipse.net4j.util.collection.Closeable;
import org.eclipse.net4j.util.container.IContainer;
@@ -38,12 +36,7 @@ public interface IDBDatabase extends IContainer<IDBTransaction>, Closeable
public IDBSchemaTransaction getSchemaTransaction();
- public void ensureSchemaElement(RunnableWithSchema updateRunnable, RunnableWithSchema commitRunnable);
-
- public <T extends IDBSchemaElement, P extends IDBSchemaElement> T ensureSchemaElement(P parent, Class<T> type,
- String name, RunnableWithSchemaElement<T, P> runnable);
-
- public IDBTable ensureTable(String name, RunnableWithTable runnable);
+ public void updateSchema(RunnableWithSchema runnable);
public IDBTransaction openTransaction();
@@ -70,20 +63,4 @@ public interface IDBDatabase extends IContainer<IDBTransaction>, Closeable
{
public void run(IDBSchema schema);
}
-
- /**
- * @author Eike Stepper
- */
- public interface RunnableWithSchemaElement<T extends IDBSchemaElement, P extends IDBSchemaElement>
- {
- public T run(P parent, String name);
- }
-
- /**
- * @author Eike Stepper
- */
- public interface RunnableWithTable
- {
- public void run(IDBTable table);
- }
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchemaElement.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchemaElement.java
index ac45e373ee..527cd9352d 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchemaElement.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchemaElement.java
@@ -12,8 +12,6 @@ package org.eclipse.net4j.db.ddl;
import org.eclipse.net4j.util.container.IContainer;
-import java.io.Serializable;
-
/**
* Specifies a hierachical namespace for elements in a {@link IDBSchema DB schema}.
*
@@ -21,8 +19,7 @@ import java.io.Serializable;
* @noimplement This interface is not intended to be implemented by clients.
* @noextend This interface is not intended to be extended by clients.
*/
-public interface IDBSchemaElement extends IDBNamedElement, IContainer<IDBSchemaElement>, Comparable<IDBSchemaElement>,
- Serializable
+public interface IDBSchemaElement extends IDBNamedElement, IContainer<IDBSchemaElement>, Comparable<IDBSchemaElement>
{
/**
* @since 4.2
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBDelta.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBDelta.java
index 578946ab91..b8cb44251f 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBDelta.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBDelta.java
@@ -15,15 +15,13 @@ import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBSchemaElement;
import org.eclipse.net4j.util.container.IContainer;
-import java.io.Serializable;
-
/**
* @since 4.2
* @author Eike Stepper
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
-public interface IDBDelta extends IDBNamedElement, IContainer<IDBDelta>, Comparable<IDBDelta>, Serializable
+public interface IDBDelta extends IDBNamedElement, IContainer<IDBDelta>, Comparable<IDBDelta>
{
public DeltaType getDeltaType();
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBDatabase.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBDatabase.java
index 2f3541b593..09f7973580 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBDatabase.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBDatabase.java
@@ -16,8 +16,6 @@ import org.eclipse.net4j.db.IDBConnectionProvider;
import org.eclipse.net4j.db.IDBDatabase;
import org.eclipse.net4j.db.IDBTransaction;
import org.eclipse.net4j.db.ddl.IDBSchema;
-import org.eclipse.net4j.db.ddl.IDBSchemaElement;
-import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.db.ddl.delta.IDBSchemaDelta;
import org.eclipse.net4j.internal.db.ddl.delta.DBSchemaDelta;
import org.eclipse.net4j.spi.db.DBAdapter;
@@ -25,8 +23,6 @@ import org.eclipse.net4j.spi.db.ddl.InternalDBSchema;
import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.container.SetContainer;
import org.eclipse.net4j.util.event.Event;
-import org.eclipse.net4j.util.event.IEvent;
-import org.eclipse.net4j.util.event.IListener;
import java.sql.Connection;
import java.sql.SQLException;
@@ -114,80 +110,22 @@ public final class DBDatabase extends SetContainer<IDBTransaction> implements ID
return schemaTransaction;
}
- public void ensureSchemaElement(RunnableWithSchema updateRunnable, final RunnableWithSchema commitRunnable)
+ public void updateSchema(RunnableWithSchema runnable)
{
- if (schemaTransaction != null)
+ DBSchemaTransaction schemaTransaction = openSchemaTransaction();
+
+ try
{
IDBSchema workingCopy = schemaTransaction.getWorkingCopy();
- updateRunnable.run(workingCopy);
-
- if (commitRunnable != null)
- {
- addListener(new IListener()
- {
- public void notifyEvent(IEvent event)
- {
- if (event instanceof SchemaChangedEvent)
- {
- commitRunnable.run(schema);
- removeListener(this);
- }
- }
- });
- }
+ runnable.run(workingCopy);
+ schemaTransaction.commit();
}
- else
+ finally
{
- if (commitRunnable != null)
- {
- commitRunnable.run(schema);
- }
+ schemaTransaction.close();
}
}
- public <T extends IDBSchemaElement, P extends IDBSchemaElement> T ensureSchemaElement(P parent, Class<T> type,
- String name, RunnableWithSchemaElement<T, P> runnable)
- {
- T element = parent.getElement(type, name);
- if (element == null)
- {
- DBSchemaTransaction schemaTransaction = openSchemaTransaction();
-
- try
- {
- IDBSchema workingCopy = schemaTransaction.getWorkingCopy();
- P parentCopy = workingCopy.findElement(parent);
-
- T elementCopy = runnable.run(parentCopy, name);
-
- schemaTransaction.commit();
- if (elementCopy != null)
- {
- element = parent.getSchema().findElement(elementCopy);
- }
- }
- finally
- {
- schemaTransaction.close();
- }
- }
-
- return element;
- }
-
- public IDBTable ensureTable(String name, final RunnableWithTable runnable)
- {
- return ensureSchemaElement(schema, IDBTable.class, name, new RunnableWithSchemaElement<IDBTable, IDBSchema>()
- {
- public IDBTable run(IDBSchema parent, String name)
- {
- IDBTable table = parent.addTable(name);
- runnable.run(table);
- return table;
- }
- });
- }
-
public DBTransaction openTransaction()
{
DBTransaction transaction = new DBTransaction(this);
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBSchemaTransaction.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBSchemaTransaction.java
index 22b14e0b56..2e14a1c846 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBSchemaTransaction.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBSchemaTransaction.java
@@ -17,6 +17,8 @@ import org.eclipse.net4j.db.IDBSchemaTransaction;
import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.delta.IDBDeltaVisitor;
import org.eclipse.net4j.db.ddl.delta.IDBSchemaDelta;
+import org.eclipse.net4j.internal.db.ddl.DelegatingDBSchema;
+import org.eclipse.net4j.internal.db.ddl.DelegatingDBSchemaElement;
import org.eclipse.net4j.internal.db.ddl.delta.DBSchemaDelta;
import org.eclipse.net4j.spi.db.DBAdapter;
import org.eclipse.net4j.spi.db.ddl.InternalDBSchema;
@@ -42,7 +44,8 @@ public final class DBSchemaTransaction implements IDBSchemaTransaction, Runnable
this.database = database;
oldSchema = database.getSchema();
- workingCopy = DBUtil.copySchema(oldSchema);
+ IDBSchema copy = DBUtil.copySchema(oldSchema);
+ workingCopy = DelegatingDBSchemaElement.wrap(copy);
}
public DBDatabase getDatabase()
@@ -117,6 +120,8 @@ public final class DBSchemaTransaction implements IDBSchemaTransaction, Runnable
DBAdapter adapter = database.getAdapter();
adapter.updateSchema(connection, oldSchema, delta);
+
+ ((DelegatingDBSchema)workingCopy).setDelegate(oldSchema);
}
finally
{
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBField.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBField.java
index 9fc5ef8cf4..e2414bcfd3 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBField.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBField.java
@@ -11,6 +11,7 @@
package org.eclipse.net4j.internal.db.ddl;
import org.eclipse.net4j.db.DBType;
+import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBSchemaElement;
import org.eclipse.net4j.db.ddl.IDBSchemaVisitor;
@@ -100,6 +101,12 @@ public class DBField extends DBSchemaElement implements InternalDBField
{
}
+ @Override
+ public IDBField getWrapper()
+ {
+ return (IDBField)super.getWrapper();
+ }
+
public SchemaElementType getSchemaElementType()
{
return SchemaElementType.FIELD;
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBIndex.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBIndex.java
index 1c385c8faf..239c3e90d5 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBIndex.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBIndex.java
@@ -64,6 +64,12 @@ public class DBIndex extends DBSchemaElement implements InternalDBIndex
{
}
+ @Override
+ public IDBIndex getWrapper()
+ {
+ return (IDBIndex)super.getWrapper();
+ }
+
public SchemaElementType getSchemaElementType()
{
return SchemaElementType.INDEX;
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBIndexField.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBIndexField.java
index f961eead99..09ea2a2c23 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBIndexField.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBIndexField.java
@@ -12,6 +12,7 @@ package org.eclipse.net4j.internal.db.ddl;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBIndex;
+import org.eclipse.net4j.db.ddl.IDBIndexField;
import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBSchemaElement;
import org.eclipse.net4j.db.ddl.IDBSchemaVisitor;
@@ -49,6 +50,12 @@ public class DBIndexField extends DBSchemaElement implements InternalDBIndexFiel
{
}
+ @Override
+ public IDBIndexField getWrapper()
+ {
+ return (IDBIndexField)super.getWrapper();
+ }
+
public SchemaElementType getSchemaElementType()
{
return SchemaElementType.INDEX_FIELD;
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBNamedElement.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBNamedElement.java
index d903aba5b8..1920bf2637 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBNamedElement.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBNamedElement.java
@@ -52,7 +52,7 @@ public abstract class DBNamedElement extends DBElement implements InternalDBName
}
@Override
- public final boolean equals(Object obj)
+ public boolean equals(Object obj)
{
if (obj == this)
{
@@ -69,7 +69,7 @@ public abstract class DBNamedElement extends DBElement implements InternalDBName
}
@Override
- public final int hashCode()
+ public int hashCode()
{
return name.hashCode();
}
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 23b7d35797..ac3c7c35bc 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,12 @@ public class DBSchema extends DBSchemaElement implements InternalDBSchema
{
}
+ @Override
+ public IDBSchema getWrapper()
+ {
+ return (IDBSchema)super.getWrapper();
+ }
+
/**
* @since 4.2
*/
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBSchemaElement.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBSchemaElement.java
index ca8a67bc73..ee998d872c 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBSchemaElement.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBSchemaElement.java
@@ -35,6 +35,8 @@ public abstract class DBSchemaElement extends DBNamedElement implements Internal
private transient IDBSchemaElement[] elements;
+ private transient IDBSchemaElement wrapper;
+
public DBSchemaElement(String name)
{
super(name);
@@ -47,6 +49,33 @@ public abstract class DBSchemaElement extends DBNamedElement implements Internal
{
}
+ public IDBSchemaElement getWrapper()
+ {
+ return wrapper;
+ }
+
+ public final void setWrapper(IDBSchemaElement wrapper)
+ {
+ this.wrapper = wrapper;
+ }
+
+ @Override
+ public final boolean equals(Object obj)
+ {
+ if (super.equals(obj))
+ {
+ return getSchemaElementType() == ((IDBSchemaElement)obj).getSchemaElementType();
+ }
+
+ return false;
+ }
+
+ @Override
+ public final int hashCode()
+ {
+ return super.hashCode() ^ getSchemaElementType().hashCode();
+ }
+
public final int compareTo(IDBSchemaElement element2)
{
int result = getSchemaElementType().compareTo(element2.getSchemaElementType());
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBTable.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBTable.java
index 6adb743e1a..c41339d3b6 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBTable.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBTable.java
@@ -17,6 +17,7 @@ import org.eclipse.net4j.db.ddl.IDBIndex;
import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBSchemaElement;
import org.eclipse.net4j.db.ddl.IDBSchemaVisitor;
+import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.db.ddl.SchemaElementNotFoundException;
import org.eclipse.net4j.spi.db.ddl.InternalDBField;
import org.eclipse.net4j.spi.db.ddl.InternalDBSchema;
@@ -52,6 +53,12 @@ public class DBTable extends DBSchemaElement implements InternalDBTable
{
}
+ @Override
+ public IDBTable getWrapper()
+ {
+ return (IDBTable)super.getWrapper();
+ }
+
public SchemaElementType getSchemaElementType()
{
return SchemaElementType.TABLE;
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBField.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBField.java
new file mode 100644
index 0000000000..da565560f2
--- /dev/null
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBField.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * 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
+ */
+package org.eclipse.net4j.internal.db.ddl;
+
+import org.eclipse.net4j.db.DBType;
+import org.eclipse.net4j.db.ddl.IDBField;
+import org.eclipse.net4j.db.ddl.IDBTable;
+import org.eclipse.net4j.spi.db.ddl.InternalDBField;
+
+/**
+ * @author Eike Stepper
+ */
+public final class DelegatingDBField extends DelegatingDBSchemaElement implements InternalDBField
+{
+ DelegatingDBField(InternalDBField delegate)
+ {
+ super(delegate);
+ }
+
+ @Override
+ public InternalDBField getDelegate()
+ {
+ return (InternalDBField)super.getDelegate();
+ }
+
+ public IDBField getWrapper()
+ {
+ return this;
+ }
+
+ public int getPosition()
+ {
+ return getDelegate().getPosition();
+ }
+
+ public void setPosition(int position)
+ {
+ getDelegate().setPosition(position);
+ }
+
+ public Exception getConstructionStackTrace()
+ {
+ return getDelegate().getConstructionStackTrace();
+ }
+
+ @Override
+ public IDBTable getParent()
+ {
+ return wrap(getDelegate().getParent());
+ }
+
+ public IDBTable getTable()
+ {
+ return wrap(getDelegate().getTable());
+ }
+
+ public DBType getType()
+ {
+ return getDelegate().getType();
+ }
+
+ public void setType(DBType type)
+ {
+ getDelegate().setType(type);
+ }
+
+ public int getPrecision()
+ {
+ return getDelegate().getPrecision();
+ }
+
+ public void setPrecision(int precision)
+ {
+ getDelegate().setPrecision(precision);
+ }
+
+ public int getScale()
+ {
+ return getDelegate().getScale();
+ }
+
+ public void setScale(int scale)
+ {
+ getDelegate().setScale(scale);
+ }
+
+ public boolean isNotNull()
+ {
+ return getDelegate().isNotNull();
+ }
+
+ public void setNotNull(boolean notNull)
+ {
+ getDelegate().setNotNull(notNull);
+ }
+
+ public String formatPrecision()
+ {
+ return getDelegate().formatPrecision();
+ }
+
+ public String formatPrecisionAndScale()
+ {
+ return getDelegate().formatPrecisionAndScale();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBIndex.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBIndex.java
new file mode 100644
index 0000000000..d70721d5fc
--- /dev/null
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBIndex.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * 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
+ */
+package org.eclipse.net4j.internal.db.ddl;
+
+import org.eclipse.net4j.db.ddl.IDBField;
+import org.eclipse.net4j.db.ddl.IDBIndex;
+import org.eclipse.net4j.db.ddl.IDBIndexField;
+import org.eclipse.net4j.db.ddl.IDBSchemaElement;
+import org.eclipse.net4j.db.ddl.IDBTable;
+import org.eclipse.net4j.db.ddl.SchemaElementNotFoundException;
+import org.eclipse.net4j.spi.db.ddl.InternalDBIndex;
+
+/**
+ * @author Eike Stepper
+ */
+public final class DelegatingDBIndex extends DelegatingDBSchemaElement implements InternalDBIndex
+{
+ DelegatingDBIndex(InternalDBIndex delegate)
+ {
+ super(delegate);
+ }
+
+ @Override
+ public InternalDBIndex getDelegate()
+ {
+ return (InternalDBIndex)super.getDelegate();
+ }
+
+ @Override
+ public void setDelegate(IDBSchemaElement delegate)
+ {
+ IDBIndexField[] wrapperIndexFields = getIndexFields();
+
+ IDBIndex delegateIndex = (IDBIndex)delegate;
+ super.setDelegate(delegateIndex);
+
+ for (IDBIndexField wrapperIndexField : wrapperIndexFields)
+ {
+ IDBIndexField delegateIndexField = delegateIndex.getIndexField(wrapperIndexField.getName());
+ ((DelegatingDBSchemaElement)wrapperIndexField).setDelegate(delegateIndexField);
+ }
+ }
+
+ public IDBIndex getWrapper()
+ {
+ return this;
+ }
+
+ @Override
+ public IDBTable getParent()
+ {
+ return wrap(getDelegate().getParent());
+ }
+
+ public IDBTable getTable()
+ {
+ return wrap(getDelegate().getTable());
+ }
+
+ public Type getType()
+ {
+ return getDelegate().getType();
+ }
+
+ public void setType(Type type)
+ {
+ getDelegate().setType(type);
+ }
+
+ public void removeIndexField(IDBIndexField indexFieldToRemove)
+ {
+ getDelegate().removeIndexField(unwrap(indexFieldToRemove));
+ }
+
+ @Deprecated
+ public int getPosition()
+ {
+ return getDelegate().getPosition();
+ }
+
+ public IDBIndexField addIndexField(IDBField field)
+ {
+ return wrap(getDelegate().addIndexField(unwrap(field)));
+ }
+
+ public IDBIndexField addIndexField(String name) throws SchemaElementNotFoundException
+ {
+ return wrap(getDelegate().addIndexField(name));
+ }
+
+ public IDBIndexField getIndexFieldSafe(String name) throws SchemaElementNotFoundException
+ {
+ return wrap(getDelegate().getIndexFieldSafe(name));
+ }
+
+ public IDBIndexField getIndexField(String name)
+ {
+ return wrap(getDelegate().getIndexField(name));
+ }
+
+ public IDBIndexField getIndexField(int position)
+ {
+ return wrap(getDelegate().getIndexField(position));
+ }
+
+ public IDBField getFieldSafe(String name) throws SchemaElementNotFoundException
+ {
+ return wrap(getDelegate().getFieldSafe(name));
+ }
+
+ public IDBField getField(String name)
+ {
+ return wrap(getDelegate().getField(name));
+ }
+
+ public IDBField getField(int position)
+ {
+ return wrap(getDelegate().getField(position));
+ }
+
+ public int getFieldCount()
+ {
+ return getDelegate().getFieldCount();
+ }
+
+ public IDBIndexField[] getIndexFields()
+ {
+ return wrap(getDelegate().getIndexFields(), IDBIndexField.class);
+ }
+
+ public IDBField[] getFields()
+ {
+ return wrap(getDelegate().getFields(), IDBField.class);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBIndexField.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBIndexField.java
new file mode 100644
index 0000000000..b688f2de66
--- /dev/null
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBIndexField.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * 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
+ */
+package org.eclipse.net4j.internal.db.ddl;
+
+import org.eclipse.net4j.db.ddl.IDBField;
+import org.eclipse.net4j.db.ddl.IDBIndex;
+import org.eclipse.net4j.db.ddl.IDBIndexField;
+import org.eclipse.net4j.spi.db.ddl.InternalDBIndexField;
+
+/**
+ * @author Eike Stepper
+ */
+public final class DelegatingDBIndexField extends DelegatingDBSchemaElement implements InternalDBIndexField
+{
+ DelegatingDBIndexField(InternalDBIndexField delegate)
+ {
+ super(delegate);
+ }
+
+ @Override
+ public InternalDBIndexField getDelegate()
+ {
+ return (InternalDBIndexField)super.getDelegate();
+ }
+
+ public IDBIndexField getWrapper()
+ {
+ return this;
+ }
+
+ public int getPosition()
+ {
+ return getDelegate().getPosition();
+ }
+
+ public void setPosition(int position)
+ {
+ getDelegate().setPosition(position);
+ }
+
+ @Override
+ public IDBIndex getParent()
+ {
+ return wrap(getDelegate().getParent());
+ }
+
+ public IDBIndex getIndex()
+ {
+ return wrap(getDelegate().getIndex());
+ }
+
+ public IDBField getField()
+ {
+ return wrap(getDelegate().getField());
+ }
+}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBSchema.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBSchema.java
new file mode 100644
index 0000000000..8934d240a3
--- /dev/null
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBSchema.java
@@ -0,0 +1,191 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * 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
+ */
+package org.eclipse.net4j.internal.db.ddl;
+
+import org.eclipse.net4j.db.DBException;
+import org.eclipse.net4j.db.IDBAdapter;
+import org.eclipse.net4j.db.IDBConnectionProvider;
+import org.eclipse.net4j.db.ddl.IDBField;
+import org.eclipse.net4j.db.ddl.IDBIndex.Type;
+import org.eclipse.net4j.db.ddl.IDBSchema;
+import org.eclipse.net4j.db.ddl.IDBSchemaElement;
+import org.eclipse.net4j.db.ddl.IDBTable;
+import org.eclipse.net4j.db.ddl.SchemaElementNotFoundException;
+import org.eclipse.net4j.db.ddl.delta.IDBSchemaDelta;
+import org.eclipse.net4j.spi.db.ddl.InternalDBSchema;
+
+import javax.sql.DataSource;
+
+import java.io.PrintStream;
+import java.sql.Connection;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public final class DelegatingDBSchema extends DelegatingDBSchemaElement implements InternalDBSchema
+{
+ DelegatingDBSchema(InternalDBSchema delegate)
+ {
+ super(delegate);
+ }
+
+ @Override
+ public InternalDBSchema getDelegate()
+ {
+ return (InternalDBSchema)super.getDelegate();
+ }
+
+ @Override
+ public void setDelegate(IDBSchemaElement delegate)
+ {
+ IDBTable[] wrapperTables = getTables();
+
+ IDBSchema delegateSchema = (IDBSchema)delegate;
+ super.setDelegate(delegateSchema);
+
+ for (IDBTable wrapperTable : wrapperTables)
+ {
+ ((DelegatingDBSchemaElement)wrapperTable).setDelegate(delegateSchema.getTable(wrapperTable.getName()));
+ }
+ }
+
+ public IDBSchema getWrapper()
+ {
+ return this;
+ }
+
+ @Override
+ public IDBSchemaElement getParent()
+ {
+ return wrap(getDelegate().getParent());
+ }
+
+ public IDBTable addTable(String name)
+ {
+ return wrap(getDelegate().addTable(name));
+ }
+
+ public IDBTable removeTable(String name)
+ {
+ return wrap(getDelegate().removeTable(name));
+ }
+
+ public String createIndexName(IDBTable table, Type type, IDBField[] fields, int position)
+ {
+ return getDelegate().createIndexName(unwrap(table), type, fields, position);
+ }
+
+ public boolean isLocked()
+ {
+ return getDelegate().isLocked();
+ }
+
+ public boolean lock()
+ {
+ return getDelegate().lock();
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T extends IDBSchemaElement> T findElement(IDBSchemaElement prototype)
+ {
+ T unwrapped = (T)unwrap(prototype);
+ return (T)wrap(getDelegate().findElement(unwrapped));
+ }
+
+ public boolean unlock()
+ {
+ return getDelegate().unlock();
+ }
+
+ public void assertUnlocked() throws DBException
+ {
+ getDelegate().assertUnlocked();
+ }
+
+ public IDBTable getTableSafe(String name) throws SchemaElementNotFoundException
+ {
+ return wrap(getDelegate().getTableSafe(name));
+ }
+
+ public IDBTable getTable(String name)
+ {
+ return wrap(getDelegate().getTable(name));
+ }
+
+ public IDBTable[] getTables()
+ {
+ IDBTable[] tables = getDelegate().getTables();
+ IDBTable[] wrappers = new IDBTable[tables.length];
+ for (int i = 0; i < tables.length; i++)
+ {
+ wrappers[i] = wrap(tables[i]);
+ }
+
+ return wrappers;
+ }
+
+ public Set<IDBTable> create(IDBAdapter dbAdapter, Connection connection) throws DBException
+ {
+ return wrap(getDelegate().create(dbAdapter, connection));
+ }
+
+ public Set<IDBTable> create(IDBAdapter dbAdapter, DataSource dataSource) throws DBException
+ {
+ return wrap(getDelegate().create(dbAdapter, dataSource));
+ }
+
+ public Set<IDBTable> create(IDBAdapter dbAdapter, IDBConnectionProvider connectionProvider) throws DBException
+ {
+ return wrap(getDelegate().create(dbAdapter, connectionProvider));
+ }
+
+ public void drop(IDBAdapter dbAdapter, Connection connection) throws DBException
+ {
+ getDelegate().drop(dbAdapter, connection);
+ }
+
+ public void drop(IDBAdapter dbAdapter, DataSource dataSource) throws DBException
+ {
+ getDelegate().drop(dbAdapter, dataSource);
+ }
+
+ public void drop(IDBAdapter dbAdapter, IDBConnectionProvider connectionProvider) throws DBException
+ {
+ getDelegate().drop(dbAdapter, connectionProvider);
+ }
+
+ public void export(Connection connection, PrintStream out) throws DBException
+ {
+ getDelegate().export(connection, out);
+ }
+
+ public void export(DataSource dataSource, PrintStream out) throws DBException
+ {
+ getDelegate().export(dataSource, out);
+ }
+
+ public void export(IDBConnectionProvider connectionProvider, PrintStream out) throws DBException
+ {
+ getDelegate().export(connectionProvider, out);
+ }
+
+ public IDBSchemaDelta compare(IDBSchema oldSchema)
+ {
+ return getDelegate().compare(unwrap(oldSchema));
+ }
+
+ private static Set<IDBTable> wrap(Set<IDBTable> tables)
+ {
+ return wrap(tables, new HashSet<IDBTable>());
+ }
+}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBSchemaElement.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBSchemaElement.java
new file mode 100644
index 0000000000..667b4e8bc2
--- /dev/null
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBSchemaElement.java
@@ -0,0 +1,284 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * 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
+ */
+package org.eclipse.net4j.internal.db.ddl;
+
+import org.eclipse.net4j.db.ddl.IDBSchema;
+import org.eclipse.net4j.db.ddl.IDBSchemaElement;
+import org.eclipse.net4j.db.ddl.IDBSchemaVisitor;
+import org.eclipse.net4j.spi.db.ddl.InternalDBField;
+import org.eclipse.net4j.spi.db.ddl.InternalDBIndex;
+import org.eclipse.net4j.spi.db.ddl.InternalDBIndexField;
+import org.eclipse.net4j.spi.db.ddl.InternalDBSchema;
+import org.eclipse.net4j.spi.db.ddl.InternalDBSchemaElement;
+import org.eclipse.net4j.spi.db.ddl.InternalDBTable;
+import org.eclipse.net4j.util.event.IListener;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class DelegatingDBSchemaElement implements InternalDBSchemaElement
+{
+ private InternalDBSchemaElement delegate;
+
+ DelegatingDBSchemaElement(InternalDBSchemaElement delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ public InternalDBSchemaElement getDelegate()
+ {
+ return delegate;
+ }
+
+ public void setDelegate(IDBSchemaElement delegate)
+ {
+ if (this.delegate != null)
+ {
+ this.delegate.setWrapper(null);
+ }
+
+ this.delegate = (InternalDBSchemaElement)delegate;
+
+ if (this.delegate != null)
+ {
+ this.delegate.setWrapper(this);
+ }
+ }
+
+ public final void setWrapper(IDBSchemaElement wrapper)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public IDBSchemaElement getParent()
+ {
+ return wrap(getDelegate().getParent());
+ }
+
+ public final String getName()
+ {
+ return getDelegate().getName();
+ }
+
+ @Deprecated
+ public final void setName(String name)
+ {
+ getDelegate().setName(name);
+ }
+
+ public final <T extends IDBSchemaElement> T getElement(Class<T> type, String name)
+ {
+ return getDelegate().getElement(type, name);
+ }
+
+ public final String getFullName()
+ {
+ return getDelegate().getFullName();
+ }
+
+ public final IDBSchema getSchema()
+ {
+ return wrap(getDelegate().getSchema());
+ }
+
+ public final Properties getProperties()
+ {
+ return getDelegate().getProperties();
+ }
+
+ public final String dumpToString()
+ {
+ return getDelegate().dumpToString();
+ }
+
+ public final void dump()
+ {
+ getDelegate().dump();
+ }
+
+ public final void dump(Writer writer) throws IOException
+ {
+ getDelegate().dump(writer);
+ }
+
+ public final SchemaElementType getSchemaElementType()
+ {
+ return getDelegate().getSchemaElementType();
+ }
+
+ public final boolean isEmpty()
+ {
+ return getDelegate().isEmpty();
+ }
+
+ public final IDBSchemaElement[] getElements()
+ {
+ IDBSchemaElement[] elements = getDelegate().getElements();
+ IDBSchemaElement[] wrappers = new IDBSchemaElement[elements.length];
+ for (int i = 0; i < elements.length; i++)
+ {
+ wrappers[i] = wrap(elements[i]);
+ }
+
+ return wrappers;
+ }
+
+ public final void accept(IDBSchemaVisitor visitor)
+ {
+ getDelegate().accept(visitor);
+ }
+
+ public final void remove()
+ {
+ getDelegate().remove();
+ }
+
+ public final void addListener(IListener listener)
+ {
+ getDelegate().addListener(listener);
+ }
+
+ public final IListener[] getListeners()
+ {
+ return getDelegate().getListeners();
+ }
+
+ public final boolean hasListeners()
+ {
+ return getDelegate().hasListeners();
+ }
+
+ public final void removeListener(IListener listener)
+ {
+ getDelegate().removeListener(listener);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return getDelegate().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return getDelegate().equals(obj);
+ }
+
+ public final int compareTo(IDBSchemaElement o)
+ {
+ return getDelegate().compareTo(unwrap(o));
+ }
+
+ @Override
+ public String toString()
+ {
+ return getDelegate().toString();
+ }
+
+ public static <T extends IDBSchemaElement> T wrap(T delegate)
+ {
+ if (delegate == null || delegate instanceof DelegatingDBSchemaElement)
+ {
+ return delegate;
+ }
+
+ InternalDBSchemaElement internalDelegate = (InternalDBSchemaElement)delegate;
+ IDBSchemaElement wrapper = internalDelegate.getWrapper();
+ if (wrapper == null)
+ {
+ SchemaElementType schemaElementType = internalDelegate.getSchemaElementType();
+ switch (schemaElementType)
+ {
+ case SCHEMA:
+ wrapper = new DelegatingDBSchema((InternalDBSchema)internalDelegate);
+ break;
+
+ case TABLE:
+ wrapper = new DelegatingDBTable((InternalDBTable)internalDelegate);
+ break;
+
+ case FIELD:
+ wrapper = new DelegatingDBField((InternalDBField)internalDelegate);
+ break;
+
+ case INDEX:
+ wrapper = new DelegatingDBIndex((InternalDBIndex)internalDelegate);
+ break;
+
+ case INDEX_FIELD:
+ wrapper = new DelegatingDBIndexField((InternalDBIndexField)internalDelegate);
+ break;
+
+ default:
+ throw new IllegalStateException("Illegal schema element type: " + schemaElementType);
+ }
+
+ internalDelegate.setWrapper(wrapper);
+ }
+
+ @SuppressWarnings("unchecked")
+ T result = (T)wrapper;
+ return result;
+ }
+
+ public static <T extends IDBSchemaElement> T[] wrap(T[] delegates, Class<T> type)
+ {
+ @SuppressWarnings("unchecked")
+ T[] wrappers = (T[])java.lang.reflect.Array.newInstance(type, delegates.length);
+ for (int i = 0; i < delegates.length; i++)
+ {
+ T wrapper = wrap(delegates[i]);
+ wrappers[i] = wrapper;
+ }
+
+ return wrappers;
+ }
+
+ public static <T extends IDBSchemaElement> Set<T> wrap(Set<T> delegates, Set<T> wrappers)
+ {
+ for (T delegate : delegates)
+ {
+ wrappers.add(wrap(delegate));
+ }
+
+ return wrappers;
+ }
+
+ public static <T extends IDBSchemaElement> T unwrap(T wrapper)
+ {
+ if (wrapper instanceof DelegatingDBSchemaElement)
+ {
+ @SuppressWarnings("unchecked")
+ T delegate = (T)((DelegatingDBSchemaElement)wrapper).getDelegate();
+ return delegate;
+ }
+
+ return wrapper;
+ }
+
+ public static <T extends IDBSchemaElement> T[] unwrap(T[] wrappers, Class<T> type)
+ {
+ @SuppressWarnings("unchecked")
+ T[] delegates = (T[])java.lang.reflect.Array.newInstance(type, wrappers.length);
+ for (int i = 0; i < wrappers.length; i++)
+ {
+ delegates[i] = unwrap(wrappers[i]);
+ }
+
+ return delegates;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBTable.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBTable.java
new file mode 100644
index 0000000000..7fa91fac9a
--- /dev/null
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBTable.java
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * 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
+ */
+package org.eclipse.net4j.internal.db.ddl;
+
+import org.eclipse.net4j.db.DBType;
+import org.eclipse.net4j.db.ddl.IDBField;
+import org.eclipse.net4j.db.ddl.IDBIndex;
+import org.eclipse.net4j.db.ddl.IDBIndex.Type;
+import org.eclipse.net4j.db.ddl.IDBSchema;
+import org.eclipse.net4j.db.ddl.IDBSchemaElement;
+import org.eclipse.net4j.db.ddl.IDBTable;
+import org.eclipse.net4j.db.ddl.SchemaElementNotFoundException;
+import org.eclipse.net4j.spi.db.ddl.InternalDBTable;
+
+/**
+ * @author Eike Stepper
+ */
+public final class DelegatingDBTable extends DelegatingDBSchemaElement implements InternalDBTable
+{
+ DelegatingDBTable(InternalDBTable delegate)
+ {
+ super(delegate);
+ }
+
+ @Override
+ public InternalDBTable getDelegate()
+ {
+ return (InternalDBTable)super.getDelegate();
+ }
+
+ @Override
+ public void setDelegate(IDBSchemaElement delegate)
+ {
+ IDBField[] wrapperFields = getFields();
+ IDBIndex[] wrapperIndices = getIndices();
+
+ IDBTable delegateTable = (IDBTable)delegate;
+ super.setDelegate(delegateTable);
+
+ for (IDBField wrapperField : wrapperFields)
+ {
+ IDBField delegateField = delegateTable.getField(wrapperField.getName());
+ ((DelegatingDBSchemaElement)wrapperField).setDelegate(delegateField);
+ }
+
+ for (IDBIndex wrapperIndex : wrapperIndices)
+ {
+ IDBIndex delegateIndex = delegateTable.getIndex(wrapperIndex.getName());
+ ((DelegatingDBSchemaElement)wrapperIndex).setDelegate(delegateIndex);
+ }
+ }
+
+ public IDBTable getWrapper()
+ {
+ return this;
+ }
+
+ @Override
+ public IDBSchema getParent()
+ {
+ return wrap(getDelegate().getParent());
+ }
+
+ public IDBField addField(String name, DBType type)
+ {
+ return wrap(getDelegate().addField(name, type));
+ }
+
+ public IDBField addField(String name, DBType type, boolean notNull)
+ {
+ return wrap(getDelegate().addField(name, type, notNull));
+ }
+
+ public void removeField(IDBField fieldToRemove)
+ {
+ getDelegate().removeField(unwrap(fieldToRemove));
+ }
+
+ public IDBField addField(String name, DBType type, int precision)
+ {
+ return wrap(getDelegate().addField(name, type, precision));
+ }
+
+ public void removeIndex(IDBIndex indexToRemove)
+ {
+ getDelegate().removeIndex(unwrap(indexToRemove));
+ }
+
+ public IDBField addField(String name, DBType type, int precision, boolean notNull)
+ {
+ return wrap(getDelegate().addField(name, type, precision, notNull));
+ }
+
+ public IDBField addField(String name, DBType type, int precision, int scale)
+ {
+ return wrap(getDelegate().addField(name, type, precision, scale));
+ }
+
+ public IDBField addField(String name, DBType type, int precision, int scale, boolean notNull)
+ {
+ return wrap(getDelegate().addField(name, type, precision, scale, notNull));
+ }
+
+ public IDBField getFieldSafe(String name) throws SchemaElementNotFoundException
+ {
+ return wrap(getDelegate().getFieldSafe(name));
+ }
+
+ public IDBField getField(String name)
+ {
+ return wrap(getDelegate().getField(name));
+ }
+
+ public IDBField getField(int position)
+ {
+ return wrap(getDelegate().getField(position));
+ }
+
+ public int getFieldCount()
+ {
+ return getDelegate().getFieldCount();
+ }
+
+ public IDBField[] getFields()
+ {
+ return wrap(getDelegate().getFields(), IDBField.class);
+ }
+
+ public IDBField[] getFields(String... fieldNames) throws SchemaElementNotFoundException
+ {
+ return wrap(getDelegate().getFields(fieldNames), IDBField.class);
+ }
+
+ public IDBIndex addIndex(String name, Type type, IDBField... fields)
+ {
+ return wrap(getDelegate().addIndex(name, type, unwrap(fields, IDBField.class)));
+ }
+
+ public IDBIndex addIndex(String name, Type type, String... fieldNames) throws SchemaElementNotFoundException
+ {
+ return wrap(getDelegate().addIndex(name, type, fieldNames));
+ }
+
+ public IDBIndex addIndexEmpty(String name, Type type)
+ {
+ return wrap(getDelegate().addIndexEmpty(name, type));
+ }
+
+ public IDBIndex addIndex(Type type, IDBField... fields)
+ {
+ return wrap(getDelegate().addIndex(type, unwrap(fields, IDBField.class)));
+ }
+
+ public IDBIndex addIndex(Type type, String... fieldNames) throws SchemaElementNotFoundException
+ {
+ return wrap(getDelegate().addIndex(type, fieldNames));
+ }
+
+ public IDBIndex addIndexEmpty(Type type)
+ {
+ return wrap(getDelegate().addIndexEmpty(type));
+ }
+
+ public IDBIndex getIndexSafe(String name) throws SchemaElementNotFoundException
+ {
+ return wrap(getDelegate().getIndexSafe(name));
+ }
+
+ public IDBIndex getIndex(String name)
+ {
+ return wrap(getDelegate().getIndex(name));
+ }
+
+ public IDBIndex getIndex(int position)
+ {
+ return wrap(getDelegate().getIndex(position));
+ }
+
+ public int getIndexCount()
+ {
+ return getDelegate().getIndexCount();
+ }
+
+ public IDBIndex[] getIndices()
+ {
+ return wrap(getDelegate().getIndices(), IDBIndex.class);
+ }
+
+ public IDBIndex getPrimaryKeyIndex()
+ {
+ return wrap(getDelegate().getPrimaryKeyIndex());
+ }
+
+ public String sqlInsert()
+ {
+ return getDelegate().sqlInsert();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBField.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBField.java
index 9a72c3f2b4..3916c1f244 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBField.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBField.java
@@ -20,6 +20,8 @@ import org.eclipse.net4j.db.ddl.IDBField;
*/
public interface InternalDBField extends IDBField, InternalDBSchemaElement
{
+ public IDBField getWrapper();
+
public void setPosition(int position);
public Exception getConstructionStackTrace();
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBIndex.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBIndex.java
index 062351b33e..6feadf6ac9 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBIndex.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBIndex.java
@@ -23,5 +23,7 @@ public interface InternalDBIndex extends IDBIndex, InternalDBSchemaElement
{
public static final IDBIndexField[] NO_INDEX_FIELDS = {};
+ public IDBIndex getWrapper();
+
public void removeIndexField(IDBIndexField indexFieldToRemove);
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBIndexField.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBIndexField.java
index 28bd2dfff5..310c9e87c9 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBIndexField.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBIndexField.java
@@ -20,5 +20,7 @@ import org.eclipse.net4j.db.ddl.IDBIndexField;
*/
public interface InternalDBIndexField extends IDBIndexField, InternalDBSchemaElement
{
+ public IDBIndexField getWrapper();
+
public void setPosition(int position);
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBSchema.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBSchema.java
index 12720dabfc..7a694bffc3 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBSchema.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBSchema.java
@@ -26,6 +26,8 @@ public interface InternalDBSchema extends IDBSchema, InternalDBSchemaElement
{
public static final IDBTable[] NO_TABLES = {};
+ public IDBSchema getWrapper();
+
public IDBTable addTable(String name);
public IDBTable removeTable(String name);
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBSchemaElement.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBSchemaElement.java
index e560758d9f..f7e3570b46 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBSchemaElement.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBSchemaElement.java
@@ -20,4 +20,7 @@ import org.eclipse.net4j.db.ddl.IDBSchemaElement;
*/
public interface InternalDBSchemaElement extends IDBSchemaElement, InternalDBNamedElement
{
+ public IDBSchemaElement getWrapper();
+
+ public void setWrapper(IDBSchemaElement wrapper);
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBTable.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBTable.java
index 9456789f9b..89e1eeaf15 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBTable.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/ddl/InternalDBTable.java
@@ -26,6 +26,8 @@ public interface InternalDBTable extends IDBTable, InternalDBSchemaElement
public static final IDBIndex[] NO_INDICES = {};
+ public IDBTable getWrapper();
+
public void removeField(IDBField fieldToRemove);
public void removeIndex(IDBIndex indexToRemove);
diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms.server.jdbc/src/org/eclipse/net4j/jms/server/internal/jdbc/JMSSchema.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms.server.jdbc/src/org/eclipse/net4j/jms/server/internal/jdbc/JMSSchema.java
index c3e9ea82bc..1fd4ae6de6 100644
--- a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms.server.jdbc/src/org/eclipse/net4j/jms/server/internal/jdbc/JMSSchema.java
+++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms.server.jdbc/src/org/eclipse/net4j/jms/server/internal/jdbc/JMSSchema.java
@@ -11,19 +11,19 @@
package org.eclipse.net4j.jms.server.internal.jdbc;
import org.eclipse.net4j.db.DBType;
+import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBIndex;
+import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBTable;
-import org.eclipse.net4j.spi.db.DBSchema;
+import org.eclipse.net4j.spi.db.ddl.InternalDBSchema;
/**
* @author Eike Stepper
*/
-public class JMSSchema extends DBSchema
+public class JMSSchema
{
- public static final JMSSchema INSTANCE = new JMSSchema();
-
- private static final long serialVersionUID = 1L;
+ public static final IDBSchema INSTANCE = DBUtil.createSchema("JMS");
/**
* DBTable Destinations
@@ -63,13 +63,8 @@ public class JMSSchema extends DBSchema
+ " FROM " + DESTINATIONS + ", " + MESSAGES + " WHERE " + DESTINATIONS_NAME + "=" + MESSAGES_DESTINATION //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ " AND " + DESTINATIONS_NAME + "=?"; //$NON-NLS-1$ //$NON-NLS-2$
- private JMSSchema()
- {
- super("JMS"); //$NON-NLS-1$
- }
-
static
{
- INSTANCE.lock();
+ ((InternalDBSchema)INSTANCE).lock();
}
}
diff --git a/plugins/org.eclipse.net4j.jms.server.jdbc/src/org/eclipse/net4j/jms/server/internal/jdbc/JMSSchema.java b/plugins/org.eclipse.net4j.jms.server.jdbc/src/org/eclipse/net4j/jms/server/internal/jdbc/JMSSchema.java
index c3e9ea82bc..1fd4ae6de6 100644
--- a/plugins/org.eclipse.net4j.jms.server.jdbc/src/org/eclipse/net4j/jms/server/internal/jdbc/JMSSchema.java
+++ b/plugins/org.eclipse.net4j.jms.server.jdbc/src/org/eclipse/net4j/jms/server/internal/jdbc/JMSSchema.java
@@ -11,19 +11,19 @@
package org.eclipse.net4j.jms.server.internal.jdbc;
import org.eclipse.net4j.db.DBType;
+import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBIndex;
+import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBTable;
-import org.eclipse.net4j.spi.db.DBSchema;
+import org.eclipse.net4j.spi.db.ddl.InternalDBSchema;
/**
* @author Eike Stepper
*/
-public class JMSSchema extends DBSchema
+public class JMSSchema
{
- public static final JMSSchema INSTANCE = new JMSSchema();
-
- private static final long serialVersionUID = 1L;
+ public static final IDBSchema INSTANCE = DBUtil.createSchema("JMS");
/**
* DBTable Destinations
@@ -63,13 +63,8 @@ public class JMSSchema extends DBSchema
+ " FROM " + DESTINATIONS + ", " + MESSAGES + " WHERE " + DESTINATIONS_NAME + "=" + MESSAGES_DESTINATION //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ " AND " + DESTINATIONS_NAME + "=?"; //$NON-NLS-1$ //$NON-NLS-2$
- private JMSSchema()
- {
- super("JMS"); //$NON-NLS-1$
- }
-
static
{
- INSTANCE.lock();
+ ((InternalDBSchema)INSTANCE).lock();
}
}

Back to the top