Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-05-30 13:57:25 -0400
committerEike Stepper2013-05-30 13:57:25 -0400
commit23b1b7dcd93da143bd4143cd4dc99e1f15b75713 (patch)
tree039cbb791095522de99eda72c7f78ef0b405e9bb
parentdbd2007e12642d7d20f30dd6d90d50305d098a26 (diff)
downloadcdo-23b1b7dcd93da143bd4143cd4dc99e1f15b75713.tar.gz
cdo-23b1b7dcd93da143bd4143cd4dc99e1f15b75713.tar.xz
cdo-23b1b7dcd93da143bd4143cd4dc99e1f15b75713.zip
Optimize list size computations
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java63
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java45
2 files changed, 71 insertions, 37 deletions
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 7507749759..586c405e54 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
@@ -38,6 +38,7 @@ import org.eclipse.emf.cdo.server.db.mapping.IListMappingDeltaSupport;
import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
import org.eclipse.emf.cdo.server.internal.db.DBStore;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
+import org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.NonAuditListTableMapping.NewListSizeResult;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta;
@@ -534,11 +535,6 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
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>>();
@@ -552,25 +548,29 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
updateContainer = false;
}
- public void process(IDBStoreAccessor a, CDORevisionDelta d, long c)
+ public void process(IDBStoreAccessor accessor, CDORevisionDelta delta, long created)
{
- // set context
- id = d.getID();
-
- branchId = d.getBranch().getID();
- oldVersion = d.getVersion();
- newVersion = oldVersion + 1;
- created = c;
- accessor = a;
+ try
+ {
+ // Set context
+ id = delta.getID();
- tempRevision = (InternalCDORevision)accessor.getTransaction().getRevision(id).copy();
+ branchId = delta.getBranch().getID();
+ oldVersion = delta.getVersion();
+ newVersion = oldVersion + 1;
+ this.created = created;
+ this.accessor = accessor;
- // process revision delta tree
- d.accept(this);
+ // Process revision delta tree
+ delta.accept(this);
- updateAttributes();
- // clean up
- reset();
+ updateAttributes();
+ }
+ finally
+ {
+ // Clean up
+ reset();
+ }
}
public void visit(CDOMoveFeatureDelta delta)
@@ -605,13 +605,18 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
public void visit(CDOListFeatureDelta delta)
{
EStructuralFeature feature = delta.getFeature();
+ int oldSize = delta.getOriginSize();
+ int newSize = -1;
- 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();
+ try
+ {
+ IListMappingDeltaSupport listMapping = (IListMappingDeltaSupport)getListMapping(feature);
+ listMapping.processDelta(accessor, id, branchId, oldVersion, oldVersion + 1, created, delta);
+ }
+ catch (NewListSizeResult result)
+ {
+ newSize = result.getNewListSize();
+ }
if (oldSize != newSize)
{
@@ -645,8 +650,8 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
private void updateAttributes()
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IDBPreparedStatement stmt = accessor.getDBConnection().prepareStatement(buildUpdateStatement(),
- ReuseProbability.MEDIUM);
+ String sql = buildUpdateSQL();
+ IDBPreparedStatement stmt = accessor.getDBConnection().prepareStatement(sql, ReuseProbability.MEDIUM);
try
{
@@ -677,7 +682,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
}
- private String buildUpdateStatement()
+ private String buildUpdateSQL()
{
StringBuilder builder = new StringBuilder(sqlUpdatePrefix);
if (updateContainer)
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 fb424964cf..99ba01cac8 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
@@ -13,7 +13,6 @@
package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal;
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.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.delta.CDOAddFeatureDelta;
@@ -31,7 +30,6 @@ import org.eclipse.emf.cdo.server.db.IIDHandler;
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.bundle.OM;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
@@ -282,15 +280,11 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
public void processDelta(final IDBStoreAccessor accessor, final CDOID id, int branchId, int oldVersion,
final int newVersion, long created, CDOListFeatureDelta delta)
{
- CDOBranchPoint main = accessor.getStore().getRepository().getBranchManager().getMainBranch().getHead();
-
- InternalCDORevision originalRevision = (InternalCDORevision)accessor.getStore().getRepository()
- .getRevisionManager().getRevision(id, main, CDORevision.UNCHUNKED, CDORevision.DEPTH_NONE, true);
- int oldListSize = originalRevision.getList(getFeature()).size();
+ int oldListSize = delta.getOriginSize();
if (TRACER.isEnabled())
{
- TRACER.format("ListTableMapping.processDelta for revision {0} - previous list size: {1}", originalRevision, //$NON-NLS-1$
+ TRACER.format("ListTableMapping.processDelta for object {0} - original list size: {1}", id, //$NON-NLS-1$
oldListSize);
}
@@ -311,6 +305,8 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
// finally, write results to the database
visitor.writeResultToDatabase(accessor, id);
+
+ throw new NewListSizeResult(visitor.getNewListSize());
}
private void close(PreparedStatement... stmts)
@@ -359,6 +355,26 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
/**
* @author Eike Stepper
*/
+ static final class NewListSizeResult extends RuntimeException
+ {
+ private static final long serialVersionUID = 1L;
+
+ private final int newListSize;
+
+ public NewListSizeResult(int newListSize)
+ {
+ this.newListSize = newListSize;
+ }
+
+ public int getNewListSize()
+ {
+ return newListSize;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
private final class ListDeltaVisitor implements CDOFeatureDeltaVisitor
{
private boolean clearFirst;
@@ -371,6 +387,8 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
*/
private int tempIndex = -1;
+ private int newListSize;
+
public ListDeltaVisitor(int oldListSize)
{
// reset the clear-flag
@@ -382,6 +400,13 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
{
manipulations.add(ManipulationElement.createOriginalElement(i));
}
+
+ newListSize = oldListSize;
+ }
+
+ public int getNewListSize()
+ {
+ return newListSize;
}
public void visit(CDOAddFeatureDelta delta)
@@ -396,6 +421,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
// create the item
manipulations.add(ManipulationElement.createInsertedElement(delta.getIndex(), delta.getValue()));
+ ++newListSize;
}
public void visit(CDORemoveFeatureDelta delta)
@@ -410,6 +436,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
// fill the gap by shifting all subsequent items down
shiftIndexes(delta.getIndex() + 1, UNBOUNDED_SHIFT, -1);
+ --newListSize;
}
public void visit(CDOSetFeatureDelta delta)
@@ -450,6 +477,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
// and also clear all manipulation items
manipulations.clear();
+ newListSize = 0;
}
public void visit(CDOClearFeatureDelta delta)
@@ -464,6 +492,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
// and also clear all manipulation items
manipulations.clear();
+ newListSize = 0;
}
public void visit(CDOMoveFeatureDelta delta)

Back to the top