Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2010-10-25 21:35:35 +0000
committerStefan Winkler2010-10-25 21:35:35 +0000
commit78d0e4e6117aae28a5edfcbdd5364782d309a8e9 (patch)
treeb779c8a4976c2286ba427e8ad469d72149673285
parent8ac0e8d84a25256c5c7c30e3cee48e5bd7b0fb89 (diff)
downloadcdo-78d0e4e6117aae28a5edfcbdd5364782d309a8e9.tar.gz
cdo-78d0e4e6117aae28a5edfcbdd5364782d309a8e9.tar.xz
cdo-78d0e4e6117aae28a5edfcbdd5364782d309a8e9.zip
Rangebased Mapping - Branching Step 2a
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractFeatureMapTableMapping.java107
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalClassMapping.java60
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractListTableMapping.java137
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMappingWithRanges.java94
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMappingWithRanges.java95
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMappingWithRanges.java99
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java42
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java45
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java273
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/CDO AllTests (H2 all).launch16
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2All.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Branching.java4
12 files changed, 362 insertions, 612 deletions
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 8ccc649b70..f0cbc82a1c 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
@@ -28,7 +28,6 @@ import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDOList;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.db.DBException;
@@ -93,8 +92,6 @@ public abstract class AbstractFeatureMapTableMapping extends BasicAbstractListTa
protected String sqlInsert;
- private String sqlGetListLastIndex;
-
private List<DBType> dbTypes;
public AbstractFeatureMapTableMapping(IMappingStrategy mappingStrategy, EClass eClass, EStructuralFeature feature)
@@ -208,31 +205,6 @@ public abstract class AbstractFeatureMapTableMapping extends BasicAbstractListTa
sqlOrderByIndex = " ORDER BY " + CDODBSchema.FEATUREMAP_IDX; //$NON-NLS-1$
- // ----------------- count list size --------------------------
-
- builder = new StringBuilder("SELECT max(");
- builder.append(CDODBSchema.FEATUREMAP_IDX);
- builder.append(") FROM ");
- builder.append(tableName);
- builder.append(" WHERE ");
-
- for (int i = 0; i < fields.length; i++)
- {
- builder.append(fields[i].getName());
- if (i + 1 < fields.length)
- {
- // more to come
- builder.append("=? AND ");
- }
- else
- {
- // last one
- builder.append("=? ");
- }
- }
-
- sqlGetListLastIndex = builder.toString();
-
// INSERT with dynamic field name
// TODO: Better: universal INSERT-Statement, because of stmt caching!
@@ -293,19 +265,10 @@ public abstract class AbstractFeatureMapTableMapping extends BasicAbstractListTa
public void readValues(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
{
MoveableList<Object> list = revision.getList(getFeature());
- int listSize = -1;
-
- if (listChunk != CDORevision.UNCHUNKED)
+ if (listChunk == 0 || list.size() == 0)
{
- listSize = getListLastIndex(accessor, revision);
- if (listSize == -1)
- {
- // list is empty - take shortcut
- return;
- }
-
- // subtract amount of items we are going to read now
- listSize -= listChunk;
+ // nothing to read take shortcut
+ return;
}
if (TRACER.isEnabled())
@@ -330,6 +293,8 @@ public abstract class AbstractFeatureMapTableMapping extends BasicAbstractListTa
}
resultSet = pstmt.executeQuery();
+ int currentIndex = 0;
+
while ((listChunk == CDORevision.UNCHUNKED || --listChunk >= 0) && resultSet.next())
{
Long tag = resultSet.getLong(1);
@@ -340,17 +305,7 @@ public abstract class AbstractFeatureMapTableMapping extends BasicAbstractListTa
TRACER.format("Read value for index {0} from result set: {1}", list.size(), value);
}
- list.add(CDORevisionUtil.createFeatureMapEntry(getFeatureByTag(tag), value));
- }
-
- while (listSize-- >= 0)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Adding UNINITIALIZED for index {0} ", list.size());
- }
-
- list.add(InternalCDOList.UNINITIALIZED);
+ list.set(currentIndex++, CDORevisionUtil.createFeatureMapEntry(getFeatureByTag(tag), value));
}
}
catch (SQLException ex)
@@ -382,56 +337,6 @@ public abstract class AbstractFeatureMapTableMapping extends BasicAbstractListTa
typeMappings.put(tag, typeMapping);
}
- /**
- * Return the last (maximum) list index. (euals to size-1)
- *
- * @param accessor
- * the accessor to use
- * @param revision
- * the revision to which the feature list belongs
- * @return the last index or <code>-1</code> if the list is empty.
- */
- private int getListLastIndex(IDBStoreAccessor accessor, InternalCDORevision revision)
- {
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement pstmt = null;
- ResultSet resultSet = null;
-
- try
- {
- pstmt = statementCache.getPreparedStatement(sqlGetListLastIndex, ReuseProbability.HIGH);
- setKeyFields(pstmt, revision);
-
- resultSet = pstmt.executeQuery();
- if (!resultSet.next())
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("No last index found -> list is empty. ");
- }
-
- return -1;
- }
-
- int result = resultSet.getInt(1);
- if (TRACER.isEnabled())
- {
- TRACER.trace("Read list last index = " + result);
- }
-
- return result;
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- finally
- {
- DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(pstmt);
- }
- }
-
public final void readChunks(IDBStoreChunkReader chunkReader, List<Chunk> chunks, String where)
{
if (TRACER.isEnabled())
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 cbd56da690..72bedc4485 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
@@ -20,6 +20,7 @@ import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.model.CDOModelUtil;
+import org.eclipse.emf.cdo.common.revision.CDOList;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
import org.eclipse.emf.cdo.common.revision.CDORevisionManager;
@@ -40,6 +41,7 @@ import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
import org.eclipse.emf.cdo.server.internal.db.DBStore;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
import org.eclipse.emf.cdo.spi.common.commit.CDOChangeSetSegment;
+import org.eclipse.emf.cdo.spi.common.revision.InternalCDOList;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.db.DBException;
@@ -57,6 +59,8 @@ import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.FeatureMapUtil;
+import org.eclipse.core.runtime.Assert;
+
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -87,6 +91,8 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping
private List<IListMapping> listMappings;
+ private Map<EStructuralFeature, String> listSizeFields;
+
private Map<EStructuralFeature, String> unsettableFields;
private String sqlSelectForHandle;
@@ -216,14 +222,20 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping
{
if (feature.isMany())
{
+ IListMapping mapping = null;
if (FeatureMapUtil.isFeatureMap(feature))
{
- listMappings.add(mappingStrategy.createFeatureMapMapping(eClass, feature));
+ mapping = mappingStrategy.createFeatureMapMapping(eClass, feature);
}
else
{
- listMappings.add(mappingStrategy.createListMapping(eClass, feature));
+ mapping = mappingStrategy.createListMapping(eClass, feature);
}
+
+ listMappings.add(mapping);
+
+ // add field for list sizes
+ createListSizeField(feature);
}
}
@@ -231,6 +243,22 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping
}
/**
+ * Create an integer field in the attribute tabel for the list size of the associated list mapping.
+ */
+ private void createListSizeField(EStructuralFeature feature)
+ {
+ if (listSizeFields == null)
+ {
+ listSizeFields = new LinkedHashMap<EStructuralFeature, String>();
+ }
+
+ String fieldName = mappingStrategy.getFieldName(feature);
+ table.addField(fieldName, DBType.INTEGER);
+
+ listSizeFields.put(feature, fieldName);
+ }
+
+ /**
* Read the revision's values from the DB.
*
* @return <code>true</code> if the revision has been read successfully.<br>
@@ -291,6 +319,29 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping
mapping.readValueToRevision(resultSet, revision);
}
+ if (listSizeFields != null)
+ {
+ for (Map.Entry<EStructuralFeature, String> listSizeEntry : listSizeFields.entrySet())
+ {
+ EStructuralFeature feature = listSizeEntry.getKey();
+ String fieldName = listSizeEntry.getValue();
+ int size = resultSet.getInt(fieldName);
+
+ // ensure the listSize (TODO: remove assertion)
+ CDOList list = revision.getList(feature, size);
+
+ for (int i = 0; i < size; i++)
+ {
+ list.add(InternalCDOList.UNINITIALIZED);
+ }
+
+ if (list.size() != size)
+ {
+ Assert.isTrue(false);
+ }
+ }
+ }
+
return true;
}
catch (SQLException ex)
@@ -336,6 +387,11 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping
return unsettableFields;
}
+ protected final Map<EStructuralFeature, String> getListSizeFields()
+ {
+ return listSizeFields;
+ }
+
public final List<ITypeMapping> getValueMappings()
{
return valueMappings;
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 b4bf2a6400..f24b0844d2 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
@@ -27,7 +27,6 @@ import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDOList;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.db.DBException;
@@ -78,8 +77,6 @@ public abstract class AbstractListTableMapping extends BasicAbstractListTableMap
private String sqlInsertEntry;
- private String sqlGetListLastIndex;
-
public AbstractListTableMapping(IMappingStrategy mappingStrategy, EClass eClass, EStructuralFeature feature)
{
super(mappingStrategy, eClass, feature);
@@ -154,31 +151,6 @@ public abstract class AbstractListTableMapping extends BasicAbstractListTableMap
sqlOrderByIndex = " ORDER BY " + CDODBSchema.LIST_IDX; //$NON-NLS-1$
- // ----------------- count list size --------------------------
-
- builder = new StringBuilder("SELECT MAX("); //$NON-NLS-1$
- builder.append(CDODBSchema.LIST_IDX);
- builder.append(") FROM "); //$NON-NLS-1$
- builder.append(tableName);
- builder.append(" WHERE "); //$NON-NLS-1$
-
- for (int i = 0; i < fields.length; i++)
- {
- builder.append(fields[i].getName());
- if (i + 1 < fields.length)
- {
- // more to come
- builder.append("=? AND "); //$NON-NLS-1$
- }
- else
- {
- // last one
- builder.append("=? "); //$NON-NLS-1$
- }
- }
-
- sqlGetListLastIndex = builder.toString();
-
// ----------------- INSERT - reference entry -----------------
builder = new StringBuilder("INSERT INTO "); //$NON-NLS-1$
builder.append(tableName);
@@ -216,19 +188,11 @@ public abstract class AbstractListTableMapping extends BasicAbstractListTableMap
public void readValues(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
{
MoveableList<Object> list = revision.getList(getFeature());
- int listSize = -1;
- if (listChunk != CDORevision.UNCHUNKED)
+ if (listChunk == 0 || list.size() == 0)
{
- listSize = getListLastIndex(accessor, revision);
- if (listSize == -1)
- {
- // list is empty - take shortcut
- return;
- }
-
- // subtract amount of items we are going to read now
- listSize -= listChunk;
+ // nothing to read take shortcut
+ return;
}
if (TRACER.isEnabled())
@@ -258,6 +222,8 @@ public abstract class AbstractListTableMapping extends BasicAbstractListTableMap
}
resultSet = pstmt.executeQuery();
+
+ int currentIndex = 0;
while ((listChunk == CDORevision.UNCHUNKED || --listChunk >= 0) && resultSet.next())
{
Object value = typeMapping.readValue(resultSet);
@@ -266,17 +232,7 @@ public abstract class AbstractListTableMapping extends BasicAbstractListTableMap
TRACER.format("Read value for index {0} from result set: {1}", list.size(), value); //$NON-NLS-1$
}
- list.add(value);
- }
-
- while (listSize-- >= 0)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Adding UNINITIALIZED for index {0} ", list.size()); //$NON-NLS-1$
- }
-
- list.add(InternalCDOList.UNINITIALIZED);
+ list.set(currentIndex++, value);
}
}
catch (SQLException ex)
@@ -296,71 +252,6 @@ public abstract class AbstractListTableMapping extends BasicAbstractListTableMap
}
}
- /**
- * Return the last (maximum) list index. (euals to size-1)
- *
- * @param accessor
- * the accessor to use
- * @param revision
- * the revision to which the feature list belongs
- * @return the last index or <code>-1</code> if the list is empty.
- */
- private int getListLastIndex(IDBStoreAccessor accessor, InternalCDORevision revision)
- {
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement pstmt = null;
- ResultSet resultSet = null;
-
- try
- {
- pstmt = statementCache.getPreparedStatement(sqlGetListLastIndex, ReuseProbability.HIGH);
- setKeyFields(pstmt, revision);
-
- if (TRACER.isEnabled())
- {
- TRACER.trace(pstmt.toString());
- }
-
- resultSet = pstmt.executeQuery();
- if (!resultSet.next())
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("No last index found -> list is empty. "); //$NON-NLS-1$
- }
-
- return -1;
- }
-
- int result = resultSet.getInt(1);
- if (resultSet.wasNull())
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("No last index found -> list is empty. NULL "); //$NON-NLS-1$
- }
-
- return -1;
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.trace("Read list last index = " + result); //$NON-NLS-1$
- }
-
- return result;
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- finally
- {
- DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(pstmt);
- }
- }
-
public final void readChunks(IDBStoreChunkReader chunkReader, List<Chunk> chunks, String where)
{
if (TRACER.isEnabled())
@@ -494,7 +385,7 @@ public abstract class AbstractListTableMapping extends BasicAbstractListTableMap
{
String tableName = getTable().getName();
String listJoin = getMappingStrategy().getListJoin("a_t", "l_t");
-
+
StringBuilder builder = new StringBuilder();
builder.append("SELECT l_t."); //$NON-NLS-1$
builder.append(CDODBSchema.LIST_REVISION_ID);
@@ -514,10 +405,10 @@ public abstract class AbstractListTableMapping extends BasicAbstractListTableMap
builder.append(" IN "); //$NON-NLS-1$
builder.append(idString);
String sql = builder.toString();
-
+
ResultSet resultSet = null;
Statement stmt = null;
-
+
try
{
stmt = accessor.getConnection().createStatement();
@@ -525,7 +416,7 @@ public abstract class AbstractListTableMapping extends BasicAbstractListTableMap
{
TRACER.format("Query XRefs (list): {0}", sql);
}
-
+
resultSet = stmt.executeQuery(sql);
while (resultSet.next())
{
@@ -534,24 +425,24 @@ public abstract class AbstractListTableMapping extends BasicAbstractListTableMap
idLong = resultSet.getLong(2);
CDOID targetId = CDOIDUtil.createLong(idLong);
int idx = resultSet.getInt(3);
-
+
boolean more = context.addXRef(targetId, srcId, (EReference)getFeature(), idx);
if (TRACER.isEnabled())
{
TRACER.format(" add XRef to context: src={0}, tgt={1}, idx={2}", srcId, targetId, idx);
}
-
+
if (!more)
{
if (TRACER.isEnabled())
{
TRACER.format(" result limit reached. Ignoring further results.");
}
-
+
return false;
}
}
-
+
return true;
}
catch (SQLException ex)
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 f2ffa29ced..5444a03358 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
@@ -45,7 +45,6 @@ import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDOList;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.db.DBException;
@@ -124,8 +123,6 @@ public class AuditFeatureMapTableMappingWithRanges extends BasicAbstractListTabl
protected String sqlInsert;
- private String sqlGetListLastIndex;
-
private List<DBType> dbTypes;
private String sqlRemoveEntry;
@@ -235,21 +232,6 @@ public class AuditFeatureMapTableMappingWithRanges extends BasicAbstractListTabl
sqlOrderByIndex = " ORDER BY " + CDODBSchema.FEATUREMAP_IDX; //$NON-NLS-1$
- // ----------------- count list size --------------------------
-
- builder = new StringBuilder("SELECT count(1) FROM "); //$NON-NLS-1$
- builder.append(tableName);
- builder.append(" WHERE "); //$NON-NLS-1$
- builder.append(CDODBSchema.FEATUREMAP_REVISION_ID);
- builder.append("=? AND "); //$NON-NLS-1$
- builder.append(CDODBSchema.FEATUREMAP_VERSION_ADDED);
- builder.append("<=? AND ("); //$NON-NLS-1$
- builder.append(CDODBSchema.FEATUREMAP_VERSION_REMOVED);
- builder.append(" IS NULL OR "); //$NON-NLS-1$
- builder.append(CDODBSchema.FEATUREMAP_VERSION_REMOVED);
- builder.append(">?)"); //$NON-NLS-1$
- sqlGetListLastIndex = builder.toString();
-
// ----------------- INSERT - prefix -----------------
builder = new StringBuilder("INSERT INTO "); //$NON-NLS-1$
builder.append(tableName);
@@ -403,19 +385,11 @@ public class AuditFeatureMapTableMappingWithRanges extends BasicAbstractListTabl
public void readValues(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
{
MoveableList<Object> list = revision.getList(getFeature());
- int listSize = -1;
- if (listChunk != CDORevision.UNCHUNKED)
+ if (listChunk == 0 || list.size() == 0)
{
- listSize = getListLastIndex(accessor, revision);
- if (listSize == -1)
- {
- // list is empty - take shortcut
- return;
- }
-
- // subtract amount of items we are going to read now
- listSize -= listChunk;
+ // nothing to read take shortcut
+ return;
}
if (TRACER.isEnabled())
@@ -444,6 +418,8 @@ public class AuditFeatureMapTableMappingWithRanges extends BasicAbstractListTabl
}
resultSet = pstmt.executeQuery();
+
+ int currentIndex = 0;
while ((listChunk == CDORevision.UNCHUNKED || --listChunk >= 0) && resultSet.next())
{
Long tag = resultSet.getLong(1);
@@ -454,17 +430,7 @@ public class AuditFeatureMapTableMappingWithRanges extends BasicAbstractListTabl
TRACER.format("Read value for index {0} from result set: {1}", list.size(), value); //$NON-NLS-1$
}
- list.add(CDORevisionUtil.createFeatureMapEntry(getFeatureByTag(tag), value));
- }
-
- while (listSize-- >= 0)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Adding UNINITIALIZED for index {0} ", list.size()); //$NON-NLS-1$
- }
-
- list.add(InternalCDOList.UNINITIALIZED);
+ list.set(currentIndex++, CDORevisionUtil.createFeatureMapEntry(getFeatureByTag(tag), value));
}
}
catch (SQLException ex)
@@ -496,54 +462,6 @@ public class AuditFeatureMapTableMappingWithRanges extends BasicAbstractListTabl
typeMappings.put(tag, typeMapping);
}
- /**
- * Return the last (maximum) list index. (euals to size-1)
- *
- * @param accessor
- * the accessor to use
- * @param revision
- * the revision to which the feature list belongs
- * @return the last index or <code>-1</code> if the list is empty.
- */
- private int getListLastIndex(IDBStoreAccessor accessor, InternalCDORevision revision)
- {
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement pstmt = null;
- ResultSet resultSet = null;
-
- try
- {
- pstmt = statementCache.getPreparedStatement(sqlGetListLastIndex, ReuseProbability.HIGH);
-
- pstmt.setLong(1, CDOIDUtil.getLong(revision.getID()));
- pstmt.setInt(2, revision.getVersion());
- pstmt.setInt(3, revision.getVersion());
-
- resultSet = pstmt.executeQuery();
- if (!resultSet.next())
- {
- throw new DBException("Count expects exactly one result");
- }
-
- int result = resultSet.getInt(1) - 1;
- if (TRACER.isEnabled())
- {
- TRACER.trace("Read list last index = " + result); //$NON-NLS-1$
- }
-
- return result;
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- finally
- {
- DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(pstmt);
- }
- }
-
public final void readChunks(IDBStoreChunkReader chunkReader, List<Chunk> chunks, String where)
{
if (TRACER.isEnabled())
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 9b774df73d..cf823a81b5 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
@@ -42,7 +42,6 @@ import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDOList;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.db.DBException;
@@ -110,8 +109,6 @@ public class AuditListTableMappingWithRanges extends BasicAbstractListTableMappi
private String sqlGetValue;
- private String sqlGetListLastIndex;
-
private String sqlClearList;
private String sqlDeleteList;
@@ -172,20 +169,6 @@ public class AuditListTableMappingWithRanges extends BasicAbstractListTableMappi
sqlOrderByIndex = " ORDER BY " + CDODBSchema.LIST_IDX; //$NON-NLS-1$
- // ----------------- count list size --------------------------
- builder = new StringBuilder("SELECT count(1) FROM "); //$NON-NLS-1$
- builder.append(tableName);
- builder.append(" WHERE "); //$NON-NLS-1$
- builder.append(CDODBSchema.LIST_REVISION_ID);
- builder.append("=? AND "); //$NON-NLS-1$
- builder.append(CDODBSchema.LIST_REVISION_VERSION_ADDED);
- builder.append("<=? AND ("); //$NON-NLS-1$
- builder.append(CDODBSchema.LIST_REVISION_VERSION_REMOVED);
- builder.append(" IS NULL OR "); //$NON-NLS-1$
- builder.append(CDODBSchema.LIST_REVISION_VERSION_REMOVED);
- builder.append(">?)"); //$NON-NLS-1$
- sqlGetListLastIndex = builder.toString();
-
// ----------------- insert entry -----------------
builder = new StringBuilder("INSERT INTO "); //$NON-NLS-1$
builder.append(tableName);
@@ -296,19 +279,10 @@ public class AuditListTableMappingWithRanges extends BasicAbstractListTableMappi
public void readValues(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
{
MoveableList<Object> list = revision.getList(getFeature());
- int listSize = -1;
-
- if (listChunk != CDORevision.UNCHUNKED)
+ if (listChunk == 0 || list.size() == 0)
{
- listSize = getListLastIndex(accessor, revision.getID(), revision.getVersion());
- if (listSize == -1)
- {
- // list is empty - take shortcut
- return;
- }
-
- // subtract amount of items we are going to read now
- listSize -= listChunk;
+ // nothing to read take shortcut
+ return;
}
if (TRACER.isEnabled())
@@ -335,6 +309,8 @@ public class AuditListTableMappingWithRanges extends BasicAbstractListTableMappi
}
resultSet = pstmt.executeQuery();
+
+ int currentIndex = 0;
while ((listChunk == CDORevision.UNCHUNKED || --listChunk >= 0) && resultSet.next())
{
Object value = typeMapping.readValue(resultSet);
@@ -343,17 +319,7 @@ public class AuditListTableMappingWithRanges extends BasicAbstractListTableMappi
TRACER.format("Read value for index {0} from result set: {1}", list.size(), value); //$NON-NLS-1$
}
- list.add(value);
- }
-
- while (listSize-- >= 0)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Adding UNINITIALIZED for index {0} ", list.size()); //$NON-NLS-1$
- }
-
- list.add(InternalCDOList.UNINITIALIZED);
+ list.set(currentIndex++, value);
}
}
catch (SQLException ex)
@@ -373,55 +339,6 @@ public class AuditListTableMappingWithRanges extends BasicAbstractListTableMappi
}
}
- /**
- * Return the last (maximum) list index. (equals to size-1)
- *
- * @param accessor
- * the accessor to use
- * @param id
- * the CDOID of the revision to which the getFeature() list belongs
- * @param version
- * the revision to which the getFeature() list belongs
- * @return the last index or <code>-1</code> if the list is empty.
- */
- private int getListLastIndex(IDBStoreAccessor accessor, CDOID id, int version)
- {
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement pstmt = null;
- ResultSet resultSet = null;
-
- try
- {
- pstmt = statementCache.getPreparedStatement(sqlGetListLastIndex, ReuseProbability.HIGH);
- pstmt.setLong(1, CDOIDUtil.getLong(id));
- pstmt.setInt(2, version);
- pstmt.setInt(3, version);
-
- resultSet = pstmt.executeQuery();
- if (!resultSet.next())
- {
- throw new DBException("Count expects exactly one result");
- }
-
- int result = resultSet.getInt(1) - 1;
- if (TRACER.isEnabled())
- {
- TRACER.trace("Read list last index = " + result); //$NON-NLS-1$
- }
-
- return result;
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- finally
- {
- DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(pstmt);
- }
- }
-
public final void readChunks(IDBStoreChunkReader chunkReader, List<Chunk> chunks, String where)
{
if (TRACER.isEnabled())
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 7da6dc596b..fc6a6e6cf7 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
@@ -40,7 +40,6 @@ import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDOList;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.db.DBException;
@@ -111,8 +110,6 @@ public class BranchingListTableMappingWithRanges extends BasicAbstractListTableM
private String sqlGetValue;
- private String sqlGetListLastIndex;
-
private String sqlClearList;
private String sqlDeleteList;
@@ -178,22 +175,6 @@ public class BranchingListTableMappingWithRanges extends BasicAbstractListTableM
sqlOrderByIndex = " ORDER BY " + CDODBSchema.LIST_IDX; //$NON-NLS-1$
- // ----------------- count list size --------------------------
- builder = new StringBuilder("SELECT count(1) FROM "); //$NON-NLS-1$
- builder.append(tableName);
- builder.append(" WHERE "); //$NON-NLS-1$
- builder.append(CDODBSchema.LIST_REVISION_ID);
- builder.append("=? AND "); //$NON-NLS-1$
- builder.append(CDODBSchema.LIST_REVISION_BRANCH);
- builder.append("=? AND "); //$NON-NLS-1$
- builder.append(CDODBSchema.LIST_REVISION_VERSION_ADDED);
- builder.append("<=? AND ("); //$NON-NLS-1$
- builder.append(CDODBSchema.LIST_REVISION_VERSION_REMOVED);
- builder.append(" IS NULL OR "); //$NON-NLS-1$
- builder.append(CDODBSchema.LIST_REVISION_VERSION_REMOVED);
- builder.append(">?)"); //$NON-NLS-1$
- sqlGetListLastIndex = builder.toString();
-
// ----------------- insert entry -----------------
builder = new StringBuilder("INSERT INTO "); //$NON-NLS-1$
builder.append(tableName);
@@ -318,19 +299,11 @@ public class BranchingListTableMappingWithRanges extends BasicAbstractListTableM
public void readValues(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
{
MoveableList<Object> list = revision.getList(getFeature());
- int listSize = -1;
- if (listChunk != CDORevision.UNCHUNKED)
+ if (listChunk == 0 || list.size() == 0)
{
- listSize = getListLastIndex(accessor, revision.getID(), revision.getBranch().getID(), revision.getVersion());
- if (listSize == -1)
- {
- // list is empty - take shortcut
- return;
- }
-
- // subtract amount of items we are going to read now
- listSize -= listChunk;
+ // nothing to read take shortcut
+ return;
}
if (TRACER.isEnabled())
@@ -358,6 +331,8 @@ public class BranchingListTableMappingWithRanges extends BasicAbstractListTableM
}
resultSet = pstmt.executeQuery();
+
+ int currentIndex = 0;
while ((listChunk == CDORevision.UNCHUNKED || --listChunk >= 0) && resultSet.next())
{
Object value = typeMapping.readValue(resultSet);
@@ -366,17 +341,7 @@ public class BranchingListTableMappingWithRanges extends BasicAbstractListTableM
TRACER.format("Read value for index {0} from result set: {1}", list.size(), value); //$NON-NLS-1$
}
- list.add(value);
- }
-
- while (listSize-- >= 0)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Adding UNINITIALIZED for index {0} ", list.size()); //$NON-NLS-1$
- }
-
- list.add(InternalCDOList.UNINITIALIZED);
+ list.set(currentIndex++, value);
}
}
catch (SQLException ex)
@@ -396,58 +361,6 @@ public class BranchingListTableMappingWithRanges extends BasicAbstractListTableM
}
}
- /**
- * Return the last (maximum) list index. (equals to size-1)
- *
- * @param accessor
- * the accessor to use
- * @param id
- * the CDOID of the revision to which the getFeature() list belongs
- * @param id
- * the branch ID of the revision
- * @param version
- * the revision to which the getFeature() list belongs
- * @return the last index or <code>-1</code> if the list is empty.
- */
- private int getListLastIndex(IDBStoreAccessor accessor, CDOID id, int branchId, int version)
- {
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement pstmt = null;
- ResultSet resultSet = null;
-
- try
- {
- pstmt = statementCache.getPreparedStatement(sqlGetListLastIndex, ReuseProbability.HIGH);
- pstmt.setLong(1, CDOIDUtil.getLong(id));
- pstmt.setInt(2, branchId);
- pstmt.setInt(3, version);
- pstmt.setInt(4, version);
-
- resultSet = pstmt.executeQuery();
- if (!resultSet.next())
- {
- throw new DBException("Count expects exactly one result");
- }
-
- int result = resultSet.getInt(1) - 1;
- if (TRACER.isEnabled())
- {
- TRACER.trace("Read list last index = " + result); //$NON-NLS-1$
- }
-
- return result;
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- finally
- {
- DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(pstmt);
- }
- }
-
public final void readChunks(IDBStoreChunkReader chunkReader, List<Chunk> chunks, String where)
{
if (TRACER.isEnabled())
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 381f483cd1..ff4f763951 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
@@ -17,6 +17,7 @@ import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.common.revision.CDOList;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.delta.CDOAddFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOClearFeatureDelta;
@@ -96,6 +97,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
private void initSQLStrings()
{
Map<EStructuralFeature, String> unsettableFields = getUnsettableFields();
+ Map<EStructuralFeature, String> listSizeFields = getListSizeFields();
// ----------- Select Revision ---------------------------
StringBuilder builder = new StringBuilder();
@@ -128,6 +130,15 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
}
+ if (listSizeFields != null)
+ {
+ for (String fieldName : listSizeFields.values())
+ {
+ builder.append(", "); //$NON-NLS-1$
+ builder.append(fieldName);
+ }
+ }
+
builder.append(" FROM "); //$NON-NLS-1$
builder.append(getTable());
builder.append(" WHERE "); //$NON-NLS-1$
@@ -196,6 +207,15 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
}
+ if (listSizeFields != null)
+ {
+ for (String fieldName : listSizeFields.values())
+ {
+ builder.append(", "); //$NON-NLS-1$
+ builder.append(fieldName);
+ }
+ }
+
builder.append(") VALUES (?, ?, ?, ?, ?, ?, ?, ?"); //$NON-NLS-1$
for (int i = 0; i < getValueMappings().size(); i++)
@@ -211,6 +231,14 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
}
+ if (listSizeFields != null)
+ {
+ for (int i = 0; i < listSizeFields.size(); i++)
+ {
+ builder.append(", ?"); //$NON-NLS-1$
+ }
+ }
+
builder.append(")"); //$NON-NLS-1$
sqlInsertAttributes = builder.toString();
@@ -452,6 +480,19 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
mapping.setValueFromRevision(stmt, col++, revision);
}
+ Map<EStructuralFeature, String> listSizeFields = getListSizeFields();
+ if (listSizeFields != null)
+ {
+ // isSetCol now points to the first listTableSize-column
+ col = isSetCol;
+
+ for (EStructuralFeature feature : listSizeFields.keySet())
+ {
+ CDOList list = revision.getList(feature);
+ stmt.setInt(col++, list.size());
+ }
+ }
+
CDODBUtil.sqlUpdate(stmt, true);
}
catch (SQLException e)
@@ -670,6 +711,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
public void visit(CDOListFeatureDelta delta)
{
+ delta.apply(newRevision);
IListMappingDeltaSupport listMapping = (IListMappingDeltaSupport)getListMapping(delta.getFeature());
listMapping.processDelta(accessor, id, branchId, oldVersion, oldVersion + 1, created, delta);
}
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 5235e36c45..bedfd417ac 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
@@ -20,6 +20,7 @@ import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.model.CDOModelUtil;
+import org.eclipse.emf.cdo.common.revision.CDOList;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
import org.eclipse.emf.cdo.common.revision.CDORevisionManager;
@@ -111,8 +112,7 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
TRACER.format("FeatureDeltaWriter: old version: {0}, new version: {1}", oldVersion, oldVersion + 1); //$NON-NLS-1$
}
- InternalCDORevision originalRevision = (InternalCDORevision)accessor.getStore().getRepository()
- .getRevisionManager().getRevisionByVersion(id, delta, 0, true);
+ InternalCDORevision originalRevision = (InternalCDORevision)accessor.getTransaction().getRevision(id);
newRevision = originalRevision.copy();
@@ -158,6 +158,7 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
public void visit(CDOListFeatureDelta delta)
{
+ delta.apply(newRevision);
IListMappingDeltaSupport listMapping = (IListMappingDeltaSupport)getListMapping(delta.getFeature());
listMapping.processDelta(accessor, id, targetBranch.getID(), oldVersion, newVersion, created, delta);
}
@@ -216,6 +217,7 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
private void initSQLStrings()
{
Map<EStructuralFeature, String> unsettableFields = getUnsettableFields();
+ Map<EStructuralFeature, String> listSizeFields = getListSizeFields();
// ----------- Select Revision ---------------------------
StringBuilder builder = new StringBuilder();
@@ -248,6 +250,15 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
}
}
+ if (listSizeFields != null)
+ {
+ for (String fieldName : listSizeFields.values())
+ {
+ builder.append(", "); //$NON-NLS-1$
+ builder.append(fieldName);
+ }
+ }
+
builder.append(" FROM "); //$NON-NLS-1$
builder.append(getTable());
builder.append(" WHERE "); //$NON-NLS-1$
@@ -320,6 +331,15 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
}
}
+ if (listSizeFields != null)
+ {
+ for (String fieldName : listSizeFields.values())
+ {
+ builder.append(", "); //$NON-NLS-1$
+ builder.append(fieldName);
+ }
+ }
+
builder.append(") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?"); //$NON-NLS-1$
for (int i = 0; i < getValueMappings().size(); i++)
@@ -335,6 +355,14 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
}
}
+ if (listSizeFields != null)
+ {
+ for (int i = 0; i < listSizeFields.size(); i++)
+ {
+ builder.append(", ?"); //$NON-NLS-1$
+ }
+ }
+
builder.append(")"); //$NON-NLS-1$
sqlInsertAttributes = builder.toString();
@@ -607,6 +635,19 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
mapping.setValueFromRevision(stmt, col++, revision);
}
+ Map<EStructuralFeature, String> listSizeFields = getListSizeFields();
+ if (listSizeFields != null)
+ {
+ // isSetCol now points to the first listTableSize-column
+ col = isSetCol;
+
+ for (EStructuralFeature feature : listSizeFields.keySet())
+ {
+ CDOList list = revision.getList(feature);
+ stmt.setInt(col++, list.size());
+ }
+ }
+
CDODBUtil.sqlUpdate(stmt, true);
}
catch (SQLException e)
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 ea62e868fd..efe25dcf0f 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
@@ -16,6 +16,7 @@ import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.common.revision.CDOList;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.delta.CDOAddFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOClearFeatureDelta;
@@ -97,6 +98,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
private void initSQLStrings()
{
Map<EStructuralFeature, String> unsettableFields = getUnsettableFields();
+ Map<EStructuralFeature, String> listSizeFields = getListSizeFields();
// ----------- Select Revision ---------------------------
StringBuilder builder = new StringBuilder();
@@ -129,6 +131,15 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
}
+ if (listSizeFields != null)
+ {
+ for (String fieldName : listSizeFields.values())
+ {
+ builder.append(", "); //$NON-NLS-1$
+ builder.append(fieldName);
+ }
+ }
+
builder.append(" FROM "); //$NON-NLS-1$
builder.append(getTable());
builder.append(" WHERE "); //$NON-NLS-1$
@@ -174,6 +185,15 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
}
+ if (listSizeFields != null)
+ {
+ for (String fieldName : listSizeFields.values())
+ {
+ builder.append(", "); //$NON-NLS-1$
+ builder.append(fieldName);
+ }
+ }
+
builder.append(") VALUES (?, ?, "); //$NON-NLS-1$
builder.append("?, ?, ?, ?, ?, ?"); //$NON-NLS-1$
for (int i = 0; i < getValueMappings().size(); i++)
@@ -189,6 +209,14 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
}
+ if (listSizeFields != null)
+ {
+ for (int i = 0; i < listSizeFields.size(); i++)
+ {
+ builder.append(", ?"); //$NON-NLS-1$
+ }
+ }
+
builder.append(")"); //$NON-NLS-1$
sqlInsertAttributes = builder.toString();
@@ -268,6 +296,19 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
mapping.setValueFromRevision(stmt, col++, revision);
}
+ Map<EStructuralFeature, String> listSizeFields = getListSizeFields();
+ if (listSizeFields != null)
+ {
+ // isSetCol now points to the first listTableSize-column
+ col = isSetCol;
+
+ for (EStructuralFeature feature : listSizeFields.keySet())
+ {
+ CDOList list = revision.getList(feature);
+ stmt.setInt(col++, list.size());
+ }
+ }
+
CDODBUtil.sqlUpdate(stmt, true);
}
catch (SQLException e)
@@ -466,6 +507,8 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
private List<Pair<ITypeMapping, Object>> attributeChanges;
+ private List<Pair<EStructuralFeature, Integer>> listSizeChanges;
+
private int newContainingFeatureID;
private CDOID newContainerID;
@@ -474,42 +517,45 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
private int branchId;
+ private int newVersion;
+
+ /*
+ * this is a temporary copy of the revision to track list size changes...
+ */
+ private InternalCDORevision tempRevision;
+
public FeatureDeltaWriter()
{
attributeChanges = new ArrayList<Pair<ITypeMapping, Object>>();
+ listSizeChanges = new ArrayList<Pair<EStructuralFeature, Integer>>();
}
protected void reset()
{
attributeChanges.clear();
+ listSizeChanges.clear();
updateContainer = false;
}
public void process(IDBStoreAccessor a, CDORevisionDelta d, long c)
{
// set context
-
- reset();
id = d.getID();
+
branchId = d.getBranch().getID();
oldVersion = d.getVersion();
- int newVersion = oldVersion + 1;
+ newVersion = oldVersion + 1;
created = c;
accessor = a;
+ tempRevision = (InternalCDORevision)accessor.getTransaction().getRevision(id).copy();
+
// process revision delta tree
d.accept(this);
- // update attributes
- if (updateContainer)
- {
- updateAttributes(accessor, id, newVersion, created, newContainerID, newContainingFeatureID, newResourceID,
- attributeChanges);
- }
- else
- {
- updateAttributes(accessor, id, newVersion, created, attributeChanges);
- }
+ updateAttributes();
+ // clean up
+ reset();
}
public void visit(CDOMoveFeatureDelta delta)
@@ -543,8 +589,19 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
public void visit(CDOListFeatureDelta delta)
{
- IListMappingDeltaSupport listMapping = (IListMappingDeltaSupport)getListMapping(delta.getFeature());
+ EStructuralFeature feature = delta.getFeature();
+
+ IListMappingDeltaSupport listMapping = (IListMappingDeltaSupport)getListMapping(feature);
listMapping.processDelta(accessor, id, branchId, oldVersion, oldVersion + 1, created, delta);
+
+ int oldSize = tempRevision.getList(feature).size();
+ delta.apply(tempRevision);
+ int newSize = tempRevision.getList(feature).size();
+
+ if (oldSize != newSize)
+ {
+ listSizeChanges.add(new Pair<EStructuralFeature, Integer>(feature, newSize));
+ }
}
public void visit(CDOClearFeatureDelta delta)
@@ -569,130 +626,122 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
newResourceID = delta.getResourceID();
updateContainer = true;
}
- }
-
- public void updateAttributes(IDBStoreAccessor accessor, CDOID id, int newVersion, long created, CDOID newContainerId,
- int newContainingFeatureId, CDOID newResourceId, List<Pair<ITypeMapping, Object>> attributeChanges)
- {
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
- try
+ private void updateAttributes()
{
- int col = 1;
- stmt = statementCache.getPreparedStatement(buildUpdateStatement(attributeChanges, true), ReuseProbability.MEDIUM);
- stmt.setInt(col++, newVersion);
- stmt.setLong(col++, created);
- stmt.setLong(col++, CDODBUtil.convertCDOIDToLong(getExternalReferenceManager(), accessor, newResourceId, created));
- stmt.setLong(col++,
- CDODBUtil.convertCDOIDToLong(getExternalReferenceManager(), accessor, newContainerId, created));
- stmt.setInt(col++, newContainingFeatureId);
+ IPreparedStatementCache statementCache = accessor.getStatementCache();
+ PreparedStatement stmt = null;
- col = setUpdateAttributeValues(attributeChanges, stmt, col);
+ try
+ {
+ int col = 1;
- stmt.setLong(col++, CDOIDUtil.getLong(id));
+ stmt = statementCache.getPreparedStatement(buildUpdateStatement(), ReuseProbability.MEDIUM);
+ stmt.setInt(col++, newVersion);
+ stmt.setLong(col++, created);
+ if (updateContainer)
+ {
+ stmt.setLong(col++,
+ CDODBUtil.convertCDOIDToLong(getExternalReferenceManager(), accessor, newResourceID, created));
+ stmt.setLong(col++,
+ CDODBUtil.convertCDOIDToLong(getExternalReferenceManager(), accessor, newContainerID, created));
+ stmt.setInt(col++, newContainingFeatureID);
+ }
- CDODBUtil.sqlUpdate(stmt, true);
- }
- catch (SQLException e)
- {
- throw new DBException(e);
- }
- finally
- {
- statementCache.releasePreparedStatement(stmt);
- }
- }
+ col = setUpdateAttributeValues(attributeChanges, stmt, col);
+ col = setUpdateListSizeChanges(listSizeChanges, stmt, col);
- private int setUpdateAttributeValues(List<Pair<ITypeMapping, Object>> attributeChanges, PreparedStatement stmt,
- int col) throws SQLException
- {
- for (Pair<ITypeMapping, Object> change : attributeChanges)
- {
- ITypeMapping typeMapping = change.getElement1();
- Object value = change.getElement2();
- if (typeMapping.getFeature().isUnsettable())
+ stmt.setLong(col++, CDOIDUtil.getLong(id));
+
+ CDODBUtil.sqlUpdate(stmt, true);
+ }
+ catch (SQLException e)
{
- // feature is unsettable
- if (value == null)
- {
- // feature is unset
- typeMapping.setDefaultValue(stmt, col++);
- stmt.setBoolean(col++, false);
- }
- else
- {
- // feature is set
- typeMapping.setValue(stmt, col++, value);
- stmt.setBoolean(col++, true);
- }
+ throw new DBException(e);
}
- else
+ finally
{
- typeMapping.setValue(stmt, col++, change.getElement2());
+ statementCache.releasePreparedStatement(stmt);
}
}
- return col;
- }
-
- public void updateAttributes(IDBStoreAccessor accessor, CDOID id, int newVersion, long created,
- List<Pair<ITypeMapping, Object>> attributeChanges)
- {
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
-
- try
+ private String buildUpdateStatement()
{
- stmt = statementCache
- .getPreparedStatement(buildUpdateStatement(attributeChanges, false), ReuseProbability.MEDIUM);
-
- int col = 1;
+ StringBuilder builder = new StringBuilder(sqlUpdatePrefix);
+ if (updateContainer)
+ {
+ builder.append(sqlUpdateContainerPart);
+ }
- stmt.setInt(col++, newVersion);
- stmt.setLong(col++, created);
+ for (Pair<ITypeMapping, Object> change : attributeChanges)
+ {
+ builder.append(", "); //$NON-NLS-1$
+ ITypeMapping typeMapping = change.getElement1();
+ builder.append(typeMapping.getField());
+ builder.append("=?"); //$NON-NLS-1$
- col = setUpdateAttributeValues(attributeChanges, stmt, col);
+ if (typeMapping.getFeature().isUnsettable())
+ {
+ builder.append(", "); //$NON-NLS-1$
+ builder.append(getUnsettableFields().get(typeMapping.getFeature()));
+ builder.append("=?"); //$NON-NLS-1$
+ }
+ }
- stmt.setLong(col++, CDOIDUtil.getLong(id));
+ for (Pair<EStructuralFeature, Integer> change : listSizeChanges)
+ {
+ builder.append(", "); //$NON-NLS-1$
+ EStructuralFeature feature = change.getElement1();
+ builder.append(getListSizeFields().get(feature));
+ builder.append("=?"); //$NON-NLS-1$
+ }
- CDODBUtil.sqlUpdate(stmt, true);
- }
- catch (SQLException e)
- {
- throw new DBException(e);
+ builder.append(sqlUpdateAffix);
+ return builder.toString();
}
- finally
- {
- statementCache.releasePreparedStatement(stmt);
- }
- }
- private String buildUpdateStatement(List<Pair<ITypeMapping, Object>> attributeChanges, boolean withContainment)
- {
- StringBuilder builder = new StringBuilder(sqlUpdatePrefix);
- if (withContainment)
+ private int setUpdateAttributeValues(List<Pair<ITypeMapping, Object>> attributeChanges, PreparedStatement stmt,
+ int col) throws SQLException
{
- builder.append(sqlUpdateContainerPart);
+ for (Pair<ITypeMapping, Object> change : attributeChanges)
+ {
+ ITypeMapping typeMapping = change.getElement1();
+ Object value = change.getElement2();
+ if (typeMapping.getFeature().isUnsettable())
+ {
+ // feature is unsettable
+ if (value == null)
+ {
+ // feature is unset
+ typeMapping.setDefaultValue(stmt, col++);
+ stmt.setBoolean(col++, false);
+ }
+ else
+ {
+ // feature is set
+ typeMapping.setValue(stmt, col++, value);
+ stmt.setBoolean(col++, true);
+ }
+ }
+ else
+ {
+ typeMapping.setValue(stmt, col++, change.getElement2());
+ }
+ }
+
+ return col;
}
- for (Pair<ITypeMapping, Object> change : attributeChanges)
+ private int setUpdateListSizeChanges(List<Pair<EStructuralFeature, Integer>> attributeChanges,
+ PreparedStatement stmt, int col) throws SQLException
{
- builder.append(", "); //$NON-NLS-1$
- ITypeMapping typeMapping = change.getElement1();
- builder.append(typeMapping.getField());
- builder.append("=?"); //$NON-NLS-1$
-
- if (typeMapping.getFeature().isUnsettable())
+ for (Pair<EStructuralFeature, Integer> change : listSizeChanges)
{
- builder.append(", "); //$NON-NLS-1$
- builder.append(getUnsettableFields().get(typeMapping.getFeature()));
- builder.append("=?"); //$NON-NLS-1$
+ stmt.setInt(col++, change.getElement2());
}
- }
- builder.append(sqlUpdateAffix);
- return builder.toString();
+ return col;
+ }
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/CDO AllTests (H2 all).launch b/plugins/org.eclipse.emf.cdo.tests.db/CDO AllTests (H2 all).launch
new file mode 100644
index 0000000000..3095e1825d
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests.db/CDO AllTests (H2 all).launch
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2All.java"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="1"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
+<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
+<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
+<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.emf.cdo.tests.db.AllTestsDBH2All"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.emf.cdo.tests.db"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms256m&#13;&#10;-Xmx1536m"/>
+</launchConfiguration>
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2All.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2All.java
index 70c6af9bc8..93ef4687b8 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2All.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2All.java
@@ -28,8 +28,10 @@ public class AllTestsDBH2All extends DBConfigs
protected void initConfigSuites(TestSuite parent)
{
addScenario(parent, COMBINED, AllTestsDBH2NonAudit.H2NonAudit.ReusableFolder.INSTANCE, JVM, NATIVE);
+ addScenario(parent, COMBINED, AllTestsDBH2.H2.ReusableFolder.INSTANCE, JVM, NATIVE);
addScenario(parent, COMBINED, AllTestsDBH2.H2.ReusableFolder.RANGE_INSTANCE, JVM, NATIVE);
addScenario(parent, COMBINED, AllTestsDBH2Branching.H2Branching.ReusableFolder.INSTANCE, JVM, NATIVE);
+ addScenario(parent, COMBINED, AllTestsDBH2Branching.H2Branching.ReusableFolder.RANGE_INSTANCE, JVM, NATIVE);
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Branching.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Branching.java
index 890dc4daa7..d80076ca25 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Branching.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Branching.java
@@ -51,8 +51,8 @@ public class AllTestsDBH2Branching extends DBConfigs
@Override
protected void initConfigSuites(TestSuite parent)
{
- // addScenario(parent, COMBINED, H2Branching.ReusableFolder.INSTANCE, JVM, NATIVE);
- addScenario(parent, COMBINED, H2Branching.ReusableFolder.RANGE_INSTANCE, JVM, NATIVE);
+ addScenario(parent, COMBINED, H2Branching.ReusableFolder.INSTANCE, JVM, NATIVE);
+ // addScenario(parent, COMBINED, H2Branching.ReusableFolder.RANGE_INSTANCE, JVM, NATIVE);
}
@Override

Back to the top