Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2011-12-21 12:54:27 +0000
committerEike Stepper2011-12-21 12:54:27 +0000
commit3c163974928f397a7d53957ba62d5e4df0c79425 (patch)
tree74f7862b977a470803ecd38c753a31e024b883c1
parent694ab8f8f8bfb3812e57d2775a7c07f1435a5770 (diff)
downloadcdo-3c163974928f397a7d53957ba62d5e4df0c79425.tar.gz
cdo-3c163974928f397a7d53957ba62d5e4df0c79425.tar.xz
cdo-3c163974928f397a7d53957ba62d5e4df0c79425.zip
[366686] [DB] Reduce amount of update statements for non-audit mode bugs/366686
https://bugs.eclipse.org/bugs/show_bug.cgi?id=366686
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IListMapping2.java28
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreChunkReader.java29
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BasicAbstractListTableMapping.java10
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java43
4 files changed, 82 insertions, 28 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IListMapping2.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IListMapping2.java
new file mode 100644
index 0000000000..9dcfd6cbc9
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IListMapping2.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.server.db.mapping;
+
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
+
+/**
+ * Extension interface to {@link IListMapping}.
+ *
+ * @author Eike Stepper
+ * @since 4.1
+ */
+public interface IListMapping2 extends IListMapping
+{
+ public void addSimpleChunkWhere(IDBStoreAccessor accessor, CDOID cdoid, StringBuilder builder, int index);
+
+ public void addRangedChunkWhere(IDBStoreAccessor accessor, CDOID cdoid, StringBuilder builder, int fromIndex,
+ int toIndex);
+}
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 13ae632f1a..2295a59bb7 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
@@ -16,8 +16,8 @@ import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.server.db.IDBStoreChunkReader;
import org.eclipse.emf.cdo.server.db.mapping.IClassMapping;
import org.eclipse.emf.cdo.server.db.mapping.IListMapping;
+import org.eclipse.emf.cdo.server.db.mapping.IListMapping2;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
-import org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.BasicAbstractListTableMapping;
import org.eclipse.emf.cdo.spi.server.StoreChunkReader;
import org.eclipse.emf.ecore.EStructuralFeature;
@@ -53,8 +53,16 @@ public class DBStoreChunkReader extends StoreChunkReader implements IDBStoreChun
super.addSimpleChunk(index);
prepareAddition();
- ((BasicAbstractListTableMapping)referenceMapping).addSimpleChunkWhere(getAccessor(), getRevision().getID(),
- builder, index);
+ if (referenceMapping instanceof IListMapping2)
+ {
+ ((IListMapping2)referenceMapping).addSimpleChunkWhere(getAccessor(), getRevision().getID(), builder, index);
+ }
+ else
+ {
+ builder.append(CDODBSchema.LIST_IDX);
+ builder.append('=');
+ builder.append(index);
+ }
}
@Override
@@ -63,8 +71,19 @@ public class DBStoreChunkReader extends StoreChunkReader implements IDBStoreChun
super.addRangedChunk(fromIndex, toIndex);
prepareAddition();
- ((BasicAbstractListTableMapping)referenceMapping).addRangedChunkWhere(getAccessor(), getRevision().getID(),
- builder, fromIndex, toIndex);
+ if (referenceMapping instanceof IListMapping2)
+ {
+ ((IListMapping2)referenceMapping).addRangedChunkWhere(getAccessor(), getRevision().getID(), builder, fromIndex,
+ toIndex);
+ }
+ else
+ {
+ builder.append(CDODBSchema.LIST_IDX);
+ builder.append(" BETWEEN "); //$NON-NLS-1$
+ builder.append(fromIndex);
+ builder.append(" AND "); //$NON-NLS-1$
+ builder.append(toIndex - 1);
+ }
}
public List<Chunk> executeRead()
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BasicAbstractListTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BasicAbstractListTableMapping.java
index 7add335a82..f5c54477e1 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BasicAbstractListTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BasicAbstractListTableMapping.java
@@ -11,10 +11,10 @@
package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal;
import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.server.db.mapping.IListMapping;
+import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
+import org.eclipse.emf.cdo.server.db.mapping.IListMapping2;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
-import org.eclipse.emf.cdo.server.internal.db.DBStoreAccessor;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
@@ -22,7 +22,7 @@ import org.eclipse.emf.ecore.EStructuralFeature;
/**
* @author Stefan Winkler
*/
-public abstract class BasicAbstractListTableMapping implements IListMapping
+public abstract class BasicAbstractListTableMapping implements IListMapping2
{
private IMappingStrategy mappingStrategy;
@@ -53,14 +53,14 @@ public abstract class BasicAbstractListTableMapping implements IListMapping
return feature;
}
- public void addSimpleChunkWhere(DBStoreAccessor accessor, CDOID cdoid, StringBuilder builder, int index)
+ public void addSimpleChunkWhere(IDBStoreAccessor accessor, CDOID cdoid, StringBuilder builder, int index)
{
builder.append(CDODBSchema.LIST_IDX);
builder.append('=');
builder.append(index);
}
- public void addRangedChunkWhere(DBStoreAccessor accessor, CDOID cdoid, StringBuilder builder, int fromIndex,
+ public void addRangedChunkWhere(IDBStoreAccessor accessor, CDOID cdoid, StringBuilder builder, int fromIndex,
int toIndex)
{
builder.append(CDODBSchema.LIST_IDX);
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 9287d11f4d..5a28077f51 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
@@ -27,11 +27,11 @@ 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.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.IListMappingDeltaSupport;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
-import org.eclipse.emf.cdo.server.internal.db.DBStoreAccessor;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
@@ -184,14 +184,14 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
@Override
- public void addSimpleChunkWhere(DBStoreAccessor accessor, CDOID cdoid, StringBuilder builder, int index)
+ public void addSimpleChunkWhere(IDBStoreAccessor accessor, CDOID cdoid, StringBuilder builder, int index)
{
int offset = getCurrentIndexOffset(accessor, cdoid);
super.addSimpleChunkWhere(accessor, cdoid, builder, index + offset);
}
@Override
- public void addRangedChunkWhere(DBStoreAccessor accessor, CDOID cdoid, StringBuilder builder, int fromIndex,
+ public void addRangedChunkWhere(IDBStoreAccessor accessor, CDOID cdoid, StringBuilder builder, int fromIndex,
int toIndex)
{
int offset = getCurrentIndexOffset(accessor, cdoid);
@@ -231,11 +231,12 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
*/
public void clearList(IDBStoreAccessor accessor, CDOID id)
{
+ IPreparedStatementCache statementCache = accessor.getStatementCache();
PreparedStatement stmt = null;
try
{
- stmt = accessor.getStatementCache().getPreparedStatement(sqlClear, ReuseProbability.HIGH);
+ stmt = statementCache.getPreparedStatement(sqlClear, ReuseProbability.HIGH);
getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 1, id);
DBUtil.update(stmt, false);
}
@@ -245,18 +246,19 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
finally
{
- accessor.getStatementCache().releasePreparedStatement(stmt);
+ statementCache.releasePreparedStatement(stmt);
}
}
public int getCurrentIndexOffset(IDBStoreAccessor accessor, CDOID id)
{
+ IPreparedStatementCache statementCache = accessor.getStatementCache();
PreparedStatement stmt = null;
ResultSet rset = null;
try
{
- stmt = accessor.getStatementCache().getPreparedStatement(sqlReadCurrentIndexOffset, ReuseProbability.HIGH);
+ stmt = statementCache.getPreparedStatement(sqlReadCurrentIndexOffset, ReuseProbability.HIGH);
getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 1, id);
rset = stmt.executeQuery();
if (!rset.next())
@@ -698,6 +700,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
private void writeResultToDatabase(IDBStoreAccessor accessor, CDOID id)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ IPreparedStatementCache statementCache = accessor.getStatementCache();
PreparedStatement deleteStmt = null;
PreparedStatement moveStmt = null;
PreparedStatement setValueStmt = null;
@@ -735,7 +738,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
if (deleteStmt == null)
{
- deleteStmt = accessor.getStatementCache().getPreparedStatement(sqlDeleteItem, ReuseProbability.HIGH);
+ deleteStmt = statementCache.getPreparedStatement(sqlDeleteItem, ReuseProbability.HIGH);
idHandler.setCDOID(deleteStmt, 1, id);
}
@@ -757,7 +760,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
*/
if (moveStmt == null)
{
- moveStmt = accessor.getStatementCache().getPreparedStatement(sqlUpdateIndex, ReuseProbability.HIGH);
+ moveStmt = statementCache.getPreparedStatement(sqlUpdateIndex, ReuseProbability.HIGH);
idHandler.setCDOID(moveStmt, 2, id);
}
@@ -825,7 +828,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
*/
if (setValueStmt == null)
{
- setValueStmt = accessor.getStatementCache().getPreparedStatement(sqlUpdateValue, ReuseProbability.HIGH);
+ setValueStmt = statementCache.getPreparedStatement(sqlUpdateValue, ReuseProbability.HIGH);
idHandler.setCDOID(setValueStmt, 2, id);
}
@@ -847,7 +850,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
*/
if (insertStmt == null)
{
- insertStmt = accessor.getStatementCache().getPreparedStatement(sqlInsertValue, ReuseProbability.HIGH);
+ insertStmt = statementCache.getPreparedStatement(sqlInsertValue, ReuseProbability.HIGH);
idHandler.setCDOID(insertStmt, 1, id);
}
@@ -994,6 +997,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
*/
ListIterator<ShiftOperation> operationIt = shiftOperations.listIterator();
+ IPreparedStatementCache statementCache = accessor.getStatementCache();
PreparedStatement shiftDownStmt = null;
int operationCounter = 0;
@@ -1007,8 +1011,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
{
if (shiftDownStmt == null)
{
- shiftDownStmt = accessor.getStatementCache().getPreparedStatement(sqlShiftDownIndex,
- ReuseProbability.HIGH);
+ shiftDownStmt = statementCache.getPreparedStatement(sqlShiftDownIndex, ReuseProbability.HIGH);
idHandler.setCDOID(shiftDownStmt, 2, id);
}
@@ -1038,6 +1041,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
PreparedStatement shiftUpStmt = null;
operationCounter = 0;
+
try
{
@@ -1046,7 +1050,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
ShiftOperation operation = operationIt.previous();
if (shiftUpStmt == null)
{
- shiftUpStmt = accessor.getStatementCache().getPreparedStatement(sqlShiftUpIndex, ReuseProbability.HIGH);
+ shiftUpStmt = statementCache.getPreparedStatement(sqlShiftUpIndex, ReuseProbability.HIGH);
idHandler.setCDOID(shiftUpStmt, 2, id);
}
@@ -1078,7 +1082,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
/**
* @author Eike Stepper
*/
- private static final class ManipulationConstants
+ private static interface ManipulationConstants
{
public static final int NO_INDEX = Integer.MIN_VALUE;
@@ -1098,7 +1102,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
/**
* @author Eike Stepper
*/
- private static final class ManipulationElement
+ private static final class ManipulationElement implements ManipulationConstants
{
public int type;
@@ -1113,7 +1117,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
public ManipulationElement(int srcIdx, int dstIdx, Object val, int t)
{
sourceIndex = srcIdx;
- tempIndex = ManipulationConstants.NO_INDEX;
+ tempIndex = NO_INDEX;
destinationIndex = dstIdx;
value = val;
type = t;
@@ -1124,7 +1128,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
*/
public static ManipulationElement createOriginalElement(int index)
{
- return new ManipulationElement(index, index, ManipulationConstants.NIL, ManipulationConstants.NONE);
+ return new ManipulationElement(index, index, NIL, NONE);
}
/**
@@ -1132,7 +1136,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
*/
public static ManipulationElement createInsertedElement(int index, Object value)
{
- return new ManipulationElement(ManipulationConstants.NO_INDEX, index, value, ManipulationConstants.INSERT);
+ return new ManipulationElement(NO_INDEX, index, value, ManipulationConstants.INSERT);
}
public boolean is(int t)
@@ -1146,6 +1150,9 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
}
+ /**
+ * @author Eike Stepper
+ */
private static class ShiftOperation
{
final int startIndex;

Back to the top