Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2011-12-21 07:54:27 -0500
committerStefan Winkler2011-12-21 16:41:33 -0500
commit35b183b6c3fdbd9a353173f6295fe5961775c56d (patch)
treec60435676ead734e1b3654e95fd5a9e20a92c08b
parent18196e2cd60574e21fe595a225946bc8303524db (diff)
downloadcdo-35b183b6c3fdbd9a353173f6295fe5961775c56d.tar.gz
cdo-35b183b6c3fdbd9a353173f6295fe5961775c56d.tar.xz
cdo-35b183b6c3fdbd9a353173f6295fe5961775c56d.zip
[367356] [DB] Reduce amount of update statements for non-audit mode
https://bugs.eclipse.org/bugs/show_bug.cgi?id=367356
-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 1b06347d93..135c6352dc 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 4e86ef893a..7617063568 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 bf2c84a4ce..570058fecf 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;
@@ -185,14 +185,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);
@@ -232,11 +232,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);
}
@@ -246,18 +247,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())
@@ -733,6 +735,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;
@@ -770,7 +773,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);
}
@@ -792,7 +795,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);
}
@@ -860,7 +863,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);
}
@@ -882,7 +885,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);
}
@@ -1029,6 +1032,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
*/
ListIterator<ShiftOperation> operationIt = shiftOperations.listIterator();
+ IPreparedStatementCache statementCache = accessor.getStatementCache();
PreparedStatement shiftDownStmt = null;
int operationCounter = 0;
@@ -1042,8 +1046,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);
}
@@ -1073,6 +1076,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
PreparedStatement shiftUpStmt = null;
operationCounter = 0;
+
try
{
@@ -1081,7 +1085,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);
}
@@ -1113,7 +1117,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;
@@ -1133,7 +1137,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;
@@ -1148,7 +1152,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;
@@ -1159,7 +1163,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);
}
/**
@@ -1167,7 +1171,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)
@@ -1181,6 +1185,9 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
}
+ /**
+ * @author Eike Stepper
+ */
private static class ShiftOperation
{
final int startIndex;

Back to the top