diff options
2 files changed, 44 insertions, 3 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreChunkReader.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreChunkReader.java index bb93304133..9449d8726f 100644 --- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreChunkReader.java +++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreChunkReader.java @@ -7,6 +7,7 @@ * * Contributors: * Eike Stepper - initial API and implementation + * Stefan Winkler - Bug 283998: [DB] Chunk reading for multiple chunks fails */ package org.eclipse.emf.cdo.server.internal.db; @@ -30,6 +31,8 @@ public class DBStoreChunkReader extends StoreChunkReader implements IDBStoreChun private StringBuilder builder = new StringBuilder(); + private boolean firstChunk = true; + public DBStoreChunkReader(DBStoreAccessor accessor, CDORevision revision, EStructuralFeature feature) { super(accessor, revision, feature); @@ -48,7 +51,15 @@ public class DBStoreChunkReader extends StoreChunkReader implements IDBStoreChun public void addSimpleChunk(int index) { super.addSimpleChunk(index); - builder.append(" AND "); //$NON-NLS-1$ + if (firstChunk) + { + builder.append(" AND ("); //$NON-NLS-1$ + firstChunk = false; + } + else + { + builder.append(" OR "); //$NON-NLS-1$ + } builder.append(CDODBSchema.LIST_IDX); builder.append("="); //$NON-NLS-1$ builder.append(index); @@ -58,7 +69,16 @@ public class DBStoreChunkReader extends StoreChunkReader implements IDBStoreChun public void addRangedChunk(int fromIndex, int toIndex) { super.addRangedChunk(fromIndex, toIndex); - builder.append(" AND "); //$NON-NLS-1$ + if (firstChunk) + { + builder.append(" AND ("); //$NON-NLS-1$ + firstChunk = false; + } + else + { + builder.append(" OR "); //$NON-NLS-1$ + } + builder.append(CDODBSchema.LIST_IDX); builder.append(" BETWEEN "); //$NON-NLS-1$ builder.append(fromIndex); @@ -69,6 +89,12 @@ public class DBStoreChunkReader extends StoreChunkReader implements IDBStoreChun public List<Chunk> executeRead() { List<Chunk> chunks = getChunks(); + + if (!firstChunk) + { // at least one chunk queried -> close parantheses. + builder.append(")"); //$NON-NLS-1$ + } + referenceMapping.readChunks(this, chunks, builder.toString()); return chunks; } 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 c330724c79..baf726b802 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 @@ -7,7 +7,8 @@ * * Contributors: * Eike Stepper - initial API and implementation - * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444 + * Stefan Winkler - Bug 271444: [DB] Multiple refactorings + * Stefan Winkler - Bug 283998: [DB] Chunk reading for multiple chunks fails */ package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal; @@ -402,9 +403,12 @@ public abstract class AbstractListTableMapping implements IListMapping int chunkIndex = 0; int indexInChunk = 0; + int resultCounter = 0; + while (resultSet.next()) { Object value = typeMapping.readValue(resultSet, 1); + resultCounter++; if (chunk == null) { @@ -436,6 +440,17 @@ public abstract class AbstractListTableMapping implements IListMapping } } + // check if result set and chunks matched + for (Chunk ch : chunks) + { + resultCounter -= ch.size(); + } + + if (resultCounter != 0) + { + throw new IllegalStateException("ResultSet contained " + -resultCounter + " entries less than expected."); + } + if (TRACER.isEnabled()) { TRACER.format("Reading list chunk values done for feature {0}.{1} of {2}v{3}", containingClass.getName(), //$NON-NLS-1$ |