Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-03-09 08:09:30 +0000
committerEike Stepper2013-03-09 08:09:30 +0000
commit5bc362a99567e233660fdffbd512a6f1b973ad1b (patch)
tree54c07874a38b975096d1d754e730638b4970b79c
parent4de7bf042c339316be23c442aeffb79deb80d2a9 (diff)
downloadcdo-5bc362a99567e233660fdffbd512a6f1b973ad1b.tar.gz
cdo-5bc362a99567e233660fdffbd512a6f1b973ad1b.tar.xz
cdo-5bc362a99567e233660fdffbd512a6f1b973ad1b.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.net4j.db/src/org/eclipse/net4j/db/ddl/IDBIndex.java3
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBTable.java27
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/SchemaElementNotFoundException.java52
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBIndex.java10
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBTable.java51
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBSchemaDelta.java2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchema.java2
7 files changed, 132 insertions, 15 deletions
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBIndex.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBIndex.java
index 0bf2f2490d..00fdd6003a 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBIndex.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBIndex.java
@@ -10,6 +10,7 @@
*/
package org.eclipse.net4j.db.ddl;
+
/**
* An index specification in a {@link IDBTable DB table}.
*
@@ -44,7 +45,7 @@ public interface IDBIndex extends IDBSchemaElement
/**
* @since 4.2
*/
- public IDBIndexField addIndexField(String name);
+ public IDBIndexField addIndexField(String name) throws SchemaElementNotFoundException;
/**
* @since 4.2
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBTable.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBTable.java
index de3893a5dd..d7af67b16c 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBTable.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBTable.java
@@ -46,7 +46,10 @@ public interface IDBTable extends IDBSchemaElement
public IDBField[] getFields();
- public IDBIndex addIndex(IDBIndex.Type type, IDBField... fields);
+ /**
+ * @since 4.2
+ */
+ public IDBField[] getFields(String... fieldNames) throws SchemaElementNotFoundException;
/**
* @since 4.2
@@ -56,6 +59,28 @@ public interface IDBTable extends IDBSchemaElement
/**
* @since 4.2
*/
+ public IDBIndex addIndex(String name, IDBIndex.Type type, String... fieldNames) throws SchemaElementNotFoundException;
+
+ /**
+ * @since 4.2
+ */
+ public IDBIndex addIndexEmpty(String name, IDBIndex.Type type);
+
+ public IDBIndex addIndex(IDBIndex.Type type, IDBField... fields);
+
+ /**
+ * @since 4.2
+ */
+ public IDBIndex addIndex(IDBIndex.Type type, String... fieldNames) throws SchemaElementNotFoundException;
+
+ /**
+ * @since 4.2
+ */
+ public IDBIndex addIndexEmpty(IDBIndex.Type type);
+
+ /**
+ * @since 4.2
+ */
public IDBIndex getIndex(String name);
/**
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/SchemaElementNotFoundException.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/SchemaElementNotFoundException.java
new file mode 100644
index 0000000000..e663db898f
--- /dev/null
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/SchemaElementNotFoundException.java
@@ -0,0 +1,52 @@
+/*
+ * 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.ddl;
+
+import org.eclipse.net4j.db.DBException;
+import org.eclipse.net4j.db.DBUtil;
+
+/**
+ * @since 4.2
+ * @author Eike Stepper
+ */
+public class SchemaElementNotFoundException extends DBException
+{
+ private static final long serialVersionUID = 1L;
+
+ private final IDBSchemaElement parent;
+
+ private final IDBSchemaElement.SchemaElementType type;
+
+ private final String name;
+
+ public SchemaElementNotFoundException(IDBSchemaElement parent, IDBSchemaElement.SchemaElementType type, String name)
+ {
+ super("Schema element '" + name + "' of type " + type + " not found in " + DBUtil.dumpToString(parent));
+ this.parent = parent;
+ this.type = type;
+ this.name = name;
+ }
+
+ public IDBSchemaElement getParent()
+ {
+ return parent;
+ }
+
+ public IDBSchemaElement.SchemaElementType getType()
+ {
+ return type;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+}
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 4195881458..1bd9cc0706 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
@@ -16,9 +16,9 @@ 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.IDBSchemaVisitor;
+import org.eclipse.net4j.db.ddl.SchemaElementNotFoundException;
import org.eclipse.net4j.spi.db.DBSchema;
import org.eclipse.net4j.spi.db.DBSchemaElement;
-import org.eclipse.net4j.util.CheckUtil;
import java.io.IOException;
import java.io.Writer;
@@ -135,10 +135,14 @@ public class DBIndex extends DBSchemaElement implements IDBIndex
return indexField;
}
- public IDBIndexField addIndexField(String name)
+ public IDBIndexField addIndexField(String name) throws SchemaElementNotFoundException
{
DBField field = table.getField(name);
- CheckUtil.checkArg(field, "Field not found: " + name);
+ if (field == null)
+ {
+ throw new SchemaElementNotFoundException(this, SchemaElementType.FIELD, name);
+ }
+
return addIndexField(field);
}
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 0ab09e568f..fc3d939d0e 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
@@ -14,10 +14,10 @@ import org.eclipse.net4j.db.DBException;
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.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.DBSchema;
import org.eclipse.net4j.spi.db.DBSchemaElement;
@@ -153,12 +153,22 @@ public class DBTable extends DBSchemaElement implements IDBTable
return fields.toArray(new DBField[fields.size()]);
}
- public DBIndex addIndex(Type type, IDBField... fields)
+ public DBField[] getFields(String... fieldNames) throws SchemaElementNotFoundException
{
- return addIndex(null, type, fields);
+ List<DBField> result = new ArrayList<DBField>();
+ for (String fieldName : fieldNames)
+ {
+ DBField field = getField(fieldName);
+ if (field == null)
+ {
+ throw new SchemaElementNotFoundException(this, SchemaElementType.FIELD, fieldName);
+ }
+ }
+
+ return result.toArray(new DBField[result.size()]);
}
- public DBIndex addIndex(String name, Type type, IDBField... fields)
+ public DBIndex addIndex(String name, IDBIndex.Type type, IDBField... fields)
{
assertUnlocked();
@@ -173,11 +183,11 @@ public class DBTable extends DBSchemaElement implements IDBTable
throw new DBException("Index exists: " + name); //$NON-NLS-1$
}
- if (type == Type.PRIMARY_KEY)
+ if (type == IDBIndex.Type.PRIMARY_KEY)
{
for (DBIndex index : getIndices())
{
- if (index.getType() == Type.PRIMARY_KEY)
+ if (index.getType() == IDBIndex.Type.PRIMARY_KEY)
{
throw new DBException("Primary key exists: " + index); //$NON-NLS-1$
}
@@ -190,6 +200,31 @@ public class DBTable extends DBSchemaElement implements IDBTable
return index;
}
+ public DBIndex addIndex(String name, IDBIndex.Type type, String... fieldNames)
+ {
+ return addIndex(name, type, getFields(fieldNames));
+ }
+
+ public DBIndex addIndexEmpty(String name, IDBIndex.Type type)
+ {
+ return addIndex(name, type, NO_FIELDS);
+ }
+
+ public DBIndex addIndex(IDBIndex.Type type, IDBField... fields)
+ {
+ return addIndex(null, type, fields);
+ }
+
+ public DBIndex addIndex(IDBIndex.Type type, String... fieldNames)
+ {
+ return addIndex(type, getFields(fieldNames));
+ }
+
+ public DBIndex addIndexEmpty(IDBIndex.Type type)
+ {
+ return addIndex(type, NO_FIELDS);
+ }
+
@SuppressWarnings("deprecation")
public void removeIndex(IDBIndex indexToRemove)
{
@@ -233,9 +268,9 @@ public class DBTable extends DBSchemaElement implements IDBTable
return indices.toArray(new DBIndex[indices.size()]);
}
- public IDBIndex getPrimaryKeyIndex()
+ public DBIndex getPrimaryKeyIndex()
{
- for (IDBIndex index : indices)
+ for (DBIndex index : indices)
{
if (index.getType() == IDBIndex.Type.PRIMARY_KEY)
{
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 b25dac5916..385d7436f4 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
@@ -204,7 +204,7 @@ public final class DBSchemaDelta extends DBDelta implements IDBSchemaDelta
IDBIndex.Type type = delta.getPropertyValue(IDBIndexDelta.TYPE_PROPERTY);
IDBTable table = delta.getParent().getSchemaElement(schema);
- table.addIndex(name, type);
+ table.addIndexEmpty(name, type);
}
@Override
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 fe7d643b98..5be3817622 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
@@ -82,7 +82,7 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
for (IDBIndex sourceIndex : sourceTable.getIndices())
{
- DBIndex index = table.addIndex(sourceIndex.getName(), sourceIndex.getType());
+ DBIndex index = table.addIndexEmpty(sourceIndex.getName(), sourceIndex.getType());
for (IDBField sourceField : sourceIndex.getFields())
{
DBField field = table.getField(sourceField.getPosition());

Back to the top