diff options
author | Stefan Winkler | 2010-10-29 08:54:53 +0000 |
---|---|---|
committer | Stefan Winkler | 2010-10-29 08:54:53 +0000 |
commit | 4700b9794bd41a23d3d0dea608cbe0f69bd0672b (patch) | |
tree | 1e86205f21af4bd993bd30ee1e59ea019a6fbc48 | |
parent | 78d0e4e6117aae28a5edfcbdd5364782d309a8e9 (diff) | |
download | cdo-4700b9794bd41a23d3d0dea608cbe0f69bd0672b.tar.gz cdo-4700b9794bd41a23d3d0dea608cbe0f69bd0672b.tar.xz cdo-4700b9794bd41a23d3d0dea608cbe0f69bd0672b.zip |
Rangebased Mapping - Branching Step 1 (implemented queryXref for audit range-based)
4 files changed, 84 insertions, 5 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMappingWithRanges.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMappingWithRanges.java index cf823a81b5..0f267bf2e9 100644 --- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMappingWithRanges.java +++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMappingWithRanges.java @@ -55,11 +55,13 @@ import org.eclipse.net4j.util.collection.MoveableList; import org.eclipse.net4j.util.om.trace.ContextTracer; import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.EStructuralFeature; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Statement; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -997,6 +999,77 @@ public class AuditListTableMappingWithRanges extends BasicAbstractListTableMappi public final boolean queryXRefs(IDBStoreAccessor accessor, String mainTableName, String mainTableWhere, QueryXRefsContext context, String idString) { - throw new UnsupportedOperationException("This mapping strategy does not support cross-reference querying."); + + String tableName = getTable().getName(); + String listJoin = getMappingStrategy().getListJoin("a_t", "l_t"); + + StringBuilder builder = new StringBuilder(); + builder.append("SELECT l_t."); //$NON-NLS-1$ + builder.append(CDODBSchema.LIST_REVISION_ID); + builder.append(", l_t."); //$NON-NLS-1$ + builder.append(CDODBSchema.LIST_VALUE); + builder.append(", l_t."); //$NON-NLS-1$ + builder.append(CDODBSchema.LIST_IDX); + builder.append(" FROM "); //$NON-NLS-1$ + builder.append(tableName); + builder.append(" AS l_t, ");//$NON-NLS-1$ + builder.append(mainTableName); + builder.append(" AS a_t WHERE ");//$NON-NLS-1$ + builder.append("a_t." + mainTableWhere);//$NON-NLS-1$ + builder.append(listJoin); + builder.append(" AND "); //$NON-NLS-1$ + builder.append(CDODBSchema.LIST_VALUE); + builder.append(" IN "); //$NON-NLS-1$ + builder.append(idString); + String sql = builder.toString(); + + ResultSet resultSet = null; + Statement stmt = null; + + try + { + stmt = accessor.getConnection().createStatement(); + if (TRACER.isEnabled()) + { + TRACER.format("Query XRefs (list): {0}", sql); + } + + resultSet = stmt.executeQuery(sql); + while (resultSet.next()) + { + long idLong = resultSet.getLong(1); + CDOID srcId = CDOIDUtil.createLong(idLong); + idLong = resultSet.getLong(2); + CDOID targetId = CDOIDUtil.createLong(idLong); + int idx = resultSet.getInt(3); + + boolean more = context.addXRef(targetId, srcId, (EReference)getFeature(), idx); + if (TRACER.isEnabled()) + { + TRACER.format(" add XRef to context: src={0}, tgt={1}, idx={2}", srcId, targetId, idx); + } + + if (!more) + { + if (TRACER.isEnabled()) + { + TRACER.format(" result limit reached. Ignoring further results."); + } + + return false; + } + } + + return true; + } + catch (SQLException ex) + { + throw new DBException(ex); + } + finally + { + DBUtil.close(resultSet); + DBUtil.close(stmt); + } } } diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategyWithRanges.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategyWithRanges.java index efcc187750..4a850ea282 100644 --- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategyWithRanges.java +++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategyWithRanges.java @@ -13,6 +13,7 @@ package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal; import org.eclipse.emf.cdo.server.db.mapping.IClassMapping; import org.eclipse.emf.cdo.server.db.mapping.IListMapping; +import org.eclipse.emf.cdo.server.internal.db.CDODBSchema; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EStructuralFeature; @@ -63,7 +64,12 @@ public class HorizontalAuditMappingStrategyWithRanges extends AbstractHorizontal @Override public String getListJoin(String attrTable, String listTable) { - // TODO: implement HorizontalAuditMappingStrategyWithRanges.getListJoin(attrTable, listTable) - throw new UnsupportedOperationException(); + String join = super.getListJoin(attrTable, listTable); + join += " AND " + listTable + "." + CDODBSchema.LIST_REVISION_VERSION_ADDED; + join += "<=" + attrTable + "." + CDODBSchema.ATTRIBUTES_VERSION; + join += " AND (" + listTable + "." + CDODBSchema.LIST_REVISION_VERSION_REMOVED; + join += " IS NULL OR " + listTable + "." + CDODBSchema.LIST_REVISION_VERSION_REMOVED; + join += ">" + attrTable + "." + CDODBSchema.ATTRIBUTES_VERSION + ")"; + return join; } } diff --git a/plugins/org.eclipse.emf.cdo.tests.db/CDO AllTests (H2 audit).launch b/plugins/org.eclipse.emf.cdo.tests.db/CDO AllTests (H2 audit).launch index caabdcdb00..9e1ef17718 100644 --- a/plugins/org.eclipse.emf.cdo.tests.db/CDO AllTests (H2 audit).launch +++ b/plugins/org.eclipse.emf.cdo.tests.db/CDO AllTests (H2 audit).launch @@ -12,5 +12,5 @@ <stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.emf.cdo.tests.db.AllTestsDBH2"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.emf.cdo.tests.db"/> -<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms40m -Xmx512m"/> +<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms40m -Xmx2048m"/> </launchConfiguration> diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2.java index e6387ccc74..a665b2e61c 100644 --- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2.java +++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2.java @@ -47,7 +47,7 @@ public class AllTestsDBH2 extends DBConfigs @Override protected void initConfigSuites(TestSuite parent) { - addScenario(parent, COMBINED, AllTestsDBH2.H2.ReusableFolder.AUDIT_INSTANCE, JVM, NATIVE); + //addScenario(parent, COMBINED, AllTestsDBH2.H2.ReusableFolder.AUDIT_INSTANCE, JVM, NATIVE); addScenario(parent, COMBINED, AllTestsDBH2.H2.ReusableFolder.RANGE_INSTANCE, JVM, NATIVE); } |