Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-03-06 03:39:06 -0500
committerEike Stepper2013-03-07 08:44:33 -0500
commitcc850b80de62e22e8b567f8d165176b83cbf81fc (patch)
treeb986efcd0bf051922d859e1cdb23b63f3f489690
parent16aa130826e48bc33f5dbd7888f75face530e90d (diff)
downloadcdo-cc850b80de62e22e8b567f8d165176b83cbf81fc.tar.gz
cdo-cc850b80de62e22e8b567f8d165176b83cbf81fc.tar.xz
cdo-cc850b80de62e22e8b567f8d165176b83cbf81fc.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/IDBField.java5
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBIndex.java1
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBIndexField.java6
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchema.java3
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchemaElement.java37
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchemaVisitor.java65
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBDeltaWithPosition.java6
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBField.java44
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBIndex.java49
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBIndexField.java33
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBTable.java59
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBDelta.java20
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/delta/DBPropertyDelta.java3
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchema.java61
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchemaElement.java101
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/PositionProvider.java20
16 files changed, 395 insertions, 118 deletions
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 95ce7314ee..0ab991768e 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
@@ -11,6 +11,7 @@
package org.eclipse.net4j.db.ddl;
import org.eclipse.net4j.db.DBType;
+import org.eclipse.net4j.util.collection.PositionProvider;
/**
* A field (column) specification in a {@link IDBTable DB table}.
@@ -19,7 +20,7 @@ import org.eclipse.net4j.db.DBType;
* @noimplement This interface is not intended to be implemented by clients.
* @noextend This interface is not intended to be extended by clients.
*/
-public interface IDBField extends IDBSchemaElement
+public interface IDBField extends IDBSchemaElement, PositionProvider
{
public static final int DEFAULT = -1;
@@ -41,8 +42,6 @@ public interface IDBField extends IDBSchemaElement
public void setNotNull(boolean notNull);
- public int getPosition();
-
public String getFullName();
public String formatPrecision();
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 e3da8c7b55..8e9de00991 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
@@ -28,6 +28,7 @@ public interface IDBIndex extends IDBSchemaElement
*/
public void setType(Type type);
+ @Deprecated
public int getPosition();
/**
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBIndexField.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBIndexField.java
index da74d42a36..73b20f5598 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBIndexField.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBIndexField.java
@@ -10,6 +10,8 @@
*/
package org.eclipse.net4j.db.ddl;
+import org.eclipse.net4j.util.collection.PositionProvider;
+
/**
* An index field specification in a {@link IDBIndex DB index}.
*
@@ -18,11 +20,9 @@ package org.eclipse.net4j.db.ddl;
* @noimplement This interface is not intended to be implemented by clients.
* @noextend This interface is not intended to be extended by clients.
*/
-public interface IDBIndexField extends IDBSchemaElement
+public interface IDBIndexField extends IDBSchemaElement, PositionProvider
{
public IDBIndex getIndex();
public IDBField getField();
-
- public int getPosition();
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchema.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchema.java
index a69b0162c0..d6971757de 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchema.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchema.java
@@ -14,7 +14,6 @@ import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.db.IDBConnectionProvider;
import org.eclipse.net4j.db.ddl.delta.IDBSchemaDelta;
-import org.eclipse.net4j.util.container.IContainer;
import javax.sql.DataSource;
@@ -30,7 +29,7 @@ import java.util.Set;
* @noimplement This interface is not intended to be implemented by clients.
* @noextend This interface is not intended to be extended by clients.
*/
-public interface IDBSchema extends IDBSchemaElement, IContainer<IDBTable>
+public interface IDBSchema extends IDBSchemaElement
{
/**
* @since 4.2
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 b637e32107..15e36e9a4a 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
@@ -11,6 +11,9 @@
package org.eclipse.net4j.db.ddl;
import org.eclipse.net4j.db.IDBNamedElement;
+import org.eclipse.net4j.util.container.IContainer;
+
+import java.io.Serializable;
/**
* Specifies a hierachical namespace for elements in a {@link IDBSchema DB schema}.
@@ -19,8 +22,14 @@ import org.eclipse.net4j.db.IDBNamedElement;
* @noimplement This interface is not intended to be implemented by clients.
* @noextend This interface is not intended to be extended by clients.
*/
-public interface IDBSchemaElement extends IDBNamedElement
+public interface IDBSchemaElement extends IDBNamedElement, IContainer<IDBSchemaElement>, Comparable<IDBSchemaElement>,
+ Serializable
{
+ /**
+ * @since 4.2
+ */
+ public SchemaElementType getSchemaElementType();
+
public IDBSchema getSchema();
/**
@@ -34,5 +43,31 @@ public interface IDBSchemaElement extends IDBNamedElement
/**
* @since 4.2
*/
+ public void accept(IDBSchemaVisitor visitor);
+
+ /**
+ * @since 4.2
+ */
public void remove();
+
+ /**
+ * @since 4.2
+ * @author Eike Stepper
+ */
+ public enum SchemaElementType
+ {
+ SCHEMA(0), TABLE(1), FIELD(2), INDEX(2), INDEX_FIELD(3);
+
+ private final int level;
+
+ private SchemaElementType(int level)
+ {
+ this.level = level;
+ }
+
+ public int getLevel()
+ {
+ return level;
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchemaVisitor.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchemaVisitor.java
new file mode 100644
index 0000000000..ec3d5286d1
--- /dev/null
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchemaVisitor.java
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+
+/**
+ * @since 4.2
+ * @author Eike Stepper
+ */
+public interface IDBSchemaVisitor
+{
+ public void visit(IDBSchema schema);
+
+ public void visit(IDBTable table);
+
+ public void visit(IDBField field);
+
+ public void visit(IDBIndex index);
+
+ public void visit(IDBIndexField indexField);
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class Default implements IDBSchemaVisitor
+ {
+ public void visit(IDBSchema element)
+ {
+ visitDefault(element);
+ }
+
+ public void visit(IDBTable element)
+ {
+ visitDefault(element);
+ }
+
+ public void visit(IDBField element)
+ {
+ visitDefault(element);
+ }
+
+ public void visit(IDBIndex element)
+ {
+ visitDefault(element);
+ }
+
+ public void visit(IDBIndexField element)
+ {
+ visitDefault(element);
+ }
+
+ protected void visitDefault(IDBSchemaElement element)
+ {
+ visitDefault(element);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBDeltaWithPosition.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBDeltaWithPosition.java
index d0f54fd1a3..49215372c9 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBDeltaWithPosition.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/delta/IDBDeltaWithPosition.java
@@ -10,15 +10,15 @@
*/
package org.eclipse.net4j.db.ddl.delta;
+import org.eclipse.net4j.util.collection.PositionProvider;
+
/**
* @since 4.2
* @author Eike Stepper
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
-public interface IDBDeltaWithPosition extends IDBDeltaWithProperties
+public interface IDBDeltaWithPosition extends IDBDeltaWithProperties, PositionProvider
{
public static final String POSITION_PROPERTY = "position";
-
- public int getPosition();
}
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 c9f563a14f..7e3bcda220 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,11 +13,13 @@ package org.eclipse.net4j.internal.db.ddl;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBSchema;
+import org.eclipse.net4j.db.ddl.IDBSchemaElement;
+import org.eclipse.net4j.db.ddl.IDBSchemaVisitor;
import org.eclipse.net4j.spi.db.DBSchemaElement;
-import org.eclipse.net4j.util.StringUtil;
import java.io.IOException;
import java.io.Writer;
+import java.util.List;
/**
* @author Eike Stepper
@@ -70,6 +72,11 @@ public class DBField extends DBSchemaElement implements IDBField
{
}
+ public SchemaElementType getSchemaElementType()
+ {
+ return SchemaElementType.FIELD;
+ }
+
public IDBSchema getSchema()
{
return table.getSchema();
@@ -87,7 +94,7 @@ public class DBField extends DBSchemaElement implements IDBField
public void setType(DBType type)
{
- table.getSchema().assertUnlocked();
+ assertUnlocked();
this.type = type;
}
@@ -124,7 +131,7 @@ public class DBField extends DBSchemaElement implements IDBField
public void setPrecision(int precision)
{
- table.getSchema().assertUnlocked();
+ assertUnlocked();
this.precision = precision;
}
@@ -140,7 +147,7 @@ public class DBField extends DBSchemaElement implements IDBField
public void setScale(int scale)
{
- table.getSchema().assertUnlocked();
+ assertUnlocked();
this.scale = scale;
}
@@ -151,7 +158,7 @@ public class DBField extends DBSchemaElement implements IDBField
public void setNotNull(boolean notNull)
{
- table.getSchema().assertUnlocked();
+ assertUnlocked();
this.notNull = notNull;
}
@@ -162,7 +169,7 @@ public class DBField extends DBSchemaElement implements IDBField
public void setPosition(int position)
{
- table.getSchema().assertUnlocked();
+ assertUnlocked();
this.position = position;
}
@@ -198,12 +205,20 @@ public class DBField extends DBSchemaElement implements IDBField
}
@Override
- public void dump(Writer writer) throws IOException
+ protected void collectElements(List<IDBSchemaElement> elements)
+ {
+ // Do nothing
+ }
+
+ @Override
+ protected void doAccept(IDBSchemaVisitor visitor)
+ {
+ visitor.visit(this);
+ }
+
+ @Override
+ protected void dumpAdditionalProperties(Writer writer) throws IOException
{
- writer.append(" FIELD ");
- writer.append(getName());
- writer.append(" (position=");
- writer.append(String.valueOf(getPosition()));
writer.append(", type=");
writer.append(getType().toString());
writer.append(", precision=");
@@ -212,7 +227,10 @@ public class DBField extends DBSchemaElement implements IDBField
writer.append(String.valueOf(getScale()));
writer.append(", notNull=");
writer.append(String.valueOf(isNotNull()));
- writer.append(")");
- writer.append(StringUtil.NL);
+ }
+
+ private void assertUnlocked()
+ {
+ table.getSchema().assertUnlocked();
}
}
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 89f537e73e..9eacac3886 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
@@ -14,9 +14,10 @@ import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBIndex;
import org.eclipse.net4j.db.ddl.IDBIndexField;
+import org.eclipse.net4j.db.ddl.IDBSchemaElement;
+import org.eclipse.net4j.db.ddl.IDBSchemaVisitor;
import org.eclipse.net4j.spi.db.DBSchema;
import org.eclipse.net4j.spi.db.DBSchemaElement;
-import org.eclipse.net4j.util.StringUtil;
import java.io.IOException;
import java.io.Writer;
@@ -63,6 +64,11 @@ public class DBIndex extends DBSchemaElement implements IDBIndex
{
}
+ public SchemaElementType getSchemaElementType()
+ {
+ return SchemaElementType.INDEX;
+ }
+
public DBSchema getSchema()
{
return table.getSchema();
@@ -80,10 +86,11 @@ public class DBIndex extends DBSchemaElement implements IDBIndex
public void setType(Type type)
{
- table.getSchema().assertUnlocked();
+ assertUnlocked();
this.type = type;
}
+ @Deprecated
public int getPosition()
{
return position;
@@ -91,13 +98,13 @@ public class DBIndex extends DBSchemaElement implements IDBIndex
public void setPosition(int position)
{
- table.getSchema().assertUnlocked();
+ assertUnlocked();
this.position = position;
}
public DBIndexField addIndexField(IDBField field)
{
- table.getSchema().assertUnlocked();
+ assertUnlocked();
if (!field.isNotNull())
{
@@ -118,12 +125,13 @@ public class DBIndex extends DBSchemaElement implements IDBIndex
int position = indexFields.size();
DBIndexField indexField = new DBIndexField(this, (DBField)field, position);
indexFields.add(indexField);
+ resetElements();
return indexField;
}
public void removeIndexField(IDBIndexField indexFieldToRemove)
{
- table.getSchema().assertUnlocked();
+ assertUnlocked();
boolean found = false;
for (Iterator<DBIndexField> it = indexFields.iterator(); it.hasNext();)
@@ -139,6 +147,8 @@ public class DBIndex extends DBSchemaElement implements IDBIndex
found = true;
}
}
+
+ resetElements();
}
public DBIndexField getIndexField(String name)
@@ -202,17 +212,26 @@ public class DBIndex extends DBSchemaElement implements IDBIndex
}
@Override
- public void dump(Writer writer) throws IOException
+ protected void collectElements(List<IDBSchemaElement> elements)
+ {
+ elements.addAll(indexFields);
+ }
+
+ @Override
+ protected void doAccept(IDBSchemaVisitor visitor)
{
- writer.append(" INDEX ");
- writer.append(getName());
- writer.append(" (type=");
+ visitor.visit(this);
+ }
+
+ @Override
+ protected void dumpAdditionalProperties(Writer writer) throws IOException
+ {
+ writer.append(", type=");
writer.append(String.valueOf(getType()));
- writer.append(")");
- writer.append(StringUtil.NL);
- for (DBIndexField indexField : indexFields)
- {
- indexField.dump(writer);
- }
+ }
+
+ private void assertUnlocked()
+ {
+ table.getSchema().assertUnlocked();
}
}
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 b74b902113..9ae7afa357 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,11 +12,11 @@ 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.db.ddl.IDBSchemaElement;
+import org.eclipse.net4j.db.ddl.IDBSchemaVisitor;
import org.eclipse.net4j.spi.db.DBSchemaElement;
-import org.eclipse.net4j.util.StringUtil;
-import java.io.IOException;
-import java.io.Writer;
+import java.util.List;
/**
* @author Eike Stepper
@@ -46,6 +46,11 @@ public class DBIndexField extends DBSchemaElement implements IDBIndexField
{
}
+ public SchemaElementType getSchemaElementType()
+ {
+ return SchemaElementType.INDEX_FIELD;
+ }
+
public DBIndex getIndex()
{
return index;
@@ -63,7 +68,7 @@ public class DBIndexField extends DBSchemaElement implements IDBIndexField
public void setPosition(int position)
{
- index.getTable().getSchema().assertUnlocked();
+ assertUnlocked();
this.position = position;
}
@@ -83,13 +88,19 @@ public class DBIndexField extends DBSchemaElement implements IDBIndexField
}
@Override
- public void dump(Writer writer) throws IOException
+ protected void collectElements(List<IDBSchemaElement> elements)
+ {
+ // Do nothing
+ }
+
+ @Override
+ protected void doAccept(IDBSchemaVisitor visitor)
+ {
+ visitor.visit(this);
+ }
+
+ private void assertUnlocked()
{
- writer.append(" FIELD ");
- writer.append(getName());
- writer.append(" (position=");
- writer.append(String.valueOf(getPosition()));
- writer.append(")");
- writer.append(StringUtil.NL);
+ index.getTable().getSchema().assertUnlocked();
}
}
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 0d0f2184fe..20c824d88f 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
@@ -15,13 +15,12 @@ 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.spi.db.DBSchema;
import org.eclipse.net4j.spi.db.DBSchemaElement;
-import org.eclipse.net4j.util.StringUtil;
-import java.io.IOException;
-import java.io.Writer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -56,6 +55,11 @@ public class DBTable extends DBSchemaElement implements IDBTable
{
}
+ public SchemaElementType getSchemaElementType()
+ {
+ return SchemaElementType.TABLE;
+ }
+
public DBSchema getSchema()
{
return schema;
@@ -88,7 +92,7 @@ public class DBTable extends DBSchemaElement implements IDBTable
public DBField addField(String name, DBType type, int precision, int scale, boolean notNull)
{
- schema.assertUnlocked();
+ assertUnlocked();
if (getField(name) != null)
{
@@ -98,12 +102,13 @@ public class DBTable extends DBSchemaElement implements IDBTable
int position = fields.size();
DBField field = new DBField(this, name, type, precision, scale, notNull, position);
fields.add(field);
+ resetElements();
return field;
}
public void removeField(IDBField fieldToRemove)
{
- schema.assertUnlocked();
+ assertUnlocked();
boolean found = false;
for (Iterator<DBField> it = fields.iterator(); it.hasNext();)
@@ -119,6 +124,8 @@ public class DBTable extends DBSchemaElement implements IDBTable
found = true;
}
}
+
+ resetElements();
}
public DBField getField(String name)
@@ -141,9 +148,14 @@ public class DBTable extends DBSchemaElement implements IDBTable
return fields.toArray(new DBField[fields.size()]);
}
+ public DBIndex addIndex(Type type, IDBField... fields)
+ {
+ return addIndex(null, type, fields);
+ }
+
public DBIndex addIndex(String name, Type type, IDBField... fields)
{
- schema.assertUnlocked();
+ assertUnlocked();
int position = indices.size();
if (name == null)
@@ -169,17 +181,14 @@ public class DBTable extends DBSchemaElement implements IDBTable
DBIndex index = new DBIndex(this, name, type, fields, position);
indices.add(index);
+ resetElements();
return index;
}
- public DBIndex addIndex(Type type, IDBField... fields)
- {
- return addIndex(null, type, fields);
- }
-
+ @SuppressWarnings("deprecation")
public void removeIndex(IDBIndex indexToRemove)
{
- schema.assertUnlocked();
+ assertUnlocked();
boolean found = false;
for (Iterator<DBIndex> it = indices.iterator(); it.hasNext();)
@@ -195,6 +204,8 @@ public class DBTable extends DBSchemaElement implements IDBTable
found = true;
}
}
+
+ resetElements();
}
public DBIndex getIndex(String name)
@@ -262,20 +273,20 @@ public class DBTable extends DBSchemaElement implements IDBTable
}
@Override
- public void dump(Writer writer) throws IOException
+ protected void collectElements(List<IDBSchemaElement> elements)
{
- writer.append(" TABLE ");
- writer.append(getName());
- writer.append(StringUtil.NL);
+ elements.addAll(fields);
+ elements.addAll(indices);
+ }
- for (DBField field : fields)
- {
- field.dump(writer);
- }
+ @Override
+ protected void doAccept(IDBSchemaVisitor visitor)
+ {
+ visitor.visit(this);
+ }
- for (DBIndex index : indices)
- {
- index.dump(writer);
- }
+ private void assertUnlocked()
+ {
+ schema.assertUnlocked();
}
}
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 639b070d4a..03ee54958e 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
@@ -13,10 +13,10 @@ 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.IDBDeltaVisitor;
-import org.eclipse.net4j.db.ddl.delta.IDBDeltaWithPosition;
import org.eclipse.net4j.spi.db.DBNamedElement;
import org.eclipse.net4j.spi.db.DBSchemaElement;
import org.eclipse.net4j.util.StringUtil;
+import org.eclipse.net4j.util.collection.PositionProvider;
import java.io.IOException;
import java.io.Writer;
@@ -68,10 +68,10 @@ public abstract class DBDelta extends DBNamedElement implements IDBDelta
int result = getDeltaType().compareTo(delta2.getDeltaType());
if (result == 0)
{
- if (this instanceof IDBDeltaWithPosition && delta2 instanceof IDBDeltaWithPosition)
+ if (this instanceof PositionProvider && delta2 instanceof PositionProvider)
{
- IDBDeltaWithPosition withPosition1 = (IDBDeltaWithPosition)this;
- IDBDeltaWithPosition withPosition2 = (IDBDeltaWithPosition)delta2;
+ PositionProvider withPosition1 = (PositionProvider)this;
+ PositionProvider withPosition2 = (PositionProvider)delta2;
return withPosition1.getPosition() - withPosition2.getPosition();
}
@@ -84,9 +84,7 @@ public abstract class DBDelta extends DBNamedElement implements IDBDelta
public final void accept(IDBDeltaVisitor visitor)
{
doAccept(visitor);
-
- IDBDelta[] deltas = getElements();
- for (IDBDelta delta : deltas)
+ for (IDBDelta delta : getElements())
{
delta.accept(visitor);
}
@@ -103,16 +101,16 @@ public abstract class DBDelta extends DBNamedElement implements IDBDelta
{
if (elements == null)
{
- List<IDBDelta> deltas = new ArrayList<IDBDelta>();
- collectElements(deltas);
+ List<IDBDelta> result = new ArrayList<IDBDelta>();
+ collectElements(result);
- if (deltas.isEmpty())
+ if (result.isEmpty())
{
elements = NO_ELEMENTS;
}
else
{
- elements = deltas.toArray(new IDBDelta[deltas.size()]);
+ elements = result.toArray(new IDBDelta[result.size()]);
Arrays.sort(elements);
}
}
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 aa1b8a0bf1..401f3eca5d 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
@@ -96,13 +96,12 @@ public final class DBPropertyDelta<T> extends DBDelta implements IDBPropertyDelt
@Override
protected void dumpAdditionalProperties(Writer writer) throws IOException
{
- writer.append(" (type=");
+ writer.append(", type=");
writer.append(getType().toString());
writer.append(", value=");
writer.append(toString(getValue()));
writer.append(", oldValue=");
writer.append(toString(getOldValue()));
- writer.append(")");
}
private static CharSequence toString(Object object)
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 9019857a06..69a41840a8 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
@@ -18,22 +18,22 @@ import org.eclipse.net4j.db.IDBRowHandler;
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.IDBSchemaElement;
+import org.eclipse.net4j.db.ddl.IDBSchemaVisitor;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.db.ddl.delta.IDBSchemaDelta;
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;
-import org.eclipse.net4j.util.StringUtil;
import javax.sql.DataSource;
-import java.io.IOException;
import java.io.PrintStream;
-import java.io.Writer;
import java.sql.Connection;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -100,9 +100,12 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
{
}
- public String getFullName()
+ /**
+ * @since 4.2
+ */
+ public SchemaElementType getSchemaElementType()
{
- return getName();
+ return SchemaElementType.SCHEMA;
}
public IDBSchema getSchema()
@@ -110,6 +113,11 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
return this;
}
+ public String getFullName()
+ {
+ return getName();
+ }
+
/**
* @since 2.0
*/
@@ -123,6 +131,7 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
DBTable table = new DBTable(this, name);
tables.put(table.getName(), table);
+ resetElements();
return table;
}
@@ -133,7 +142,9 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
{
assertUnlocked();
name = name(name);
- return tables.remove(name);
+ DBTable table = tables.remove(name);
+ resetElements();
+ return table;
}
/**
@@ -156,22 +167,6 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
/**
* @since 4.2
*/
- public boolean isEmpty()
- {
- return tables.isEmpty();
- }
-
- /**
- * @since 4.2
- */
- public IDBTable[] getElements()
- {
- return getTables();
- }
-
- /**
- * @since 4.2
- */
public void remove()
{
assertUnlocked();
@@ -331,15 +326,21 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
return "I" + System.currentTimeMillis() + "_" + ++indexCounter;
}
+ /**
+ * @since 4.2
+ */
@Override
- public void dump(Writer writer) throws IOException
+ protected void collectElements(List<IDBSchemaElement> elements)
{
- writer.append("SCHEMA ");
- writer.append(getName());
- writer.append(StringUtil.NL);
- for (DBTable table : tables.values())
- {
- table.dump(writer);
- }
+ elements.addAll(tables.values());
+ }
+
+ /**
+ * @since 4.2
+ */
+ @Override
+ protected void doAccept(IDBSchemaVisitor visitor)
+ {
+ visitor.visit(this);
}
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchemaElement.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchemaElement.java
index 2405e18d7f..4c362326d4 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchemaElement.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchemaElement.java
@@ -11,6 +11,15 @@
package org.eclipse.net4j.spi.db;
import org.eclipse.net4j.db.ddl.IDBSchemaElement;
+import org.eclipse.net4j.db.ddl.IDBSchemaVisitor;
+import org.eclipse.net4j.util.StringUtil;
+import org.eclipse.net4j.util.collection.PositionProvider;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
/**
* @author Eike Stepper
@@ -21,6 +30,10 @@ public abstract class DBSchemaElement extends DBNamedElement implements IDBSchem
{
private static final long serialVersionUID = 1L;
+ private static final IDBSchemaElement[] NO_ELEMENTS = {};
+
+ private transient IDBSchemaElement[] elements;
+
public DBSchemaElement(String name)
{
super(name);
@@ -32,4 +45,92 @@ public abstract class DBSchemaElement extends DBNamedElement implements IDBSchem
protected DBSchemaElement()
{
}
+
+ public final int compareTo(IDBSchemaElement element2)
+ {
+ int result = getSchemaElementType().compareTo(element2.getSchemaElementType());
+ if (result == 0)
+ {
+ if (this instanceof PositionProvider && element2 instanceof PositionProvider)
+ {
+ PositionProvider withPosition1 = (PositionProvider)this;
+ PositionProvider withPosition2 = (PositionProvider)element2;
+ return withPosition1.getPosition() - withPosition2.getPosition();
+ }
+
+ result = getName().compareTo(element2.getName());
+ }
+
+ return result;
+ }
+
+ public final boolean isEmpty()
+ {
+ return getElements().length == 0;
+ }
+
+ public final IDBSchemaElement[] getElements()
+ {
+ if (elements == null)
+ {
+ List<IDBSchemaElement> result = new ArrayList<IDBSchemaElement>();
+ collectElements(result);
+
+ if (result.isEmpty())
+ {
+ elements = NO_ELEMENTS;
+ }
+ else
+ {
+ elements = result.toArray(new IDBSchemaElement[result.size()]);
+ Arrays.sort(elements);
+ }
+ }
+
+ return elements;
+ }
+
+ protected final void resetElements()
+ {
+ elements = null;
+ }
+
+ protected abstract void collectElements(List<IDBSchemaElement> elements);
+
+ public final void accept(IDBSchemaVisitor visitor)
+ {
+ doAccept(visitor);
+ for (IDBSchemaElement element : getElements())
+ {
+ element.accept(visitor);
+ }
+ }
+
+ protected abstract void doAccept(IDBSchemaVisitor visitor);
+
+ @Override
+ public void dump(Writer writer) throws IOException
+ {
+ SchemaElementType schemaElementType = getSchemaElementType();
+ int level = schemaElementType.getLevel();
+ for (int i = 0; i < level; i++)
+ {
+ writer.append(" ");
+ }
+
+ writer.append(schemaElementType.toString());
+ writer.append(" ");
+ writer.append(getName());
+ dumpAdditionalProperties(writer);
+ writer.append(StringUtil.NL);
+
+ for (IDBSchemaElement element : getElements())
+ {
+ ((DBSchemaElement)element).dump(writer);
+ }
+ }
+
+ protected void dumpAdditionalProperties(Writer writer) throws IOException
+ {
+ }
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/PositionProvider.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/PositionProvider.java
new file mode 100644
index 0000000000..110cead45d
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/PositionProvider.java
@@ -0,0 +1,20 @@
+/*
+ * 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.util.collection;
+
+/**
+ * @author Eike Stepper
+ * @since 3.3
+ */
+public interface PositionProvider
+{
+ public int getPosition();
+}

Back to the top