Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-03-08 03:35:06 -0500
committerEike Stepper2013-03-08 03:38:52 -0500
commitf2879b592ade925aa9b793a36e3884efc63e52ba (patch)
tree10a53f26fdf77b43327354c326c5cb115053bb8d
parentc811a8460f00883d9f81b8429e1b3f908f73493a (diff)
downloadcdo-f2879b592ade925aa9b793a36e3884efc63e52ba.tar.gz
cdo-f2879b592ade925aa9b793a36e3884efc63e52ba.tar.xz
cdo-f2879b592ade925aa9b793a36e3884efc63e52ba.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.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java7
-rw-r--r--plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/AbstractDBTest.java47
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBDatabase.java5
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBSchemaTransaction.java13
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBDatabase.java42
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBSchemaTransaction.java36
6 files changed, 71 insertions, 79 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
index db1532f447..f1350f017e 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
@@ -43,6 +43,7 @@ import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.db.IDBConnectionProvider;
import org.eclipse.net4j.db.IDBDatabase;
+import org.eclipse.net4j.db.IDBSchemaTransaction;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBTable;
@@ -621,10 +622,10 @@ public class DBStore extends Store implements IDBStore, CDOAllRevisionsProvider
DBUtil.close(connection);
}
- IDBSchema schema = createSchema();
-
database = DBUtil.openDatabase(dbAdapter, dbConnectionProvider, repository.getName());
- database.ensureSchema(schema);
+ IDBSchemaTransaction schemaTransaction = database.openSchemaTransaction();
+ schemaTransaction.ensureSchema(CDODBSchema.INSTANCE);
+ schemaTransaction.commit();
LifecycleUtil.activate(idHandler);
LifecycleUtil.activate(metaDataManager);
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 0843467764..4f45ddb833 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
@@ -33,7 +33,7 @@ import java.util.Set;
*/
public abstract class AbstractDBTest extends AbstractOMTest
{
- public static final String SCHEMA_NAME = "test";
+ public static final String SCHEMA_NAME = "TEST";
private IDBAdapter adapter;
@@ -130,7 +130,7 @@ public abstract class AbstractDBTest extends AbstractOMTest
assertEquals(true, schema.isEmpty());
IDBSchemaTransaction schemaTransaction = database.openSchemaTransaction();
- IDBSchema workingCopy = schemaTransaction.getSchema();
+ IDBSchema workingCopy = schemaTransaction.getWorkingCopy();
assertEquals(false, workingCopy.isLocked());
assertEquals(true, workingCopy.isEmpty());
assertEquals(schema, workingCopy);
@@ -190,7 +190,7 @@ public abstract class AbstractDBTest extends AbstractOMTest
IDBSchema schema = database.getSchema();
IDBSchemaTransaction schemaTransaction = database.openSchemaTransaction();
- IDBSchema workingCopy = schemaTransaction.getSchema();
+ IDBSchema workingCopy = schemaTransaction.getWorkingCopy();
IDBTable table1 = workingCopy.addTable("table1");
IDBField field11 = table1.addField("field11", DBType.INTEGER, true);
@@ -226,7 +226,7 @@ public abstract class AbstractDBTest extends AbstractOMTest
assertNotNull(index13);
schemaTransaction = database2.openSchemaTransaction();
- workingCopy = schemaTransaction.getSchema();
+ workingCopy = schemaTransaction.getWorkingCopy();
assertEquals(true, schema2.isLocked());
assertEquals(false, schema2.isEmpty());
assertEquals(1, schema2.getTables().length);
@@ -286,19 +286,21 @@ public abstract class AbstractDBTest extends AbstractOMTest
public void testEnsureSchema() throws Exception
{
- // Init database
- IDBDatabase database = DBUtil.openDatabase(adapter, connectionProvider, SCHEMA_NAME);
- IDBSchemaTransaction schemaTransaction = database.openSchemaTransaction();
- IDBSchema workingCopy = schemaTransaction.getSchema();
+ {
+ // Init database
+ IDBDatabase database = DBUtil.openDatabase(adapter, connectionProvider, SCHEMA_NAME);
+ IDBSchemaTransaction schemaTransaction = database.openSchemaTransaction();
+ IDBSchema workingCopy = schemaTransaction.getWorkingCopy();
- IDBTable table1 = workingCopy.addTable("table1");
- table1.addField("field11", DBType.INTEGER, true);
- table1.addField("field12", DBType.VARCHAR, 64, true);
- table1.addField("field13", DBType.BOOLEAN);
+ IDBTable table1 = workingCopy.addTable("table1");
+ table1.addField("field11", DBType.INTEGER, true);
+ table1.addField("field12", DBType.VARCHAR, 64, true);
+ table1.addField("field13", DBType.BOOLEAN);
- schemaTransaction.commit();
+ schemaTransaction.commit();
+ }
- IDBSchema newSchema = DBUtil.createSchema("bla");
+ IDBSchema newSchema = DBUtil.createSchema("DIFFERENT_NAME");
IDBTable table2 = newSchema.addTable("table2");
IDBField field21 = table2.addField("field21", DBType.INTEGER, true);
IDBField field22 = table2.addField("field22", DBType.VARCHAR, 64, true);
@@ -308,14 +310,17 @@ public abstract class AbstractDBTest extends AbstractOMTest
table2.addIndex("index23", IDBIndex.Type.NON_UNIQUE, field22);
// Reload database
- IDBDatabase database2 = DBUtil.openDatabase(adapter, connectionProvider, SCHEMA_NAME);
- database2.ensureSchema(newSchema);
+ IDBDatabase database = DBUtil.openDatabase(adapter, connectionProvider, SCHEMA_NAME);
+ IDBSchemaTransaction schemaTransaction = database.openSchemaTransaction();
+ schemaTransaction.ensureSchema(newSchema);
+ schemaTransaction.commit();
- IDBSchema schema2 = database2.getSchema();
- assertEquals(true, schema2.isLocked());
- assertEquals(false, schema2.isEmpty());
- assertEquals(2, schema2.getTables().length);
+ IDBSchema schema = database.getSchema();
+ assertEquals(true, schema.isLocked());
+ assertEquals(false, schema.isEmpty());
+ assertEquals(SCHEMA_NAME, schema.getName());
+ assertEquals(2, schema.getTables().length);
- DBUtil.dump(schema2);
+ DBUtil.dump(schema);
}
}
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 ef313c5004..82c00288cf 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,7 +11,6 @@
package org.eclipse.net4j.db;
import org.eclipse.net4j.db.ddl.IDBSchema;
-import org.eclipse.net4j.db.ddl.delta.IDBDeltaVisitor;
import org.eclipse.net4j.util.collection.Closeable;
import org.eclipse.net4j.util.container.IContainer;
@@ -35,10 +34,6 @@ public interface IDBDatabase extends IContainer<IDBTransaction>, Closeable
public IDBSchemaTransaction getSchemaTransaction();
- public void ensureSchema(IDBSchema schema, IDBDeltaVisitor.Filter.Policy policy);
-
- public void ensureSchema(IDBSchema schema);
-
public IDBTransaction openTransaction();
public IDBTransaction[] getTransactions();
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 5248cba6f5..d782936db3 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
@@ -11,6 +11,10 @@
package org.eclipse.net4j.db;
import org.eclipse.net4j.db.ddl.IDBSchema;
+import org.eclipse.net4j.db.ddl.delta.IDBDelta.ChangeKind;
+import org.eclipse.net4j.db.ddl.delta.IDBDelta.DeltaType;
+import org.eclipse.net4j.db.ddl.delta.IDBDeltaVisitor;
+import org.eclipse.net4j.db.ddl.delta.IDBDeltaVisitor.Filter.Policy;
import org.eclipse.net4j.db.ddl.delta.IDBSchemaDelta;
import org.eclipse.net4j.util.collection.Closeable;
@@ -22,11 +26,18 @@ import org.eclipse.net4j.util.collection.Closeable;
*/
public interface IDBSchemaTransaction extends Closeable
{
+ public static final Policy DEFAULT_ENSURE_SCHEMA_POLICY = //
+ new IDBDeltaVisitor.Filter.Policy().allow(DeltaType.SCHEMA, ChangeKind.CHANGE).allow(ChangeKind.ADD).freeze();
+
public IDBDatabase getDatabase();
public IDBTransaction getTransaction();
- public IDBSchema getSchema();
+ public IDBSchema getWorkingCopy();
+
+ public IDBSchemaDelta ensureSchema(IDBSchema schema, IDBDeltaVisitor.Filter.Policy policy);
+
+ public IDBSchemaDelta ensureSchema(IDBSchema schema);
public IDBSchemaDelta getSchemaDelta();
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 c1fac3c719..c52be7c5a3 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
@@ -14,14 +14,7 @@ import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.DBUtil.RunnableWithConnection;
import org.eclipse.net4j.db.IDBConnectionProvider;
import org.eclipse.net4j.db.IDBDatabase;
-import org.eclipse.net4j.db.IDBSchemaTransaction;
import org.eclipse.net4j.db.IDBTransaction;
-import org.eclipse.net4j.db.ddl.IDBSchema;
-import org.eclipse.net4j.db.ddl.delta.IDBDelta.ChangeKind;
-import org.eclipse.net4j.db.ddl.delta.IDBDelta.DeltaType;
-import org.eclipse.net4j.db.ddl.delta.IDBDeltaVisitor;
-import org.eclipse.net4j.db.ddl.delta.IDBDeltaVisitor.Filter.Policy;
-import org.eclipse.net4j.db.ddl.delta.IDBSchemaDelta;
import org.eclipse.net4j.spi.db.DBAdapter;
import org.eclipse.net4j.spi.db.DBSchema;
import org.eclipse.net4j.util.WrappedException;
@@ -36,9 +29,6 @@ import java.util.LinkedList;
*/
public final class DBDatabase extends SetContainer<IDBTransaction> implements IDBDatabase
{
- private static final Policy DEFAULT_ENSURE_SCHEMA_POLICY = //
- new IDBDeltaVisitor.Filter.Policy().allow(DeltaType.SCHEMA, ChangeKind.CHANGE).allow(ChangeKind.ADD).freeze();
-
private DBAdapter adapter;
private IDBConnectionProvider connectionProvider;
@@ -124,38 +114,6 @@ public final class DBDatabase extends SetContainer<IDBTransaction> implements ID
return schemaTransaction;
}
- public void ensureSchema(IDBSchema schema, IDBDeltaVisitor.Filter.Policy policy)
- {
- IDBSchemaTransaction schemaTransaction = null;
-
- try
- {
- schemaTransaction = openSchemaTransaction();
- IDBSchema workingCopy = schemaTransaction.getSchema();
-
- IDBSchemaDelta delta = schema.compare(workingCopy);
-
- IDBDeltaVisitor.Copier copier = new IDBDeltaVisitor.Copier(policy);
- delta.accept(copier);
- IDBSchemaDelta result = copier.getResult();
-
- result.applyTo(workingCopy);
- schemaTransaction.commit();
- }
- finally
- {
- if (schemaTransaction != null)
- {
- schemaTransaction.close();
- }
- }
- }
-
- public void ensureSchema(IDBSchema schema)
- {
- ensureSchema(schema, DEFAULT_ENSURE_SCHEMA_POLICY);
- }
-
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 acf371ea4b..c5da299906 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
@@ -14,6 +14,9 @@ import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.DBUtil.RunnableWithConnection;
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.delta.DBSchemaDelta;
import org.eclipse.net4j.spi.db.DBAdapter;
import org.eclipse.net4j.spi.db.DBSchema;
@@ -32,14 +35,14 @@ public final class DBSchemaTransaction implements IDBSchemaTransaction, Runnable
private DBSchema oldSchema;
- private DBSchema schema;
+ private DBSchema workingCopy;
public DBSchemaTransaction(DBDatabase database)
{
this.database = database;
oldSchema = database.getSchema();
- schema = new DBSchema(oldSchema);
+ workingCopy = new DBSchema(oldSchema);
}
public DBDatabase getDatabase()
@@ -57,14 +60,33 @@ public final class DBSchemaTransaction implements IDBSchemaTransaction, Runnable
transaction = getTransaction;
}
- public DBSchema getSchema()
+ public DBSchema getWorkingCopy()
{
- return schema;
+ return workingCopy;
+ }
+
+ public IDBSchemaDelta ensureSchema(IDBSchema schema, IDBDeltaVisitor.Filter.Policy policy)
+ {
+ IDBSchema workingCopy = getWorkingCopy();
+
+ IDBDeltaVisitor.Copier copier = new IDBDeltaVisitor.Copier(policy);
+ IDBSchemaDelta delta = schema.compare(workingCopy);
+ delta.accept(copier);
+
+ DBSchemaDelta result = (DBSchemaDelta)copier.getResult();
+ result.setName(workingCopy.getName());
+ result.applyTo(workingCopy);
+ return result;
+ }
+
+ public IDBSchemaDelta ensureSchema(IDBSchema schema)
+ {
+ return ensureSchema(schema, DEFAULT_ENSURE_SCHEMA_POLICY);
}
public DBSchemaDelta getSchemaDelta()
{
- return (DBSchemaDelta)schema.compare(oldSchema);
+ return (DBSchemaDelta)workingCopy.compare(oldSchema);
}
public DBSchemaDelta commit()
@@ -112,12 +134,12 @@ public final class DBSchemaTransaction implements IDBSchemaTransaction, Runnable
database.closeSchemaTransaction();
transaction = null;
oldSchema = null;
- schema = null;
+ workingCopy = null;
}
}
public boolean isClosed()
{
- return schema == null;
+ return workingCopy == null;
}
}

Back to the top