Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-03-04 06:10:58 -0500
committerEike Stepper2013-03-07 08:44:17 -0500
commita500d7231be01e2d63dd0c56f22594a2ae853057 (patch)
treeb921862ee66670406e064649e62a64e4d1f90fcf
parentfab9f3b32fccae1c8be5f34776d2fd0bf18f7c3c (diff)
downloadcdo-a500d7231be01e2d63dd0c56f22594a2ae853057.tar.gz
cdo-a500d7231be01e2d63dd0c56f22594a2ae853057.tar.xz
cdo-a500d7231be01e2d63dd0c56f22594a2ae853057.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.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.lissome/src/org/eclipse/emf/cdo/server/internal/lissome/db/Index.java2
-rw-r--r--plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/AbstractDBTest.java70
-rw-r--r--plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/TestSchema.java2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBDatabase.java2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBNamedElement.java22
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBPreparedStatement.java2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBResultSet.java2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBSchemaTransaction.java2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBTransaction.java2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBField.java2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchemaElement.java10
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBIndexDelta.java2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBPropertyDelta.java3
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBDatabase.java44
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBPreparedStatement.java4
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBSchemaTransaction.java3
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBTransaction.java4
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBField.java26
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBIndex.java37
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBIndexField.java16
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBTable.java54
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBDelta.java76
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBFieldDelta.java13
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBIndexDelta.java30
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBIndexFieldDelta.java20
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBPropertyDelta.java19
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBSchemaDelta.java13
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBTableDelta.java69
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBTableElementDelta.java8
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBAdapter.java15
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBElement.java (renamed from plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBElement.java)10
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBNamedElement.java97
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchema.java63
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchemaElement.java (renamed from plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBSchemaElement.java)20
-rw-r--r--plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms.server.jdbc/META-INF/MANIFEST.MF8
-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.java4
-rw-r--r--plugins/org.eclipse.net4j.jms.server.jdbc/META-INF/MANIFEST.MF8
-rw-r--r--plugins/org.eclipse.net4j.jms.server.jdbc/src/org/eclipse/net4j/jms/server/internal/jdbc/JMSSchema.java4
40 files changed, 454 insertions, 338 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 7761b84898..8126370e4b 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
@@ -24,6 +24,8 @@ public class DBRevisionCacheSchema extends DBSchema
{
public static final DBRevisionCacheSchema INSTANCE = new DBRevisionCacheSchema();
+ private static final long serialVersionUID = 1L;
+
/**
* DBTable dbrevisioncache_revisions.
* <p>
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java
index 127d40bd51..f03b3cf777 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java
@@ -27,6 +27,8 @@ public class CDODBSchema extends DBSchema
{
public static final CDODBSchema INSTANCE = new CDODBSchema();
+ private static final long serialVersionUID = 1L;
+
/**
* DBTable cdo_properties
*/
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 d3a2ed49e9..5719c214c0 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
@@ -46,6 +46,8 @@ public class Index extends DBSchema implements IDBConnectionProvider
private static final String INDENT = " ";
+ private static final long serialVersionUID = 1L;
+
private LissomeStore store;
private IDBAdapter adapter;
diff --git a/plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/AbstractDBTest.java b/plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/AbstractDBTest.java
index 51fe109ef9..2274341522 100644
--- a/plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/AbstractDBTest.java
+++ b/plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/AbstractDBTest.java
@@ -130,7 +130,7 @@ public abstract class AbstractDBTest extends AbstractOMTest
IDBSchemaTransaction schemaTransaction = database.openSchemaTransaction();
assertEquals(false, schemaTransaction.getSchema().isLocked());
assertEquals(true, schemaTransaction.getSchema().isEmpty());
- assertEquals(database.getSchema().getName(), schemaTransaction.getSchema().getName());
+ assertEquals(database.getSchema(), schemaTransaction.getSchema());
IDBTable table1 = schemaTransaction.getSchema().addTable("table1");
IDBField field11 = table1.addField("field1", DBType.INTEGER);
@@ -153,35 +153,36 @@ public abstract class AbstractDBTest extends AbstractOMTest
assertEquals(false, database.getSchema().isEmpty());
assertEquals(2, database.getSchema().getTables().length);
- assertEquals(table1.getName(), database.getSchema().getTables()[0].getName());
+ assertEquals(table1, database.getSchema().getTables()[0]);
assertEquals(table1.getFieldCount(), database.getSchema().getTables()[0].getFieldCount());
- assertEquals(field11.getName(), database.getSchema().getTables()[0].getField(0).getName());
- assertEquals(field12.getName(), database.getSchema().getTables()[0].getField(1).getName());
- assertEquals(field13.getName(), database.getSchema().getTables()[0].getField(2).getName());
+ assertEquals(field11, database.getSchema().getTables()[0].getField(0));
+ assertEquals(field12, database.getSchema().getTables()[0].getField(1));
+ assertEquals(field13, database.getSchema().getTables()[0].getField(2));
assertEquals(table1.getIndexCount(), database.getSchema().getTables()[0].getIndexCount());
- assertEquals(index11.getName(), database.getSchema().getTables()[0].getIndex(0).getName());
+ assertEquals(index11, database.getSchema().getTables()[0].getIndex(0));
assertEquals(index11.getType(), database.getSchema().getTables()[0].getIndex(0).getType());
- assertEquals(index12.getName(), database.getSchema().getTables()[0].getIndex(1).getName());
+ assertEquals(index12, database.getSchema().getTables()[0].getIndex(1));
assertEquals(index12.getType(), database.getSchema().getTables()[0].getIndex(1).getType());
- assertEquals(index13.getName(), database.getSchema().getTables()[0].getIndex(2).getName());
+ assertEquals(index13, database.getSchema().getTables()[0].getIndex(2));
assertEquals(index13.getType(), database.getSchema().getTables()[0].getIndex(2).getType());
- assertEquals(table2.getName(), database.getSchema().getTables()[1].getName());
+ assertEquals(table2, database.getSchema().getTables()[1]);
assertEquals(table2.getFieldCount(), database.getSchema().getTables()[1].getFieldCount());
- assertEquals(field21.getName(), database.getSchema().getTables()[1].getField(0).getName());
- assertEquals(field22.getName(), database.getSchema().getTables()[1].getField(1).getName());
- assertEquals(field23.getName(), database.getSchema().getTables()[1].getField(2).getName());
+ assertEquals(field21, database.getSchema().getTables()[1].getField(0));
+ assertEquals(field22, database.getSchema().getTables()[1].getField(1));
+ assertEquals(field23, database.getSchema().getTables()[1].getField(2));
assertEquals(table2.getIndexCount(), database.getSchema().getTables()[1].getIndexCount());
- assertEquals(index21.getName(), database.getSchema().getTables()[1].getIndex(0).getName());
+ assertEquals(index21, database.getSchema().getTables()[1].getIndex(0));
assertEquals(index21.getType(), database.getSchema().getTables()[1].getIndex(0).getType());
- assertEquals(index22.getName(), database.getSchema().getTables()[1].getIndex(1).getName());
+ assertEquals(index22, database.getSchema().getTables()[1].getIndex(1));
assertEquals(index22.getType(), database.getSchema().getTables()[1].getIndex(1).getType());
- assertEquals(index23.getName(), database.getSchema().getTables()[1].getIndex(2).getName());
+ assertEquals(index23, database.getSchema().getTables()[1].getIndex(2));
assertEquals(index23.getType(), database.getSchema().getTables()[1].getIndex(2).getType());
}
public void testSchemaAddition() throws Exception
{
+ // Init database
IDBDatabase database = DBUtil.openDatabase(adapter, connectionProvider, SCHEMA_NAME);
IDBSchemaTransaction schemaTransaction = database.openSchemaTransaction();
@@ -196,6 +197,7 @@ public abstract class AbstractDBTest extends AbstractOMTest
schemaTransaction.commit();
assertEquals(1, database.getSchema().getTables().length);
+ // Reload database
database = DBUtil.openDatabase(adapter, connectionProvider, SCHEMA_NAME);
assertEquals(true, database.getSchema().isLocked());
assertEquals(false, database.getSchema().isEmpty());
@@ -208,9 +210,15 @@ public abstract class AbstractDBTest extends AbstractOMTest
index11 = table.getIndex("index1");
index12 = table.getIndex("index2");
index13 = table.getIndex("index3");
+ assertNotNull(field11);
+ assertNotNull(field12);
+ assertNotNull(field13);
+ assertNotNull(index11);
+ assertNotNull(index12);
+ assertNotNull(index13);
schemaTransaction = database.openSchemaTransaction();
- assertEquals(false, database.getSchema().isLocked());
+ assertEquals(true, database.getSchema().isLocked());
assertEquals(false, database.getSchema().isEmpty());
assertEquals(1, database.getSchema().getTables().length);
@@ -222,35 +230,37 @@ public abstract class AbstractDBTest extends AbstractOMTest
IDBIndex index22 = table2.addIndex("index2", IDBIndex.Type.UNIQUE, field21, field22);
IDBIndex index23 = table2.addIndex("index3", IDBIndex.Type.NON_UNIQUE, field22);
+ // IDBSchemaDelta schemaDelta = schemaTransaction.getSchemaDelta();
+
schemaTransaction.commit();
assertEquals(true, database.getSchema().isLocked());
assertEquals(false, database.getSchema().isEmpty());
assertEquals(2, database.getSchema().getTables().length);
- assertEquals(table1.getName(), database.getSchema().getTables()[0].getName());
+ assertEquals(table1, database.getSchema().getTables()[0]);
assertEquals(table1.getFieldCount(), database.getSchema().getTables()[0].getFieldCount());
- assertEquals(field11.getName(), database.getSchema().getTables()[0].getField(0).getName());
- assertEquals(field12.getName(), database.getSchema().getTables()[0].getField(1).getName());
- assertEquals(field13.getName(), database.getSchema().getTables()[0].getField(2).getName());
+ assertEquals(field11, database.getSchema().getTables()[0].getField(0));
+ assertEquals(field12, database.getSchema().getTables()[0].getField(1));
+ assertEquals(field13, database.getSchema().getTables()[0].getField(2));
assertEquals(table1.getIndexCount(), database.getSchema().getTables()[0].getIndexCount());
- assertEquals(index11.getName(), database.getSchema().getTables()[0].getIndex(0).getName());
+ assertEquals(index11, database.getSchema().getTables()[0].getIndex(0));
assertEquals(index11.getType(), database.getSchema().getTables()[0].getIndex(0).getType());
- assertEquals(index12.getName(), database.getSchema().getTables()[0].getIndex(1).getName());
+ assertEquals(index12, database.getSchema().getTables()[0].getIndex(1));
assertEquals(index12.getType(), database.getSchema().getTables()[0].getIndex(1).getType());
- assertEquals(index13.getName(), database.getSchema().getTables()[0].getIndex(2).getName());
+ assertEquals(index13, database.getSchema().getTables()[0].getIndex(2));
assertEquals(index13.getType(), database.getSchema().getTables()[0].getIndex(2).getType());
- assertEquals(table2.getName(), database.getSchema().getTables()[1].getName());
+ assertEquals(table2, database.getSchema().getTables()[1]);
assertEquals(table2.getFieldCount(), database.getSchema().getTables()[1].getFieldCount());
- assertEquals(field21.getName(), database.getSchema().getTables()[1].getField(0).getName());
- assertEquals(field22.getName(), database.getSchema().getTables()[1].getField(1).getName());
- assertEquals(field23.getName(), database.getSchema().getTables()[1].getField(2).getName());
+ assertEquals(field21, database.getSchema().getTables()[1].getField(0));
+ assertEquals(field22, database.getSchema().getTables()[1].getField(1));
+ assertEquals(field23, database.getSchema().getTables()[1].getField(2));
assertEquals(table2.getIndexCount(), database.getSchema().getTables()[1].getIndexCount());
- assertEquals(index21.getName(), database.getSchema().getTables()[1].getIndex(0).getName());
+ assertEquals(index21, database.getSchema().getTables()[1].getIndex(0));
assertEquals(index21.getType(), database.getSchema().getTables()[1].getIndex(0).getType());
- assertEquals(index22.getName(), database.getSchema().getTables()[1].getIndex(1).getName());
+ assertEquals(index22, database.getSchema().getTables()[1].getIndex(1));
assertEquals(index22.getType(), database.getSchema().getTables()[1].getIndex(1).getType());
- assertEquals(index23.getName(), database.getSchema().getTables()[1].getIndex(2).getName());
+ assertEquals(index23, database.getSchema().getTables()[1].getIndex(2));
assertEquals(index23.getType(), database.getSchema().getTables()[1].getIndex(2).getType());
}
}
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 9ca4be9869..f62eb9bf55 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
@@ -23,6 +23,8 @@ public class TestSchema extends DBSchema
{
public static final TestSchema INSTANCE = new TestSchema();
+ private static final long serialVersionUID = 1L;
+
/**
* DBTable cdo_repository
*/
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 bf3f08e10f..a79bf1e563 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
@@ -19,7 +19,7 @@ import org.eclipse.net4j.util.container.IContainer;
* @noextend This interface is not intended to be extended by clients.
* @since 4.2
*/
-public interface IDBDatabase extends IDBElement, IContainer<IDBTransaction>
+public interface IDBDatabase extends IContainer<IDBTransaction>
{
public static final int DEFAULT_STATEMENT_CACHE_CAPACITY = 200;
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBNamedElement.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBNamedElement.java
new file mode 100644
index 0000000000..611577dfab
--- /dev/null
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBNamedElement.java
@@ -0,0 +1,22 @@
+/*
+ * 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.db;
+
+/**
+ * @author Eike Stepper
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @noextend This interface is not intended to be extended by clients.
+ * @since 4.2
+ */
+public interface IDBNamedElement extends IDBElement
+{
+ public String getName();
+}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBPreparedStatement.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBPreparedStatement.java
index cb2c56d7d4..9b8b1a7512 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBPreparedStatement.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBPreparedStatement.java
@@ -20,7 +20,7 @@ import java.sql.SQLException;
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
-public interface IDBPreparedStatement extends IDBElement, Comparable<IDBPreparedStatement>, PreparedStatement
+public interface IDBPreparedStatement extends Comparable<IDBPreparedStatement>, PreparedStatement
{
public IDBTransaction getTransaction();
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBResultSet.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBResultSet.java
index 13bf4fe966..9558ea77a7 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBResultSet.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBResultSet.java
@@ -19,7 +19,7 @@ import java.sql.SQLException;
* @noimplement This interface is not intended to be implemented by clients.
* @since 4.2
*/
-public interface IDBResultSet extends IDBElement, ResultSet
+public interface IDBResultSet extends ResultSet
{
public IDBPreparedStatement getStatement() throws SQLException;
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBSchemaTransaction.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBSchemaTransaction.java
index 784112d005..5248cba6f5 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBSchemaTransaction.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBSchemaTransaction.java
@@ -20,7 +20,7 @@ import org.eclipse.net4j.util.collection.Closeable;
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
-public interface IDBSchemaTransaction extends IDBElement, Closeable
+public interface IDBSchemaTransaction extends Closeable
{
public IDBDatabase getDatabase();
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBTransaction.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBTransaction.java
index 82494dcbea..5f2e1a3157 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBTransaction.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBTransaction.java
@@ -20,7 +20,7 @@ import org.eclipse.net4j.util.collection.Closeable;
* @noimplement This interface is not intended to be implemented by clients.
* @noextend This interface is not intended to be extended by clients.
*/
-public interface IDBTransaction extends IDBElement, Closeable
+public interface IDBTransaction extends Closeable
{
public IDBDatabase getDatabase();
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBField.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBField.java
index b66a873f44..95ce7314ee 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBField.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBField.java
@@ -25,8 +25,6 @@ public interface IDBField extends IDBSchemaElement
public IDBTable getTable();
- public void setName(String name); // TODO Move to IDBSchemaElement
-
public DBType getType();
public void setType(DBType type);
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 f26f6d5919..b637e32107 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
@@ -10,7 +10,7 @@
*/
package org.eclipse.net4j.db.ddl;
-import org.eclipse.net4j.db.IDBElement;
+import org.eclipse.net4j.db.IDBNamedElement;
/**
* Specifies a hierachical namespace for elements in a {@link IDBSchema DB schema}.
@@ -19,11 +19,15 @@ import org.eclipse.net4j.db.IDBElement;
* @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 IDBElement
+public interface IDBSchemaElement extends IDBNamedElement
{
public IDBSchema getSchema();
- public String getName();
+ /**
+ * @since 4.2
+ */
+ @Deprecated
+ public void setName(String name);
public String getFullName();
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBIndexDelta.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBIndexDelta.java
index 6ed3f5194c..def7c19ac3 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBIndexDelta.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBIndexDelta.java
@@ -26,6 +26,8 @@ public interface IDBIndexDelta extends IDBTableElementDelta, IContainer<IDBIndex
{
public static final String TYPE_PROPERTY = "type";
+ public IDBIndexFieldDelta[] getIndexFieldDeltasSortedByPosition();
+
public Map<String, IDBIndexFieldDelta> getIndexFieldDeltas();
public IDBIndex getElement(IDBSchema schema);
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBPropertyDelta.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBPropertyDelta.java
index d08ce10f95..7a209b7e23 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBPropertyDelta.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBPropertyDelta.java
@@ -10,6 +10,7 @@
*/
package org.eclipse.net4j.db.ddl.delta;
+import org.eclipse.net4j.db.IDBElement;
import org.eclipse.net4j.db.ddl.delta.IDBDelta.ChangeKind;
import java.io.Serializable;
@@ -20,7 +21,7 @@ import java.io.Serializable;
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
-public interface IDBPropertyDelta<T> extends Serializable
+public interface IDBPropertyDelta<T> extends IDBElement, Serializable
{
public String getName();
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 4317203650..ded98ac7a4 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
@@ -17,20 +17,17 @@ import org.eclipse.net4j.db.IDBDatabase;
import org.eclipse.net4j.db.IDBTransaction;
import org.eclipse.net4j.spi.db.DBAdapter;
import org.eclipse.net4j.spi.db.DBSchema;
-import org.eclipse.net4j.util.container.IContainerDelta;
-import org.eclipse.net4j.util.container.SingleDeltaContainerEvent;
+import org.eclipse.net4j.util.container.SetContainer;
import java.sql.Connection;
import java.sql.SQLException;
-import java.util.HashSet;
-import java.util.Set;
/**
* @author Eike Stepper
*/
-public final class DBDatabase extends DBElement implements IDBDatabase
+public final class DBDatabase extends SetContainer<IDBTransaction> implements IDBDatabase
{
- private final Set<DBTransaction> transactions = new HashSet<DBTransaction>();
+ // private final Set<DBTransaction> transactions = new HashSet<DBTransaction>();
private DBAdapter adapter;
@@ -44,6 +41,7 @@ public final class DBDatabase extends DBElement implements IDBDatabase
public DBDatabase(DBAdapter adapter, IDBConnectionProvider dbConnectionProvider, final String schemaName)
{
+ super(IDBTransaction.class);
this.adapter = adapter;
connectionProvider = dbConnectionProvider;
@@ -93,44 +91,18 @@ public final class DBDatabase extends DBElement implements IDBDatabase
public DBTransaction openTransaction()
{
DBTransaction transaction = new DBTransaction(this);
- synchronized (transactions)
- {
- transactions.add(transaction);
- }
-
- fireEvent(new SingleDeltaContainerEvent<IDBTransaction>(this, transaction, IContainerDelta.Kind.ADDED));
+ addElement(transaction);
return transaction;
}
public void closeTransaction(DBTransaction transaction)
{
- synchronized (transactions)
- {
- transactions.remove(transaction);
- }
-
- fireEvent(new SingleDeltaContainerEvent<IDBTransaction>(this, transaction, IContainerDelta.Kind.REMOVED));
- }
-
- public DBTransaction[] getTransactions()
- {
- synchronized (transactions)
- {
- return transactions.toArray(new DBTransaction[transactions.size()]);
- }
- }
-
- public boolean isEmpty()
- {
- synchronized (transactions)
- {
- return transactions.isEmpty();
- }
+ removeElement(transaction);
}
- public DBTransaction[] getElements()
+ public IDBTransaction[] getTransactions()
{
- return getTransactions();
+ return getElements();
}
public int getStatementCacheCapacity()
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBPreparedStatement.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBPreparedStatement.java
index 6346e03c0b..fd5cb8b401 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBPreparedStatement.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBPreparedStatement.java
@@ -40,7 +40,7 @@ import java.util.Map;
/**
* @author Eike Stepper
*/
-public final class DBPreparedStatement extends DBElement implements IDBPreparedStatement
+public final class DBPreparedStatement implements IDBPreparedStatement
{
private final DBTransaction transaction;
@@ -593,7 +593,7 @@ public final class DBPreparedStatement extends DBElement implements IDBPreparedS
/**
* @author Eike Stepper
*/
- private final class DBResultSet extends DBElement implements IDBResultSet
+ private final class DBResultSet implements IDBResultSet
{
private final ResultSet delegate;
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 b2a29f9ed9..0c584ec41f 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
@@ -24,8 +24,7 @@ import java.sql.SQLException;
/**
* @author Eike Stepper
*/
-public final class DBSchemaTransaction extends DBElement implements IDBSchemaTransaction,
- RunnableWithConnection<DBSchemaDelta>
+public final class DBSchemaTransaction implements IDBSchemaTransaction, RunnableWithConnection<DBSchemaDelta>
{
private DBDatabase database;
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBTransaction.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBTransaction.java
index caa45f135b..1e44b5a670 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBTransaction.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBTransaction.java
@@ -12,10 +12,10 @@ package org.eclipse.net4j.internal.db;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
-import org.eclipse.net4j.db.IDBTransaction;
import org.eclipse.net4j.db.IDBPreparedStatement;
import org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability;
import org.eclipse.net4j.db.IDBSchemaTransaction;
+import org.eclipse.net4j.db.IDBTransaction;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -28,7 +28,7 @@ import java.util.TreeMap;
/**
* @author Eike Stepper
*/
-public final class DBTransaction extends DBElement implements IDBTransaction
+public final class DBTransaction implements IDBTransaction
{
private final DBDatabase database;
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 f16bc4fd10..a7ed7897fb 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
@@ -13,6 +13,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.spi.db.DBSchemaElement;
/**
* @author Eike Stepper
@@ -27,9 +28,9 @@ public class DBField extends DBSchemaElement implements IDBField
public static final int DEFAULT_VARCHAR_LENGTH = 255;
- private DBTable table;
+ private static final long serialVersionUID = 1L;
- private String name;
+ private DBTable table;
private DBType type;
@@ -43,8 +44,8 @@ public class DBField extends DBSchemaElement implements IDBField
public DBField(DBTable table, String name, DBType type, int precision, int scale, boolean notNull, int position)
{
+ super(name);
this.table = table;
- this.name = name;
this.type = type;
this.precision = precision;
this.scale = scale;
@@ -52,6 +53,13 @@ public class DBField extends DBSchemaElement implements IDBField
this.position = position;
}
+ /**
+ * Constructor for deserialization.
+ */
+ protected DBField()
+ {
+ }
+
public IDBSchema getSchema()
{
return table.getSchema();
@@ -62,16 +70,6 @@ public class DBField extends DBSchemaElement implements IDBField
return table;
}
- public String getName()
- {
- return name;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-
public DBType getType()
{
return type;
@@ -151,7 +149,7 @@ public class DBField extends DBSchemaElement implements IDBField
public String getFullName()
{
- return table.getName() + "." + name; //$NON-NLS-1$
+ return table.getName() + "." + getName(); //$NON-NLS-1$
}
public void remove()
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 811f71e048..046f11d37e 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
@@ -15,6 +15,7 @@ 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.DBSchema;
+import org.eclipse.net4j.spi.db.DBSchemaElement;
import java.util.ArrayList;
import java.util.Iterator;
@@ -27,9 +28,9 @@ public class DBIndex extends DBSchemaElement implements IDBIndex
{
public static final IDBIndexField[] NO_INDEX_FIELDS = {};
- private DBTable table;
+ private static final long serialVersionUID = 1L;
- private String name;
+ private DBTable table;
private Type type;
@@ -39,13 +40,8 @@ public class DBIndex extends DBSchemaElement implements IDBIndex
public DBIndex(DBTable table, String name, Type type, IDBField[] fields, int position)
{
- if (name == null)
- {
- name = table.getSchema().createIndexName(table, type, fields, position);
- }
-
+ super(name);
this.table = table;
- this.name = name;
this.type = type;
for (int i = 0; i < fields.length; i++)
@@ -57,6 +53,13 @@ public class DBIndex extends DBSchemaElement implements IDBIndex
this.position = position;
}
+ /**
+ * Constructor for deserialization.
+ */
+ protected DBIndex()
+ {
+ }
+
public DBSchema getSchema()
{
return table.getSchema();
@@ -132,15 +135,7 @@ public class DBIndex extends DBSchemaElement implements IDBIndex
public DBIndexField getIndexField(String name)
{
- for (DBIndexField indexField : indexFields)
- {
- if (indexField.getName().equals(name))
- {
- return indexField;
- }
- }
-
- return null;
+ return findElement(getIndexFields(), name);
}
public DBIndexField getIndexField(int position)
@@ -150,9 +145,10 @@ public class DBIndex extends DBSchemaElement implements IDBIndex
public DBField getField(String name)
{
+ name = name(name);
for (DBIndexField indexField : indexFields)
{
- if (indexField.getName().equals(name))
+ if (indexField.getName() == name)
{
return indexField.getField();
}
@@ -187,11 +183,6 @@ public class DBIndex extends DBSchemaElement implements IDBIndex
return fields;
}
- public String getName()
- {
- return name;
- }
-
public String getFullName()
{
return getName();
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 13bdeffbdb..7137160554 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,12 +12,15 @@ package org.eclipse.net4j.internal.db.ddl;
import org.eclipse.net4j.db.ddl.IDBIndexField;
import org.eclipse.net4j.db.ddl.IDBSchema;
+import org.eclipse.net4j.spi.db.DBSchemaElement;
/**
* @author Eike Stepper
*/
public class DBIndexField extends DBSchemaElement implements IDBIndexField
{
+ private static final long serialVersionUID = 1L;
+
private DBIndex index;
private DBField field;
@@ -26,11 +29,19 @@ public class DBIndexField extends DBSchemaElement implements IDBIndexField
public DBIndexField(DBIndex index, DBField field, int position)
{
+ super(field.getName());
this.index = index;
this.field = field;
this.position = position;
}
+ /**
+ * Constructor for deserialization.
+ */
+ protected DBIndexField()
+ {
+ }
+
public DBIndex getIndex()
{
return index;
@@ -57,11 +68,6 @@ public class DBIndexField extends DBSchemaElement implements IDBIndexField
return field.getSchema();
}
- public String getName()
- {
- return field.getName();
- }
-
public String getFullName()
{
return field.getFullName();
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 99925617f0..35dfd9bb66 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.IDBIndex.Type;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.spi.db.DBSchema;
+import org.eclipse.net4j.spi.db.DBSchemaElement;
import java.util.ArrayList;
import java.util.Iterator;
@@ -31,9 +32,9 @@ public class DBTable extends DBSchemaElement implements IDBTable
public static final IDBIndex[] NO_INDICES = {};
- private DBSchema schema;
+ private static final long serialVersionUID = 1L;
- private String name;
+ private DBSchema schema;
private List<DBField> fields = new ArrayList<DBField>();
@@ -41,18 +42,20 @@ public class DBTable extends DBSchemaElement implements IDBTable
public DBTable(DBSchema schema, String name)
{
+ super(name);
this.schema = schema;
- this.name = name;
}
- public DBSchema getSchema()
+ /**
+ * Constructor for deserialization.
+ */
+ protected DBTable()
{
- return schema;
}
- public String getName()
+ public DBSchema getSchema()
{
- return name;
+ return schema;
}
public DBField addField(String name, DBType type)
@@ -117,15 +120,7 @@ public class DBTable extends DBSchemaElement implements IDBTable
public DBField getField(String name)
{
- for (DBField field : fields)
- {
- if (field.getName().equals(name))
- {
- return field;
- }
- }
-
- return null;
+ return findElement(getFields(), name);
}
public DBField getField(int position)
@@ -147,7 +142,18 @@ public class DBTable extends DBSchemaElement implements IDBTable
{
schema.assertUnlocked();
- DBIndex index = new DBIndex(this, name, type, fields, indices.size());
+ int position = indices.size();
+ if (name == null)
+ {
+ name = schema.createIndexName(this, type, fields, position);
+ }
+
+ if (getIndex(name) != null)
+ {
+ throw new DBException("Index exists: " + name); //$NON-NLS-1$
+ }
+
+ DBIndex index = new DBIndex(this, name, type, fields, position);
indices.add(index);
return index;
}
@@ -179,15 +185,7 @@ public class DBTable extends DBSchemaElement implements IDBTable
public DBIndex getIndex(String name)
{
- for (DBIndex index : indices)
- {
- if (index.getName().equals(name))
- {
- return index;
- }
- }
-
- return null;
+ return findElement(getIndices(), name);
}
public DBIndex getIndex(int position)
@@ -220,12 +218,12 @@ public class DBTable extends DBSchemaElement implements IDBTable
public String getFullName()
{
- return name;
+ return getName();
}
public void remove()
{
- schema.removeTable(name);
+ schema.removeTable(getName());
}
public String sqlInsert()
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBDelta.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBDelta.java
index fe27e48ccb..f704072134 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBDelta.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBDelta.java
@@ -12,35 +12,33 @@ package org.eclipse.net4j.internal.db.ddl.delta;
import org.eclipse.net4j.db.ddl.IDBSchemaElement;
import org.eclipse.net4j.db.ddl.delta.IDBDelta;
+import org.eclipse.net4j.db.ddl.delta.IDBFieldDelta;
import org.eclipse.net4j.db.ddl.delta.IDBPropertyDelta;
-import org.eclipse.net4j.internal.db.DBElement;
-import org.eclipse.net4j.util.CheckUtil;
+import org.eclipse.net4j.spi.db.DBNamedElement;
+import org.eclipse.net4j.spi.db.DBSchemaElement;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
/**
* @author Eike Stepper
*/
-public abstract class DBDelta extends DBElement implements IDBDelta
+public abstract class DBDelta extends DBNamedElement implements IDBDelta
{
private static final long serialVersionUID = 1L;
- private IDBDelta parent;
-
- private String name;
+ private DBDelta parent;
private ChangeKind changeKind;
private Map<String, IDBPropertyDelta<?>> propertyDeltas = new HashMap<String, IDBPropertyDelta<?>>();
- public DBDelta(IDBDelta parent, String name, ChangeKind changeKind)
+ public DBDelta(DBDelta parent, String name, ChangeKind changeKind)
{
- CheckUtil.checkArg(name, "name");
-
+ super(name);
this.parent = parent;
- this.name = name;
this.changeKind = changeKind;
}
@@ -51,25 +49,22 @@ public abstract class DBDelta extends DBElement implements IDBDelta
{
}
- public IDBDelta getParent()
+ public DBDelta getParent()
{
return parent;
}
- public final String getName()
- {
- return name;
- }
-
public final ChangeKind getChangeKind()
{
return changeKind;
}
- public <T> IDBPropertyDelta<T> getPropertyDelta(String name)
+ public <T> DBPropertyDelta<T> getPropertyDelta(String name)
{
+ name = name(name);
+
@SuppressWarnings("unchecked")
- IDBPropertyDelta<T> propertyDelta = (IDBPropertyDelta<T>)propertyDeltas.get(name);
+ DBPropertyDelta<T> propertyDelta = (DBPropertyDelta<T>)propertyDeltas.get(name);
return propertyDelta;
}
@@ -81,6 +76,11 @@ public abstract class DBDelta extends DBElement implements IDBDelta
public <T> T getPropertyValue(String name, boolean old)
{
IDBPropertyDelta<T> propertyDelta = getPropertyDelta(name);
+ if (propertyDelta == null)
+ {
+ return null;
+ }
+
if (old)
{
return propertyDelta.getOldValue();
@@ -117,7 +117,7 @@ public abstract class DBDelta extends DBElement implements IDBDelta
T element = elements[i];
String name = element.getName();
- T oldElement = findElement(oldElements, name);
+ T oldElement = DBSchemaElement.findElement(oldElements, name);
comparator.compare(element, oldElement);
}
@@ -126,32 +126,42 @@ public abstract class DBDelta extends DBElement implements IDBDelta
T oldElement = oldElements[i];
String name = oldElement.getName();
- if (findElement(elements, name) == null)
+ if (DBSchemaElement.findElement(elements, name) == null)
{
comparator.compare(null, oldElement);
}
}
}
- private static <T extends IDBSchemaElement> T findElement(T[] elements, String name)
+ /**
+ * @author Eike Stepper
+ */
+ public interface SchemaElementComparator<T extends IDBSchemaElement>
{
- for (int i = 0; i < elements.length; i++)
- {
- T element = elements[i];
- if (element.getName().equals(name))
- {
- return element;
- }
- }
-
- return null;
+ public void compare(T element, T oldElement);
}
/**
* @author Eike Stepper
*/
- public interface SchemaElementComparator<T extends IDBSchemaElement>
+ public static final class PositionComparator implements Comparator<IDBDelta>
{
- public void compare(T element, T oldElement);
+ public int compare(IDBDelta delta1, IDBDelta delta2)
+ {
+ int v1 = getValue(delta1);
+ int v2 = getValue(delta2);
+ return v2 - v1;
+ }
+
+ private Integer getValue(IDBDelta delta)
+ {
+ Integer value = delta.getPropertyValue(IDBFieldDelta.POSITION_PROPERTY);
+ if (value == null)
+ {
+ return 0;
+ }
+
+ return value;
+ }
}
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBFieldDelta.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBFieldDelta.java
index 53cd451df4..1cc23df9b9 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBFieldDelta.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBFieldDelta.java
@@ -11,13 +11,12 @@
package org.eclipse.net4j.internal.db.ddl.delta;
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.IDBTable;
-import org.eclipse.net4j.db.ddl.delta.IDBDelta;
import org.eclipse.net4j.db.ddl.delta.IDBDeltaVisitor;
import org.eclipse.net4j.db.ddl.delta.IDBFieldDelta;
import org.eclipse.net4j.db.ddl.delta.IDBPropertyDelta;
+import org.eclipse.net4j.internal.db.ddl.DBField;
+import org.eclipse.net4j.internal.db.ddl.DBTable;
import org.eclipse.net4j.util.ObjectUtil;
/**
@@ -27,12 +26,12 @@ public final class DBFieldDelta extends DBTableElementDelta implements IDBFieldD
{
private static final long serialVersionUID = 1L;
- public DBFieldDelta(IDBDelta parent, String name, ChangeKind changeKind)
+ public DBFieldDelta(DBDelta parent, String name, ChangeKind changeKind)
{
super(parent, name, changeKind);
}
- public DBFieldDelta(DBTableDelta parent, IDBField field, IDBField oldField)
+ public DBFieldDelta(DBDelta parent, DBField field, DBField oldField)
{
this(parent, getName(field, oldField), getChangeKind(field, oldField));
@@ -92,9 +91,9 @@ public final class DBFieldDelta extends DBTableElementDelta implements IDBFieldD
visitor.visit(this);
}
- public IDBField getElement(IDBSchema schema)
+ public DBField getElement(IDBSchema schema)
{
- IDBTable table = getParent().getElement(schema);
+ DBTable table = getParent().getElement(schema);
if (table == null)
{
return null;
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBIndexDelta.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBIndexDelta.java
index baea331d77..f88310f09e 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBIndexDelta.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBIndexDelta.java
@@ -13,13 +13,13 @@ package org.eclipse.net4j.internal.db.ddl.delta;
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.IDBTable;
-import org.eclipse.net4j.db.ddl.delta.IDBDelta;
import org.eclipse.net4j.db.ddl.delta.IDBDeltaVisitor;
import org.eclipse.net4j.db.ddl.delta.IDBIndexDelta;
import org.eclipse.net4j.db.ddl.delta.IDBIndexFieldDelta;
import org.eclipse.net4j.db.ddl.delta.IDBPropertyDelta;
import org.eclipse.net4j.internal.db.ddl.DBIndex;
+import org.eclipse.net4j.internal.db.ddl.DBIndexField;
+import org.eclipse.net4j.internal.db.ddl.DBTable;
import org.eclipse.net4j.util.ObjectUtil;
import java.util.Arrays;
@@ -40,12 +40,12 @@ public final class DBIndexDelta extends DBTableElementDelta implements IDBIndexD
private Map<String, IDBIndexFieldDelta> indexFieldDeltas = new HashMap<String, IDBIndexFieldDelta>();
- public DBIndexDelta(IDBDelta parent, String name, ChangeKind changeKind)
+ public DBIndexDelta(DBDelta parent, String name, ChangeKind changeKind)
{
super(parent, name, changeKind);
}
- public DBIndexDelta(DBTableDelta parent, IDBIndex index, IDBIndex oldIndex)
+ public DBIndexDelta(DBDelta parent, DBIndex index, DBIndex oldIndex)
{
this(parent, getName(index, oldIndex), getChangeKind(index, oldIndex));
@@ -62,7 +62,8 @@ public final class DBIndexDelta extends DBTableElementDelta implements IDBIndexD
{
public void compare(IDBIndexField indexField, IDBIndexField oldIndexField)
{
- DBIndexFieldDelta indexFieldDelta = new DBIndexFieldDelta(DBIndexDelta.this, indexField, oldIndexField);
+ DBIndexFieldDelta indexFieldDelta = new DBIndexFieldDelta(DBIndexDelta.this, (DBIndexField)indexField,
+ (DBIndexField)oldIndexField);
addIndexFieldDelta(indexFieldDelta);
}
});
@@ -100,6 +101,13 @@ public final class DBIndexDelta extends DBTableElementDelta implements IDBIndexD
this.oldType = oldType;
}
+ public DBIndexFieldDelta[] getIndexFieldDeltasSortedByPosition()
+ {
+ DBIndexFieldDelta[] result = indexFieldDeltas.values().toArray(new DBIndexFieldDelta[indexFieldDeltas.size()]);
+ Arrays.sort(result, new PositionComparator());
+ return result;
+ }
+
public Map<String, IDBIndexFieldDelta> getIndexFieldDeltas()
{
return Collections.unmodifiableMap(indexFieldDeltas);
@@ -110,11 +118,9 @@ public final class DBIndexDelta extends DBTableElementDelta implements IDBIndexD
return indexFieldDeltas.isEmpty();
}
- public IDBIndexFieldDelta[] getElements()
+ public DBIndexFieldDelta[] getElements()
{
- IDBIndexFieldDelta[] elements = indexFieldDeltas.values().toArray(new IDBIndexFieldDelta[indexFieldDeltas.size()]);
- Arrays.sort(elements);
- return elements;
+ return getIndexFieldDeltasSortedByPosition();
}
public void addIndexFieldDelta(DBIndexFieldDelta indexFieldDelta)
@@ -125,15 +131,15 @@ public final class DBIndexDelta extends DBTableElementDelta implements IDBIndexD
public void accept(IDBDeltaVisitor visitor)
{
visitor.visit(this);
- for (IDBIndexFieldDelta indexFieldDelta : getElements())
+ for (IDBIndexFieldDelta indexFieldDelta : getIndexFieldDeltasSortedByPosition())
{
indexFieldDelta.accept(visitor);
}
}
- public IDBIndex getElement(IDBSchema schema)
+ public DBIndex getElement(IDBSchema schema)
{
- IDBTable table = getParent().getElement(schema);
+ DBTable table = getParent().getElement(schema);
if (table == null)
{
return null;
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBIndexFieldDelta.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBIndexFieldDelta.java
index 82ea36e41d..19f262fae9 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBIndexFieldDelta.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBIndexFieldDelta.java
@@ -10,14 +10,12 @@
*/
package org.eclipse.net4j.internal.db.ddl.delta;
-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.delta.IDBDelta;
import org.eclipse.net4j.db.ddl.delta.IDBDeltaVisitor;
-import org.eclipse.net4j.db.ddl.delta.IDBIndexDelta;
import org.eclipse.net4j.db.ddl.delta.IDBIndexFieldDelta;
import org.eclipse.net4j.db.ddl.delta.IDBPropertyDelta;
+import org.eclipse.net4j.internal.db.ddl.DBIndex;
+import org.eclipse.net4j.internal.db.ddl.DBIndexField;
import org.eclipse.net4j.util.ObjectUtil;
/**
@@ -27,16 +25,16 @@ public final class DBIndexFieldDelta extends DBDelta implements IDBIndexFieldDel
{
private static final long serialVersionUID = 1L;
- public DBIndexFieldDelta(IDBDelta parent, ChangeKind changeKind, String name)
+ public DBIndexFieldDelta(DBDelta parent, ChangeKind changeKind, String name)
{
super(parent, name, changeKind);
}
- public DBIndexFieldDelta(DBIndexDelta parent, IDBIndexField indexField, IDBIndexField oldIndexField)
+ public DBIndexFieldDelta(DBIndexDelta parent, DBIndexField indexField, DBIndexField oldIndexField)
{
this(parent, getChangeKind(indexField, oldIndexField), getName(indexField, oldIndexField));
- Integer position = oldIndexField == null ? null : indexField.getPosition();
+ Integer position = indexField == null ? null : indexField.getPosition();
Integer oldPosition = oldIndexField == null ? null : oldIndexField.getPosition();
if (!ObjectUtil.equals(position, oldPosition))
{
@@ -53,9 +51,9 @@ public final class DBIndexFieldDelta extends DBDelta implements IDBIndexFieldDel
}
@Override
- public IDBIndexDelta getParent()
+ public DBIndexDelta getParent()
{
- return (IDBIndexDelta)super.getParent();
+ return (DBIndexDelta)super.getParent();
}
public int compareTo(IDBIndexFieldDelta o)
@@ -68,9 +66,9 @@ public final class DBIndexFieldDelta extends DBDelta implements IDBIndexFieldDel
visitor.visit(this);
}
- public IDBIndexField getElement(IDBSchema schema)
+ public DBIndexField getElement(IDBSchema schema)
{
- IDBIndex index = getParent().getElement(schema);
+ DBIndex index = getParent().getElement(schema);
if (index == null)
{
return null;
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBPropertyDelta.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBPropertyDelta.java
index f104957842..73f441a762 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBPropertyDelta.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBPropertyDelta.java
@@ -12,33 +12,34 @@ package org.eclipse.net4j.internal.db.ddl.delta;
import org.eclipse.net4j.db.ddl.delta.IDBDelta.ChangeKind;
import org.eclipse.net4j.db.ddl.delta.IDBPropertyDelta;
+import org.eclipse.net4j.spi.db.DBNamedElement;
/**
* @author Eike Stepper
*/
-public final class DBPropertyDelta<T> implements IDBPropertyDelta<T>
+public final class DBPropertyDelta<T> extends DBNamedElement implements IDBPropertyDelta<T>
{
private static final long serialVersionUID = 1L;
- private final String name;
+ private Type type;
- private final Type type;
+ private T value;
- private final T value;
-
- private final T oldValue;
+ private T oldValue;
public DBPropertyDelta(String name, Type type, T value, T oldValue)
{
- this.name = name;
+ super(name);
this.type = type;
this.value = value;
this.oldValue = oldValue;
}
- public String getName()
+ /**
+ * Constructor for deserialization.
+ */
+ protected DBPropertyDelta()
{
- return name;
}
public ChangeKind getChangeKind()
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBSchemaDelta.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBSchemaDelta.java
index b47cdcd73d..2cc754ef9d 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBSchemaDelta.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBSchemaDelta.java
@@ -15,6 +15,7 @@ import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.db.ddl.delta.IDBDeltaVisitor;
import org.eclipse.net4j.db.ddl.delta.IDBSchemaDelta;
import org.eclipse.net4j.db.ddl.delta.IDBTableDelta;
+import org.eclipse.net4j.internal.db.ddl.DBTable;
import org.eclipse.net4j.spi.db.DBSchema;
import java.util.Arrays;
@@ -46,7 +47,7 @@ public final class DBSchemaDelta extends DBDelta implements IDBSchemaDelta
{
public void compare(IDBTable table, IDBTable oldTable)
{
- DBTableDelta tableDelta = new DBTableDelta(DBSchemaDelta.this, table, oldTable);
+ DBTableDelta tableDelta = new DBTableDelta(DBSchemaDelta.this, (DBTable)table, (DBTable)oldTable);
addTableDelta(tableDelta);
}
});
@@ -69,9 +70,9 @@ public final class DBSchemaDelta extends DBDelta implements IDBSchemaDelta
return tableDeltas.isEmpty();
}
- public IDBTableDelta[] getElements()
+ public DBTableDelta[] getElements()
{
- IDBTableDelta[] elements = tableDeltas.values().toArray(new IDBTableDelta[tableDeltas.size()]);
+ DBTableDelta[] elements = tableDeltas.values().toArray(new DBTableDelta[tableDeltas.size()]);
Arrays.sort(elements);
return elements;
}
@@ -89,15 +90,15 @@ public final class DBSchemaDelta extends DBDelta implements IDBSchemaDelta
public void accept(IDBDeltaVisitor visitor)
{
visitor.visit(this);
- for (IDBTableDelta tableDelta : getElements())
+ for (DBDelta tableDelta : getElements())
{
tableDelta.accept(visitor);
}
}
- public IDBSchema getElement(IDBSchema schema)
+ public DBSchema getElement(IDBSchema schema)
{
- return schema;
+ return (DBSchema)schema;
}
public void applyTo(IDBSchema schema)
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBTableDelta.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBTableDelta.java
index 73edbf30d9..6f274c4dcd 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBTableDelta.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBTableDelta.java
@@ -13,19 +13,16 @@ package org.eclipse.net4j.internal.db.ddl.delta;
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.db.ddl.delta.IDBDelta;
import org.eclipse.net4j.db.ddl.delta.IDBDeltaVisitor;
import org.eclipse.net4j.db.ddl.delta.IDBFieldDelta;
import org.eclipse.net4j.db.ddl.delta.IDBIndexDelta;
-import org.eclipse.net4j.db.ddl.delta.IDBSchemaDelta;
import org.eclipse.net4j.db.ddl.delta.IDBTableDelta;
-import org.eclipse.net4j.db.ddl.delta.IDBTableElementDelta;
+import org.eclipse.net4j.internal.db.ddl.DBField;
+import org.eclipse.net4j.internal.db.ddl.DBIndex;
import org.eclipse.net4j.internal.db.ddl.DBTable;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
@@ -40,12 +37,12 @@ public final class DBTableDelta extends DBDelta implements IDBTableDelta
private Map<String, IDBIndexDelta> indexDeltas = new HashMap<String, IDBIndexDelta>();
- public DBTableDelta(IDBDelta parent, String name, ChangeKind changeKind)
+ public DBTableDelta(DBDelta parent, String name, ChangeKind changeKind)
{
super(parent, name, changeKind);
}
- public DBTableDelta(DBSchemaDelta parent, IDBTable table, IDBTable oldTable)
+ public DBTableDelta(DBSchemaDelta parent, DBTable table, DBTable oldTable)
{
this(parent, table.getName(), oldTable == null ? ChangeKind.ADDED : ChangeKind.CHANGED);
@@ -55,7 +52,7 @@ public final class DBTableDelta extends DBDelta implements IDBTableDelta
{
public void compare(IDBField field, IDBField oldField)
{
- DBFieldDelta fieldDelta = new DBFieldDelta(DBTableDelta.this, field, oldField);
+ DBFieldDelta fieldDelta = new DBFieldDelta(DBTableDelta.this, (DBField)field, (DBField)oldField);
addFieldDelta(fieldDelta);
}
});
@@ -66,7 +63,7 @@ public final class DBTableDelta extends DBDelta implements IDBTableDelta
{
public void compare(IDBIndex index, IDBIndex oldIndex)
{
- DBIndexDelta indexDelta = new DBIndexDelta(DBTableDelta.this, index, oldIndex);
+ DBIndexDelta indexDelta = new DBIndexDelta(DBTableDelta.this, (DBIndex)index, (DBIndex)oldIndex);
addIndexDelta(indexDelta);
}
});
@@ -80,35 +77,15 @@ public final class DBTableDelta extends DBDelta implements IDBTableDelta
}
@Override
- public IDBSchemaDelta getParent()
+ public DBSchemaDelta getParent()
{
- return (IDBSchemaDelta)super.getParent();
+ return (DBSchemaDelta)super.getParent();
}
- public IDBFieldDelta[] getFieldDeltasSortedByPosition()
+ public DBFieldDelta[] getFieldDeltasSortedByPosition()
{
- IDBFieldDelta[] result = fieldDeltas.values().toArray(new IDBFieldDelta[fieldDeltas.size()]);
- Arrays.sort(result, new Comparator<IDBFieldDelta>()
- {
- public int compare(IDBFieldDelta o1, IDBFieldDelta o2)
- {
- int v1 = getValue(o1);
- int v2 = getValue(o2);
- return v2 - v1;
- }
-
- private Integer getValue(IDBFieldDelta fieldDelta)
- {
- Integer value = fieldDelta.getPropertyValue(IDBFieldDelta.POSITION_PROPERTY);
- if (value == null)
- {
- return 0;
- }
-
- return value;
- }
- });
-
+ DBFieldDelta[] result = fieldDeltas.values().toArray(new DBFieldDelta[fieldDeltas.size()]);
+ Arrays.sort(result, new PositionComparator());
return result;
}
@@ -127,19 +104,19 @@ public final class DBTableDelta extends DBDelta implements IDBTableDelta
return fieldDeltas.isEmpty() && indexDeltas.isEmpty();
}
- public IDBTableElementDelta[] getElements()
+ public DBTableElementDelta[] getElements()
{
- IDBTableElementDelta[] elements = new IDBTableElementDelta[fieldDeltas.size() + indexDeltas.size()];
+ DBTableElementDelta[] elements = new DBTableElementDelta[fieldDeltas.size() + indexDeltas.size()];
int i = 0;
- for (IDBFieldDelta fieldDelta : fieldDeltas.values())
+ for (IDBFieldDelta fieldDelta : getFieldDeltasSortedByPosition())
{
- elements[i++] = fieldDelta;
+ elements[i++] = (DBTableElementDelta)fieldDelta;
}
for (IDBIndexDelta indexDelta : indexDeltas.values())
{
- elements[i++] = indexDelta;
+ elements[i++] = (DBTableElementDelta)indexDelta;
}
Arrays.sort(elements);
@@ -164,14 +141,20 @@ public final class DBTableDelta extends DBDelta implements IDBTableDelta
public void accept(IDBDeltaVisitor visitor)
{
visitor.visit(this);
- for (IDBTableElementDelta tableElementDelta : getElements())
+
+ for (IDBFieldDelta fieldDelta : getFieldDeltasSortedByPosition())
+ {
+ fieldDelta.accept(visitor);
+ }
+
+ for (IDBIndexDelta indexDelta : getIndexDeltas().values())
{
- tableElementDelta.accept(visitor);
+ indexDelta.accept(visitor);
}
}
- public IDBTable getElement(IDBSchema schema)
+ public DBTable getElement(IDBSchema schema)
{
- return schema.getTable(getName());
+ return (DBTable)schema.getTable(getName());
}
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBTableElementDelta.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBTableElementDelta.java
index cbf5ad787c..6991d5e078 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBTableElementDelta.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBTableElementDelta.java
@@ -10,8 +10,6 @@
*/
package org.eclipse.net4j.internal.db.ddl.delta;
-import org.eclipse.net4j.db.ddl.delta.IDBDelta;
-import org.eclipse.net4j.db.ddl.delta.IDBTableDelta;
import org.eclipse.net4j.db.ddl.delta.IDBTableElementDelta;
/**
@@ -21,7 +19,7 @@ public abstract class DBTableElementDelta extends DBDelta implements IDBTableEle
{
private static final long serialVersionUID = 1L;
- public DBTableElementDelta(IDBDelta parent, String name, ChangeKind changeKind)
+ public DBTableElementDelta(DBDelta parent, String name, ChangeKind changeKind)
{
super(parent, name, changeKind);
}
@@ -34,9 +32,9 @@ public abstract class DBTableElementDelta extends DBDelta implements IDBTableEle
}
@Override
- public IDBTableDelta getParent()
+ public DBTableDelta getParent()
{
- return (IDBTableDelta)super.getParent();
+ return (DBTableDelta)super.getParent();
}
public int compareTo(IDBTableElementDelta o)
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBAdapter.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBAdapter.java
index c3facf6231..46e468011d 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBAdapter.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBAdapter.java
@@ -93,8 +93,6 @@ public abstract class DBAdapter implements IDBAdapter
private Set<String> reservedWords;
- private int indexCounter;
-
public DBAdapter(String name, String version)
{
this.name = name;
@@ -235,7 +233,6 @@ public abstract class DBAdapter implements IDBAdapter
protected void createIndex(Connection connection, IDBIndex index, IDBIndexDelta delta)
{
IDBTable table = index.getTable();
- String indexName = getIndexNameFor(index, index.getPosition());
StringBuilder builder = new StringBuilder();
builder.append("CREATE "); //$NON-NLS-1$
@@ -245,7 +242,7 @@ public abstract class DBAdapter implements IDBAdapter
}
builder.append("INDEX "); //$NON-NLS-1$
- builder.append(indexName);
+ builder.append(index);
builder.append(" ON "); //$NON-NLS-1$
builder.append(table);
builder.append(" ("); //$NON-NLS-1$
@@ -476,7 +473,7 @@ public abstract class DBAdapter implements IDBAdapter
}
builder.append("INDEX "); //$NON-NLS-1$
- builder.append(getIndexNameFor(index, num));
+ builder.append(index);
builder.append(" ON "); //$NON-NLS-1$
builder.append(table);
builder.append(" ("); //$NON-NLS-1$
@@ -501,14 +498,6 @@ public abstract class DBAdapter implements IDBAdapter
statement.execute(sql);
}
- /**
- * @since 4.2
- */
- protected String getIndexNameFor(IDBIndex index, int num)
- {
- return "I" + System.currentTimeMillis() + "_" + ++indexCounter;
- }
-
protected void addIndexField(StringBuilder builder, IDBField field)
{
builder.append(field);
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBElement.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBElement.java
index cf261d63f3..a9957f8c1e 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBElement.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBElement.java
@@ -8,19 +8,23 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.net4j.internal.db;
+package org.eclipse.net4j.spi.db;
import org.eclipse.net4j.db.IDBElement;
import org.eclipse.net4j.util.event.Notifier;
+import java.io.Serializable;
import java.util.Properties;
/**
* @author Eike Stepper
- * @since 2.0
+ * @since 4.2
+ * @noextend This class is not intended to be subclassed by clients.
*/
-public abstract class DBElement extends Notifier implements IDBElement
+public abstract class DBElement extends Notifier implements IDBElement, Serializable
{
+ private static final long serialVersionUID = 1L;
+
private Properties properties;
public DBElement()
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBNamedElement.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBNamedElement.java
new file mode 100644
index 0000000000..244d0633aa
--- /dev/null
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBNamedElement.java
@@ -0,0 +1,97 @@
+/*
+ * 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.spi.db;
+
+import org.eclipse.net4j.db.IDBNamedElement;
+import org.eclipse.net4j.db.ddl.IDBSchemaElement;
+
+/**
+ * @author Eike Stepper
+ * @since 4.2
+ * @noextend This class is not intended to be subclassed by clients.
+ */
+public abstract class DBNamedElement extends DBElement implements IDBNamedElement
+{
+ private static final long serialVersionUID = 1L;
+
+ private String name;
+
+ public DBNamedElement(String name)
+ {
+ setName(name);
+ }
+
+ /**
+ * Constructor for deserialization.
+ */
+ protected DBNamedElement()
+ {
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name(name);
+ }
+
+ @Override
+ public final boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+
+ if (obj instanceof IDBNamedElement)
+ {
+ IDBNamedElement that = (IDBNamedElement)obj;
+ return name == that.getName();
+ }
+
+ return false;
+ }
+
+ @Override
+ public final int hashCode()
+ {
+ return name.hashCode();
+ }
+
+ @Override
+ public final String toString()
+ {
+ return name;
+ }
+
+ public static String name(String name)
+ {
+ return name.toUpperCase().intern();
+ }
+
+ public static <T extends IDBSchemaElement> T findElement(T[] elements, String name)
+ {
+ name = name(name);
+ for (int i = 0; i < elements.length; i++)
+ {
+ T element = elements[i];
+ if (element.getName() == name)
+ {
+ return element;
+ }
+ }
+
+ return null;
+ }
+}
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 a0302c423e..baeb0e1911 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
@@ -21,7 +21,8 @@ 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.db.ddl.delta.IDBSchemaDelta;
-import org.eclipse.net4j.internal.db.ddl.DBSchemaElement;
+import org.eclipse.net4j.internal.db.ddl.DBField;
+import org.eclipse.net4j.internal.db.ddl.DBIndex;
import org.eclipse.net4j.internal.db.ddl.DBTable;
import org.eclipse.net4j.internal.db.ddl.delta.DBSchemaDelta;
@@ -54,15 +55,17 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
*/
public static final IDBTable[] NO_TABLES = {};
- private String name;
+ private static final long serialVersionUID = 1L;
private Map<String, DBTable> tables = new HashMap<String, DBTable>();
- private boolean locked;
+ private transient boolean locked;
+
+ private transient int indexCounter;
public DBSchema(String name)
{
- this.name = name;
+ super(name);
}
/**
@@ -78,15 +81,14 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
statement = connection.createStatement();
DatabaseMetaData metaData = connection.getMetaData();
- ResultSet tables = metaData.getTables(null, name, null, new String[] { "TABLE" });
+ ResultSet tables = metaData.getTables(null, getName(), null, new String[] { "TABLE" });
while (tables.next())
{
String tableName = tables.getString(3);
IDBTable table = addTable(tableName);
readFields(table, statement);
-
- readIndices(table, metaData, name);
+ readIndices(table, metaData, getName());
}
}
catch (SQLException ex)
@@ -104,7 +106,7 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
*/
public DBSchema(IDBSchema source)
{
- name = source.getName();
+ super(source.getName());
for (IDBTable sourceTable : source.getTables())
{
@@ -117,24 +119,33 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
for (IDBIndex sourceIndex : sourceTable.getIndices())
{
- table.addIndex(sourceIndex.getType(), sourceIndex.getFields());
+ DBIndex index = table.addIndex(sourceIndex.getType());
+ for (IDBField sourceField : sourceIndex.getFields())
+ {
+ DBField field = table.getField(sourceField.getPosition());
+ index.addIndexField(field);
+ }
}
}
}
- public String getFullName()
+ /**
+ * Constructor for deserialization.
+ *
+ * @since 4.2
+ */
+ protected DBSchema()
{
- return name;
}
- public IDBSchema getSchema()
+ public String getFullName()
{
- return this;
+ return getName();
}
- public String getName()
+ public IDBSchema getSchema()
{
- return name;
+ return this;
}
/**
@@ -149,7 +160,7 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
}
DBTable table = new DBTable(this, name);
- tables.put(name, table);
+ tables.put(table.getName(), table);
return table;
}
@@ -159,6 +170,7 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
public IDBTable removeTable(String name)
{
assertUnlocked();
+ name = name(name);
return tables.remove(name);
}
@@ -167,6 +179,7 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
*/
public IDBTable getTable(String name)
{
+ name = name(name);
return tables.get(name);
}
@@ -221,6 +234,14 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
return locked = false;
}
+ public void assertUnlocked() throws DBException
+ {
+ if (locked)
+ {
+ throw new DBException("Schema locked: " + this); //$NON-NLS-1$
+ }
+ }
+
public Set<IDBTable> create(IDBAdapter dbAdapter, Connection connection) throws DBException
{
return dbAdapter.createTables(tables.values(), connection);
@@ -345,15 +366,7 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
*/
public String createIndexName(IDBTable table, IDBIndex.Type type, IDBField[] fields, int position)
{
- return "idx_" + table.getName() + "_" + position;
- }
-
- public void assertUnlocked() throws DBException
- {
- if (locked)
- {
- throw new DBException("Schema locked: " + name); //$NON-NLS-1$
- }
+ return "I" + System.currentTimeMillis() + "_" + ++indexCounter;
}
private void readFields(IDBTable table, Statement statement) throws SQLException
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/spi/db/DBSchemaElement.java
index 6ffd01e9bb..2405e18d7f 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/spi/db/DBSchemaElement.java
@@ -8,24 +8,28 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.net4j.internal.db.ddl;
+package org.eclipse.net4j.spi.db;
import org.eclipse.net4j.db.ddl.IDBSchemaElement;
-import org.eclipse.net4j.internal.db.DBElement;
/**
* @author Eike Stepper
- * @since 2.0
+ * @since 4.2
+ * @noextend This class is not intended to be subclassed by clients.
*/
-public abstract class DBSchemaElement extends DBElement implements IDBSchemaElement
+public abstract class DBSchemaElement extends DBNamedElement implements IDBSchemaElement
{
- public DBSchemaElement()
+ private static final long serialVersionUID = 1L;
+
+ public DBSchemaElement(String name)
{
+ super(name);
}
- @Override
- public final String toString()
+ /**
+ * Constructor for deserialization.
+ */
+ protected DBSchemaElement()
{
- return getName();
}
}
diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms.server.jdbc/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms.server.jdbc/META-INF/MANIFEST.MF
index 7b696b453b..de91ba158d 100644
--- a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms.server.jdbc/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms.server.jdbc/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.net4j.jms.server.jdbc
-Bundle-Version: 4.0.100.qualifier
+Bundle-Version: 4.0.200.qualifier
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
@@ -13,6 +13,6 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
org.eclipse.net4j.jms.server;bundle-version="[4.0.0,5.0.0)";visibility:=reexport,
org.eclipse.net4j.db;bundle-version="[4.0.0,5.0.0)";visibility:=reexport
Import-Package: javax.jms;version="[1.1.0,2.0.0)"
-Export-Package: org.eclipse.net4j.jms.server.internal.jdbc;version="4.0.100";x-internal:=true,
- org.eclipse.net4j.jms.server.internal.jdbc.bundle;version="4.0.100";x-internal:=true,
- org.eclipse.net4j.jms.server.jdbc;version="4.0.100"
+Export-Package: org.eclipse.net4j.jms.server.internal.jdbc;version="4.0.200";x-internal:=true,
+ org.eclipse.net4j.jms.server.internal.jdbc.bundle;version="4.0.200";x-internal:=true,
+ org.eclipse.net4j.jms.server.jdbc;version="4.0.200"
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 75fb324616..c3e9ea82bc 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
@@ -4,7 +4,7 @@
* 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
*/
@@ -23,6 +23,8 @@ public class JMSSchema extends DBSchema
{
public static final JMSSchema INSTANCE = new JMSSchema();
+ private static final long serialVersionUID = 1L;
+
/**
* DBTable Destinations
*/
diff --git a/plugins/org.eclipse.net4j.jms.server.jdbc/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.jms.server.jdbc/META-INF/MANIFEST.MF
index 7b696b453b..de91ba158d 100644
--- a/plugins/org.eclipse.net4j.jms.server.jdbc/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.jms.server.jdbc/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.net4j.jms.server.jdbc
-Bundle-Version: 4.0.100.qualifier
+Bundle-Version: 4.0.200.qualifier
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
@@ -13,6 +13,6 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
org.eclipse.net4j.jms.server;bundle-version="[4.0.0,5.0.0)";visibility:=reexport,
org.eclipse.net4j.db;bundle-version="[4.0.0,5.0.0)";visibility:=reexport
Import-Package: javax.jms;version="[1.1.0,2.0.0)"
-Export-Package: org.eclipse.net4j.jms.server.internal.jdbc;version="4.0.100";x-internal:=true,
- org.eclipse.net4j.jms.server.internal.jdbc.bundle;version="4.0.100";x-internal:=true,
- org.eclipse.net4j.jms.server.jdbc;version="4.0.100"
+Export-Package: org.eclipse.net4j.jms.server.internal.jdbc;version="4.0.200";x-internal:=true,
+ org.eclipse.net4j.jms.server.internal.jdbc.bundle;version="4.0.200";x-internal:=true,
+ org.eclipse.net4j.jms.server.jdbc;version="4.0.200"
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 75fb324616..c3e9ea82bc 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
@@ -4,7 +4,7 @@
* 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
*/
@@ -23,6 +23,8 @@ public class JMSSchema extends DBSchema
{
public static final JMSSchema INSTANCE = new JMSSchema();
+ private static final long serialVersionUID = 1L;
+
/**
* DBTable Destinations
*/

Back to the top