Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategy.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategyWithRanges.java227
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Bugzilla_351078_DB_Test.java77
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_351078_Test.java10
5 files changed, 316 insertions, 10 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategy.java
index d4975b6538..f1161c174e 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategy.java
@@ -77,17 +77,22 @@ public class HorizontalBranchingMappingStrategy extends AbstractHorizontalMappin
@Override
public String getListJoin(String attrTable, String listTable)
{
- String join = super.getListJoin(attrTable, listTable);
+ String join = getListJoinBasic(attrTable, listTable);
return modifyListJoin(attrTable, listTable, join, false);
}
@Override
protected String getListJoinForRawExport(String attrTable, String listTable)
{
- String join = super.getListJoin(attrTable, listTable);
+ String join = getListJoinBasic(attrTable, listTable);
return modifyListJoin(attrTable, listTable, join, true);
}
+ protected String getListJoinBasic(String attrTable, String listTable)
+ {
+ return super.getListJoin(attrTable, listTable);
+ }
+
protected String modifyListJoin(String attrTable, String listTable, String join, boolean forRawExport)
{
join += " AND " + attrTable + "." + CDODBSchema.ATTRIBUTES_VERSION;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategyWithRanges.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategyWithRanges.java
index f608e5eaef..dbd9adc48c 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategyWithRanges.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategyWithRanges.java
@@ -13,16 +13,23 @@
package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal;
import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.protocol.CDODataInput;
+import org.eclipse.emf.cdo.common.protocol.CDODataOutput;
import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.IIDHandler;
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.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.DBUtil.DeserializeRowHandler;
import org.eclipse.net4j.db.ddl.IDBField;
+import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.io.ExtendedDataInput;
+import org.eclipse.net4j.util.om.monitor.OMMonitor;
+import org.eclipse.net4j.util.om.monitor.OMMonitor.Async;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
@@ -30,7 +37,9 @@ import org.eclipse.emf.ecore.EStructuralFeature;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
+import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.Collection;
/**
* @author Eike Stepper
@@ -74,15 +83,222 @@ public class HorizontalBranchingMappingStrategyWithRanges extends HorizontalBran
}
@Override
+ protected void rawExportList(CDODataOutput out, Connection connection, IListMapping listMapping, IDBTable attrTable,
+ String attrSuffix) throws IOException
+ {
+ super.rawExportList(out, connection, listMapping, attrTable, attrSuffix);
+
+ for (IDBTable table : listMapping.getDBTables())
+ {
+ rawExportListPostProcess(out, connection, attrTable, attrSuffix, table);
+ }
+ }
+
+ private void rawExportListPostProcess(CDODataOutput out, Connection connection, IDBTable attrTable,
+ String attrSuffix, IDBTable table) throws IOException
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("SELECT l_t.");
+ builder.append(CDODBSchema.LIST_REVISION_ID);
+ builder.append(", l_t.");
+ builder.append(CDODBSchema.LIST_REVISION_BRANCH);
+ builder.append(", l_t.");
+ builder.append(CDODBSchema.LIST_REVISION_VERSION_ADDED);
+ builder.append(", l_t.");
+ builder.append(CDODBSchema.LIST_REVISION_VERSION_REMOVED);
+ builder.append(", l_t.");
+ builder.append(CDODBSchema.LIST_IDX);
+ builder.append(" FROM ");
+ builder.append(table);
+ builder.append(" l_t, ");
+ builder.append(attrTable);
+ builder.append(" a_t");
+ builder.append(attrSuffix);
+ builder.append(getListJoinForPostProcess("a_t", "l_t"));
+ builder.append(" AND l_t.");
+ builder.append(CDODBSchema.LIST_REVISION_VERSION_REMOVED);
+ builder.append(" IS NOT NULL");
+ String sql = DBUtil.trace(builder.toString());
+
+ IIDHandler idHandler = getStore().getIDHandler();
+ PreparedStatement stmt = null;
+ ResultSet resultSet = null;
+
+ try
+ {
+ stmt = connection.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+ resultSet = stmt.executeQuery();
+
+ // Write resultSet size for progress monitoring
+ int size = DBUtil.getRowCount(resultSet);
+ out.writeInt(size);
+ if (size == 0)
+ {
+ return;
+ }
+
+ while (resultSet.next())
+ {
+ CDOID source = idHandler.getCDOID(resultSet, 1);
+ int branch = resultSet.getInt(2);
+ int versionAdded = resultSet.getInt(3);
+ int versionRemoved = resultSet.getInt(4);
+ int idx = resultSet.getInt(5);
+
+ out.writeCDOID(source);
+ out.writeInt(branch);
+ out.writeInt(versionAdded);
+ out.writeInt(versionRemoved);
+ out.writeInt(idx);
+ }
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ DBUtil.close(resultSet);
+ DBUtil.close(stmt);
+ }
+ }
+
+ @Override
+ protected void rawImportList(CDODataInput in, Connection connection, IListMapping listMapping, OMMonitor monitor)
+ throws IOException
+ {
+ Collection<IDBTable> tables = listMapping.getDBTables();
+ int size = tables.size();
+ if (size == 0)
+ {
+ return;
+ }
+
+ monitor.begin(2 * size);
+
+ try
+ {
+ super.rawImportList(in, connection, listMapping, monitor.fork(size));
+
+ for (IDBTable table : tables)
+ {
+ rawImportListPostProcess(in, connection, table, monitor.fork());
+ }
+ }
+ finally
+ {
+ monitor.done();
+ }
+ }
+
+ private void rawImportListPostProcess(CDODataInput in, Connection connection, IDBTable table, OMMonitor monitor)
+ throws IOException
+ {
+ int size = in.readInt();
+ if (size == 0)
+ {
+ return;
+ }
+
+ StringBuilder builder = new StringBuilder();
+ builder.append("UPDATE "); //$NON-NLS-1$
+ builder.append(table);
+ builder.append(" SET "); //$NON-NLS-1$
+ builder.append(CDODBSchema.LIST_REVISION_VERSION_REMOVED);
+ builder.append("=? WHERE "); //$NON-NLS-1$
+ builder.append(CDODBSchema.LIST_REVISION_ID);
+ builder.append("=? AND "); //$NON-NLS-1$
+ builder.append(CDODBSchema.LIST_REVISION_BRANCH);
+ builder.append("=? AND "); //$NON-NLS-1$
+ builder.append(CDODBSchema.LIST_REVISION_VERSION_ADDED);
+ builder.append("=? AND "); //$NON-NLS-1$
+ builder.append(CDODBSchema.LIST_IDX);
+ builder.append("=?"); //$NON-NLS-1$
+ String sql = DBUtil.trace(builder.toString());
+
+ IIDHandler idHandler = getStore().getIDHandler();
+ PreparedStatement stmt = null;
+
+ monitor.begin(1 + 2 * size);
+
+ try
+ {
+ stmt = connection.prepareStatement(sql);
+ monitor.worked();
+
+ for (int row = 0; row < size; row++)
+ {
+ CDOID source = in.readCDOID();
+ int branch = in.readInt();
+ int versionAdded = in.readInt();
+ int versionRemoved = in.readInt();
+ int idx = in.readInt();
+
+ stmt.setInt(1, versionRemoved);
+ idHandler.setCDOID(stmt, 2, source);
+ stmt.setInt(3, branch);
+ stmt.setInt(4, versionAdded);
+ stmt.setInt(5, idx);
+
+ stmt.addBatch();
+ monitor.worked();
+ }
+
+ Async async = monitor.forkAsync(size);
+
+ try
+ {
+ stmt.executeBatch();
+ }
+ finally
+ {
+ async.stop();
+ }
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ DBUtil.close(stmt);
+ monitor.done();
+ }
+ }
+
+ protected String getListJoinForPostProcess(String attrTable, String listTable)
+ {
+ String join = getListJoinBasic(attrTable, listTable);
+ return modifyListJoin2(attrTable, listTable, join, true, true);
+ }
+
+ @Override
protected String modifyListJoin(String attrTable, String listTable, String join, boolean forRawExport)
{
- join += " AND " + listTable + "." + CDODBSchema.LIST_REVISION_VERSION_ADDED;
+ return modifyListJoin2(attrTable, listTable, join, forRawExport, false);
+ }
+
+ private String modifyListJoin2(String attrTable, String listTable, String join, boolean forRawExport,
+ boolean forPostProcess)
+ {
+ join += " AND " + listTable + ".";
+
if (forRawExport)
{
+ if (forPostProcess)
+ {
+ join += CDODBSchema.LIST_REVISION_VERSION_REMOVED;
+ }
+ else
+ {
+ join += CDODBSchema.LIST_REVISION_VERSION_ADDED;
+ }
+
join += "=" + attrTable + "." + CDODBSchema.ATTRIBUTES_VERSION;
}
else
{
+ join += 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;
@@ -91,6 +307,15 @@ public class HorizontalBranchingMappingStrategyWithRanges extends HorizontalBran
join += " AND " + attrTable + "." + CDODBSchema.ATTRIBUTES_BRANCH;
join += "=" + listTable + "." + CDODBSchema.LIST_REVISION_BRANCH;
+
+ if (forRawExport && !forPostProcess)
+ {
+ join += " ORDER BY " + listTable + "." + CDODBSchema.LIST_REVISION_ID;
+ join += ", " + listTable + "." + CDODBSchema.LIST_REVISION_BRANCH;
+ join += ", " + listTable + "." + CDODBSchema.LIST_REVISION_VERSION_ADDED;
+ join += ", " + listTable + "." + CDODBSchema.LIST_IDX;
+ }
+
return join;
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java
index f7bd71af25..f5f207c5ff 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java
@@ -18,7 +18,6 @@ import org.eclipse.emf.cdo.tests.offline.Bugzilla_325097_Test;
import org.eclipse.emf.cdo.tests.offline.Bugzilla_326047_Test;
import org.eclipse.emf.cdo.tests.offline.Bugzilla_328352_Test;
import org.eclipse.emf.cdo.tests.offline.Bugzilla_329014_Test;
-import org.eclipse.emf.cdo.tests.offline.Bugzilla_351078_Test;
import org.eclipse.emf.cdo.tests.offline.FailoverTest;
import org.eclipse.emf.cdo.tests.offline.OfflineDelayedTest;
import org.eclipse.emf.cdo.tests.offline.OfflineLockRawReplicationTest;
@@ -65,7 +64,7 @@ public class AllTestsDBH2Offline extends DBConfigs
testClasses.add(Bugzilla_326047_Test.class);
testClasses.add(Bugzilla_325097_Test.class);
testClasses.add(Bugzilla_319552_Test.class);
- testClasses.add(Bugzilla_351078_Test.class);
+ testClasses.add(Bugzilla_351078_DB_Test.class);
testClasses.add(FailoverTest.class);
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Bugzilla_351078_DB_Test.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Bugzilla_351078_DB_Test.java
new file mode 100644
index 0000000000..3d3499e20f
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Bugzilla_351078_DB_Test.java
@@ -0,0 +1,77 @@
+/*
+ * 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.tests.db;
+
+import org.eclipse.emf.cdo.server.db.IDBStore;
+import org.eclipse.emf.cdo.server.db.mapping.IClassMapping;
+import org.eclipse.emf.cdo.server.db.mapping.IListMapping;
+import org.eclipse.emf.cdo.spi.server.InternalRepository;
+import org.eclipse.emf.cdo.tests.model1.Company;
+import org.eclipse.emf.cdo.tests.offline.Bugzilla_351078_Test;
+
+import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.ddl.IDBTable;
+import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+import java.io.ByteArrayOutputStream;
+import java.sql.Connection;
+import java.util.Arrays;
+
+/**
+ * @author Eike Stepper
+ */
+public class Bugzilla_351078_DB_Test extends Bugzilla_351078_Test
+{
+ @Override
+ protected void check(InternalRepository master, Company masterCompany, String when)
+ {
+ super.check(master, masterCompany, when);
+
+ H2OfflineConfig config = (H2OfflineConfig)getRepositoryConfig();
+ if (config.isWithRanges())
+ {
+ byte[] masterTable = readTable(master);
+ byte[] cloneTable = readTable(getRepository());
+
+ assertEquals(true, Arrays.equals(masterTable, cloneTable));
+ }
+ }
+
+ protected byte[] readTable(InternalRepository repository)
+ {
+ IDBStore store = (IDBStore)repository.getStore();
+ IClassMapping classMapping = store.getMappingStrategy().getClassMapping(getModel1Package().getCompany());
+ IListMapping listMapping = classMapping.getListMapping(getModel1Package().getCompany_Categories());
+ IDBTable table = listMapping.getDBTables().iterator().next();
+
+ Connection connection = null;
+
+ try
+ {
+ connection = store.getConnection();
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ DBUtil.serializeTable(new ExtendedDataOutputStream(out), connection, table, null,
+ " ORDER BY CDO_SOURCE, CDO_BRANCH, CDO_VERSION_ADDED, CDO_IDX");
+
+ return out.toByteArray();
+ }
+ catch (Exception ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ finally
+ {
+ DBUtil.close(connection);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_351078_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_351078_Test.java
index ce9cc4200b..4642ee963d 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_351078_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_351078_Test.java
@@ -558,7 +558,7 @@ public class Bugzilla_351078_Test extends AbstractSyncingTest
});
}
- private void run(CompanyChanger changer) throws Exception
+ protected void run(CompanyChanger changer) throws Exception
{
// Create master session & transaction.
InternalRepository master = getRepository("master");
@@ -578,7 +578,7 @@ public class Bugzilla_351078_Test extends AbstractSyncingTest
waitForOnline(clone);
sleep(500); // TODO Clarify why waitForOnline() alone is not enough
- check(masterCompany, "after connect");
+ check(master, masterCompany, "after connect");
getOfflineConfig().stopMasterTransport();
waitForOffline(clone);
@@ -590,10 +590,10 @@ public class Bugzilla_351078_Test extends AbstractSyncingTest
waitForOnline(clone);
sleep(500);
- check(masterCompany, "after reconnect");
+ check(master, masterCompany, "after reconnect");
}
- private void check(Company masterCompany, String when)
+ protected void check(InternalRepository master, Company masterCompany, String when)
{
EList<Category> masterCategories = masterCompany.getCategories();
@@ -619,7 +619,7 @@ public class Bugzilla_351078_Test extends AbstractSyncingTest
/**
* @author Eike Stepper
*/
- private static class CompanyChanger
+ protected static class CompanyChanger
{
public void beforeConnect(EList<Category> categories, CDOTransaction transaction) throws Exception
{

Back to the top