diff options
author | Eike Stepper | 2018-01-04 08:10:10 +0000 |
---|---|---|
committer | Eike Stepper | 2018-01-04 08:10:10 +0000 |
commit | 70610a4427a792688d7fc11d39fc74afd494ae46 (patch) | |
tree | efbafe6e1e4426d23881dada630d91010a7d5457 /plugins/org.eclipse.emf.cdo.server.db | |
parent | dded79ebbc8b2c01c768b9791f5529d24072ab5e (diff) | |
download | cdo-70610a4427a792688d7fc11d39fc74afd494ae46.tar.gz cdo-70610a4427a792688d7fc11d39fc74afd494ae46.tar.xz cdo-70610a4427a792688d7fc11d39fc74afd494ae46.zip |
[527002] ClassCastException in mapping strategy
https://bugs.eclipse.org/bugs/show_bug.cgi?id=527002
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.db')
2 files changed, 38 insertions, 27 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractBasicListTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractBasicListTableMapping.java index 266089cada..bbb8163fc6 100644 --- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractBasicListTableMapping.java +++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractBasicListTableMapping.java @@ -165,8 +165,10 @@ public abstract class AbstractBasicListTableMapping implements IListMapping3, IM listDelta.accept(this); } - boolean zeroBasedIndex = ((HorizontalNonAuditMappingStrategy)accessor.getStore().getMappingStrategy()).shallForceZeroBasedIndex(); - if (!zeroBasedIndex) + // boolean zeroBasedIndex = + // ((HorizontalNonAuditMappingStrategy)accessor.getStore().getMappingStrategy()).shallForceZeroBasedIndex(); + // if (!zeroBasedIndex) + if (!isZeroBasedIndex()) { if (TRACER.isEnabled()) { @@ -336,6 +338,11 @@ public abstract class AbstractBasicListTableMapping implements IListMapping3, IM throw new UnsupportedOperationException("Should never be called"); } + protected boolean isZeroBasedIndex() + { + return false; + } + protected List<Manipulation> createManipulations(CDOID id, List<CDOFeatureDelta> listChanges, int oldListSize) { List<Manipulation> manipulations = new ArrayList<Manipulation>(oldListSize); @@ -406,12 +413,12 @@ public abstract class AbstractBasicListTableMapping implements IListMapping3, IM private void optimizeListIndexes() { /* - * This is an optimization which reduces the amount of modifications on the database to maintain list indexes. For - * the optimization, we let go of the assumption that indexes are zero-based. Instead, we work with an offset at - * the database level which can change with every change to the list (e.g. if the second element is removed from a - * list with 1000 elements, instead of shifting down indexes 2 to 1000 by 1, we shift up index 0 by 1 and have now - * a list with indexes starting at 1 instead of 0. This optimization is applied by modifying the list of - * Manipulations, which can be seen as the database modification plan. + * This is an optimization which reduces the amount of modifications on the database to maintain list indexes. For the + * optimization, we let go of the assumption that indexes are zero-based. Instead, we work with an offset at the + * database level which can change with every change to the list (e.g. if the second element is removed from a list with + * 1000 elements, instead of shifting down indexes 2 to 1000 by 1, we shift up index 0 by 1 and have now a list with + * indexes starting at 1 instead of 0. This optimization is applied by modifying the list of Manipulations, which can be + * seen as the database modification plan. */ // First, get the current offset. @@ -575,8 +582,8 @@ public abstract class AbstractBasicListTableMapping implements IListMapping3, IM if (manipulation.is(MOVE)) { /* - * Step 2: MOVE all elements e (by e.srcIndex) which have e.is(MOVE) to tmpIndex (-1, -2, -3, -4, ...) and - * store tmpIndex in e.tempIndex + * Step 2: MOVE all elements e (by e.srcIndex) which have e.is(MOVE) to tmpIndex (-1, -2, -3, -4, ...) and store + * tmpIndex in e.tempIndex */ manipulation.tmpIndex = getNextTmpIndex(); dbMove(idHandler, manipulation.srcIndex, manipulation.tmpIndex, manipulation.srcIndex); @@ -596,8 +603,8 @@ public abstract class AbstractBasicListTableMapping implements IListMapping3, IM if (manipulation.is(MOVE)) { /* - * Step 4: MOVE all elements e have e.is(MOVE) from e.tempIdx to e.dstIndex (because we have moved them - * before, moveStmt is always initialized + * Step 4: MOVE all elements e have e.is(MOVE) from e.tempIdx to e.dstIndex (because we have moved them before, moveStmt + * is always initialized */ dbMove(idHandler, manipulation.tmpIndex, manipulation.dstIndex, manipulation.srcIndex); @@ -644,16 +651,16 @@ public abstract class AbstractBasicListTableMapping implements IListMapping3, IM protected void writeShifts(IIDHandler idHandler) throws SQLException { /* - * Step 3: shift all elements which have to be shifted up or down because of add, remove or move of other elements - * 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. + * Step 3: shift all elements which have to be shifted up or down because of add, remove or move of other elements 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. */ LinkedList<Shift> shiftOperations = new LinkedList<Shift>(); /* - * If a necessary shift is detected (source and destination indices differ), firstIndex is set to the current - * index and currentOffset is set to the offset of the shift operation. When a new offset is detected or the range - * is interrupted, we record the range and start a new one if needed. + * If a necessary shift is detected (source and destination indices differ), firstIndex is set to the current index and + * currentOffset is set to the offset of the shift operation. When a new offset is detected or the range is interrupted, + * we record the range and start a new one if needed. */ int rangeStartIndex = NO_INDEX; int rangeOffset = 0; @@ -663,16 +670,15 @@ public abstract class AbstractBasicListTableMapping implements IListMapping3, IM for (Manipulation manipulation : manipulations) { /* - * Shift applies only to elements which are not moved, inserted or deleted (i.e. only plain SET and NONE are - * affected) + * Shift applies only to elements which are not moved, inserted or deleted (i.e. only plain SET and NONE are affected) */ if (manipulation.types == NONE || manipulation.types == SET) { int elementOffset = manipulation.dstIndex - manipulation.srcIndex; /* - * First make sure if we have to close a previous range. This is the case, if the current element's offset - * differs from the rangeOffset and a range is open. + * First make sure if we have to close a previous range. This is the case, if the current element's offset differs from + * the rangeOffset and a range is open. */ if (elementOffset != rangeOffset && rangeStartIndex != NO_INDEX) { @@ -685,9 +691,8 @@ public abstract class AbstractBasicListTableMapping implements IListMapping3, IM } /* - * At this point, either a range is open, which means that the current element also fits in the range (i.e. - * the offsets match) or no range is open. In the latter case, we have to open one if the current element's - * offset is not 0. + * At this point, either a range is open, which means that the current element also fits in the range (i.e. the offsets + * match) or no range is open. In the latter case, we have to open one if the current element's offset is not 0. */ if (elementOffset != 0 && rangeStartIndex == NO_INDEX) { @@ -719,8 +724,8 @@ public abstract class AbstractBasicListTableMapping implements IListMapping3, IM } /* - * Now process the operations. Move down operations can be performed directly, move up operations need to be - * performed later in the reverse direction + * Now process the operations. Move down operations can be performed directly, move up operations need to be performed + * later in the reverse direction */ ListIterator<Shift> operationIt = shiftOperations.listIterator(); writeShiftsDown(idHandler, operationIt); 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 15216499a6..bc791c94ac 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 @@ -311,6 +311,12 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement } @Override + protected boolean isZeroBasedIndex() + { + return ((HorizontalNonAuditMappingStrategy)getMappingStrategy()).shallForceZeroBasedIndex(); + } + + @Override protected ITypeMapping getTypeMapping() { return NonAuditListTableMapping.this.getTypeMapping(); |