Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-03-11 10:26:40 +0000
committerEike Stepper2013-03-11 10:26:40 +0000
commit95e9abf2c58f24f845ca8e771701a7c937095cee (patch)
treef1f50193000e0bd4535a6757d6ce7a170d19f3bd
parente281dd0e6474ce8d294459f1a7ae2d118591317b (diff)
downloadcdo-95e9abf2c58f24f845ca8e771701a7c937095cee.tar.gz
cdo-95e9abf2c58f24f845ca8e771701a7c937095cee.tar.xz
cdo-95e9abf2c58f24f845ca8e771701a7c937095cee.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/db/mapping/AbstractTypeMapping.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/ITypeMapping.java32
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java17
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DurableLockingManager.java267
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ExternalReferenceManager.java132
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java35
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractFeatureMapTableMapping.java137
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalClassMapping.java299
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractListTableMapping.java88
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMapping.java24
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMappingWithRanges.java80
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMapping.java31
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMappingWithRanges.java49
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMapping.java18
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMappingWithRanges.java106
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMapping.java30
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMappingWithRanges.java45
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/FieldInfo.java20
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java103
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategy.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategyWithRanges.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java104
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategy.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategyWithRanges.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java94
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditMappingStrategy.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/IMappingConstants.java34
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditFeatureMapTableMapping.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java48
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/ObjectTypeTable.java56
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java43
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AdapterManagerTest.java34
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RepositoryTest.java4
35 files changed, 837 insertions, 1146 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/AbstractTypeMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/AbstractTypeMapping.java
index 9cbac4031a..e2600732e4 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/AbstractTypeMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/AbstractTypeMapping.java
@@ -66,7 +66,6 @@ public abstract class AbstractTypeMapping implements ITypeMapping
*/
public AbstractTypeMapping()
{
- super();
}
public final void setMappingStrategy(IMappingStrategy mappingStrategy)
@@ -138,6 +137,7 @@ public abstract class AbstractTypeMapping implements ITypeMapping
}
}
+ @Deprecated
public final void createDBField(IDBTable table)
{
createDBField(table, mappingStrategy.getFieldName(feature));
@@ -152,7 +152,7 @@ public abstract class AbstractTypeMapping implements ITypeMapping
public final void setDBField(IDBTable table, String fieldName)
{
- field = table.getField(fieldName);
+ field = table.getFieldSafe(fieldName);
}
public final IDBField getField()
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/ITypeMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/ITypeMapping.java
index 8a7bca2835..5aec9d092c 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/ITypeMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/ITypeMapping.java
@@ -31,7 +31,7 @@ import java.util.Collection;
/**
* Mapping of single values to and from the database.
- *
+ *
* @author Eike Stepper
* @author Stefan Winkler
* @since 2.0
@@ -70,17 +70,15 @@ public interface ITypeMapping
public void setDBType(DBType dbType);
/**
- * Creates the DBField and adds it to the given table. The name of the DBField is derived from the feature.
- *
- * @param table
- * the table to add this field to.
+ * @deprecated As of 4.2 use {@link #createDBField(IDBTable, String)}.
*/
+ @Deprecated
public void createDBField(IDBTable table);
/**
* Creates the DBField and adds it to the given table. The name of the DBField is explicitly determined by the
* corresponding parameter.
- *
+ *
* @param table
* the table to add this field to.
* @param fieldName
@@ -90,7 +88,7 @@ public interface ITypeMapping
/**
* Sets the DBField. The name of the DBField is explicitly determined by the corresponding parameter.
- *
+ *
* @param table
* the table to add this field to.
* @param fieldName
@@ -101,7 +99,7 @@ public interface ITypeMapping
/**
* Set the given value to the JDBC {@link PreparedStatement} using an appropriate <code>setXxx</code> method.
- *
+ *
* @param stmt
* the prepared statement to set the value
* @param index
@@ -116,7 +114,7 @@ public interface ITypeMapping
/**
* Set the feature's default value to the JDBC {@link PreparedStatement} using an appropriate <code>setXxx</code>
* method.
- *
+ *
* @param stmt
* the prepared statement to set the value
* @param index
@@ -130,7 +128,7 @@ public interface ITypeMapping
/**
* Set a value of the given revision to the JDBC {@link PreparedStatement} using an appropriate <code>setXxx</code>
* method. The feature from which the value is taken is determined by {@link #getFeature()}.
- *
+ *
* @param stmt
* the prepared statement to set the value
* @param index
@@ -145,7 +143,7 @@ public interface ITypeMapping
/**
* Read the value from a {@link ResultSet} and convert it from the DB to the CDO representation. The resultSet field
* to read from is determined automatically by the internal {@link #getField()} name.
- *
+ *
* @param resultSet
* the result set to read from
* @return the read value
@@ -159,7 +157,7 @@ public interface ITypeMapping
* Read a value from a {@link ResultSet}, convert it from the DB to the CDO representation and set it to the feature
* of the revision. The feature is determined by getFeature() The resultSet field to read from is determined
* automatically by the internal {@link #getField()} name.
- *
+ *
* @param resultSet
* the result set to read from
* @param revision
@@ -174,7 +172,7 @@ public interface ITypeMapping
* A descriptor which describes one type mapping class. The descriptor is encoded in the factoryType which is used as
* a string description for the extension point mechanism. Translations and instantiations can be done using the
* methods in {@link TypeMappingUtil}.
- *
+ *
* @author Stefan Winkler
* @since 4.0
*/
@@ -205,7 +203,7 @@ public interface ITypeMapping
/**
* A global (singleton) registry which collects all available type mappings which are either available in the CDO
* core, as declared extensions, or registered manually.
- *
+ *
* @author Stefan Winkler
* @since 4.0
*/
@@ -232,7 +230,7 @@ public interface ITypeMapping
* A provider for type mapping information. This provider is used by the {@link TypeMappingRegistry} to create an
* {@link ITypeMapping} instance suitable for a given feature and DB field. Usually, one factory is responsible for
* one type mapping.
- *
+ *
* @author Stefan Winkler
* @since 4.0
*/
@@ -245,7 +243,7 @@ public interface ITypeMapping
/**
* Create an {@link ITypeMapping} implementation.
- *
+ *
* @param mappingStrategy
* the mapping strategy
* @param feature
@@ -259,7 +257,7 @@ public interface ITypeMapping
* A factory for typeMappings. This is a regular Net4j factory registered by the respective extension point. It
* enhances the regular factory using a descriptor which is translated from and to the factoryType by the methods in
* {@link TypeMappingUtil}.
- *
+ *
* @author Stefan Winkler
* @since 4.0
*/
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 9b9dfd7e54..38b2f89e51 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
@@ -15,19 +15,19 @@
package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.net4j.db.DBType;
+import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBIndex;
+import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBTable;
-import org.eclipse.net4j.spi.db.DBSchema;
+import org.eclipse.net4j.spi.db.ddl.InternalDBSchema;
/**
* @author Eike Stepper
*/
-public class CDODBSchema extends DBSchema
+public class CDODBSchema
{
- public static final CDODBSchema INSTANCE = new CDODBSchema();
-
- private static final long serialVersionUID = 1L;
+ public static final IDBSchema INSTANCE = DBUtil.createSchema("CDO");
/**
* DBTable cdo_properties
@@ -198,13 +198,8 @@ public class CDODBSchema extends DBSchema
*/
public static final String CDO_OBJECTS = "cdo_objects"; //$NON-NLS-1$
- private CDODBSchema()
- {
- super("CDO"); //$NON-NLS-1$
- }
-
static
{
- INSTANCE.lock();
+ ((InternalDBSchema)INSTANCE).lock();
}
}
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 105f82b8ac..97d11ca253 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
@@ -48,7 +48,6 @@ 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;
-import org.eclipse.net4j.spi.db.DBSchema;
import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.om.monitor.ProgressDistributor;
@@ -615,7 +614,7 @@ public class DBStore extends Store implements IDBStore, IMappingConstants, CDOAl
migrateSchema(schemaVersion);
}
- CDODBSchema.INSTANCE.create(dbAdapter, connection);
+ // CDODBSchema.INSTANCE.create(dbAdapter, connection);
connection.commit();
}
finally
@@ -824,12 +823,6 @@ public class DBStore extends Store implements IDBStore, IMappingConstants, CDOAl
}
}
- protected IDBSchema createSchema()
- {
- String name = getRepository().getName();
- return new DBSchema(name);
- }
-
protected int selectSchemaVersion(Connection connection) throws SQLException
{
Statement statement = null;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DurableLockingManager.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DurableLockingManager.java
index e7e8145a3d..f3b21b49dc 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DurableLockingManager.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DurableLockingManager.java
@@ -31,9 +31,9 @@ import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBDatabase;
-import org.eclipse.net4j.db.IDBDatabase.RunnableWithTable;
-import org.eclipse.net4j.db.ddl.IDBField;
+import org.eclipse.net4j.db.IDBDatabase.RunnableWithSchema;
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.util.concurrent.IRWLockManager.LockType;
import org.eclipse.net4j.util.lifecycle.Lifecycle;
@@ -53,31 +53,35 @@ import java.util.Map.Entry;
*/
public class DurableLockingManager extends Lifecycle
{
- private DBStore store;
+ private static final String LOCK_AREAS = "CDO_LOCK_AREAS";
- private InternalCDOBranchManager branchManager;
+ private static final String LOCK_AREAS_ID = "ID";
- private IIDHandler idHandler;
+ private static final String LOCK_AREAS_USER_ID = "USER_ID";
- private IDBTable lockAreas;
+ private static final String LOCK_AREAS_VIEW_BRANCH = "VIEW_BRANCH";
- private IDBField lockAreasID;
+ private static final String LOCK_AREAS_VIEW_TIME = "VIEW_TIME";
- private IDBField lockAreasUser;
+ private static final String LOCK_AREAS_READ_ONLY = "READ_ONLY";
- private IDBField lockAreasBranch;
+ private static final String LOCKS = "CDO_LOCKS";
- private IDBField lockAreasTime;
+ private static final String LOCKS_AREA_ID = "AREA_ID";
- private IDBField lockAreasReadOnly;
+ private static final String LOCKS_OBJECT_ID = "OBJECT_ID";
- private IDBTable locks;
+ private static final String LOCKS_LOCK_GRADE = "LOCK_GRADE";
- private IDBField locksArea;
+ private DBStore store;
- private IDBField locksObject;
+ private InternalCDOBranchManager branchManager;
- private IDBField locksGrade;
+ private IIDHandler idHandler;
+
+ private IDBTable lockAreasTable;
+
+ private IDBTable locksTable;
private String sqlInsertLockArea;
@@ -386,185 +390,64 @@ public class DurableLockingManager extends Lifecycle
IDBDatabase database = store.getDatabase();
// Lock areas
- lockAreas = database.ensureTable("cdo_lock_areas", new RunnableWithTable()
+ lockAreasTable = database.getSchema().getTable(LOCK_AREAS);
+ if (lockAreasTable == null)
{
- public void run(IDBTable table)
+ database.updateSchema(new RunnableWithSchema()
{
- IDBField lockAreasID = table.addField("id", DBType.VARCHAR, true);
- IDBField lockAreasUser = table.addField("user_id", DBType.VARCHAR);
- table.addField("view_branch", DBType.INTEGER);
- table.addField("view_time", DBType.BIGINT);
- table.addField("read_only", DBType.BOOLEAN);
- table.addIndex(IDBIndex.Type.PRIMARY_KEY, lockAreasID);
- table.addIndex(IDBIndex.Type.NON_UNIQUE, lockAreasUser);
- }
- });
+ public void run(IDBSchema schema)
+ {
+ lockAreasTable = schema.addTable(LOCK_AREAS);
+ lockAreasTable.addField(LOCK_AREAS_ID, DBType.VARCHAR, true);
+ lockAreasTable.addField(LOCK_AREAS_USER_ID, DBType.VARCHAR);
+ lockAreasTable.addField(LOCK_AREAS_VIEW_BRANCH, DBType.INTEGER);
+ lockAreasTable.addField(LOCK_AREAS_VIEW_TIME, DBType.BIGINT);
+ lockAreasTable.addField(LOCK_AREAS_READ_ONLY, DBType.BOOLEAN);
+ lockAreasTable.addIndex(IDBIndex.Type.PRIMARY_KEY, LOCK_AREAS_ID);
+ lockAreasTable.addIndex(IDBIndex.Type.NON_UNIQUE, LOCK_AREAS_USER_ID);
+ }
+ });
+ }
- lockAreasID = lockAreas.getField(0);
- lockAreasUser = lockAreas.getField(1);
- lockAreasBranch = lockAreas.getField(2);
- lockAreasTime = lockAreas.getField(3);
- lockAreasReadOnly = lockAreas.getField(4);
+ sqlInsertLockArea = "INSERT INTO " + LOCK_AREAS + "(" + LOCK_AREAS_ID + "," + LOCK_AREAS_USER_ID + ","
+ + LOCK_AREAS_VIEW_BRANCH + "," + LOCK_AREAS_VIEW_TIME + "," + LOCK_AREAS_READ_ONLY + ") VALUES (?, ?, ?, ?, ?)";
+ sqlSelectLockArea = "SELECT " + LOCK_AREAS_USER_ID + "," + LOCK_AREAS_VIEW_BRANCH + "," + LOCK_AREAS_VIEW_TIME
+ + "," + LOCK_AREAS_READ_ONLY + " FROM " + LOCK_AREAS + " WHERE " + LOCK_AREAS_ID + "=?";
+ sqlSelectAllLockAreas = "SELECT " + LOCK_AREAS_ID + "," + LOCK_AREAS_USER_ID + "," + LOCK_AREAS_VIEW_BRANCH + ","
+ + LOCK_AREAS_VIEW_TIME + "," + LOCK_AREAS_READ_ONLY + " FROM " + LOCK_AREAS;
+ sqlSelectLockAreas = sqlSelectAllLockAreas + " WHERE " + LOCK_AREAS_USER_ID + " LIKE ?";
+ sqlDeleteLockArea = "DELETE FROM " + LOCK_AREAS + " WHERE " + LOCK_AREAS_ID + "=?";
+ sqlDeleteLockAreas = "DELETE FROM " + LOCK_AREAS + " WHERE EXISTS (SELECT * FROM " + LOCKS + " WHERE " + LOCKS
+ + "." + LOCKS_AREA_ID + "=" + LOCK_AREAS + "." + LOCK_AREAS_ID + ")";
// Locks
- locks = database.ensureTable("cdo_locks", new RunnableWithTable()
+ locksTable = database.getSchema().getTable(LOCKS);
+ if (locksTable == null)
{
- public void run(IDBTable table)
+ database.updateSchema(new RunnableWithSchema()
{
- IDBField locksArea = table.addField("area_id", DBType.VARCHAR, true);
- IDBField locksObject = table.addField("object_id", idHandler.getDBType(), store.getIDColumnLength(), true);
- table.addField("lock_grade", DBType.INTEGER);
- table.addIndex(IDBIndex.Type.PRIMARY_KEY, locksArea, locksObject);
- table.addIndex(IDBIndex.Type.NON_UNIQUE, locksArea);
- }
- });
-
- locksArea = locks.getField(0);
- locksObject = locks.getField(1);
- locksGrade = locks.getField(2);
-
- StringBuilder builder = new StringBuilder();
- builder.append("INSERT INTO "); //$NON-NLS-1$
- builder.append(lockAreas);
- builder.append("("); //$NON-NLS-1$
- builder.append(lockAreasID);
- builder.append(","); //$NON-NLS-1$
- builder.append(lockAreasUser);
- builder.append(","); //$NON-NLS-1$
- builder.append(lockAreasBranch);
- builder.append(","); //$NON-NLS-1$
- builder.append(lockAreasTime);
- builder.append(","); //$NON-NLS-1$
- builder.append(lockAreasReadOnly);
- builder.append(") VALUES (?, ?, ?, ?, ?)"); //$NON-NLS-1$
- sqlInsertLockArea = builder.toString();
-
- builder = new StringBuilder();
- builder.append("SELECT "); //$NON-NLS-1$
- builder.append(lockAreasUser);
- builder.append(","); //$NON-NLS-1$
- builder.append(lockAreasBranch);
- builder.append(","); //$NON-NLS-1$
- builder.append(lockAreasTime);
- builder.append(","); //$NON-NLS-1$
- builder.append(lockAreasReadOnly);
- builder.append(" FROM "); //$NON-NLS-1$
- builder.append(lockAreas);
- builder.append(" WHERE "); //$NON-NLS-1$
- builder.append(lockAreasID);
- builder.append("=?"); //$NON-NLS-1$
- sqlSelectLockArea = builder.toString();
-
- builder = new StringBuilder();
- builder.append("SELECT "); //$NON-NLS-1$
- builder.append(lockAreasID);
- builder.append(","); //$NON-NLS-1$
- builder.append(lockAreasUser);
- builder.append(","); //$NON-NLS-1$
- builder.append(lockAreasBranch);
- builder.append(","); //$NON-NLS-1$
- builder.append(lockAreasTime);
- builder.append(","); //$NON-NLS-1$
- builder.append(lockAreasReadOnly);
- builder.append(" FROM "); //$NON-NLS-1$
- builder.append(lockAreas);
- sqlSelectAllLockAreas = builder.toString();
-
- builder.append(" WHERE "); //$NON-NLS-1$
- builder.append(lockAreasUser);
- builder.append(" LIKE ?"); //$NON-NLS-1$
- sqlSelectLockAreas = builder.toString();
-
- builder = new StringBuilder();
- builder.append("DELETE FROM "); //$NON-NLS-1$
- builder.append(lockAreas);
- builder.append(" WHERE "); //$NON-NLS-1$
- builder.append(lockAreasID);
- builder.append("=?"); //$NON-NLS-1$
- sqlDeleteLockArea = builder.toString();
-
- builder = new StringBuilder();
- builder.append("DELETE FROM ");
- builder.append(lockAreas);
- builder.append(" WHERE EXISTS (SELECT * FROM ");
- builder.append(locks);
- builder.append(" WHERE ");
- builder.append(locks);
- builder.append(".");
- builder.append(locksArea);
- builder.append("=");
- builder.append(lockAreas);
- builder.append(".");
- builder.append(lockAreasID);
- builder.append(")");
- sqlDeleteLockAreas = builder.toString();
-
- builder = new StringBuilder();
- builder.append("SELECT "); //$NON-NLS-1$
- builder.append(locksObject);
- builder.append(","); //$NON-NLS-1$
- builder.append(locksGrade);
- builder.append(" FROM "); //$NON-NLS-1$
- builder.append(locks);
- builder.append(" WHERE "); //$NON-NLS-1$
- builder.append(locksArea);
- builder.append("=?"); //$NON-NLS-1$
- sqlSelectLocks = builder.toString();
-
- builder = new StringBuilder();
- builder.append("SELECT "); //$NON-NLS-1$
- builder.append(locksGrade);
- builder.append(" FROM "); //$NON-NLS-1$
- builder.append(locks);
- builder.append(" WHERE "); //$NON-NLS-1$
- builder.append(locksArea);
- builder.append("=? AND "); //$NON-NLS-1$
- builder.append(locksObject);
- builder.append("=?"); //$NON-NLS-1$
- sqlSelectLock = builder.toString();
-
- builder = new StringBuilder();
- builder.append("INSERT INTO "); //$NON-NLS-1$
- builder.append(locks);
- builder.append("("); //$NON-NLS-1$
- builder.append(locksArea);
- builder.append(","); //$NON-NLS-1$
- builder.append(locksObject);
- builder.append(","); //$NON-NLS-1$
- builder.append(locksGrade);
- builder.append(") VALUES (?, ?, ?)"); //$NON-NLS-1$
- sqlInsertLock = builder.toString();
-
- builder = new StringBuilder();
- builder.append("UPDATE "); //$NON-NLS-1$
- builder.append(locks);
- builder.append(" SET "); //$NON-NLS-1$
- builder.append(locksGrade);
- builder.append("=? "); //$NON-NLS-1$
- builder.append(" WHERE "); //$NON-NLS-1$
- builder.append(locksArea);
- builder.append("=? AND "); //$NON-NLS-1$
- builder.append(locksObject);
- builder.append("=?"); //$NON-NLS-1$
- sqlUpdateLock = builder.toString();
-
- builder = new StringBuilder();
- builder.append("DELETE FROM "); //$NON-NLS-1$
- builder.append(locks);
- builder.append(" WHERE "); //$NON-NLS-1$
- builder.append(locksArea);
- builder.append("=? AND "); //$NON-NLS-1$
- builder.append(locksObject);
- builder.append("=?"); //$NON-NLS-1$
- sqlDeleteLock = builder.toString();
-
- builder = new StringBuilder();
- builder.append("DELETE FROM "); //$NON-NLS-1$
- builder.append(locks);
- builder.append(" WHERE "); //$NON-NLS-1$
- builder.append(locksArea);
- builder.append("=?"); //$NON-NLS-1$
- sqlDeleteLocks = builder.toString();
+ public void run(IDBSchema schema)
+ {
+ locksTable = schema.addTable(LOCKS);
+ locksTable.addField(LOCKS_AREA_ID, DBType.VARCHAR, true);
+ locksTable.addField(LOCKS_OBJECT_ID, idHandler.getDBType(), store.getIDColumnLength(), true);
+ locksTable.addField(LOCKS_LOCK_GRADE, DBType.INTEGER);
+ locksTable.addIndex(IDBIndex.Type.PRIMARY_KEY, LOCKS_AREA_ID, LOCKS_OBJECT_ID);
+ locksTable.addIndex(IDBIndex.Type.NON_UNIQUE, LOCKS_AREA_ID);
+ }
+ });
+ }
+
+ sqlSelectLocks = "SELECT " + LOCKS_OBJECT_ID + "," + LOCKS_LOCK_GRADE + " FROM " + LOCKS + " WHERE "
+ + LOCKS_AREA_ID + "=?";
+ sqlSelectLock = "SELECT " + LOCKS_LOCK_GRADE + " FROM " + LOCKS + " WHERE " + LOCKS_AREA_ID + "=? AND "
+ + LOCKS_OBJECT_ID + "=?";
+ sqlInsertLock = "INSERT INTO " + LOCKS + "(" + LOCKS_AREA_ID + "," + LOCKS_OBJECT_ID + "," + LOCKS_LOCK_GRADE
+ + ") VALUES (?, ?, ?)";
+ sqlUpdateLock = "UPDATE " + LOCKS + " SET " + LOCKS_LOCK_GRADE + "=? " + " WHERE " + LOCKS_AREA_ID + "=? AND "
+ + LOCKS_OBJECT_ID + "=?";
+ sqlDeleteLock = "DELETE FROM " + LOCKS + " WHERE " + LOCKS_AREA_ID + "=? AND " + LOCKS_OBJECT_ID + "=?";
+ sqlDeleteLocks = "DELETE FROM " + LOCKS + " WHERE " + LOCKS_AREA_ID + "=?";
}
private String getNextDurableLockingID(DBStoreAccessor accessor)
@@ -704,8 +587,8 @@ public class DurableLockingManager extends Lifecycle
public void rawExport(Connection connection, CDODataOutput out, long fromCommitTime, long toCommitTime)
throws IOException
{
- DBUtil.serializeTable(out, connection, lockAreas, null, null);
- DBUtil.serializeTable(out, connection, locks, null, null);
+ DBUtil.serializeTable(out, connection, lockAreasTable, null, null);
+ DBUtil.serializeTable(out, connection, locksTable, null, null);
}
public void rawImport(Connection connection, CDODataInput in, long fromCommitTime, long toCommitTime,
@@ -719,12 +602,12 @@ public class DurableLockingManager extends Lifecycle
DBUtil.update(connection, sqlDeleteLockAreas);
monitor.worked();
- DBUtil.deserializeTable(in, connection, lockAreas, monitor.fork());
+ DBUtil.deserializeTable(in, connection, lockAreasTable, monitor.fork());
- DBUtil.clearTable(connection, locks);
+ DBUtil.clearTable(connection, locksTable);
monitor.worked();
- DBUtil.deserializeTable(in, connection, locks, monitor.fork());
+ DBUtil.deserializeTable(in, connection, locksTable, monitor.fork());
}
finally
{
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ExternalReferenceManager.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ExternalReferenceManager.java
index d5dd79771f..0b006126db 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ExternalReferenceManager.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ExternalReferenceManager.java
@@ -29,9 +29,9 @@ import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBDatabase;
-import org.eclipse.net4j.db.IDBDatabase.RunnableWithTable;
-import org.eclipse.net4j.db.ddl.IDBField;
+import org.eclipse.net4j.db.IDBDatabase.RunnableWithSchema;
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.util.ReflectUtil.ExcludeFromDump;
import org.eclipse.net4j.util.lifecycle.Lifecycle;
@@ -50,15 +50,17 @@ import java.util.concurrent.atomic.AtomicLong;
*/
public class ExternalReferenceManager extends Lifecycle
{
- private static final int NULL = 0;
+ private static final String EXTERNAL_REFS = "cdo_external_refs";
- private IDBTable table;
+ private static final String EXTERNAL_REFS_ID = "ID";
+
+ private static final String EXTERNAL_REFS_URI = "URI";
- private IDBField idField;
+ private static final String EXTERNAL_REFS_COMMITTIME = "COMMITTIME";
- private IDBField uriField;
+ private static final int NULL = 0;
- private IDBField timestampField;
+ private IDBTable table;
private final IIDHandler idHandler;
@@ -173,7 +175,7 @@ public class ExternalReferenceManager extends Lifecycle
public void rawExport(Connection connection, CDODataOutput out, long fromCommitTime, long toCommitTime)
throws IOException
{
- String where = " WHERE " + timestampField + " BETWEEN " + fromCommitTime + " AND " + toCommitTime;
+ String where = " WHERE " + EXTERNAL_REFS_COMMITTIME + " BETWEEN " + fromCommitTime + " AND " + toCommitTime;
DBUtil.serializeTable(out, connection, table, null, where);
}
@@ -191,85 +193,61 @@ public class ExternalReferenceManager extends Lifecycle
final IDBStore store = idHandler.getStore();
IDBDatabase database = store.getDatabase();
- table = database.ensureTable("cdo_external_refs", new RunnableWithTable()
+ table = database.getSchema().getTable(EXTERNAL_REFS);
+ if (table == null)
{
- public void run(IDBTable table)
+ database.updateSchema(new RunnableWithSchema()
{
- IDBField idField = table.addField("id", idHandler.getDBType(), store.getIDColumnLength(), true); //$NON-NLS-1$
- IDBField uriField = table.addField("uri", DBType.VARCHAR, 1024); //$NON-NLS-1$
- table.addField("committime", DBType.BIGINT); //$NON-NLS-1$
- table.addIndex(IDBIndex.Type.PRIMARY_KEY, idField);
- table.addIndex(IDBIndex.Type.NON_UNIQUE, uriField);
- }
- });
-
- idField = table.getField(0);
- uriField = table.getField(1);
- timestampField = table.getField(2);
+ public void run(IDBSchema schema)
+ {
+ table = schema.addTable(EXTERNAL_REFS);
+ table.addField(EXTERNAL_REFS_ID, idHandler.getDBType(), store.getIDColumnLength(), true);
+ table.addField(EXTERNAL_REFS_URI, DBType.VARCHAR, 1024);
+ table.addField(EXTERNAL_REFS_COMMITTIME, DBType.BIGINT);
+ table.addIndex(IDBIndex.Type.PRIMARY_KEY, EXTERNAL_REFS_ID);
+ table.addIndex(IDBIndex.Type.NON_UNIQUE, EXTERNAL_REFS_URI);
+ }
+ });
+ }
+ else
+ {
+ IDBStoreAccessor writer = store.getWriter(null);
+ Connection connection = writer.getConnection();
+ Statement statement = null;
+ ResultSet resultSet = null;
- IDBStoreAccessor writer = store.getWriter(null);
- Connection connection = writer.getConnection();
- Statement statement = null;
- ResultSet resultSet = null;
+ try
+ {
+ statement = connection.createStatement();
- try
- {
- statement = connection.createStatement();
+ String sql = "SELECT MIN(" + EXTERNAL_REFS_ID + ") FROM " + table;
+ resultSet = statement.executeQuery(sql);
- String sql = "SELECT MIN(" + idField + ") FROM " + table;
- resultSet = statement.executeQuery(sql);
+ if (resultSet.next())
+ {
+ lastMappedID.set(resultSet.getLong(1));
+ }
- if (resultSet.next())
+ // else: resultSet is empty => table is empty
+ // and lastMappedId stays 0 - as initialized.
+ }
+ catch (SQLException ex)
{
- lastMappedID.set(resultSet.getLong(1));
+ connection.rollback();
+ throw new DBException(ex);
+ }
+ finally
+ {
+ DBUtil.close(resultSet);
+ DBUtil.close(statement);
+ writer.release();
}
-
- // else: resultSet is empty => table is empty
- // and lastMappedId stays 0 - as initialized.
- }
- catch (SQLException ex)
- {
- connection.rollback();
- throw new DBException(ex);
- }
- finally
- {
- DBUtil.close(resultSet);
- DBUtil.close(statement);
- writer.release();
}
- StringBuilder builder = new StringBuilder();
- builder.append("INSERT INTO ");
- builder.append(table);
- builder.append("(");
- builder.append(idField);
- builder.append(",");
- builder.append(uriField);
- builder.append(",");
- builder.append(timestampField);
- builder.append(") VALUES (?, ?, ?)");
- sqlInsert = builder.toString();
-
- builder = new StringBuilder();
- builder.append("SELECT "); //$NON-NLS-1$
- builder.append(idField);
- builder.append(" FROM "); //$NON-NLS-1$
- builder.append(table);
- builder.append(" WHERE "); //$NON-NLS-1$
- builder.append(uriField);
- builder.append("=?"); //$NON-NLS-1$
- sqlSelectByURI = builder.toString();
-
- builder = new StringBuilder();
- builder.append("SELECT "); //$NON-NLS-1$
- builder.append(uriField);
- builder.append(" FROM "); //$NON-NLS-1$
- builder.append(table);
- builder.append(" WHERE "); //$NON-NLS-1$
- builder.append(idField);
- builder.append("=?"); //$NON-NLS-1$
- sqlSelectByLongID = builder.toString();
+ sqlInsert = "INSERT INTO " + table + "(" + EXTERNAL_REFS_ID + "," + EXTERNAL_REFS_URI + ","
+ + EXTERNAL_REFS_COMMITTIME + ") VALUES (?, ?, ?)";
+ sqlSelectByURI = "SELECT " + EXTERNAL_REFS_ID + " FROM " + table + " WHERE " + EXTERNAL_REFS_URI + "=?";
+ sqlSelectByLongID = "SELECT " + EXTERNAL_REFS_URI + " FROM " + table + " WHERE " + EXTERNAL_REFS_ID + "=?";
}
private long insertNew(IDBStoreAccessor accessor, String uri, long commitTime)
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
index d0e992479d..85539c0134 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
@@ -43,9 +43,11 @@ import org.eclipse.emf.cdo.spi.server.InternalRepository;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.IDBSchemaTransaction;
import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.ImplementationError;
+import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.StringUtil;
import org.eclipse.net4j.util.collection.CloseableIterator;
import org.eclipse.net4j.util.lifecycle.Lifecycle;
@@ -424,13 +426,17 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
try
{
async = monitor.forkAsync();
+ IDBSchemaTransaction schemaTransaction = null;
try
{
+ schemaTransaction = store.getDatabase().openSchemaTransaction();
mapPackageUnits(packageUnits, connection, false);
+ schemaTransaction.commit();
}
finally
{
+ ObjectUtil.close(schemaTransaction);
if (async != null)
{
async.stop();
@@ -486,24 +492,27 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
continue;
}
- if (!unmap)
+ if (unmap)
{
- // TODO Bug 296087: Before we go ahead with creation, we should check if it's already there
- IClassMapping mapping = createClassMapping(eClass, true);
- getStore().getDBAdapter().createTables(mapping.getDBTables(), connection);
+ int todo;
+ // IClassMapping mapping = removeClassMapping(eClass);
+ // getStore().getDBAdapter().dropTables(mapping.getDBTables(), connection);
}
else
{
- IClassMapping mapping = removeClassMapping(eClass);
- getStore().getDBAdapter().dropTables(mapping.getDBTables(), connection);
+ createClassMapping(eClass);
+
+ // TODO Bug 296087: Before we go ahead with creation, we should check if it's already there
+ // IClassMapping mapping = createClassMapping(eClass);
+ // getStore().getDBAdapter().createTables(mapping.getDBTables(), connection);
}
}
}
}
- private IClassMapping createClassMapping(EClass eClass, boolean create)
+ private IClassMapping createClassMapping(EClass eClass)
{
- IClassMapping mapping = doCreateClassMapping(eClass, create);
+ IClassMapping mapping = doCreateClassMapping(eClass);
if (mapping != null)
{
classMappings.put(eClass, mapping);
@@ -528,7 +537,7 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
return mapping;
}
- protected abstract IClassMapping doCreateClassMapping(EClass eClass, boolean create);
+ protected abstract IClassMapping doCreateClassMapping(EClass eClass);
public final IClassMapping getClassMapping(EClass eClass)
{
@@ -551,7 +560,7 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
result = classMappings.get(eClass);
if (result == null)
{
- result = createClassMapping(eClass, false);
+ result = createClassMapping(eClass);
}
}
}
@@ -625,15 +634,13 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
public final IListMapping createListMapping(EClass containingClass, EStructuralFeature feature)
{
checkArg(feature.isMany(), "Only many-valued features allowed"); //$NON-NLS-1$
- IListMapping mapping = doCreateListMapping(containingClass, feature);
- return mapping;
+ return doCreateListMapping(containingClass, feature);
}
public final IListMapping createFeatureMapMapping(EClass containingClass, EStructuralFeature feature)
{
checkArg(FeatureMapUtil.isFeatureMap(feature), "Only FeatureMaps allowed"); //$NON-NLS-1$
- IListMapping mapping = doCreateFeatureMapMapping(containingClass, feature);
- return mapping;
+ return doCreateFeatureMapMapping(containingClass, feature);
}
public abstract IListMapping doCreateListMapping(EClass containingClass, EStructuralFeature feature);
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractFeatureMapTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractFeatureMapTableMapping.java
index 2567e35824..fec2590376 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractFeatureMapTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractFeatureMapTableMapping.java
@@ -37,7 +37,9 @@ import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.IDBDatabase;
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.IDBTable;
import org.eclipse.net4j.util.ImplementationError;
@@ -52,8 +54,8 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -73,20 +75,22 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
*/
private IDBTable table;
+ private FieldInfo[] keyFields;
+
/**
- * The tags mapped to column names
+ * The tags mapped to column names.
*/
- private Map<CDOID, String> tagMap;
+ private Map<CDOID, String> tagMap = CDOIDUtil.createMap();
/**
- * Column name Set
+ * Column names.
*/
- private List<String> columnNames;
+ private List<String> columnNames = new ArrayList<String>();
/**
* The type mappings for the value fields.
*/
- private Map<CDOID, ITypeMapping> typeMappings;
+ private Map<CDOID, ITypeMapping> typeMappings = CDOIDUtil.createMap();
// --------- SQL strings - see initSQLStrings() -----------------
private String sqlSelectChunksPrefix;
@@ -119,66 +123,67 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
private void initTable()
{
- IDBStore store = getMappingStrategy().getStore();
- DBType idType = store.getIDHandler().getDBType();
- int idLength = store.getIDColumnLength();
-
String tableName = getMappingStrategy().getTableName(getContainingClass(), getFeature());
- table = store.getDBSchema().addTable(tableName);
-
- // add fields for keys (cdo_id, version, feature_id)
- FieldInfo[] fields = getKeyFields();
- IDBField[] dbFields = new IDBField[fields.length];
+ DBType idType = getMappingStrategy().getStore().getIDHandler().getDBType();
+ int idLength = getMappingStrategy().getStore().getIDColumnLength();
- for (int i = 0; i < fields.length; i++)
+ IDBDatabase database = getMappingStrategy().getStore().getDatabase();
+ table = database.getSchema().getTable(tableName);
+ if (table == null)
{
- dbFields[i] = table.addField(fields[i].getName(), fields[i].getDbType(), fields[i].getPrecision());
- }
+ table = database.getSchemaTransaction().getWorkingCopy().addTable(tableName);
+
+ IDBIndex index = table.addIndexEmpty(Type.NON_UNIQUE);
+ for (FieldInfo fieldInfo : getKeyFields())
+ {
+ IDBField field = table.addField(fieldInfo.getName(), fieldInfo.getType(), fieldInfo.getPrecision());
+ index.addIndexField(field);
+ }
- // add field for list index
- IDBField idxField = table.addField(FEATUREMAP_IDX, DBType.INTEGER);
+ // Add field for list index
+ table.addField(FEATUREMAP_IDX, DBType.INTEGER);
- // add field for FeatureMap tag (MetaID for Feature in CDO registry)
- IDBField tagField = table.addField(FEATUREMAP_TAG, idType, idLength);
+ // Add field for FeatureMap tag (MetaID for Feature in CDO registry)
+ table.addField(FEATUREMAP_TAG, idType, idLength);
- tagMap = CDOIDUtil.createMap();
- typeMappings = CDOIDUtil.createMap();
- columnNames = new ArrayList<String>();
+ // Create columns for all DBTypes
+ initTypeColumns(true);
- // create columns for all DBTypes
- for (DBType type : getDBTypes())
+ table.addIndex(Type.NON_UNIQUE, FEATUREMAP_IDX);
+ table.addIndex(Type.NON_UNIQUE, FEATUREMAP_TAG);
+ }
+ else
{
- String column = FEATUREMAP_VALUE + "_" + type.name();
- table.addField(column, type);
- columnNames.add(column);
+ initTypeColumns(false);
}
-
- table.addIndex(Type.NON_UNIQUE, dbFields);
- table.addIndex(Type.NON_UNIQUE, idxField);
- table.addIndex(Type.NON_UNIQUE, tagField);
}
- protected abstract FieldInfo[] getKeyFields();
-
- protected abstract void setKeyFields(PreparedStatement stmt, CDORevision revision) throws SQLException;
-
- public Collection<IDBTable> getDBTables()
+ private void initTypeColumns(boolean create)
{
- return Arrays.asList(table);
+ for (DBType type : getDBTypes())
+ {
+ String column = FEATUREMAP_VALUE + "_" + type.name();
+ if (create)
+ {
+ table.addField(column, type);
+ }
+
+ columnNames.add(column);
+ }
}
private void initSQLStrings()
{
String tableName = getTable().getName();
FieldInfo[] fields = getKeyFields();
-
+
// ---------------- SELECT to read chunks ----------------------------
StringBuilder builder = new StringBuilder();
builder.append("SELECT ");
-
+
builder.append(FEATUREMAP_TAG);
builder.append(", ");
-
+
Iterator<String> iter = columnNames.iterator();
while (iter.hasNext())
{
@@ -188,11 +193,11 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
builder.append(", ");
}
}
-
+
builder.append(" FROM ");
builder.append(tableName);
builder.append(" WHERE ");
-
+
for (int i = 0; i < fields.length; i++)
{
builder.append(fields[i].getName());
@@ -207,14 +212,14 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
builder.append("=? ");
}
}
-
+
sqlSelectChunksPrefix = builder.toString();
-
+
sqlOrderByIndex = " ORDER BY " + FEATUREMAP_IDX; //$NON-NLS-1$
-
+
// INSERT with dynamic field name
// TODO: Better: universal INSERT-Statement, because of stmt caching!
-
+
// ----------------- INSERT - prefix -----------------
builder = new StringBuilder("INSERT INTO ");
builder.append(tableName);
@@ -224,13 +229,13 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
builder.append(fields[i].getName());
builder.append(", "); //$NON-NLS-1$
}
-
+
for (int i = 0; i < columnNames.size(); i++)
{
builder.append(columnNames.get(i));
builder.append(", "); //$NON-NLS-1$
}
-
+
builder.append(FEATUREMAP_IDX);
builder.append(", "); //$NON-NLS-1$
builder.append(FEATUREMAP_TAG);
@@ -239,11 +244,39 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
{
builder.append("?, ");
}
-
+
builder.append("?, ?)");
sqlInsert = builder.toString();
}
+ protected final FieldInfo[] getKeyFields()
+ {
+ if (keyFields == null)
+ {
+ List<FieldInfo> list = new ArrayList<FieldInfo>(3);
+
+ IDBStore store = getMappingStrategy().getStore();
+ DBType type = store.getIDHandler().getDBType();
+ int precision = store.getIDColumnLength();
+ list.add(new FieldInfo(FEATUREMAP_REVISION_ID, type, precision));
+
+ addKeyFields(list);
+
+ keyFields = list.toArray(new FieldInfo[list.size()]);
+ }
+
+ return keyFields;
+ }
+
+ protected abstract void addKeyFields(List<FieldInfo> list);
+
+ protected abstract void setKeyFields(PreparedStatement stmt, CDORevision revision) throws SQLException;
+
+ public Collection<IDBTable> getDBTables()
+ {
+ return Collections.singleton(table);
+ }
+
protected List<DBType> getDBTypes()
{
return dbTypes;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalClassMapping.java
index 1310e933b1..84bfa281e2 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalClassMapping.java
@@ -18,7 +18,6 @@ import org.eclipse.emf.cdo.common.branch.CDOBranchManager;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.model.CDOClassInfo;
import org.eclipse.emf.cdo.common.model.CDOModelUtil;
import org.eclipse.emf.cdo.common.revision.CDOList;
import org.eclipse.emf.cdo.common.revision.CDORevision;
@@ -27,7 +26,6 @@ import org.eclipse.emf.cdo.common.revision.CDORevisionManager;
import org.eclipse.emf.cdo.eresource.EresourcePackage;
import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.IStoreAccessor.QueryXRefsContext;
-import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IIDHandler;
import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
@@ -45,9 +43,9 @@ import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBDatabase;
-import org.eclipse.net4j.db.IDBDatabase.RunnableWithTable;
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.util.om.monitor.OMMonitor;
import org.eclipse.net4j.util.om.monitor.OMMonitor.Async;
@@ -66,6 +64,7 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
@@ -91,180 +90,169 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping, I
private List<IListMapping> listMappings;
- private Map<EStructuralFeature, String> listSizeFields;
+ private Map<EStructuralFeature, IDBField> listSizeFields;
- private Map<EStructuralFeature, String> unsettableFields;
+ private Map<EStructuralFeature, IDBField> unsettableFields;
private String sqlSelectForHandle;
private String sqlSelectForChangeSet;
- public AbstractHorizontalClassMapping(AbstractHorizontalMappingStrategy mappingStrategy, EClass eClass, boolean create)
+ public AbstractHorizontalClassMapping(AbstractHorizontalMappingStrategy mappingStrategy, EClass eClass)
{
this.mappingStrategy = mappingStrategy;
this.eClass = eClass;
- initTable();
-
- CDOClassInfo classInfo = CDOModelUtil.getClassInfo(eClass);
- EStructuralFeature[] allPersistentFeatures = classInfo.getAllPersistentFeatures();
- initFeatures(allPersistentFeatures);
+ initTable();
+ initFields();
initSQLStrings();
}
private void initTable()
{
- final IDBStore store = getMappingStrategy().getStore();
- final DBType idType = store.getIDHandler().getDBType();
- final int idLength = store.getIDColumnLength();
- final String name = getMappingStrategy().getTableName(eClass);
+ final String tableName = mappingStrategy.getTableName(eClass);
+ final DBType idType = mappingStrategy.getStore().getIDHandler().getDBType();
+ final int idLength = mappingStrategy.getStore().getIDColumnLength();
- IDBDatabase database = store.getDatabase();
- table = database.ensureTable(name, new RunnableWithTable()
+ IDBDatabase database = mappingStrategy.getStore().getDatabase();
+ table = database.getSchema().getTable(tableName);
+ if (table == null)
{
- public void run(IDBTable table)
- {
- IDBField idField = table.addField(ATTRIBUTES_ID, idType, idLength, true);
- IDBField versionField = table.addField(ATTRIBUTES_VERSION, DBType.INTEGER, true);
+ IDBSchema workingCopy = database.getSchemaTransaction().getWorkingCopy();
+ table = workingCopy.addTable(tableName);
+ table.addField(ATTRIBUTES_ID, idType, idLength, true);
+ table.addField(ATTRIBUTES_VERSION, DBType.INTEGER, true);
- IDBField branchField = addBranchingField(table);
+ IDBField branchField = addBranchField(table);
- table.addField(ATTRIBUTES_CREATED, DBType.BIGINT, true);
- IDBField revisedField = table.addField(ATTRIBUTES_REVISED, DBType.BIGINT, true);
- table.addField(ATTRIBUTES_RESOURCE, idType, idLength, true);
- table.addField(ATTRIBUTES_CONTAINER, idType, idLength, true);
- table.addField(ATTRIBUTES_FEATURE, DBType.INTEGER, true);
-
- if (branchField != null)
- {
- table.addIndex(IDBIndex.Type.PRIMARY_KEY, idField, versionField, branchField);
- }
- else
- {
- table.addIndex(IDBIndex.Type.PRIMARY_KEY, idField, versionField);
- }
+ table.addField(ATTRIBUTES_CREATED, DBType.BIGINT, true);
+ table.addField(ATTRIBUTES_REVISED, DBType.BIGINT, true);
+ table.addField(ATTRIBUTES_RESOURCE, idType, idLength, true);
+ table.addField(ATTRIBUTES_CONTAINER, idType, idLength, true);
+ table.addField(ATTRIBUTES_FEATURE, DBType.INTEGER, true);
- table.addIndex(IDBIndex.Type.NON_UNIQUE, idField, revisedField);
+ IDBIndex primaryKey = table.addIndex(IDBIndex.Type.PRIMARY_KEY, ATTRIBUTES_ID, ATTRIBUTES_VERSION);
+ if (branchField != null)
+ {
+ primaryKey.addIndexField(branchField);
}
- });
- }
- protected IDBField addBranchingField(IDBTable table)
- {
- return null;
+ table.addIndex(IDBIndex.Type.NON_UNIQUE, ATTRIBUTES_ID, ATTRIBUTES_REVISED);
+ }
}
- private void initFeatures(EStructuralFeature[] features)
+ private void initFields()
{
- if (features == null)
+ final EStructuralFeature[] allPersistentFeatures = CDOModelUtil.getClassInfo(eClass).getAllPersistentFeatures();
+ if (allPersistentFeatures == null)
{
valueMappings = Collections.emptyList();
listMappings = Collections.emptyList();
}
else
{
- valueMappings = createValueMappings(features);
- listMappings = createListMappings(features);
- }
- }
-
- private void initSQLStrings()
- {
- // ----------- Select all revisions (for handleRevisions) ---
- StringBuilder builder = new StringBuilder("SELECT "); //$NON-NLS-1$
- builder.append(ATTRIBUTES_ID);
- builder.append(", "); //$NON-NLS-1$
- builder.append(ATTRIBUTES_VERSION);
- builder.append(" FROM "); //$NON-NLS-1$
- builder.append(getTable());
- sqlSelectForHandle = builder.toString();
-
- // ----------- Select all revisions (for readChangeSet) ---
- builder = new StringBuilder("SELECT DISTINCT "); //$NON-NLS-1$
- builder.append(ATTRIBUTES_ID);
- builder.append(" FROM "); //$NON-NLS-1$
- builder.append(getTable());
- builder.append(" WHERE "); //$NON-NLS-1$
- sqlSelectForChangeSet = builder.toString();
- }
+ valueMappings = new ArrayList<ITypeMapping>();
+ listMappings = new ArrayList<IListMapping>();
- private List<ITypeMapping> createValueMappings(EStructuralFeature[] features)
- {
- List<ITypeMapping> mappings = new ArrayList<ITypeMapping>();
- for (EStructuralFeature feature : features)
- {
- if (!feature.isMany())
+ boolean hasUnsettableFeatures = false;
+ for (EStructuralFeature feature : allPersistentFeatures)
{
- ITypeMapping mapping = mappingStrategy.createValueMapping(feature);
- mapping.createDBField(getTable());
- mappings.add(mapping);
-
- if (feature.isUnsettable())
+ String fieldName = mappingStrategy.getFieldName(feature);
+ if (feature.isMany())
{
- String fieldName = mappingStrategy.getUnsettableFieldName(feature);
- if (unsettableFields == null)
+ IListMapping mapping = null;
+ if (FeatureMapUtil.isFeatureMap(feature))
{
- unsettableFields = new LinkedHashMap<EStructuralFeature, String>();
+ mapping = mappingStrategy.createFeatureMapMapping(eClass, feature);
+ }
+ else
+ {
+ mapping = mappingStrategy.createListMapping(eClass, feature);
}
- unsettableFields.put(feature, fieldName);
- }
- }
- }
+ listMappings.add(mapping);
- // Add unsettable fields to end of table
- if (unsettableFields != null)
- {
- for (String fieldName : unsettableFields.values())
- {
- table.addField(fieldName, DBType.BOOLEAN, 1);
- }
- }
+ // Add field for list sizes
+ if (listSizeFields == null)
+ {
+ listSizeFields = new LinkedHashMap<EStructuralFeature, IDBField>();
+ }
- return mappings;
- }
+ IDBField field = table.getField(fieldName);
+ if (field == null)
+ {
+ field = table.addField(fieldName, DBType.INTEGER);
+ }
- private List<IListMapping> createListMappings(EStructuralFeature[] features)
- {
- List<IListMapping> listMappings = new ArrayList<IListMapping>();
- for (EStructuralFeature feature : features)
- {
- if (feature.isMany())
- {
- IListMapping mapping = null;
- if (FeatureMapUtil.isFeatureMap(feature))
- {
- mapping = mappingStrategy.createFeatureMapMapping(eClass, feature);
+ listSizeFields.put(feature, field);
}
else
{
- mapping = mappingStrategy.createListMapping(eClass, feature);
+ ITypeMapping mapping = mappingStrategy.createValueMapping(feature);
+ IDBField field = table.getField(fieldName);
+ if (field == null)
+ {
+ mapping.createDBField(table, fieldName);
+ }
+ else
+ {
+ mapping.setDBField(table, fieldName);
+ }
+
+ valueMappings.add(mapping);
+
+ if (feature.isUnsettable())
+ {
+ hasUnsettableFeatures = true;
+ }
}
+ }
- listMappings.add(mapping);
+ // Add unsettable fields to end of table
+ if (hasUnsettableFeatures)
+ {
+ unsettableFields = new LinkedHashMap<EStructuralFeature, IDBField>();
+ for (EStructuralFeature feature : allPersistentFeatures)
+ {
+ if (!feature.isMany() && feature.isUnsettable())
+ {
+ String fieldName = mappingStrategy.getUnsettableFieldName(feature);
+ IDBField field = table.getField(fieldName);
+ if (field == null)
+ {
+ field = table.addField(fieldName, DBType.BOOLEAN);
+ }
- // Add field for list sizes
- createListSizeField(feature);
+ unsettableFields.put(feature, field);
+ }
+ }
}
}
-
- return listMappings;
}
- /**
- * Create an integer field in the attribute tabel for the list size of the associated list mapping.
- */
- private void createListSizeField(EStructuralFeature feature)
+ private void initSQLStrings()
{
- if (listSizeFields == null)
- {
- listSizeFields = new LinkedHashMap<EStructuralFeature, String>();
- }
+ // ----------- Select all revisions (for handleRevisions) ---
+ StringBuilder builder = new StringBuilder("SELECT "); //$NON-NLS-1$
+ builder.append(ATTRIBUTES_ID);
+ builder.append(", "); //$NON-NLS-1$
+ builder.append(ATTRIBUTES_VERSION);
+ builder.append(" FROM "); //$NON-NLS-1$
+ builder.append(table);
+ sqlSelectForHandle = builder.toString();
- String fieldName = mappingStrategy.getFieldName(feature);
- table.addField(fieldName, DBType.INTEGER);
+ // ----------- Select all revisions (for readChangeSet) ---
+ builder = new StringBuilder("SELECT DISTINCT "); //$NON-NLS-1$
+ builder.append(ATTRIBUTES_ID);
+ builder.append(" FROM "); //$NON-NLS-1$
+ builder.append(table);
+ builder.append(" WHERE "); //$NON-NLS-1$
+ sqlSelectForChangeSet = builder.toString();
+ }
- listSizeFields.put(feature, fieldName);
+ protected IDBField addBranchField(IDBTable table)
+ {
+ return null;
}
/**
@@ -316,7 +304,8 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping, I
EStructuralFeature feature = mapping.getFeature();
if (feature.isUnsettable())
{
- if (!resultSet.getBoolean(unsettableFields.get(feature)))
+ IDBField field = unsettableFields.get(feature);
+ if (!resultSet.getBoolean(field.getName()))
{
// isSet==false -- setValue: null
revision.setValue(feature, null);
@@ -329,11 +318,11 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping, I
if (listSizeFields != null)
{
- for (Map.Entry<EStructuralFeature, String> listSizeEntry : listSizeFields.entrySet())
+ for (Map.Entry<EStructuralFeature, IDBField> listSizeEntry : listSizeFields.entrySet())
{
EStructuralFeature feature = listSizeEntry.getKey();
- String fieldName = listSizeEntry.getValue();
- int size = resultSet.getInt(fieldName);
+ IDBField field = listSizeEntry.getValue();
+ int size = resultSet.getInt(field.getName());
// ensure the listSize (TODO: remove assertion)
CDOList list = revision.getList(feature, size);
@@ -380,12 +369,12 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping, I
return eClass;
}
- protected final Map<EStructuralFeature, String> getUnsettableFields()
+ protected final Map<EStructuralFeature, IDBField> getUnsettableFields()
{
return unsettableFields;
}
- protected final Map<EStructuralFeature, String> getListSizeFields()
+ protected final Map<EStructuralFeature, IDBField> getListSizeFields()
{
return listSizeFields;
}
@@ -806,7 +795,7 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping, I
public final boolean queryXRefs(IDBStoreAccessor accessor, QueryXRefsContext context, String idString)
{
- String tableName = getTable().getName();
+ String tableName = table.getName();
List<EReference> refs = context.getSourceCandidates().get(eClass);
List<EReference> scalarRefs = new ArrayList<EReference>();
@@ -844,7 +833,7 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping, I
protected final boolean queryScalarXRefs(IDBStoreAccessor accessor, List<EReference> scalarRefs,
QueryXRefsContext context, String idString)
{
- String tableName = getTable().getName();
+ String tableName = table.getName();
String where = getListXRefsWhere(context);
for (EReference ref : scalarRefs)
@@ -926,4 +915,50 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping, I
protected abstract void reviseOldRevision(IDBStoreAccessor accessor, CDOID id, CDOBranch branch, long timeStamp);
protected abstract void writeValues(IDBStoreAccessor accessor, InternalCDORevision revision);
+
+ protected static void appendTypeMappingNames(StringBuilder builder, Collection<ITypeMapping> typeMappings)
+ {
+ if (typeMappings != null)
+ {
+ for (ITypeMapping typeMapping : typeMappings)
+ {
+ builder.append(", "); //$NON-NLS-1$
+ builder.append(typeMapping.getField());
+ }
+ }
+ }
+
+ protected static void appendFieldNames(StringBuilder builder, Map<EStructuralFeature, IDBField> fields)
+ {
+ if (fields != null)
+ {
+ for (IDBField field : fields.values())
+ {
+ builder.append(", "); //$NON-NLS-1$
+ builder.append(field);
+ }
+ }
+ }
+
+ protected static void appendTypeMappingParameters(StringBuilder builder, Collection<ITypeMapping> typeMappings)
+ {
+ if (typeMappings != null)
+ {
+ for (int i = 0; i < typeMappings.size(); i++)
+ {
+ builder.append(", ?"); //$NON-NLS-1$
+ }
+ }
+ }
+
+ protected static void appendFieldParameters(StringBuilder builder, Map<EStructuralFeature, IDBField> fields)
+ {
+ if (fields != null)
+ {
+ for (int i = 0; i < fields.size(); i++)
+ {
+ builder.append(", ?"); //$NON-NLS-1$
+ }
+ }
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
index ab385a3fa7..3903ff4fef 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
@@ -72,6 +72,10 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS
*/
private IObjectTypeMapper objectTypeMapper;
+ public AbstractHorizontalMappingStrategy()
+ {
+ }
+
public CDOClassifierRef readObjectType(IDBStoreAccessor accessor, CDOID id)
{
return objectTypeMapper.getObjectType(accessor, id);
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractListTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractListTableMapping.java
index e2bb08b818..767435d030 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractListTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractListTableMapping.java
@@ -18,6 +18,7 @@ import org.eclipse.emf.cdo.common.revision.CDOList;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.server.IStoreAccessor.QueryXRefsContext;
import org.eclipse.emf.cdo.server.IStoreChunkReader.Chunk;
+import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IDBStoreChunkReader;
import org.eclipse.emf.cdo.server.db.IIDHandler;
@@ -31,7 +32,9 @@ import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.IDBDatabase;
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.IDBTable;
import org.eclipse.net4j.util.collection.MoveableList;
@@ -45,8 +48,9 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.Arrays;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
/**
@@ -64,6 +68,8 @@ public abstract class AbstractListTableMapping extends AbstractBasicListTableMap
*/
private IDBTable table;
+ private FieldInfo[] keyFields;
+
/**
* The type mapping for the value field.
*/
@@ -85,42 +91,38 @@ public abstract class AbstractListTableMapping extends AbstractBasicListTableMap
private void initTable()
{
- IMappingStrategy mappingStrategy = getMappingStrategy();
- String tableName = mappingStrategy.getTableName(getContainingClass(), getFeature());
- table = mappingStrategy.getStore().getDBSchema().addTable(tableName);
-
- // add fields for keys (cdo_id, version, feature_id)
- FieldInfo[] fields = getKeyFields();
- IDBField[] dbFields = new IDBField[fields.length + 1];
+ String tableName = getMappingStrategy().getTableName(getContainingClass(), getFeature());
+ typeMapping = getMappingStrategy().createValueMapping(getFeature());
- for (int i = 0; i < fields.length; i++)
+ IDBDatabase database = getMappingStrategy().getStore().getDatabase();
+ table = database.getSchema().getTable(tableName);
+ if (table == null)
{
- dbFields[i] = table.addField(fields[i].getName(), fields[i].getDbType(), fields[i].getPrecision(), true);
- }
-
- // add field for list index
- dbFields[dbFields.length - 1] = table.addField(LIST_IDX, DBType.INTEGER, true);
-
- // add field for value
- typeMapping = mappingStrategy.createValueMapping(getFeature());
- typeMapping.createDBField(table, LIST_VALUE);
-
- // add table indexes
- table.addIndex(Type.PRIMARY_KEY, dbFields);
- }
+ table = database.getSchemaTransaction().getWorkingCopy().addTable(tableName);
- protected abstract FieldInfo[] getKeyFields();
+ IDBIndex primaryKey = table.addIndexEmpty(Type.PRIMARY_KEY);
+ for (FieldInfo info : getKeyFields())
+ {
+ IDBField field = table.addField(info.getName(), info.getType(), info.getPrecision(), true);
+ primaryKey.addIndexField(field);
+ }
- protected abstract void setKeyFields(PreparedStatement stmt, CDORevision revision) throws SQLException;
+ // Add field for list index
+ IDBField field = table.addField(LIST_IDX, DBType.INTEGER, true);
+ primaryKey.addIndexField(field);
- public Collection<IDBTable> getDBTables()
- {
- return Arrays.asList(table);
+ // Add field for value
+ typeMapping.createDBField(table, LIST_VALUE);
+ }
+ else
+ {
+ typeMapping.setDBField(table, LIST_VALUE);
+ }
}
private void initSQLStrings()
{
- String tableName = getTable().getName();
+ String tableName = table.getName();
FieldInfo[] fields = getKeyFields();
// ---------------- SELECT to read chunks ----------------------------
@@ -174,6 +176,34 @@ public abstract class AbstractListTableMapping extends AbstractBasicListTableMap
sqlInsertEntry = builder.toString();
}
+ protected final FieldInfo[] getKeyFields()
+ {
+ if (keyFields == null)
+ {
+ List<FieldInfo> list = new ArrayList<FieldInfo>(3);
+
+ IDBStore store = getMappingStrategy().getStore();
+ DBType type = store.getIDHandler().getDBType();
+ int precision = store.getIDColumnLength();
+ list.add(new FieldInfo(LIST_REVISION_ID, type, precision));
+
+ addKeyFields(list);
+
+ keyFields = list.toArray(new FieldInfo[list.size()]);
+ }
+
+ return keyFields;
+ }
+
+ protected abstract void addKeyFields(List<FieldInfo> list);
+
+ protected abstract void setKeyFields(PreparedStatement stmt, CDORevision revision) throws SQLException;
+
+ public Collection<IDBTable> getDBTables()
+ {
+ return Collections.singleton(table);
+ }
+
protected final IDBTable getTable()
{
return table;
@@ -382,7 +412,7 @@ public abstract class AbstractListTableMapping extends AbstractBasicListTableMap
public boolean queryXRefs(IDBStoreAccessor accessor, String mainTableName, String mainTableWhere,
QueryXRefsContext context, String idString)
{
- String tableName = getTable().getName();
+ String tableName = table.getName();
String listJoin = getMappingStrategy().getListJoin("a_t", "l_t");
StringBuilder builder = new StringBuilder();
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMapping.java
index 67f98079f7..baf32ed022 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMapping.java
@@ -15,8 +15,8 @@ package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal;
import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
+import org.eclipse.emf.cdo.server.db.IIDHandler;
import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
@@ -30,6 +30,7 @@ import org.eclipse.emf.ecore.EStructuralFeature;
import java.sql.PreparedStatement;
import java.sql.SQLException;
+import java.util.List;
/**
* This is a featuremap-table mapping for audit mode. It has ID and version columns and no delta support.
@@ -39,8 +40,6 @@ import java.sql.SQLException;
*/
public class AuditFeatureMapTableMapping extends AbstractFeatureMapTableMapping
{
- private FieldInfo[] keyFields;
-
private String sqlClear;
public AuditFeatureMapTableMapping(IMappingStrategy mappingStrategy, EClass eClass, EStructuralFeature feature)
@@ -64,24 +63,16 @@ public class AuditFeatureMapTableMapping extends AbstractFeatureMapTableMapping
}
@Override
- protected FieldInfo[] getKeyFields()
+ protected void addKeyFields(List<FieldInfo> list)
{
- if (keyFields == null)
- {
- IDBStore store = getMappingStrategy().getStore();
-
- keyFields = new FieldInfo[] {
- new FieldInfo(FEATUREMAP_REVISION_ID, store.getIDHandler().getDBType(), store.getIDColumnLength()),
- new FieldInfo(FEATUREMAP_VERSION, DBType.INTEGER) };
- }
-
- return keyFields;
+ list.add(new FieldInfo(FEATUREMAP_VERSION, DBType.INTEGER));
}
@Override
protected void setKeyFields(PreparedStatement stmt, CDORevision revision) throws SQLException
{
- getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 1, revision.getID());
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ idHandler.setCDOID(stmt, 1, revision.getID());
stmt.setInt(2, revision.getVersion());
}
@@ -93,13 +84,14 @@ public class AuditFeatureMapTableMapping extends AbstractFeatureMapTableMapping
@Override
public void rawDeleted(IDBStoreAccessor accessor, CDOID id, CDOBranch branch, int version)
{
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
IPreparedStatementCache statementCache = accessor.getStatementCache();
PreparedStatement stmt = null;
try
{
stmt = statementCache.getPreparedStatement(sqlClear, ReuseProbability.HIGH);
- getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 1, id);
+ idHandler.setCDOID(stmt, 1, id);
stmt.setInt(2, version);
DBUtil.update(stmt, false);
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMappingWithRanges.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMappingWithRanges.java
index f6993c7396..db0dfbd238 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMappingWithRanges.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMappingWithRanges.java
@@ -51,7 +51,7 @@ import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
-import org.eclipse.net4j.db.ddl.IDBField;
+import org.eclipse.net4j.db.IDBDatabase;
import org.eclipse.net4j.db.ddl.IDBIndex.Type;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.ImplementationError;
@@ -66,8 +66,8 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -102,24 +102,23 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
private IDBTable table;
/**
- * The tags mapped to column names
+ * Column names.
*/
- private Map<CDOID, String> tagMap;
+ private List<String> columnNames = new ArrayList<String>();
/**
- * Column name Set
+ * The type mappings for the value fields.
*/
- private List<String> columnNames;
+ private Map<CDOID, ITypeMapping> typeMappings = CDOIDUtil.createMap();
/**
- * The type mappings for the value fields.
+ * The tags mapped to column names
*/
- private Map<CDOID, ITypeMapping> typeMappings;
+ private Map<CDOID, String> tagMap = CDOIDUtil.createMap();
private List<DBType> dbTypes;
// --------- SQL strings - see initSQLStrings() -----------------
-
private String sqlSelectChunksPrefix;
private String sqlOrderByIndex;
@@ -156,44 +155,49 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
private void initTable()
{
+ String tableName = getMappingStrategy().getTableName(getContainingClass(), getFeature());
IDBStore store = getMappingStrategy().getStore();
DBType idType = store.getIDHandler().getDBType();
int idLength = store.getIDColumnLength();
- String tableName = getMappingStrategy().getTableName(getContainingClass(), getFeature());
- table = store.getDBSchema().addTable(tableName);
-
- // add fields for CDOID
- IDBField idField = table.addField(FEATUREMAP_REVISION_ID, idType, idLength);
-
- // add fields for version range
- IDBField versionAddedField = table.addField(FEATUREMAP_VERSION_ADDED, DBType.INTEGER);
- IDBField versionRemovedField = table.addField(FEATUREMAP_VERSION_REMOVED, DBType.INTEGER);
-
- // add field for list index
- IDBField idxField = table.addField(FEATUREMAP_IDX, DBType.INTEGER);
-
- // add field for FeatureMap tag (MetaID for Feature in CDO registry)
- IDBField tagField = table.addField(FEATUREMAP_TAG, idType, idLength);
-
- tagMap = CDOIDUtil.createMap();
- typeMappings = CDOIDUtil.createMap();
- columnNames = new ArrayList<String>();
+ IDBDatabase database = getMappingStrategy().getStore().getDatabase();
+ table = database.getSchema().getTable(tableName);
+ if (table == null)
+ {
+ table = database.getSchemaTransaction().getWorkingCopy().addTable(tableName);
+ table.addField(FEATUREMAP_REVISION_ID, idType, idLength);
+ table.addField(FEATUREMAP_VERSION_ADDED, DBType.INTEGER);
+ table.addField(FEATUREMAP_VERSION_REMOVED, DBType.INTEGER);
+ table.addField(FEATUREMAP_IDX, DBType.INTEGER);
+ table.addField(FEATUREMAP_TAG, idType, idLength);
+
+ initTypeColumns(true);
+
+ // TODO think about indices
+ table.addIndex(Type.NON_UNIQUE, FEATUREMAP_REVISION_ID);
+ table.addIndex(Type.NON_UNIQUE, FEATUREMAP_VERSION_ADDED);
+ table.addIndex(Type.NON_UNIQUE, FEATUREMAP_VERSION_REMOVED);
+ table.addIndex(Type.NON_UNIQUE, FEATUREMAP_IDX);
+ table.addIndex(Type.NON_UNIQUE, FEATUREMAP_TAG);
+ }
+ else
+ {
+ initTypeColumns(false);
+ }
+ }
- // create columns for all DBTypes
+ private void initTypeColumns(boolean create)
+ {
for (DBType type : getDBTypes())
{
String column = FEATUREMAP_VALUE + "_" + type.name();
- table.addField(column, type);
+ if (create)
+ {
+ table.addField(column, type);
+ }
+
columnNames.add(column);
}
-
- // TODO think about indices
- table.addIndex(Type.NON_UNIQUE, idField);
- table.addIndex(Type.NON_UNIQUE, versionAddedField);
- table.addIndex(Type.NON_UNIQUE, versionRemovedField);
- table.addIndex(Type.NON_UNIQUE, idxField);
- table.addIndex(Type.NON_UNIQUE, tagField);
}
private void initSQLStrings()
@@ -361,7 +365,7 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
public Collection<IDBTable> getDBTables()
{
- return Arrays.asList(table);
+ return Collections.singleton(table);
}
protected final IDBTable getTable()
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMapping.java
index 85b0e3d319..d57dae7eca 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMapping.java
@@ -14,8 +14,8 @@ package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal;
import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
+import org.eclipse.emf.cdo.server.db.IIDHandler;
import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
@@ -23,12 +23,14 @@ import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import java.sql.PreparedStatement;
import java.sql.SQLException;
+import java.util.List;
/**
* This is a list-table mapping for audit mode. It has ID and version columns and no delta support.
@@ -38,8 +40,6 @@ import java.sql.SQLException;
*/
public class AuditListTableMapping extends AbstractListTableMapping
{
- private FieldInfo[] keyFields;
-
private String sqlClear;
public AuditListTableMapping(IMappingStrategy mappingStrategy, EClass eClass, EStructuralFeature feature)
@@ -50,37 +50,31 @@ public class AuditListTableMapping extends AbstractListTableMapping
private void initSQLStrings()
{
+ IDBTable table = getTable();
+
// ----------- clear list -------------------------
StringBuilder builder = new StringBuilder();
builder.append("DELETE FROM "); //$NON-NLS-1$
- builder.append(getTable());
+ builder.append(table);
builder.append(" WHERE "); //$NON-NLS-1$
builder.append(LIST_REVISION_ID);
builder.append("=? AND "); //$NON-NLS-1$
builder.append(LIST_REVISION_VERSION);
- builder.append("=? "); //$NON-NLS-1$
+ builder.append("=?"); //$NON-NLS-1$
sqlClear = builder.toString();
}
@Override
- protected FieldInfo[] getKeyFields()
+ protected void addKeyFields(List<FieldInfo> list)
{
- if (keyFields == null)
- {
- IDBStore store = getMappingStrategy().getStore();
-
- keyFields = new FieldInfo[] {
- new FieldInfo(LIST_REVISION_ID, store.getIDHandler().getDBType(), store.getIDColumnLength()),
- new FieldInfo(LIST_REVISION_VERSION, DBType.INTEGER) };
- }
-
- return keyFields;
+ list.add(new FieldInfo(LIST_REVISION_VERSION, DBType.INTEGER));
}
@Override
protected void setKeyFields(PreparedStatement stmt, CDORevision revision) throws SQLException
{
- getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 1, revision.getID());
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ idHandler.setCDOID(stmt, 1, revision.getID());
stmt.setInt(2, revision.getVersion());
}
@@ -92,13 +86,14 @@ public class AuditListTableMapping extends AbstractListTableMapping
@Override
public void rawDeleted(IDBStoreAccessor accessor, CDOID id, CDOBranch branch, int version)
{
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
IPreparedStatementCache statementCache = accessor.getStatementCache();
PreparedStatement stmt = null;
try
{
stmt = statementCache.getPreparedStatement(sqlClear, ReuseProbability.HIGH);
- getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 1, id);
+ idHandler.setCDOID(stmt, 1, id);
stmt.setInt(2, version);
DBUtil.update(stmt, false);
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMappingWithRanges.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMappingWithRanges.java
index 5054ed3ebf..b2eb2cd7cd 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMappingWithRanges.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMappingWithRanges.java
@@ -47,7 +47,7 @@ import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
-import org.eclipse.net4j.db.ddl.IDBField;
+import org.eclipse.net4j.db.IDBDatabase;
import org.eclipse.net4j.db.ddl.IDBIndex.Type;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.ImplementationError;
@@ -62,8 +62,8 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
/**
@@ -124,31 +124,33 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
private void initTable()
{
+ String tableName = getMappingStrategy().getTableName(getContainingClass(), getFeature());
+ typeMapping = getMappingStrategy().createValueMapping(getFeature());
+
IDBStore store = getMappingStrategy().getStore();
DBType idType = store.getIDHandler().getDBType();
int idLength = store.getIDColumnLength();
- String tableName = getMappingStrategy().getTableName(getContainingClass(), getFeature());
- table = store.getDBSchema().addTable(tableName);
-
- IDBField[] dbFields = new IDBField[4];
- dbFields[0] = table.addField(LIST_REVISION_ID, idType, idLength, true);
- dbFields[1] = table.addField(LIST_REVISION_VERSION_ADDED, DBType.INTEGER);
- dbFields[2] = table.addField(LIST_REVISION_VERSION_REMOVED, DBType.INTEGER);
- dbFields[3] = table.addField(LIST_IDX, DBType.INTEGER, true);
-
- // add field for value
- typeMapping = getMappingStrategy().createValueMapping(getFeature());
- typeMapping.createDBField(table, LIST_VALUE);
+ IDBDatabase database = getMappingStrategy().getStore().getDatabase();
+ table = database.getSchema().getTable(tableName);
+ if (table == null)
+ {
+ table = database.getSchemaTransaction().getWorkingCopy().addTable(tableName);
+ table.addField(LIST_REVISION_ID, idType, idLength, true);
+ table.addField(LIST_REVISION_VERSION_ADDED, DBType.INTEGER);
+ table.addField(LIST_REVISION_VERSION_REMOVED, DBType.INTEGER);
+ table.addField(LIST_IDX, DBType.INTEGER, true);
- // TODO think about indexes
- // add table indexes
- table.addIndex(Type.NON_UNIQUE, dbFields);
- }
+ // TODO think about indexes
+ table.addIndex(Type.NON_UNIQUE, LIST_REVISION_ID, LIST_REVISION_VERSION_ADDED, LIST_REVISION_VERSION_REMOVED,
+ LIST_IDX);
- public Collection<IDBTable> getDBTables()
- {
- return Arrays.asList(table);
+ typeMapping.createDBField(table, LIST_VALUE);
+ }
+ else
+ {
+ typeMapping.setDBField(table, LIST_VALUE);
+ }
}
private void initSQLStrings()
@@ -271,6 +273,11 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
sqlDeleteList = builder.toString();
}
+ public Collection<IDBTable> getDBTables()
+ {
+ return Collections.singleton(table);
+ }
+
protected final IDBTable getTable()
{
return table;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMapping.java
index 837750670e..ead2cea41c 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMapping.java
@@ -16,7 +16,6 @@ package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal;
import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
@@ -31,6 +30,7 @@ import org.eclipse.emf.ecore.EStructuralFeature;
import java.sql.PreparedStatement;
import java.sql.SQLException;
+import java.util.List;
/**
* This is a featuremap-table mapping for audit mode. It has ID and version columns and no delta support.
@@ -41,8 +41,6 @@ import java.sql.SQLException;
*/
public class BranchingFeatureMapTableMapping extends AbstractFeatureMapTableMapping
{
- private FieldInfo[] keyFields;
-
private String sqlClear;
public BranchingFeatureMapTableMapping(IMappingStrategy mappingStrategy, EClass eClass, EStructuralFeature feature)
@@ -68,18 +66,10 @@ public class BranchingFeatureMapTableMapping extends AbstractFeatureMapTableMapp
}
@Override
- protected FieldInfo[] getKeyFields()
+ protected void addKeyFields(List<FieldInfo> list)
{
- if (keyFields == null)
- {
- IDBStore store = getMappingStrategy().getStore();
-
- keyFields = new FieldInfo[] {
- new FieldInfo(FEATUREMAP_REVISION_ID, store.getIDHandler().getDBType(), store.getIDColumnLength()),
- new FieldInfo(FEATUREMAP_BRANCH, DBType.INTEGER), new FieldInfo(FEATUREMAP_VERSION, DBType.INTEGER) };
- }
-
- return keyFields;
+ list.add(new FieldInfo(FEATUREMAP_BRANCH, DBType.INTEGER));
+ list.add(new FieldInfo(FEATUREMAP_VERSION, DBType.INTEGER));
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMappingWithRanges.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMappingWithRanges.java
index 2e88827b88..d2a522aca6 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMappingWithRanges.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMappingWithRanges.java
@@ -49,7 +49,7 @@ import org.eclipse.emf.cdo.spi.server.InternalRepository;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
-import org.eclipse.net4j.db.ddl.IDBField;
+import org.eclipse.net4j.db.IDBDatabase;
import org.eclipse.net4j.db.ddl.IDBIndex.Type;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.ImplementationError;
@@ -64,8 +64,8 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -152,51 +152,54 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
private void initTable()
{
+ String tableName = getMappingStrategy().getTableName(getContainingClass(), getFeature());
IDBStore store = getMappingStrategy().getStore();
DBType idType = store.getIDHandler().getDBType();
int idLength = store.getIDColumnLength();
- String tableName = getMappingStrategy().getTableName(getContainingClass(), getFeature());
- table = store.getDBSchema().addTable(tableName);
-
- // add fields for CDOID
- IDBField idField = table.addField(FEATUREMAP_REVISION_ID, idType, idLength);
-
- IDBField branchField = table.addField(LIST_REVISION_BRANCH, DBType.INTEGER);
-
- // add fields for version range
- IDBField versionAddedField = table.addField(FEATUREMAP_VERSION_ADDED, DBType.INTEGER);
- IDBField versionRemovedField = table.addField(FEATUREMAP_VERSION_REMOVED, DBType.INTEGER);
-
- // add field for list index
- IDBField idxField = table.addField(FEATUREMAP_IDX, DBType.INTEGER);
-
- // add field for FeatureMap tag (MetaID for Feature in CDO registry)
- IDBField tagField = table.addField(FEATUREMAP_TAG, idType, idLength);
-
- tagMap = CDOIDUtil.createMap();
- typeMappings = CDOIDUtil.createMap();
- columnNames = new ArrayList<String>();
+ IDBDatabase database = getMappingStrategy().getStore().getDatabase();
+ table = database.getSchema().getTable(tableName);
+ if (table == null)
+ {
+ table = database.getSchemaTransaction().getWorkingCopy().addTable(tableName);
+ table.addField(FEATUREMAP_REVISION_ID, idType, idLength);
+ table.addField(LIST_REVISION_BRANCH, DBType.INTEGER);
+ table.addField(FEATUREMAP_VERSION_ADDED, DBType.INTEGER);
+ table.addField(FEATUREMAP_VERSION_REMOVED, DBType.INTEGER);
+ table.addField(FEATUREMAP_IDX, DBType.INTEGER);
+ table.addField(FEATUREMAP_TAG, idType, idLength);
+
+ tagMap = CDOIDUtil.createMap();
+ typeMappings = CDOIDUtil.createMap();
+ columnNames = new ArrayList<String>();
+
+ initTypeColumns(true);
+
+ table.addIndex(Type.NON_UNIQUE, FEATUREMAP_REVISION_ID);
+ table.addIndex(Type.NON_UNIQUE, LIST_REVISION_BRANCH);
+ table.addIndex(Type.NON_UNIQUE, FEATUREMAP_VERSION_ADDED);
+ table.addIndex(Type.NON_UNIQUE, FEATUREMAP_VERSION_REMOVED);
+ table.addIndex(Type.NON_UNIQUE, FEATUREMAP_IDX);
+ table.addIndex(Type.NON_UNIQUE, FEATUREMAP_TAG);
+ }
+ else
+ {
+ initTypeColumns(false);
+ }
+ }
- // create columns for all DBTypes
+ private void initTypeColumns(boolean create)
+ {
for (DBType type : getDBTypes())
{
String column = FEATUREMAP_VALUE + "_" + type.name();
- table.addField(column, type);
+ if (create)
+ {
+ table.addField(column, type);
+ }
+
columnNames.add(column);
}
-
- table.addIndex(Type.NON_UNIQUE, idField);
- table.addIndex(Type.NON_UNIQUE, branchField);
- table.addIndex(Type.NON_UNIQUE, versionAddedField);
- table.addIndex(Type.NON_UNIQUE, versionRemovedField);
- table.addIndex(Type.NON_UNIQUE, idxField);
- table.addIndex(Type.NON_UNIQUE, tagField);
- }
-
- public Collection<IDBTable> getDBTables()
- {
- return Arrays.asList(table);
}
private void initSQLStrings()
@@ -361,6 +364,11 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
sqlClearList = builder.toString();
}
+ public Collection<IDBTable> getDBTables()
+ {
+ return Collections.singleton(table);
+ }
+
protected List<DBType> getDBTypes()
{
return dbTypes;
@@ -511,18 +519,6 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
}
}
- private void addFeature(CDOID tag)
- {
- EStructuralFeature modelFeature = getFeatureByTag(tag);
-
- ITypeMapping typeMapping = getMappingStrategy().createValueMapping(modelFeature);
- String column = FEATUREMAP_VALUE + "_" + typeMapping.getDBType(); //$NON-NLS-1$
-
- tagMap.put(tag, column);
- typeMapping.setDBField(table, column);
- typeMappings.put(tag, typeMapping);
- }
-
public final void readChunks(IDBStoreChunkReader chunkReader, List<Chunk> chunks, String where)
{
CDORevision revision = chunkReader.getRevision();
@@ -758,6 +754,18 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
return typeMapping;
}
+ private void addFeature(CDOID tag)
+ {
+ EStructuralFeature modelFeature = getFeatureByTag(tag);
+
+ ITypeMapping typeMapping = getMappingStrategy().createValueMapping(modelFeature);
+ String column = FEATUREMAP_VALUE + "_" + typeMapping.getDBType(); //$NON-NLS-1$
+
+ tagMap.put(tag, column);
+ typeMapping.setDBField(table, column);
+ typeMappings.put(tag, typeMapping);
+ }
+
/**
* @param metaID
* @return the column name where the values are stored
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMapping.java
index 99302d1841..18fd444567 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMapping.java
@@ -15,8 +15,8 @@ package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal;
import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
+import org.eclipse.emf.cdo.server.db.IIDHandler;
import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
@@ -24,12 +24,14 @@ import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import java.sql.PreparedStatement;
import java.sql.SQLException;
+import java.util.List;
/**
* This is a list-table mapping for audit mode. It has ID and version columns and no delta support.
@@ -40,8 +42,6 @@ import java.sql.SQLException;
*/
public class BranchingListTableMapping extends AbstractListTableMapping
{
- private FieldInfo[] keyFields;
-
private String sqlClear;
public BranchingListTableMapping(IMappingStrategy mappingStrategy, EClass eClass, EStructuralFeature feature)
@@ -52,10 +52,12 @@ public class BranchingListTableMapping extends AbstractListTableMapping
private void initSQLStrings()
{
+ IDBTable table = getTable();
+
// ----------- clear list -------------------------
StringBuilder builder = new StringBuilder();
builder.append("DELETE FROM "); //$NON-NLS-1$
- builder.append(getTable());
+ builder.append(table);
builder.append(" WHERE "); //$NON-NLS-1$
builder.append(LIST_REVISION_ID);
builder.append("=? AND "); //$NON-NLS-1$
@@ -67,24 +69,17 @@ public class BranchingListTableMapping extends AbstractListTableMapping
}
@Override
- protected FieldInfo[] getKeyFields()
+ protected void addKeyFields(List<FieldInfo> list)
{
- if (keyFields == null)
- {
- IDBStore store = getMappingStrategy().getStore();
-
- keyFields = new FieldInfo[] {
- new FieldInfo(LIST_REVISION_ID, store.getIDHandler().getDBType(), store.getIDColumnLength()),
- new FieldInfo(LIST_REVISION_BRANCH, DBType.INTEGER), new FieldInfo(LIST_REVISION_VERSION, DBType.INTEGER) };
- }
-
- return keyFields;
+ list.add(new FieldInfo(LIST_REVISION_BRANCH, DBType.INTEGER));
+ list.add(new FieldInfo(LIST_REVISION_VERSION, DBType.INTEGER));
}
@Override
protected void setKeyFields(PreparedStatement stmt, CDORevision revision) throws SQLException
{
- getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 1, revision.getID());
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ idHandler.setCDOID(stmt, 1, revision.getID());
stmt.setInt(2, revision.getBranch().getID());
stmt.setInt(3, revision.getVersion());
}
@@ -97,13 +92,14 @@ public class BranchingListTableMapping extends AbstractListTableMapping
@Override
public void rawDeleted(IDBStoreAccessor accessor, CDOID id, CDOBranch branch, int version)
{
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
IPreparedStatementCache statementCache = accessor.getStatementCache();
PreparedStatement stmt = null;
try
{
stmt = statementCache.getPreparedStatement(sqlClear, ReuseProbability.HIGH);
- getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 1, id);
+ idHandler.setCDOID(stmt, 1, id);
stmt.setInt(2, branch.getID());
stmt.setInt(3, version);
DBUtil.update(stmt, false);
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMappingWithRanges.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMappingWithRanges.java
index a165c0a120..a029ae0ebe 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMappingWithRanges.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMappingWithRanges.java
@@ -50,7 +50,7 @@ import org.eclipse.emf.cdo.spi.server.InternalRepository;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
-import org.eclipse.net4j.db.ddl.IDBField;
+import org.eclipse.net4j.db.IDBDatabase;
import org.eclipse.net4j.db.ddl.IDBIndex.Type;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.ImplementationError;
@@ -67,8 +67,8 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -129,34 +129,39 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
private void initTable()
{
+ String tableName = getMappingStrategy().getTableName(getContainingClass(), getFeature());
+ typeMapping = getMappingStrategy().createValueMapping(getFeature());
+
IDBStore store = getMappingStrategy().getStore();
DBType idType = store.getIDHandler().getDBType();
int idLength = store.getIDColumnLength();
- String tableName = getMappingStrategy().getTableName(getContainingClass(), getFeature());
- table = store.getDBSchema().addTable(tableName);
-
- IDBField[] dbFields = new IDBField[5];
- dbFields[0] = table.addField(LIST_REVISION_ID, idType, idLength, true);
- dbFields[1] = table.addField(LIST_REVISION_BRANCH, DBType.INTEGER, true);
- dbFields[2] = table.addField(LIST_REVISION_VERSION_ADDED, DBType.INTEGER);
- dbFields[3] = table.addField(LIST_REVISION_VERSION_REMOVED, DBType.INTEGER);
- dbFields[4] = table.addField(LIST_IDX, DBType.INTEGER, true);
-
- // add field for value
- typeMapping = getMappingStrategy().createValueMapping(getFeature());
- typeMapping.createDBField(table, LIST_VALUE);
-
- // add table indexes
- for (IDBField dbField : dbFields)
+ IDBDatabase database = getMappingStrategy().getStore().getDatabase();
+ table = database.getSchema().getTable(tableName);
+ if (table == null)
+ {
+ table = database.getSchemaTransaction().getWorkingCopy().addTable(tableName);
+ table.addField(LIST_REVISION_ID, idType, idLength, true);
+ table.addField(LIST_REVISION_BRANCH, DBType.INTEGER, true);
+ table.addField(LIST_REVISION_VERSION_ADDED, DBType.INTEGER);
+ table.addField(LIST_REVISION_VERSION_REMOVED, DBType.INTEGER);
+ table.addField(LIST_IDX, DBType.INTEGER, true);
+
+ // TODO think about indexes
+ table.addIndex(Type.NON_UNIQUE, LIST_REVISION_ID, LIST_REVISION_BRANCH, LIST_REVISION_VERSION_ADDED,
+ LIST_REVISION_VERSION_REMOVED, LIST_IDX);
+
+ typeMapping.createDBField(table, LIST_VALUE);
+ }
+ else
{
- table.addIndex(Type.NON_UNIQUE, dbField);
+ typeMapping.setDBField(table, LIST_VALUE);
}
}
public Collection<IDBTable> getDBTables()
{
- return Arrays.asList(table);
+ return Collections.singleton(table);
}
private void initSQLStrings()
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/FieldInfo.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/FieldInfo.java
index edd4bdff04..f8ccd32dd7 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/FieldInfo.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/FieldInfo.java
@@ -22,20 +22,20 @@ public final class FieldInfo
{
private final String name;
- private final DBType dbType;
+ private final DBType type;
private final int precision;
- public FieldInfo(String name, DBType dbType, int precision)
+ public FieldInfo(String name, DBType type, int precision)
{
this.name = name;
- this.dbType = dbType;
+ this.type = type;
this.precision = precision;
}
- public FieldInfo(String name, DBType dbType)
+ public FieldInfo(String name, DBType type)
{
- this(name, dbType, IDBField.DEFAULT);
+ this(name, type, IDBField.DEFAULT);
}
public String getName()
@@ -43,13 +43,19 @@ public final class FieldInfo
return name;
}
- public DBType getDbType()
+ public DBType getType()
{
- return dbType;
+ return type;
}
public int getPrecision()
{
return precision;
}
+
+ @Override
+ public String toString()
+ {
+ return "FieldInfo[name=" + name + ", type=" + type + ", precision=" + precision + "]";
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java
index e67c9b6e84..763582bd94 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java
@@ -45,6 +45,7 @@ import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.util.ImplementationError;
import org.eclipse.net4j.util.om.monitor.OMMonitor;
import org.eclipse.net4j.util.om.monitor.OMMonitor.Async;
@@ -89,21 +90,16 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
};
- public HorizontalAuditClassMapping(AbstractHorizontalMappingStrategy mappingStrategy, EClass eClass, boolean create)
+ public HorizontalAuditClassMapping(AbstractHorizontalMappingStrategy mappingStrategy, EClass eClass)
{
- super(mappingStrategy, eClass, create);
-
+ super(mappingStrategy, eClass);
initSQLStrings();
}
private void initSQLStrings()
{
- Map<EStructuralFeature, String> unsettableFields = getUnsettableFields();
- Map<EStructuralFeature, String> listSizeFields = getListSizeFields();
-
// ----------- Select Revision ---------------------------
StringBuilder builder = new StringBuilder();
-
builder.append("SELECT "); //$NON-NLS-1$
builder.append(ATTRIBUTES_VERSION);
builder.append(", "); //$NON-NLS-1$
@@ -116,68 +112,38 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
builder.append(ATTRIBUTES_CONTAINER);
builder.append(", "); //$NON-NLS-1$
builder.append(ATTRIBUTES_FEATURE);
-
- for (ITypeMapping singleMapping : getValueMappings())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(singleMapping.getField());
- }
-
- if (unsettableFields != null)
- {
- for (String fieldName : unsettableFields.values())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(fieldName);
- }
- }
-
- if (listSizeFields != null)
- {
- for (String fieldName : listSizeFields.values())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(fieldName);
- }
- }
-
+ appendTypeMappingNames(builder, getValueMappings());
+ appendFieldNames(builder, getUnsettableFields());
+ appendFieldNames(builder, getListSizeFields());
builder.append(" FROM "); //$NON-NLS-1$
builder.append(getTable());
builder.append(" WHERE "); //$NON-NLS-1$
builder.append(ATTRIBUTES_ID);
builder.append("=? AND ("); //$NON-NLS-1$
-
String sqlSelectAttributesPrefix = builder.toString();
-
builder.append(ATTRIBUTES_REVISED);
builder.append("=0)"); //$NON-NLS-1$
-
sqlSelectCurrentAttributes = builder.toString();
builder = new StringBuilder(sqlSelectAttributesPrefix);
-
builder.append(ATTRIBUTES_CREATED);
builder.append("<=? AND ("); //$NON-NLS-1$
builder.append(ATTRIBUTES_REVISED);
builder.append("=0 OR "); //$NON-NLS-1$
builder.append(ATTRIBUTES_REVISED);
builder.append(">=?))"); //$NON-NLS-1$
-
sqlSelectAttributesByTime = builder.toString();
builder = new StringBuilder(sqlSelectAttributesPrefix);
-
builder.append("ABS(");
builder.append(ATTRIBUTES_VERSION);
builder.append(")=?)"); //$NON-NLS-1$
-
sqlSelectAttributesByVersion = builder.toString();
// ----------- Insert Attributes -------------------------
builder = new StringBuilder();
builder.append("INSERT INTO "); //$NON-NLS-1$
builder.append(getTable());
-
builder.append("("); //$NON-NLS-1$
builder.append(ATTRIBUTES_ID);
builder.append(", "); //$NON-NLS-1$
@@ -192,54 +158,13 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
builder.append(ATTRIBUTES_CONTAINER);
builder.append(", "); //$NON-NLS-1$
builder.append(ATTRIBUTES_FEATURE);
-
- for (ITypeMapping singleMapping : getValueMappings())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(singleMapping.getField());
- }
-
- if (unsettableFields != null)
- {
- for (String fieldName : unsettableFields.values())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(fieldName);
- }
- }
-
- if (listSizeFields != null)
- {
- for (String fieldName : listSizeFields.values())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(fieldName);
- }
- }
-
+ appendTypeMappingNames(builder, getValueMappings());
+ appendFieldNames(builder, getUnsettableFields());
+ appendFieldNames(builder, getListSizeFields());
builder.append(") VALUES (?, ?, ?, ?, ?, ?, ?"); //$NON-NLS-1$
-
- for (int i = 0; i < getValueMappings().size(); i++)
- {
- builder.append(", ?"); //$NON-NLS-1$
- }
-
- if (unsettableFields != null)
- {
- for (int i = 0; i < unsettableFields.size(); i++)
- {
- builder.append(", ?"); //$NON-NLS-1$
- }
- }
-
- if (listSizeFields != null)
- {
- for (int i = 0; i < listSizeFields.size(); i++)
- {
- builder.append(", ?"); //$NON-NLS-1$
- }
- }
-
+ appendTypeMappingParameters(builder, getValueMappings());
+ appendFieldParameters(builder, getUnsettableFields());
+ appendFieldParameters(builder, getListSizeFields());
builder.append(")"); //$NON-NLS-1$
sqlInsertAttributes = builder.toString();
@@ -491,7 +416,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
mapping.setValueFromRevision(stmt, column++, revision);
}
- Map<EStructuralFeature, String> listSizeFields = getListSizeFields();
+ Map<EStructuralFeature, IDBField> listSizeFields = getListSizeFields();
if (listSizeFields != null)
{
// isSetCol now points to the first listTableSize-column
@@ -551,7 +476,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
mapping.setDefaultValue(stmt, column++);
}
- Map<EStructuralFeature, String> listSizeFields = getListSizeFields();
+ Map<EStructuralFeature, IDBField> listSizeFields = getListSizeFields();
if (listSizeFields != null)
{
// list size columns begin after isSet-columns
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategy.java
index dac8e1d441..bdcc90e5c5 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategy.java
@@ -43,9 +43,9 @@ public class HorizontalAuditMappingStrategy extends AbstractHorizontalMappingStr
}
@Override
- protected IClassMapping doCreateClassMapping(EClass eClass, boolean create)
+ protected IClassMapping doCreateClassMapping(EClass eClass)
{
- return new HorizontalAuditClassMapping(this, eClass, create);
+ return new HorizontalAuditClassMapping(this, eClass);
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategyWithRanges.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategyWithRanges.java
index 06e7c375c3..a599d1a15b 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategyWithRanges.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategyWithRanges.java
@@ -35,9 +35,9 @@ public class HorizontalAuditMappingStrategyWithRanges extends HorizontalAuditMap
}
@Override
- protected IClassMapping doCreateClassMapping(EClass eClass, boolean create)
+ protected IClassMapping doCreateClassMapping(EClass eClass)
{
- return new HorizontalAuditClassMapping(this, eClass, create);
+ return new HorizontalAuditClassMapping(this, eClass);
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java
index 0a2794b640..858509363c 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java
@@ -200,28 +200,22 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
}
};
- public HorizontalBranchingClassMapping(AbstractHorizontalMappingStrategy mappingStrategy, EClass eClass,
- boolean create)
+ public HorizontalBranchingClassMapping(AbstractHorizontalMappingStrategy mappingStrategy, EClass eClass)
{
- super(mappingStrategy, eClass, create);
-
+ super(mappingStrategy, eClass);
initSQLStrings();
}
@Override
- protected IDBField addBranchingField(IDBTable table)
+ protected IDBField addBranchField(IDBTable table)
{
return table.addField(ATTRIBUTES_BRANCH, DBType.INTEGER, true);
}
private void initSQLStrings()
{
- Map<EStructuralFeature, String> unsettableFields = getUnsettableFields();
- Map<EStructuralFeature, String> listSizeFields = getListSizeFields();
-
// ----------- Select Revision ---------------------------
StringBuilder builder = new StringBuilder();
-
builder.append("SELECT "); //$NON-NLS-1$
builder.append(ATTRIBUTES_VERSION);
builder.append(", "); //$NON-NLS-1$
@@ -234,31 +228,9 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
builder.append(ATTRIBUTES_CONTAINER);
builder.append(", "); //$NON-NLS-1$
builder.append(ATTRIBUTES_FEATURE);
-
- for (ITypeMapping singleMapping : getValueMappings())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(singleMapping.getField());
- }
-
- if (unsettableFields != null)
- {
- for (String fieldName : unsettableFields.values())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(fieldName);
- }
- }
-
- if (listSizeFields != null)
- {
- for (String fieldName : listSizeFields.values())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(fieldName);
- }
- }
-
+ appendTypeMappingNames(builder, getValueMappings());
+ appendFieldNames(builder, getUnsettableFields());
+ appendFieldNames(builder, getListSizeFields());
builder.append(" FROM "); //$NON-NLS-1$
builder.append(getTable());
builder.append(" WHERE "); //$NON-NLS-1$
@@ -267,36 +239,29 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
builder.append(ATTRIBUTES_BRANCH);
builder.append("=? AND ("); //$NON-NLS-1$
String sqlSelectAttributesPrefix = builder.toString();
-
builder.append(ATTRIBUTES_REVISED);
builder.append("=0)"); //$NON-NLS-1$
-
sqlSelectCurrentAttributes = builder.toString();
builder = new StringBuilder(sqlSelectAttributesPrefix);
-
builder.append(ATTRIBUTES_CREATED);
builder.append("<=? AND ("); //$NON-NLS-1$
builder.append(ATTRIBUTES_REVISED);
builder.append("=0 OR "); //$NON-NLS-1$
builder.append(ATTRIBUTES_REVISED);
builder.append(">=?))"); //$NON-NLS-1$
-
sqlSelectAttributesByTime = builder.toString();
builder = new StringBuilder(sqlSelectAttributesPrefix);
-
builder.append("ABS("); //$NON-NLS-1$
builder.append(ATTRIBUTES_VERSION);
builder.append(")=?)"); //$NON-NLS-1$
-
sqlSelectAttributesByVersion = builder.toString();
// ----------- Insert Attributes -------------------------
builder = new StringBuilder();
builder.append("INSERT INTO "); //$NON-NLS-1$
builder.append(getTable());
-
builder.append("("); //$NON-NLS-1$
builder.append(ATTRIBUTES_ID);
builder.append(", "); //$NON-NLS-1$
@@ -313,54 +278,13 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
builder.append(ATTRIBUTES_CONTAINER);
builder.append(", "); //$NON-NLS-1$
builder.append(ATTRIBUTES_FEATURE);
-
- for (ITypeMapping singleMapping : getValueMappings())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(singleMapping.getField());
- }
-
- if (unsettableFields != null)
- {
- for (String fieldName : unsettableFields.values())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(fieldName);
- }
- }
-
- if (listSizeFields != null)
- {
- for (String fieldName : listSizeFields.values())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(fieldName);
- }
- }
-
+ appendTypeMappingNames(builder, getValueMappings());
+ appendFieldNames(builder, getUnsettableFields());
+ appendFieldNames(builder, getListSizeFields());
builder.append(") VALUES (?, ?, ?, ?, ?, ?, ?, ?"); //$NON-NLS-1$
-
- for (int i = 0; i < getValueMappings().size(); i++)
- {
- builder.append(", ?"); //$NON-NLS-1$
- }
-
- if (unsettableFields != null)
- {
- for (int i = 0; i < unsettableFields.size(); i++)
- {
- builder.append(", ?"); //$NON-NLS-1$
- }
- }
-
- if (listSizeFields != null)
- {
- for (int i = 0; i < listSizeFields.size(); i++)
- {
- builder.append(", ?"); //$NON-NLS-1$
- }
- }
-
+ appendTypeMappingParameters(builder, getValueMappings());
+ appendFieldParameters(builder, getUnsettableFields());
+ appendFieldParameters(builder, getListSizeFields());
builder.append(")"); //$NON-NLS-1$
sqlInsertAttributes = builder.toString();
@@ -647,7 +571,7 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
mapping.setValueFromRevision(stmt, column++, revision);
}
- Map<EStructuralFeature, String> listSizeFields = getListSizeFields();
+ Map<EStructuralFeature, IDBField> listSizeFields = getListSizeFields();
if (listSizeFields != null)
{
// isSetCol now points to the first listTableSize-column
@@ -707,7 +631,7 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
mapping.setDefaultValue(stmt, column++);
}
- Map<EStructuralFeature, String> listSizeFields = getListSizeFields();
+ Map<EStructuralFeature, IDBField> listSizeFields = getListSizeFields();
if (listSizeFields != null)
{
// list size columns begin after isSet-columns
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategy.java
index 987ba07229..de8ef13795 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategy.java
@@ -56,9 +56,9 @@ public class HorizontalBranchingMappingStrategy extends AbstractHorizontalMappin
}
@Override
- protected IClassMapping doCreateClassMapping(EClass eClass, boolean create)
+ protected IClassMapping doCreateClassMapping(EClass eClass)
{
- return new HorizontalBranchingClassMapping(this, eClass, create);
+ return new HorizontalBranchingClassMapping(this, eClass);
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategyWithRanges.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategyWithRanges.java
index 92864344c0..d32d36e355 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategyWithRanges.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategyWithRanges.java
@@ -64,9 +64,9 @@ public class HorizontalBranchingMappingStrategyWithRanges extends HorizontalBran
}
@Override
- protected IClassMapping doCreateClassMapping(EClass eClass, boolean create)
+ protected IClassMapping doCreateClassMapping(EClass eClass)
{
- return new HorizontalBranchingClassMapping(this, eClass, create);
+ return new HorizontalBranchingClassMapping(this, eClass);
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java
index 23c7e359ea..c6548b4d6b 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java
@@ -43,6 +43,7 @@ import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.util.ImplementationError;
import org.eclipse.net4j.util.collection.Pair;
import org.eclipse.net4j.util.om.monitor.OMMonitor;
@@ -89,21 +90,16 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
};
- public HorizontalNonAuditClassMapping(AbstractHorizontalMappingStrategy mappingStrategy, EClass eClass, boolean create)
+ public HorizontalNonAuditClassMapping(AbstractHorizontalMappingStrategy mappingStrategy, EClass eClass)
{
- super(mappingStrategy, eClass, create);
-
+ super(mappingStrategy, eClass);
initSQLStrings();
}
private void initSQLStrings()
{
- Map<EStructuralFeature, String> unsettableFields = getUnsettableFields();
- Map<EStructuralFeature, String> listSizeFields = getListSizeFields();
-
// ----------- Select Revision ---------------------------
StringBuilder builder = new StringBuilder();
-
builder.append("SELECT "); //$NON-NLS-1$
builder.append(ATTRIBUTES_VERSION);
builder.append(", "); //$NON-NLS-1$
@@ -116,44 +112,20 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
builder.append(ATTRIBUTES_CONTAINER);
builder.append(", "); //$NON-NLS-1$
builder.append(ATTRIBUTES_FEATURE);
-
- for (ITypeMapping singleMapping : getValueMappings())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(singleMapping.getField());
- }
-
- if (unsettableFields != null)
- {
- for (String fieldName : unsettableFields.values())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(fieldName);
- }
- }
-
- if (listSizeFields != null)
- {
- for (String fieldName : listSizeFields.values())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(fieldName);
- }
- }
-
+ appendTypeMappingNames(builder, getValueMappings());
+ appendFieldNames(builder, getUnsettableFields());
+ appendFieldNames(builder, getListSizeFields());
builder.append(" FROM "); //$NON-NLS-1$
builder.append(getTable());
builder.append(" WHERE "); //$NON-NLS-1$
builder.append(ATTRIBUTES_ID);
builder.append("=?"); //$NON-NLS-1$
-
sqlSelectCurrentAttributes = builder.toString();
// ----------- Insert Attributes -------------------------
builder = new StringBuilder();
builder.append("INSERT INTO "); //$NON-NLS-1$
builder.append(getTable());
-
builder.append("("); //$NON-NLS-1$
builder.append(ATTRIBUTES_ID);
builder.append(", "); //$NON-NLS-1$
@@ -168,53 +140,13 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
builder.append(ATTRIBUTES_CONTAINER);
builder.append(", "); //$NON-NLS-1$
builder.append(ATTRIBUTES_FEATURE);
-
- for (ITypeMapping singleMapping : getValueMappings())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(singleMapping.getField());
- }
-
- if (unsettableFields != null)
- {
- for (String fieldName : unsettableFields.values())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(fieldName);
- }
- }
-
- if (listSizeFields != null)
- {
- for (String fieldName : listSizeFields.values())
- {
- builder.append(", "); //$NON-NLS-1$
- builder.append(fieldName);
- }
- }
-
+ appendTypeMappingNames(builder, getValueMappings());
+ appendFieldNames(builder, getUnsettableFields());
+ appendFieldNames(builder, getListSizeFields());
builder.append(") VALUES (?, ?, ?, ?, ?, ?, ?"); //$NON-NLS-1$
- for (int i = 0; i < getValueMappings().size(); i++)
- {
- builder.append(", ?"); //$NON-NLS-1$
- }
-
- if (unsettableFields != null)
- {
- for (int i = 0; i < unsettableFields.size(); i++)
- {
- builder.append(", ?"); //$NON-NLS-1$
- }
- }
-
- if (listSizeFields != null)
- {
- for (int i = 0; i < listSizeFields.size(); i++)
- {
- builder.append(", ?"); //$NON-NLS-1$
- }
- }
-
+ appendTypeMappingParameters(builder, getValueMappings());
+ appendFieldParameters(builder, getUnsettableFields());
+ appendFieldParameters(builder, getListSizeFields());
builder.append(")"); //$NON-NLS-1$
sqlInsertAttributes = builder.toString();
@@ -298,7 +230,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
mapping.setValueFromRevision(stmt, column++, revision);
}
- Map<EStructuralFeature, String> listSizeFields = getListSizeFields();
+ Map<EStructuralFeature, IDBField> listSizeFields = getListSizeFields();
if (listSizeFields != null)
{
// isSetCol now points to the first listTableSize-column
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditMappingStrategy.java
index d266958f27..7f6d87b1e3 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditMappingStrategy.java
@@ -63,9 +63,9 @@ public class HorizontalNonAuditMappingStrategy extends AbstractHorizontalMapping
}
@Override
- protected IClassMapping doCreateClassMapping(EClass eClass, boolean create)
+ protected IClassMapping doCreateClassMapping(EClass eClass)
{
- return new HorizontalNonAuditClassMapping(this, eClass, create);
+ return new HorizontalNonAuditClassMapping(this, eClass);
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/IMappingConstants.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/IMappingConstants.java
index 015ff5b9ff..a40ee2fde5 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/IMappingConstants.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/IMappingConstants.java
@@ -19,43 +19,43 @@ public interface IMappingConstants
* Field names of attribute tables
*/
- public static final String ATTRIBUTES_ID = "cdo_id"; //$NON-NLS-1$
+ public static final String ATTRIBUTES_ID = "CDO_ID"; //$NON-NLS-1$
- public static final String ATTRIBUTES_BRANCH = "cdo_branch"; //$NON-NLS-1$
+ public static final String ATTRIBUTES_BRANCH = "CDO_BRANCH"; //$NON-NLS-1$
- public static final String ATTRIBUTES_VERSION = "cdo_version"; //$NON-NLS-1$
+ public static final String ATTRIBUTES_VERSION = "CDO_VERSION"; //$NON-NLS-1$
- public static final String ATTRIBUTES_CLASS = "cdo_class"; //$NON-NLS-1$
+ public static final String ATTRIBUTES_CLASS = "CDO_CLASS"; //$NON-NLS-1$
- public static final String ATTRIBUTES_CREATED = "cdo_created"; //$NON-NLS-1$
+ public static final String ATTRIBUTES_CREATED = "CDO_CREATED"; //$NON-NLS-1$
- public static final String ATTRIBUTES_REVISED = "cdo_revised"; //$NON-NLS-1$
+ public static final String ATTRIBUTES_REVISED = "CDO_REVISED"; //$NON-NLS-1$
- public static final String ATTRIBUTES_RESOURCE = "cdo_resource"; //$NON-NLS-1$
+ public static final String ATTRIBUTES_RESOURCE = "CDO_RESOURCE"; //$NON-NLS-1$
- public static final String ATTRIBUTES_CONTAINER = "cdo_container"; //$NON-NLS-1$
+ public static final String ATTRIBUTES_CONTAINER = "CDO_CONTAINER"; //$NON-NLS-1$
- public static final String ATTRIBUTES_FEATURE = "cdo_feature"; //$NON-NLS-1$
+ public static final String ATTRIBUTES_FEATURE = "CDO_FEATURE"; //$NON-NLS-1$
/*
* Field names of list tables
*/
- public static final String LIST_FEATURE = "cdo_feature"; //$NON-NLS-1$
+ public static final String LIST_FEATURE = "CDO_FEATURE"; //$NON-NLS-1$
- public static final String LIST_REVISION_ID = "cdo_source"; //$NON-NLS-1$
+ public static final String LIST_REVISION_ID = "CDO_SOURCE"; //$NON-NLS-1$
- public static final String LIST_REVISION_VERSION = "cdo_version"; //$NON-NLS-1$
+ public static final String LIST_REVISION_VERSION = "CDO_VERSION"; //$NON-NLS-1$
- public static final String LIST_REVISION_VERSION_ADDED = "cdo_version_added"; //$NON-NLS-1$
+ public static final String LIST_REVISION_VERSION_ADDED = "CDO_VERSION_ADDED"; //$NON-NLS-1$
- public static final String LIST_REVISION_VERSION_REMOVED = "cdo_version_removed"; //$NON-NLS-1$
+ public static final String LIST_REVISION_VERSION_REMOVED = "CDO_VERSION_REMOVED"; //$NON-NLS-1$
- public static final String LIST_REVISION_BRANCH = "cdo_branch"; //$NON-NLS-1$
+ public static final String LIST_REVISION_BRANCH = "CDO_BRANCH"; //$NON-NLS-1$
- public static final String LIST_IDX = "cdo_idx"; //$NON-NLS-1$
+ public static final String LIST_IDX = "CDO_IDX"; //$NON-NLS-1$
- public static final String LIST_VALUE = "cdo_value"; //$NON-NLS-1$
+ public static final String LIST_VALUE = "CDO_VALUE"; //$NON-NLS-1$
/*
* Field names of featuremap tables
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditFeatureMapTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditFeatureMapTableMapping.java
index c6db29b53b..d64c2cc547 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditFeatureMapTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditFeatureMapTableMapping.java
@@ -26,7 +26,6 @@ import org.eclipse.emf.cdo.common.revision.delta.CDOMoveFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDORemoveFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOSetFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOUnsetFeatureDelta;
-import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IIDHandler;
import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
@@ -46,6 +45,7 @@ import org.eclipse.emf.ecore.util.FeatureMap;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Iterator;
+import java.util.List;
/**
* This is a featuremap-to-table mapping optimized for non-audit-mode. It doesn't care about version and has delta
@@ -56,8 +56,6 @@ import java.util.Iterator;
*/
public class NonAuditFeatureMapTableMapping extends AbstractFeatureMapTableMapping implements IListMappingDeltaSupport
{
- private FieldInfo[] keyFields;
-
private static final int TEMP_INDEX = -1;
private static final int UNBOUNDED_MOVE = -1;
@@ -191,17 +189,9 @@ public class NonAuditFeatureMapTableMapping extends AbstractFeatureMapTableMappi
}
@Override
- protected FieldInfo[] getKeyFields()
+ protected void addKeyFields(List<FieldInfo> list)
{
- if (keyFields == null)
- {
- IDBStore store = getMappingStrategy().getStore();
-
- keyFields = new FieldInfo[] { new FieldInfo(FEATUREMAP_REVISION_ID, store.getIDHandler().getDBType(),
- store.getIDColumnLength()) };
- }
-
- return keyFields;
+ // Do nothing
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java
index 19ae5f747d..34416d7e58 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java
@@ -26,7 +26,6 @@ import org.eclipse.emf.cdo.common.revision.delta.CDOMoveFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDORemoveFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOSetFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOUnsetFeatureDelta;
-import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IIDHandler;
import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
@@ -38,6 +37,7 @@ import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.om.trace.ContextTracer;
import org.eclipse.emf.ecore.EClass;
@@ -51,6 +51,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
+import java.util.List;
import java.util.ListIterator;
/**
@@ -63,8 +64,6 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, NonAuditListTableMapping.class);
- private FieldInfo[] keyFields;
-
private static final int UNBOUNDED_SHIFT = -1;
private String sqlClear;
@@ -91,21 +90,20 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
private void initSQLStrings()
{
+ IDBTable table = getTable();
+
// ----------- clear list -------------------------
StringBuilder builder = new StringBuilder();
-
builder.append("DELETE FROM "); //$NON-NLS-1$
- builder.append(getTable());
+ builder.append(table);
builder.append(" WHERE "); //$NON-NLS-1$
builder.append(LIST_REVISION_ID);
- builder.append("=? "); //$NON-NLS-1$
-
+ builder.append("=?"); //$NON-NLS-1$
sqlClear = builder.toString();
builder.append(" AND "); //$NON-NLS-1$
builder.append(LIST_IDX);
- builder.append("=? "); //$NON-NLS-1$
-
+ builder.append("=?"); //$NON-NLS-1$
sqlDeleteItem = builder.toString();
// ----------- update one item --------------------
@@ -119,7 +117,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
builder.append(LIST_REVISION_ID);
builder.append("=? AND "); //$NON-NLS-1$
builder.append(LIST_IDX);
- builder.append("=? "); //$NON-NLS-1$
+ builder.append("=?"); //$NON-NLS-1$
sqlUpdateValue = builder.toString();
// ----------- insert one item --------------------
@@ -132,7 +130,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
builder.append(LIST_IDX);
builder.append(", "); //$NON-NLS-1$
builder.append(LIST_VALUE);
- builder.append(") VALUES(?, ?, ?) "); //$NON-NLS-1$
+ builder.append(") VALUES(?, ?, ?)"); //$NON-NLS-1$
sqlInsertValue = builder.toString();
// ----------- update one item index --------------
@@ -146,7 +144,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
builder.append(LIST_REVISION_ID);
builder.append("=? AND "); //$NON-NLS-1$
builder.append(LIST_IDX);
- builder.append("=? "); //$NON-NLS-1$
+ builder.append("=?"); //$NON-NLS-1$
sqlUpdateIndex = builder.toString();
// ----------- mass update item indexes --------------
@@ -162,12 +160,12 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
builder.append("=? AND "); //$NON-NLS-1$
builder.append(LIST_IDX);
builder.append(" BETWEEN ? AND ?"); //$NON-NLS-1$
- // getMappingStrategy().getStore().getDBAdapter()
// needed because of MySQL:
- builder.append("/*! ORDER BY "); //$NON-NLS-1$ /
+ builder.append(" /*! ORDER BY "); //$NON-NLS-1$ /
builder.append(LIST_IDX);
sqlShiftDownIndex = builder.toString() + " */"; //$NON-NLS-1$
+
builder.append(" DESC"); //$NON-NLS-1$
sqlShiftUpIndex = builder.toString() + " */"; //$NON-NLS-1$
@@ -199,23 +197,16 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
@Override
- protected FieldInfo[] getKeyFields()
+ protected void addKeyFields(List<FieldInfo> list)
{
- if (keyFields == null)
- {
- IDBStore store = getMappingStrategy().getStore();
-
- keyFields = new FieldInfo[] { new FieldInfo(LIST_REVISION_ID, store.getIDHandler().getDBType(),
- store.getIDColumnLength()) };
- }
-
- return keyFields;
+ // Do nothing
}
@Override
protected void setKeyFields(PreparedStatement stmt, CDORevision revision) throws SQLException
{
- getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 1, revision.getID());
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ idHandler.setCDOID(stmt, 1, revision.getID());
}
public void objectDetached(IDBStoreAccessor accessor, CDOID id, long revised)
@@ -233,13 +224,14 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
*/
public void clearList(IDBStoreAccessor accessor, CDOID id)
{
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
IPreparedStatementCache statementCache = accessor.getStatementCache();
PreparedStatement stmt = null;
try
{
stmt = statementCache.getPreparedStatement(sqlClear, ReuseProbability.HIGH);
- getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 1, id);
+ idHandler.setCDOID(stmt, 1, id);
DBUtil.update(stmt, false);
}
catch (SQLException e)
@@ -260,6 +252,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
public int getCurrentIndexOffset(IDBStoreAccessor accessor, CDOID id)
{
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
IPreparedStatementCache statementCache = accessor.getStatementCache();
PreparedStatement stmt = null;
ResultSet rset = null;
@@ -267,7 +260,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
try
{
stmt = statementCache.getPreparedStatement(sqlReadCurrentIndexOffset, ReuseProbability.HIGH);
- getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 1, id);
+ idHandler.setCDOID(stmt, 1, id);
rset = stmt.executeQuery();
if (!rset.next())
{
@@ -928,7 +921,6 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
* to their proper position. This has to be done in two phases to avoid collisions, as the index has to be unique
* and shift up operations have to be executed in top to bottom order.
*/
-
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
int size = manipulations.size();
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/ObjectTypeTable.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/ObjectTypeTable.java
index 471e0a550a..4d09e4f466 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/ObjectTypeTable.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/ObjectTypeTable.java
@@ -28,9 +28,9 @@ import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBDatabase;
-import org.eclipse.net4j.db.IDBDatabase.RunnableWithTable;
-import org.eclipse.net4j.db.ddl.IDBField;
+import org.eclipse.net4j.db.IDBDatabase.RunnableWithSchema;
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.util.om.monitor.OMMonitor;
@@ -51,12 +51,6 @@ public class ObjectTypeTable extends AbstractObjectTypeMapper implements IMappin
{
private IDBTable table;
- private IDBField idField;
-
- private IDBField typeField;
-
- private IDBField timeField;
-
private String sqlDelete;
private String sqlInsert;
@@ -189,7 +183,7 @@ public class ObjectTypeTable extends AbstractObjectTypeMapper implements IMappin
try
{
stmt = connection.createStatement();
- resultSet = stmt.executeQuery("SELECT MAX(" + idField + ") FROM " + table);
+ resultSet = stmt.executeQuery("SELECT MAX(" + ATTRIBUTES_ID + ") FROM " + table);
if (resultSet.next())
{
@@ -212,7 +206,7 @@ public class ObjectTypeTable extends AbstractObjectTypeMapper implements IMappin
public void rawExport(Connection connection, CDODataOutput out, long fromCommitTime, long toCommitTime)
throws IOException
{
- String where = " WHERE " + timeField + " BETWEEN " + fromCommitTime + " AND " + toCommitTime;
+ String where = " WHERE " + ATTRIBUTES_CREATED + " BETWEEN " + fromCommitTime + " AND " + toCommitTime;
DBUtil.serializeTable(out, connection, table, null, where);
}
@@ -231,33 +225,25 @@ public class ObjectTypeTable extends AbstractObjectTypeMapper implements IMappin
final int idLength = store.getIDColumnLength();
IDBDatabase database = store.getDatabase();
-
- table = database.ensureTable(CDODBSchema.CDO_OBJECTS, new RunnableWithTable()
+ table = database.getSchema().getTable(CDODBSchema.CDO_OBJECTS);
+ if (table == null)
{
- public void run(IDBTable table)
+ database.updateSchema(new RunnableWithSchema()
{
- IDBField idField = table.addField(ATTRIBUTES_ID, idType, idLength, true);
- table.addField(ATTRIBUTES_CLASS, idType, idLength);
- table.addField(ATTRIBUTES_CREATED, DBType.BIGINT);
- table.addIndex(IDBIndex.Type.PRIMARY_KEY, idField);
- }
- });
-
- idField = table.getField(0);
- typeField = table.getField(1);
- timeField = table.getField(2);
-
- sqlSelect = "SELECT " + typeField + " FROM " + table + " WHERE " + idField + "=?"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- sqlInsert = "INSERT INTO " + table + "(" + idField + "," + typeField + "," + timeField + ") VALUES (?, ?, ?)";
- sqlDelete = "DELETE FROM " + table + " WHERE " + idField + "=?"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
+ public void run(IDBSchema schema)
+ {
+ table = schema.addTable(CDODBSchema.CDO_OBJECTS);
+ table.addField(ATTRIBUTES_ID, idType, idLength, true);
+ table.addField(ATTRIBUTES_CLASS, idType, idLength);
+ table.addField(ATTRIBUTES_CREATED, DBType.BIGINT);
+ table.addIndex(IDBIndex.Type.PRIMARY_KEY, ATTRIBUTES_ID);
+ }
+ });
+ }
- @Override
- protected void doDeactivate() throws Exception
- {
- table = null;
- idField = null;
- typeField = null;
- super.doDeactivate();
+ sqlSelect = "SELECT " + ATTRIBUTES_CLASS + " FROM " + table + " WHERE " + ATTRIBUTES_ID + "=?";
+ sqlInsert = "INSERT INTO " + table + "(" + ATTRIBUTES_ID + "," + ATTRIBUTES_CLASS + "," + ATTRIBUTES_CREATED
+ + ") VALUES (?, ?, ?)";
+ sqlDelete = "DELETE FROM " + table + " WHERE " + ATTRIBUTES_ID + "=?";
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java
index 2d88867838..9a0b2daaf3 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java
@@ -15,6 +15,7 @@ import org.eclipse.emf.cdo.tests.AbstractCDOTest;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.IDBDatabase;
import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.collection.Pair;
@@ -341,29 +342,33 @@ public class Net4jDBTest extends AbstractCDOTest
columns.add(column);
}
- private void prepareTable(String tableName)
+ private void prepareTable(final String tableName)
{
- IDBSchema schema = store.getDBSchema();
- IDBTable table = schema.addTable(tableName);
- int c = 0;
-
- for (Pair<DBType, Object> column : columns)
+ IDBDatabase database = store.getDatabase();
+ database.updateSchema(new IDBDatabase.RunnableWithSchema()
{
- switch (column.getElement1())
+
+ public void run(IDBSchema schema)
{
- case NUMERIC:
- case DECIMAL:
- BigDecimal value = (BigDecimal)column.getElement2();
- table.addField(FIELD_NAME + c++, column.getElement1(), value.precision(), value.scale());
- break;
-
- default:
- table.addField(FIELD_NAME + c++, column.getElement1());
- break;
+ IDBTable table = schema.addTable(tableName);
+ int c = 0;
+ for (Pair<DBType, Object> column : columns)
+ {
+ switch (column.getElement1())
+ {
+ case NUMERIC:
+ case DECIMAL:
+ BigDecimal value = (BigDecimal)column.getElement2();
+ table.addField(FIELD_NAME + c++, column.getElement1(), value.precision(), value.scale());
+ break;
+
+ default:
+ table.addField(FIELD_NAME + c++, column.getElement1());
+ break;
+ }
+ }
}
- }
-
- store.getDBAdapter().createTables(Arrays.asList(table), connection);
+ });
}
private void writeValues(String tableName) throws Exception
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AdapterManagerTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AdapterManagerTest.java
index 4ef1d57fea..df08a5757c 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AdapterManagerTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AdapterManagerTest.java
@@ -32,24 +32,19 @@ public class AdapterManagerTest extends AbstractCDOTest
{
public void testStrongReferencePolicy_NONE() throws Exception
{
- msg("Opening session");
final CDOSession session = openSession();
-
session.options().setPassiveUpdateEnabled(false);
// ************************************************************* //
- msg("Creating company");
Company companyA = getModel1Factory().createCompany();
TestAdapter testAdapter = new TestAdapter();
- msg("Opening transaction");
+
final CDOTransaction transaction = session.openTransaction();
transaction.options().setCacheReferenceType(ReferenceType.WEAK);
transaction.options().setStrongReferencePolicy(CDOAdapterPolicy.NONE);
transaction.createResource(getResourcePath("/resA")).getContents().add(companyA);
-
- msg("Committing");
transaction.commit();
final CDOID id = CDOUtil.getCDOObject(companyA).cdoID();
@@ -66,69 +61,58 @@ public class AdapterManagerTest extends AbstractCDOTest
public void testStrongReferencePolicy_ALL() throws Exception
{
- msg("Opening session");
final CDOSession session = openSession();
-
session.options().setPassiveUpdateEnabled(false);
// ************************************************************* //
- msg("Creating company");
Company companyA = getModel1Factory().createCompany();
- TestAdapter testAdapter = new TestAdapter();
- msg("Opening transaction");
+
CDOTransaction transaction = session.openTransaction();
transaction.options().setCacheReferenceType(ReferenceType.WEAK);
transaction.options().setStrongReferencePolicy(CDOAdapterPolicy.ALL);
transaction.createResource(getResourcePath("/resA")).getContents().add(companyA);
-
- msg("Committing");
transaction.commit();
CDOID id = CDOUtil.getCDOObject(companyA).cdoID();
+
+ TestAdapter testAdapter = new TestAdapter();
companyA.eAdapters().add(testAdapter);
- companyA = null;
+ companyA = null;
testAdapter.clearNotifications();
System.gc();
assertEquals(true, transaction.isObjectRegistered(id));
companyA = (Company)CDOUtil.getEObject(transaction.getObject(id));
-
assertEquals(0, testAdapter.getNotifications().length);
+
companyA.setCity("Ottawa");
assertEquals(1, testAdapter.getNotifications().length);
}
public void testStrongReferencePolicy_ALL_AttachObject() throws Exception
{
- msg("Opening session");
final CDOSession session = openSession();
-
session.options().setPassiveUpdateEnabled(false);
// ************************************************************* //
- msg("Creating company");
Company companyA = getModel1Factory().createCompany();
TestAdapter testAdapter = new TestAdapter();
-
companyA.eAdapters().add(testAdapter);
- msg("Opening transaction");
CDOTransaction transaction = session.openTransaction();
transaction.options().setCacheReferenceType(ReferenceType.WEAK);
transaction.options().setStrongReferencePolicy(CDOAdapterPolicy.ALL);
transaction.createResource(getResourcePath("/resA")).getContents().add(companyA);
- msg("Committing");
transaction.commit();
CDOID id = CDOUtil.getCDOObject(companyA).cdoID();
companyA = null;
-
testAdapter.clearNotifications();
System.gc();
@@ -143,29 +127,23 @@ public class AdapterManagerTest extends AbstractCDOTest
public void testStrongReferencePolicy_ALL_DetachObject() throws Exception
{
- msg("Opening session");
final CDOSession session = openSession();
-
session.options().setPassiveUpdateEnabled(false);
// ************************************************************* //
- msg("Creating company");
Company companyA = getModel1Factory().createCompany();
WeakReference<Company> weakCompanyA = new WeakReference<Company>(companyA);
TestAdapter testAdapter = new TestAdapter();
-
companyA.eAdapters().add(testAdapter);
- msg("Opening transaction");
CDOTransaction transaction = session.openTransaction();
transaction.options().setCacheReferenceType(ReferenceType.WEAK);
transaction.options().setStrongReferencePolicy(CDOAdapterPolicy.ALL);
transaction.createResource(getResourcePath("/resA")).getContents().add(companyA);
- msg("Committing");
transaction.commit();
CDOID id = CDOUtil.getCDOObject(companyA).cdoID();
companyA = null;
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RepositoryTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RepositoryTest.java
index 431cc0281b..9d8ce2f568 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RepositoryTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RepositoryTest.java
@@ -201,9 +201,9 @@ public class RepositoryTest extends AbstractCDOTest
resource.getContents().add(createCustomer("Martin"));
transaction.commit();
+
resource.getContents().add(createCustomer("Nick"));
transaction.commit();
- session.close();
}
public void testWriteAccessHandlers_WithServerCDOView() throws Exception
@@ -261,9 +261,9 @@ public class RepositoryTest extends AbstractCDOTest
resource.getContents().add(createCustomer("Martin"));
transaction.commit();
+
resource.getContents().add(createCustomer("Nick"));
transaction.commit();
- session.close();
}
public void testObjectWriteAccessHandler() throws Exception

Back to the top