Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2011-09-13 05:49:18 +0000
committerEike Stepper2011-09-13 05:49:18 +0000
commit51e4170064a1fdfac043c2de968be6724bda5668 (patch)
tree981704a6d5558fb78d1a8438aa81454bd79bb0da
parent2ca9689e606023cad3a7a2d4a8b1262cc143a022 (diff)
downloadcdo-51e4170064a1fdfac043c2de968be6724bda5668.tar.gz
cdo-51e4170064a1fdfac043c2de968be6724bda5668.tar.xz
cdo-51e4170064a1fdfac043c2de968be6724bda5668.zip
[351078] [DB] Support raw replication in HorizontalBranchingMappingStrategyWithRanges
https://bugs.eclipse.org/bugs/show_bug.cgi?id=351078
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IIDHandler.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/LongIDHandler.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/StringIDHandler.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/UUIDHandler.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMappingWithRanges.java72
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategy.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategyWithRanges.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategy.java34
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingMappingStrategyWithRanges.java115
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java38
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2All.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Branching.java4
-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/H2OfflineConfig.java18
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_328352_Test.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_351078_Test.java394
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java263
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java114
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java11
22 files changed, 915 insertions, 217 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IIDHandler.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IIDHandler.java
index 0bbee5d23a..fab707b0f4 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IIDHandler.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IIDHandler.java
@@ -65,6 +65,11 @@ public interface IIDHandler extends Comparator<CDOID>
public void appendCDOID(StringBuilder builder, CDOID id);
+ /**
+ * @since 4.1
+ */
+ public void setCDOIDRaw(PreparedStatement stmt, int column, Object id) throws SQLException;
+
public void setCDOID(PreparedStatement stmt, int column, CDOID id) throws SQLException;
public void setCDOID(PreparedStatement stmt, int column, CDOID id, long commitTime) throws SQLException;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/LongIDHandler.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/LongIDHandler.java
index 79d06158c7..81104c8f45 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/LongIDHandler.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/LongIDHandler.java
@@ -153,6 +153,11 @@ public class LongIDHandler extends Lifecycle implements IIDHandler
builder.append(value);
}
+ public void setCDOIDRaw(PreparedStatement stmt, int column, Object rawID) throws SQLException
+ {
+ stmt.setLong(column, (Long)rawID);
+ }
+
public void setCDOID(PreparedStatement stmt, int column, CDOID id) throws SQLException
{
setCDOID(stmt, column, id, CDOBranchPoint.INVALID_DATE);
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/StringIDHandler.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/StringIDHandler.java
index 803958428d..e75c4e77f3 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/StringIDHandler.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/StringIDHandler.java
@@ -144,6 +144,11 @@ public class StringIDHandler extends Lifecycle implements IIDHandler
builder.append("'");
}
+ public void setCDOIDRaw(PreparedStatement stmt, int column, Object rawID) throws SQLException
+ {
+ stmt.setString(column, (String)rawID);
+ }
+
public void setCDOID(PreparedStatement stmt, int column, CDOID id) throws SQLException
{
setCDOID(stmt, column, id, CDOBranchPoint.INVALID_DATE);
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/UUIDHandler.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/UUIDHandler.java
index 088cf83c62..1df5967a58 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/UUIDHandler.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/UUIDHandler.java
@@ -128,6 +128,11 @@ public class UUIDHandler extends Lifecycle implements IIDHandler
builder.append("'");
}
+ public void setCDOIDRaw(PreparedStatement stmt, int column, Object rawID) throws SQLException
+ {
+ stmt.setString(column, (String)rawID);
+ }
+
public void setCDOID(PreparedStatement stmt, int column, CDOID id) throws SQLException
{
setCDOID(stmt, column, id, CDOBranchPoint.INVALID_DATE);
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
index 7a9cd33b45..6a4a2ca70a 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
@@ -33,6 +33,7 @@ import org.eclipse.emf.cdo.server.internal.db.mapping.AbstractMappingStrategy;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.DBUtil.DeserializeRowHandler;
import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
@@ -195,7 +196,7 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS
for (IDBTable table : listMapping.getDBTables())
{
String listSuffix = ", " + attrTable + " a_t" + attrSuffix;
- String listJoin = getListJoin("a_t", "l_t");
+ String listJoin = getListJoinForRawExport("a_t", "l_t");
if (listJoin != null)
{
listSuffix += listJoin;
@@ -205,6 +206,11 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS
}
}
+ protected String getListJoinForRawExport(String attrTable, String listTable)
+ {
+ return getListJoin(attrTable, listTable);
+ }
+
public void rawImport(IDBStoreAccessor accessor, CDODataInput in, long fromCommitTime, long toCommitTime,
OMMonitor monitor) throws IOException
{
@@ -290,7 +296,7 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS
{
for (IDBTable table : tables)
{
- DBUtil.deserializeTable(in, connection, table, monitor.fork());
+ DBUtil.deserializeTable(in, connection, table, monitor.fork(), getImportListHandler());
}
}
finally
@@ -299,6 +305,12 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS
}
}
+ protected DeserializeRowHandler getImportListHandler()
+ {
+ // Only needed with ranges
+ return null;
+ }
+
public String getListJoin(String attrTable, String listTable)
{
return " AND " + attrTable + "." + CDODBSchema.ATTRIBUTES_ID + "=" + listTable + "." + CDODBSchema.LIST_REVISION_ID;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMappingWithRanges.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMappingWithRanges.java
index f7b056a00b..678813766a 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMappingWithRanges.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMappingWithRanges.java
@@ -762,35 +762,6 @@ public class BranchingListTableMappingWithRanges extends BasicAbstractListTableM
lastIndex = originalRevision.getList(getFeature()).size() - 1;
}
- public void visit(CDOMoveFeatureDelta delta)
- {
- int fromIdx = delta.getOldPosition();
- int toIdx = delta.getNewPosition();
-
- if (TRACER.isEnabled())
- {
- TRACER.format("Delta Moving: {0} to {1}", fromIdx, toIdx); //$NON-NLS-1$
- }
-
- Object value = getValue(accessor, id, branchID, fromIdx, true);
-
- // remove the item
- removeEntry(accessor, id, branchID, oldVersion, newVersion, fromIdx);
-
- // adjust indexes and shift either up or down
- if (fromIdx < toIdx)
- {
- moveOneUp(accessor, id, branchID, oldVersion, newVersion, fromIdx + 1, toIdx);
- }
- else
- { // fromIdx > toIdx here
- moveOneDown(accessor, id, branchID, oldVersion, newVersion, toIdx, fromIdx - 1);
- }
-
- // create the item
- addEntry(accessor, id, branchID, newVersion, toIdx, value);
- }
-
public void visit(CDOAddFeatureDelta delta)
{
int startIndex = delta.getIndex();
@@ -864,11 +835,6 @@ public class BranchingListTableMappingWithRanges extends BasicAbstractListTableM
lastIndex = -1;
}
- public void visit(CDOListFeatureDelta delta)
- {
- throw new ImplementationError("Should not be called"); //$NON-NLS-1$
- }
-
public void visit(CDOClearFeatureDelta delta)
{
if (TRACER.isEnabled())
@@ -880,6 +846,40 @@ public class BranchingListTableMappingWithRanges extends BasicAbstractListTableM
lastIndex = -1;
}
+ public void visit(CDOMoveFeatureDelta delta)
+ {
+ int fromIdx = delta.getOldPosition();
+ int toIdx = delta.getNewPosition();
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Delta Moving: {0} to {1}", fromIdx, toIdx); //$NON-NLS-1$
+ }
+
+ Object value = getValue(accessor, id, branchID, fromIdx, true);
+
+ // remove the item
+ removeEntry(accessor, id, branchID, oldVersion, newVersion, fromIdx);
+
+ // adjust indexes and shift either up or down
+ if (fromIdx < toIdx)
+ {
+ moveOneUp(accessor, id, branchID, oldVersion, newVersion, fromIdx + 1, toIdx);
+ }
+ else
+ { // fromIdx > toIdx here
+ moveOneDown(accessor, id, branchID, oldVersion, newVersion, toIdx, fromIdx - 1);
+ }
+
+ // create the item
+ addEntry(accessor, id, branchID, newVersion, toIdx, value);
+ }
+
+ public void visit(CDOListFeatureDelta delta)
+ {
+ throw new ImplementationError("Should not be called"); //$NON-NLS-1$
+ }
+
public void visit(CDOContainerFeatureDelta delta)
{
throw new ImplementationError("Should not be called"); //$NON-NLS-1$
@@ -1157,7 +1157,7 @@ public class BranchingListTableMappingWithRanges extends BasicAbstractListTableM
try
{
- // try to delete a temporary entry first
+ // Try to delete a temporary entry first
stmt = statementCache.getPreparedStatement(sqlDeleteEntry, ReuseProbability.HIGH);
int column = 1;
@@ -1328,7 +1328,7 @@ public class BranchingListTableMappingWithRanges extends BasicAbstractListTableM
* prefetchDepth
* =
*/
- CDORevision.DEPTH_NONE, true);
+ CDORevision.DEPTH_NONE, true);
IStoreChunkReader chunkReader = accessor.createChunkReader(baseRevision, getFeature());
return chunkReader;
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategy.java
index c9eff1a73d..80617b054a 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditMappingStrategy.java
@@ -65,6 +65,11 @@ public class HorizontalAuditMappingStrategy extends AbstractHorizontalMappingStr
public String getListJoin(String attrTable, String listTable)
{
String join = super.getListJoin(attrTable, listTable);
+ return modifyListJoin(attrTable, listTable, join);
+ }
+
+ protected String modifyListJoin(String attrTable, String listTable, String join)
+ {
join += " AND " + attrTable + "." + CDODBSchema.ATTRIBUTES_VERSION;
join += "=" + listTable + "." + CDODBSchema.LIST_REVISION_VERSION;
return join;
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 93de7d84bb..e91c8f2255 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
@@ -23,22 +23,13 @@ import org.eclipse.emf.ecore.EStructuralFeature;
* @author Eike Stepper
* @since 2.0
*/
-public class HorizontalAuditMappingStrategyWithRanges extends AbstractHorizontalMappingStrategy
+public class HorizontalAuditMappingStrategyWithRanges extends HorizontalAuditMappingStrategy
{
public HorizontalAuditMappingStrategyWithRanges()
{
}
- public boolean hasAuditSupport()
- {
- return true;
- }
-
- public boolean hasBranchingSupport()
- {
- return false;
- }
-
+ @Override
public boolean hasDeltaSupport()
{
return true;
@@ -63,9 +54,8 @@ public class HorizontalAuditMappingStrategyWithRanges extends AbstractHorizontal
}
@Override
- public String getListJoin(String attrTable, String listTable)
+ protected String modifyListJoin(String attrTable, String listTable, String join)
{
- 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;
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 473883b53e..91590916ae 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
@@ -75,6 +75,29 @@ public class HorizontalBranchingMappingStrategy extends AbstractHorizontalMappin
}
@Override
+ public String getListJoin(String attrTable, String listTable)
+ {
+ String join = super.getListJoin(attrTable, listTable);
+ return modifyListJoin(attrTable, listTable, join, false);
+ }
+
+ @Override
+ protected String getListJoinForRawExport(String attrTable, String listTable)
+ {
+ String join = super.getListJoin(attrTable, listTable);
+ return modifyListJoin(attrTable, listTable, join, true);
+ }
+
+ protected String modifyListJoin(String attrTable, String listTable, String join, boolean forRawExport)
+ {
+ join += " AND " + attrTable + "." + CDODBSchema.ATTRIBUTES_VERSION;
+ join += "=" + listTable + "." + CDODBSchema.LIST_REVISION_VERSION;
+ join += " AND " + attrTable + "." + CDODBSchema.ATTRIBUTES_BRANCH;
+ join += "=" + listTable + "." + CDODBSchema.LIST_REVISION_BRANCH;
+ return join;
+ }
+
+ @Override
protected void rawImportReviseOldRevisions(Connection connection, IDBTable table, OMMonitor monitor)
{
String sqlUpdate = "UPDATE " + table + " SET " + CDODBSchema.ATTRIBUTES_REVISED + "=? WHERE "
@@ -182,15 +205,4 @@ public class HorizontalBranchingMappingStrategy extends AbstractHorizontalMappin
monitor.done();
}
}
-
- @Override
- public String getListJoin(String attrTable, String listTable)
- {
- String join = super.getListJoin(attrTable, listTable);
- join += " AND " + attrTable + "." + CDODBSchema.ATTRIBUTES_VERSION;
- join += "=" + listTable + "." + CDODBSchema.LIST_REVISION_VERSION;
- join += " AND " + attrTable + "." + CDODBSchema.ATTRIBUTES_BRANCH;
- join += "=" + listTable + "." + CDODBSchema.LIST_REVISION_BRANCH;
- return join;
- }
}
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 16508c6e0b..ceb36c26e1 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
@@ -12,19 +12,31 @@
*/
package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal;
+import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
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.DBUtil;
+import org.eclipse.net4j.db.DBUtil.DeserializeRowHandler;
+import org.eclipse.net4j.db.ddl.IDBField;
+import org.eclipse.net4j.util.io.ExtendedDataInput;
+
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
/**
* @author Eike Stepper
* @since 2.0
*/
-public class HorizontalBranchingMappingStrategyWithRanges extends AbstractHorizontalMappingStrategy
+public class HorizontalBranchingMappingStrategyWithRanges extends HorizontalBranchingMappingStrategy
{
private boolean copyOnBranch;
@@ -32,16 +44,7 @@ public class HorizontalBranchingMappingStrategyWithRanges extends AbstractHorizo
{
}
- public boolean hasAuditSupport()
- {
- return true;
- }
-
- public boolean hasBranchingSupport()
- {
- return true;
- }
-
+ @Override
public boolean hasDeltaSupport()
{
return true;
@@ -71,20 +74,33 @@ public class HorizontalBranchingMappingStrategyWithRanges extends AbstractHorizo
}
@Override
- public String getListJoin(String attrTable, String listTable)
+ protected String modifyListJoin(String attrTable, String listTable, String join, boolean forRawExport)
{
- 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;
- join += ") AND " + attrTable + "." + CDODBSchema.ATTRIBUTES_BRANCH;
+ if (forRawExport)
+ {
+ join += "=" + attrTable + "." + CDODBSchema.ATTRIBUTES_VERSION;
+ }
+ else
+ {
+ 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 + ")";
+ }
+
+ join += " AND " + attrTable + "." + CDODBSchema.ATTRIBUTES_BRANCH;
join += "=" + listTable + "." + CDODBSchema.LIST_REVISION_BRANCH;
return join;
}
@Override
+ protected DeserializeRowHandler getImportListHandler()
+ {
+ return new ImportListHandler();
+ }
+
+ @Override
protected void doAfterActivate() throws Exception
{
super.doAfterActivate();
@@ -92,4 +108,67 @@ public class HorizontalBranchingMappingStrategyWithRanges extends AbstractHorizo
String value = getProperties().get(CDODBUtil.PROP_COPY_ON_BRANCH);
copyOnBranch = value == null ? false : Boolean.valueOf(value);
}
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class ImportListHandler implements DeserializeRowHandler
+ {
+ private final IIDHandler idHandler = getStore().getIDHandler();
+
+ private PreparedStatement stmt;
+
+ public void handleRow(ExtendedDataInput in, Connection connection, IDBField[] fields, Object[] values)
+ throws SQLException, IOException
+ {
+ int versionAdded = (Integer)values[2];
+ if (versionAdded == CDOBranchVersion.FIRST_VERSION)
+ {
+ return;
+ }
+
+ if (stmt == null)
+ {
+ String sql = "UPDATE " + fields[0].getTable() //
+ + " SET " + CDODBSchema.LIST_REVISION_VERSION_REMOVED + "=?" //
+ + " WHERE " + CDODBSchema.LIST_REVISION_ID + "=?" //
+ + " AND " + CDODBSchema.LIST_REVISION_BRANCH + "=?" //
+ + " AND " + CDODBSchema.LIST_IDX + "=?" //
+ + " AND " + CDODBSchema.LIST_REVISION_VERSION_ADDED + "<?" //
+ + " AND " + CDODBSchema.LIST_REVISION_VERSION_REMOVED + " IS NULL";
+ stmt = connection.prepareStatement(sql);
+ }
+
+ Object sourceID = values[0];
+ int branch = (Integer)values[1];
+ int index = (Integer)values[4];
+
+ stmt.setInt(1, versionAdded);
+ idHandler.setCDOIDRaw(stmt, 2, sourceID);
+ stmt.setInt(3, branch);
+ stmt.setInt(4, index);
+ stmt.setInt(5, versionAdded);
+
+ stmt.addBatch();
+ }
+
+ public void done(boolean successful) throws SQLException, IOException
+ {
+ if (stmt != null)
+ {
+ try
+ {
+ if (successful)
+ {
+ stmt.executeBatch();
+ }
+ }
+ finally
+ {
+ DBUtil.close(stmt);
+ stmt = null;
+ }
+ }
+ }
+ }
}
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 92d96aad20..887b0abf32 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
@@ -682,6 +682,25 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
}
+ public void visit(CDOUnsetFeatureDelta delta)
+ {
+ if (delta.getFeature().isUnsettable())
+ {
+ Assert.isTrue(false);
+ }
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.format(" - unset list"); //$NON-NLS-1$
+ }
+
+ // set the clear-flag
+ clearFirst = true;
+
+ // and also clear all manipulation items
+ manipulations.clear();
+ }
+
public void visit(CDOClearFeatureDelta delta)
{
if (TRACER.isEnabled())
@@ -736,25 +755,6 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
}
- public void visit(CDOUnsetFeatureDelta delta)
- {
- if (delta.getFeature().isUnsettable())
- {
- Assert.isTrue(false);
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.format(" - unset list"); //$NON-NLS-1$
- }
-
- // set the clear-flag
- clearFirst = true;
-
- // and also clear all manipulation items
- manipulations.clear();
- }
-
public void visit(CDOListFeatureDelta delta)
{
// never called
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2All.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2All.java
index 8c9f6e7ce3..1a598a1f88 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2All.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2All.java
@@ -30,7 +30,7 @@ public class AllTestsDBH2All extends DBConfigs
protected void initConfigSuites(TestSuite parent)
{
addScenarios(parent, IDGenerationLocation.STORE);
- addScenarios(parent, IDGenerationLocation.CLIENT);
+ // addScenarios(parent, IDGenerationLocation.CLIENT);
}
private void addScenarios(TestSuite parent, IDGenerationLocation idGenerationLocation)
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Branching.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Branching.java
index f45fba0372..c8cfbdcb30 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Branching.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Branching.java
@@ -28,9 +28,9 @@ public class AllTestsDBH2Branching extends DBConfigs
public static void initConfigSuites(ConfigTestSuite suite, TestSuite parent, IDGenerationLocation idGenerationLocation)
{
- suite.addScenario(parent, COMBINED, new H2Config(true, true, false, false, idGenerationLocation), JVM, NATIVE);
+ // suite.addScenario(parent, COMBINED, new H2Config(true, true, false, false, idGenerationLocation), JVM, NATIVE);
suite.addScenario(parent, COMBINED, new H2Config(true, true, true, false, idGenerationLocation), JVM, NATIVE);
- suite.addScenario(parent, COMBINED, new H2Config(true, true, true, true, idGenerationLocation), JVM, NATIVE);
+ // suite.addScenario(parent, COMBINED, new H2Config(true, true, true, true, idGenerationLocation), JVM, NATIVE);
}
@Override
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 26d0419211..cb782e7730 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,6 +18,7 @@ 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.OfflineLockingTest;
@@ -44,6 +45,7 @@ public class AllTestsDBH2Offline extends DBConfigs
{
addScenario(parent, COMBINED, new H2OfflineConfig(false, false, IDGenerationLocation.STORE), JVM, NATIVE);
addScenario(parent, COMBINED, new H2OfflineConfig(false, false, IDGenerationLocation.CLIENT), JVM, NATIVE);
+ addScenario(parent, COMBINED, new H2OfflineConfig(true, false, IDGenerationLocation.STORE), JVM, NATIVE);
}
@Override
@@ -59,6 +61,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(FailoverTest.class);
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/H2OfflineConfig.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/H2OfflineConfig.java
index ff5a88a14a..51c4d68079 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/H2OfflineConfig.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/H2OfflineConfig.java
@@ -34,6 +34,7 @@ import java.sql.Connection;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
/**
* @author Eike Stepper
@@ -73,6 +74,23 @@ public class H2OfflineConfig extends OfflineConfig
return copyOnBranch;
}
+ @Override
+ public void initCapabilities(Set<String> capabilities)
+ {
+ super.initCapabilities(capabilities);
+ capabilities.add(H2Config.DB_ADAPTER_NAME);
+
+ if (isWithRanges())
+ {
+ capabilities.add(DBConfig.CAPABILITY_RANGES);
+ }
+
+ if (isCopyOnBranch())
+ {
+ capabilities.add(DBConfig.CAPABILITY_COPY_ON_BRANCH);
+ }
+ }
+
public IStore createStore(String repoName)
{
IMappingStrategy mappingStrategy = createMappingStrategy();
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java
index 7f5ed20a7c..3c4ff1343a 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java
@@ -395,7 +395,7 @@ public class Net4jDBTest extends AbstractCDOTest
for (Pair<DBType, Object> column : columns)
{
- column.getElement1().readValue(ins, stmt, c++, false);
+ column.getElement1().readValueWithResult(ins, stmt, c++, false);
}
stmt.executeUpdate();
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java
index 4186b96b2c..7ffa1f1540 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java
@@ -266,8 +266,8 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
props.put(Props.OVERRIDE_UUID, ""); // UUID := name !!!
props.put(Props.SUPPORTING_AUDITS, Boolean.toString(supportingAudits));
props.put(Props.SUPPORTING_BRANCHES, Boolean.toString(supportingBranches));
+ props.put(Props.SUPPORTING_ECORE, "false");
props.put(Props.ID_GENERATION_LOCATION, idGenerationLocation.toString());
-
}
public void registerRepository(final InternalRepository repository)
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_328352_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_328352_Test.java
index 37caf351af..fd451271ed 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_328352_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_328352_Test.java
@@ -45,6 +45,8 @@ public class Bugzilla_328352_Test extends AbstractSyncingTest
private final int NUM_CLIENT_VIEWS = 10;
@Requires(IRepositoryConfig.CAPABILITY_OFFLINE)
+ @Skips("DB.ranges")
+ // Too slow in DB.ranges (11 minutes), see bug 357441
public void testOfflineCloneSynchronization() throws Exception
{
disableConsole();
@@ -126,6 +128,7 @@ public class Bugzilla_328352_Test extends AbstractSyncingTest
System.out.println(MessageFormat.format("## Committing changes on {0} products took: {1}", NUM_PRODUCTS,
System.currentTimeMillis() - start));
+ // session.waitForUpdate(masterTransaction.getLastCommitTime(), 5000);
for (CDOView view : cloneViews)
{
view.waitForUpdate(masterTransaction.getLastCommitTime(), 5000);
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
new file mode 100644
index 0000000000..e000ea9efd
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_351078_Test.java
@@ -0,0 +1,394 @@
+/**
+ * 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.offline;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.spi.server.InternalRepository;
+import org.eclipse.emf.cdo.tests.AbstractSyncingTest;
+import org.eclipse.emf.cdo.tests.config.IRepositoryConfig;
+import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.CleanRepositoriesBefore;
+import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.Requires;
+import org.eclipse.emf.cdo.tests.model1.Category;
+import org.eclipse.emf.cdo.tests.model1.Company;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.trace.PrintTraceHandler;
+
+import org.eclipse.emf.common.util.EList;
+
+/**
+ * Support raw replication in HorizontalBranchingMappingStrategyWithRanges.
+ * <p>
+ * See bug 351078
+ *
+ * @author Eike Stepper
+ */
+@Requires(IRepositoryConfig.CAPABILITY_OFFLINE)
+@CleanRepositoriesBefore
+public class Bugzilla_351078_Test extends AbstractSyncingTest
+{
+ @Override
+ protected boolean isRawReplication()
+ {
+ return true;
+ }
+
+ @Override
+ protected void doSetUp() throws Exception
+ {
+ OMPlatform.INSTANCE.setDebugging(false);
+ OMPlatform.INSTANCE.removeTraceHandler(PrintTraceHandler.CONSOLE);
+ super.doSetUp();
+ }
+
+ public void testDoNothing() throws Exception
+ {
+ run(new CompanyChanger());
+ }
+
+ public void testAddOne_AddOne() throws Exception
+ {
+ run(new CompanyChanger()
+ {
+ @Override
+ public void beforeConnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+ }
+
+ @Override
+ public void beforeReconnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+ }
+ });
+ }
+
+ public void testAddTwo_AddTwo() throws Exception
+ {
+ run(new CompanyChanger()
+ {
+ @Override
+ public void beforeConnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+ }
+
+ @Override
+ public void beforeReconnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+ }
+ });
+ }
+
+ public void testAddThree_MoveFirst() throws Exception
+ {
+ run(new CompanyChanger()
+ {
+ @Override
+ public void beforeConnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.add(getModel1Factory().createCategory());
+ categories.add(getModel1Factory().createCategory());
+ categories.add(getModel1Factory().createCategory());
+ categories.add(getModel1Factory().createCategory());
+ categories.add(getModel1Factory().createCategory());
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+ }
+
+ @Override
+ public void beforeReconnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.move(5, 0);
+ transaction.commit();
+ }
+ });
+ }
+
+ public void testAddThree_MoveLast() throws Exception
+ {
+ run(new CompanyChanger()
+ {
+ @Override
+ public void beforeConnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.add(getModel1Factory().createCategory());
+ categories.add(getModel1Factory().createCategory());
+ categories.add(getModel1Factory().createCategory());
+ categories.add(getModel1Factory().createCategory());
+ categories.add(getModel1Factory().createCategory());
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+ }
+
+ @Override
+ public void beforeReconnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.move(0, 5);
+ transaction.commit();
+ }
+ });
+ }
+
+ public void testAddOne_ReplaceIt() throws Exception
+ {
+ run(new CompanyChanger()
+ {
+ @Override
+ public void beforeConnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+ }
+
+ @Override
+ public void beforeReconnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.set(0, getModel1Factory().createCategory());
+ transaction.commit();
+ }
+ });
+ }
+
+ public void testAddOneAddOne_ReplaceFirst() throws Exception
+ {
+ run(new CompanyChanger()
+ {
+ @Override
+ public void beforeConnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+ }
+
+ @Override
+ public void beforeReconnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.set(0, getModel1Factory().createCategory());
+ transaction.commit();
+ }
+ });
+ }
+
+ public void testAddOneRemoveIt() throws Exception
+ {
+ run(new CompanyChanger()
+ {
+ @Override
+ public void beforeConnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+ }
+
+ @Override
+ public void beforeReconnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.remove(0);
+ transaction.commit();
+ }
+ });
+ }
+
+ public void testAddOneAddOne_RemoveFirst() throws Exception
+ {
+ run(new CompanyChanger()
+ {
+ @Override
+ public void beforeConnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+ }
+
+ @Override
+ public void beforeReconnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.remove(0);
+ transaction.commit();
+ }
+ });
+ }
+
+ public void testAddOneReplaceFirst_ReplaceFirst() throws Exception
+ {
+ run(new CompanyChanger()
+ {
+ @Override
+ public void beforeConnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+
+ categories.set(0, getModel1Factory().createCategory());
+ transaction.commit();
+ }
+
+ @Override
+ public void beforeReconnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.set(0, getModel1Factory().createCategory());
+ transaction.commit();
+ }
+ });
+ }
+
+ public void testAddOneAddOneReplaceFirst_ReplaceFirst() throws Exception
+ {
+ run(new CompanyChanger()
+ {
+ @Override
+ public void beforeConnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+
+ categories.set(0, getModel1Factory().createCategory());
+ transaction.commit();
+ }
+
+ @Override
+ public void beforeReconnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.set(0, getModel1Factory().createCategory());
+ transaction.commit();
+ }
+ });
+ }
+
+ public void testAddAddReplaceAddRmove_ReplaceAdd() throws Exception
+ {
+ run(new CompanyChanger()
+ {
+ @Override
+ public void beforeConnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+
+ categories.set(0, getModel1Factory().createCategory());
+ transaction.commit();
+
+ categories.add(getModel1Factory().createCategory());
+ transaction.commit();
+
+ categories.remove(0);
+ transaction.commit();
+ }
+
+ @Override
+ public void beforeReconnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ categories.set(0, getModel1Factory().createCategory());
+ transaction.commit();
+
+ categories.add(0, getModel1Factory().createCategory());
+ transaction.commit();
+ }
+ });
+ }
+
+ private void run(CompanyChanger changer) throws Exception
+ {
+ // Create master session & transaction.
+ InternalRepository master = getRepository("master");
+ CDOSession masterSession = openSession(master.getName());
+ CDOTransaction masterTransaction = masterSession.openTransaction();
+
+ // Create resource and base model.
+ CDOResource resource = masterTransaction.createResource(getResourcePath("/my/resource"));
+ Company masterCompany = getModel1Factory().createCompany();
+ resource.getContents().add(masterCompany);
+ masterTransaction.commit();
+
+ changer.beforeConnect(masterCompany.getCategories(), masterTransaction);
+
+ // Create an offline clone.
+ InternalRepository clone = getRepository();
+ waitForOnline(clone);
+ sleep(500); // TODO Clarify why waitForOnline() alone is not enough
+
+ // Create client session & transaction.
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+
+ CDOID id = CDOUtil.getCDOObject(masterCompany).cdoID();
+ Company company = (Company)transaction.getObject(id);
+ EList<Category> categories = company.getCategories();
+
+ for (int i = 0; i < masterCompany.getCategories().size(); i++)
+ {
+ CDOObject masterCategory = CDOUtil.getCDOObject(masterCompany.getCategories().get(i));
+ CDOObject category = CDOUtil.getCDOObject(categories.get(i));
+ assertEquals(masterCategory.cdoID(), category.cdoID());
+ }
+
+ getOfflineConfig().stopMasterTransport();
+ waitForOffline(clone);
+ sleep(500);
+
+ changer.beforeReconnect(masterCompany.getCategories(), masterTransaction);
+
+ getOfflineConfig().startMasterTransport();
+ waitForOnline(clone);
+ sleep(500);
+
+ for (int i = 0; i < masterCompany.getCategories().size(); i++)
+ {
+ CDOObject masterCategory = CDOUtil.getCDOObject(masterCompany.getCategories().get(i));
+ CDOObject category = CDOUtil.getCDOObject(categories.get(i));
+ assertEquals("Element " + i, masterCategory.cdoID(), category.cdoID());
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static class CompanyChanger
+ {
+ public void beforeConnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ }
+
+ public void beforeReconnect(EList<Category> categories, CDOTransaction transaction) throws Exception
+ {
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java
index 47a385f54c..2413abae63 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java
@@ -37,41 +37,41 @@ public enum DBType
BOOLEAN(16)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
- writeValueBoolean(out, resultSet, column, canBeNull);
+ return writeValueBoolean(out, resultSet, column, canBeNull);
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
- readValueBoolean(in, statement, column, canBeNull, getCode());
+ return readValueBoolean(in, statement, column, canBeNull, getCode());
}
},
BIT(-7)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
- writeValueBoolean(out, resultSet, column, canBeNull);
+ return writeValueBoolean(out, resultSet, column, canBeNull);
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
- readValueBoolean(in, statement, column, canBeNull, getCode());
+ return readValueBoolean(in, statement, column, canBeNull, getCode());
}
},
TINYINT(-6)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
byte value = resultSet.getByte(column);
@@ -80,34 +80,36 @@ public enum DBType
if (resultSet.wasNull())
{
out.writeBoolean(false);
- return;
+ return null;
}
out.writeBoolean(true);
}
out.writeByte(value);
+ return value;
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
if (canBeNull && !in.readBoolean())
{
statement.setNull(column, getCode());
- return;
+ return null;
}
byte value = in.readByte();
statement.setByte(column, value);
+ return value;
}
},
SMALLINT(5)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
short value = resultSet.getShort(column);
@@ -116,34 +118,36 @@ public enum DBType
if (resultSet.wasNull())
{
out.writeBoolean(false);
- return;
+ return null;
}
out.writeBoolean(true);
}
out.writeShort(value);
+ return value;
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
if (canBeNull && !in.readBoolean())
{
statement.setNull(column, getCode());
- return;
+ return null;
}
short value = in.readShort();
statement.setShort(column, value);
+ return value;
}
},
INTEGER(4)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
int value = resultSet.getInt(column);
@@ -152,34 +156,36 @@ public enum DBType
if (resultSet.wasNull())
{
out.writeBoolean(false);
- return;
+ return null;
}
out.writeBoolean(true);
}
out.writeInt(value);
+ return value;
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
if (canBeNull && !in.readBoolean())
{
statement.setNull(column, getCode());
- return;
+ return null;
}
int value = in.readInt();
statement.setInt(column, value);
+ return value;
}
},
BIGINT(-5)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
long value = resultSet.getLong(column);
@@ -188,34 +194,36 @@ public enum DBType
if (resultSet.wasNull())
{
out.writeBoolean(false);
- return;
+ return null;
}
out.writeBoolean(true);
}
out.writeLong(value);
+ return value;
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
if (canBeNull && !in.readBoolean())
{
statement.setNull(column, getCode());
- return;
+ return null;
}
long value = in.readLong();
statement.setLong(column, value);
+ return value;
}
},
FLOAT(6)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
float value = resultSet.getFloat(column);
@@ -224,34 +232,36 @@ public enum DBType
if (resultSet.wasNull())
{
out.writeBoolean(false);
- return;
+ return null;
}
out.writeBoolean(true);
}
out.writeFloat(value);
+ return value;
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
if (canBeNull && !in.readBoolean())
{
statement.setNull(column, getCode());
- return;
+ return null;
}
float value = in.readFloat();
statement.setFloat(column, value);
+ return value;
}
},
REAL(7)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
float value = resultSet.getFloat(column);
@@ -260,34 +270,36 @@ public enum DBType
if (resultSet.wasNull())
{
out.writeBoolean(false);
- return;
+ return null;
}
out.writeBoolean(true);
}
out.writeFloat(value);
+ return value;
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
if (canBeNull && !in.readBoolean())
{
statement.setNull(column, getCode());
- return;
+ return null;
}
float value = in.readFloat();
statement.setFloat(column, value);
+ return value;
}
},
DOUBLE(8)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
double value = resultSet.getDouble(column);
@@ -296,34 +308,36 @@ public enum DBType
if (resultSet.wasNull())
{
out.writeBoolean(false);
- return;
+ return null;
}
out.writeBoolean(true);
}
out.writeDouble(value);
+ return value;
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
if (canBeNull && !in.readBoolean())
{
statement.setNull(column, getCode());
- return;
+ return null;
}
double value = in.readDouble();
statement.setDouble(column, value);
+ return value;
}
},
NUMERIC(2)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
throw new UnsupportedOperationException("SQL NULL has to be considered");
@@ -337,7 +351,7 @@ public enum DBType
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
throw new UnsupportedOperationException("SQL NULL has to be considered");
@@ -354,7 +368,7 @@ public enum DBType
DECIMAL(3)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
throw new UnsupportedOperationException("SQL NULL has to be considered");
@@ -368,7 +382,7 @@ public enum DBType
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
throw new UnsupportedOperationException("SQL NULL has to be considered");
@@ -384,64 +398,70 @@ public enum DBType
CHAR(1)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
String value = resultSet.getString(column);
out.writeString(value);
+ return value;
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
String value = in.readString();
statement.setString(column, value);
+ return value;
}
},
VARCHAR(12)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
String value = resultSet.getString(column);
out.writeString(value);
+ return value;
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
String value = in.readString();
statement.setString(column, value);
+ return value;
}
},
LONGVARCHAR(-1, "LONG VARCHAR") //$NON-NLS-1$
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
String value = resultSet.getString(column);
out.writeString(value);
+ return value;
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
String value = in.readString();
statement.setString(column, value);
+ return value;
}
},
CLOB(2005)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
Clob value = resultSet.getClob(column);
@@ -450,7 +470,7 @@ public enum DBType
if (resultSet.wasNull())
{
out.writeBoolean(false);
- return;
+ return null;
}
out.writeBoolean(true);
@@ -472,16 +492,18 @@ public enum DBType
{
IOUtil.close(reader);
}
+
+ return null;
}
@Override
- public void readValue(final ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
- throws SQLException, IOException
+ public Object readValueWithResult(final ExtendedDataInput in, PreparedStatement statement, int column,
+ boolean canBeNull) throws SQLException, IOException
{
if (canBeNull && !in.readBoolean())
{
statement.setNull(column, getCode());
- return;
+ return null;
}
Reader reader;
@@ -537,13 +559,14 @@ public enum DBType
statement.setCharacterStream(column, reader, (int)length);
reader.close();
+ return null;
}
},
DATE(91)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
java.sql.Date value = resultSet.getDate(column);
@@ -552,34 +575,37 @@ public enum DBType
if (resultSet.wasNull())
{
out.writeBoolean(false);
- return;
+ return null;
}
out.writeBoolean(true);
}
- out.writeLong(value.getTime());
+ long longValue = value.getTime();
+ out.writeLong(longValue);
+ return longValue;
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
if (canBeNull && !in.readBoolean())
{
statement.setNull(column, getCode());
- return;
+ return null;
}
long value = in.readLong();
statement.setDate(column, new java.sql.Date(value));
+ return value;
}
},
TIME(92)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
java.sql.Time value = resultSet.getTime(column);
@@ -588,34 +614,37 @@ public enum DBType
if (resultSet.wasNull())
{
out.writeBoolean(false);
- return;
+ return null;
}
out.writeBoolean(true);
}
- out.writeLong(value.getTime());
+ long longValue = value.getTime();
+ out.writeLong(longValue);
+ return longValue;
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
if (canBeNull && !in.readBoolean())
{
statement.setNull(column, getCode());
- return;
+ return null;
}
long value = in.readLong();
statement.setTime(column, new java.sql.Time(value));
+ return value;
}
},
TIMESTAMP(93)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
java.sql.Timestamp value = resultSet.getTimestamp(column);
@@ -624,7 +653,7 @@ public enum DBType
if (resultSet.wasNull())
{
out.writeBoolean(false);
- return;
+ return null;
}
out.writeBoolean(true);
@@ -632,16 +661,17 @@ public enum DBType
out.writeLong(value.getTime());
out.writeInt(value.getNanos());
+ return value;
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
if (canBeNull && !in.readBoolean())
{
statement.setNull(column, getCode());
- return;
+ return null;
}
long value = in.readLong();
@@ -649,13 +679,14 @@ public enum DBType
java.sql.Timestamp timeStamp = new java.sql.Timestamp(value);
timeStamp.setNanos(nanos);
statement.setTimestamp(column, timeStamp);
+ return timeStamp;
}
},
BINARY(-2)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
byte[] value = resultSet.getBytes(column);
@@ -664,7 +695,7 @@ public enum DBType
if (resultSet.wasNull())
{
out.writeBoolean(false);
- return;
+ return null;
}
out.writeBoolean(true);
@@ -672,27 +703,29 @@ public enum DBType
out.writeInt(value.length);
out.write(value);
+ return value;
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
if (canBeNull && !in.readBoolean())
{
statement.setNull(column, getCode());
- return;
+ return null;
}
byte[] value = in.readByteArray();
statement.setBytes(column, value);
+ return value;
}
},
VARBINARY(-3)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
byte[] value = resultSet.getBytes(column);
@@ -701,7 +734,7 @@ public enum DBType
if (resultSet.wasNull())
{
out.writeBoolean(false);
- return;
+ return null;
}
out.writeBoolean(true);
@@ -709,27 +742,29 @@ public enum DBType
out.writeInt(value.length);
out.write(value);
+ return value;
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
if (canBeNull && !in.readBoolean())
{
statement.setNull(column, getCode());
- return;
+ return null;
}
byte[] value = in.readByteArray();
statement.setBytes(column, value);
+ return value;
}
},
LONGVARBINARY(-4, "LONG VARBINARY") //$NON-NLS-1$
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
byte[] value = resultSet.getBytes(column);
@@ -738,7 +773,7 @@ public enum DBType
if (resultSet.wasNull())
{
out.writeBoolean(false);
- return;
+ return null;
}
out.writeBoolean(true);
@@ -746,27 +781,29 @@ public enum DBType
out.writeInt(value.length);
out.write(value);
+ return value;
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ public Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
throws SQLException, IOException
{
if (canBeNull && !in.readBoolean())
{
statement.setNull(column, getCode());
- return;
+ return null;
}
byte[] value = in.readByteArray();
statement.setBytes(column, value);
+ return value;
}
},
BLOB(2004)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
Blob value = resultSet.getBlob(column);
@@ -775,7 +812,7 @@ public enum DBType
if (resultSet.wasNull())
{
out.writeBoolean(false);
- return;
+ return null;
}
out.writeBoolean(true);
@@ -797,16 +834,18 @@ public enum DBType
{
IOUtil.close(stream);
}
+
+ return null;
}
@Override
- public void readValue(final ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
- throws SQLException, IOException
+ public Object readValueWithResult(final ExtendedDataInput in, PreparedStatement statement, int column,
+ boolean canBeNull) throws SQLException, IOException
{
if (canBeNull && !in.readBoolean())
{
statement.setNull(column, getCode());
- return;
+ return null;
}
long length = in.readLong();
@@ -836,6 +875,8 @@ public enum DBType
{
IOUtil.close(value);
}
+
+ return null;
}
};
@@ -879,16 +920,34 @@ public enum DBType
/**
* @since 3.0
*/
- public abstract void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
+ {
+ writeValueWithResult(out, resultSet, column, canBeNull);
+ }
+
+ /**
+ * @since 4.1
+ */
+ public abstract Object writeValueWithResult(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException;
/**
* @since 3.0
*/
- public abstract void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
- throws SQLException, IOException;
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
+ {
+ readValueWithResult(in, statement, column, canBeNull);
+ }
+
+ /**
+ * @since 4.1
+ */
+ public abstract Object readValueWithResult(ExtendedDataInput in, PreparedStatement statement, int column,
+ boolean canBeNull) throws SQLException, IOException;
- private static void writeValueBoolean(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ private static Boolean writeValueBoolean(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
throws SQLException, IOException
{
boolean value = resultSet.getBoolean(column);
@@ -897,19 +956,18 @@ public enum DBType
if (resultSet.wasNull())
{
out.writeByte(BOOLEAN_NULL);
+ return null;
}
- else
- {
- out.writeByte(value ? BOOLEAN_TRUE : BOOLEAN_FALSE);
- }
- }
- else
- {
- out.writeBoolean(value);
+
+ out.writeByte(value ? BOOLEAN_TRUE : BOOLEAN_FALSE);
+ return value;
}
+
+ out.writeBoolean(value);
+ return value;
}
- private static void readValueBoolean(ExtendedDataInput in, PreparedStatement statement, int column,
+ private static Boolean readValueBoolean(ExtendedDataInput in, PreparedStatement statement, int column,
boolean canBeNull, int sqlType) throws IOException, SQLException
{
if (canBeNull)
@@ -919,25 +977,24 @@ public enum DBType
{
case BOOLEAN_NULL:
statement.setNull(column, sqlType);
- break;
+ return null;
case BOOLEAN_FALSE:
statement.setBoolean(column, false);
- break;
+ return false;
case BOOLEAN_TRUE:
statement.setBoolean(column, true);
- break;
+ return true;
default:
throw new IOException("Invalid boolean opcode: " + opcode);
}
}
- else
- {
- boolean value = in.readBoolean();
- statement.setBoolean(column, value);
- }
+
+ boolean value = in.readBoolean();
+ statement.setBoolean(column, value);
+ return value;
}
/**
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
index e19f028f0b..acebe265bf 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
@@ -766,6 +766,15 @@ public final class DBUtil
public static void serializeTable(ExtendedDataOutput out, Connection connection, IDBTable table, String tableAlias,
String sqlSuffix) throws DBException, IOException
{
+ serializeTable(out, connection, table, tableAlias, sqlSuffix, null);
+ }
+
+ /**
+ * @since 4.1
+ */
+ public static void serializeTable(ExtendedDataOutput out, Connection connection, IDBTable table, String tableAlias,
+ String sqlSuffix, SerializeRowHandler handler) throws DBException, IOException
+ {
IDBField[] fields = table.getFields();
StringBuilder builder = new StringBuilder();
@@ -802,6 +811,7 @@ public final class DBUtil
String sql = trace(builder.toString());
Statement statement = null;
ResultSet resultSet = null;
+ boolean successful = false;
try
{
@@ -819,6 +829,8 @@ public final class DBUtil
return;
}
+ Object[] values = handler != null ? new Object[fields.length] : null;
+
while (resultSet.next())
{
for (int i = 0; i < fields.length; i++)
@@ -826,9 +838,21 @@ public final class DBUtil
IDBField field = fields[i];
DBType type = field.getType();
boolean canBeNull = !field.isNotNull();
- type.writeValue(out, resultSet, i + 1, canBeNull);
+
+ Object value = type.writeValueWithResult(out, resultSet, i + 1, canBeNull);
+ if (values != null)
+ {
+ values[i] = value;
+ }
+ }
+
+ if (handler != null)
+ {
+ handler.handleRow(out, connection, fields, values);
}
}
+
+ successful = true;
}
catch (SQLException ex)
{
@@ -845,7 +869,21 @@ public final class DBUtil
}
finally
{
- close(statement);
+ try
+ {
+ if (handler != null)
+ {
+ handler.done(successful);
+ }
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ close(statement);
+ }
}
}
@@ -855,6 +893,15 @@ public final class DBUtil
public static void deserializeTable(ExtendedDataInput in, Connection connection, IDBTable table, OMMonitor monitor)
throws IOException
{
+ deserializeTable(in, connection, table, monitor, null);
+ }
+
+ /**
+ * @since 4.1
+ */
+ public static void deserializeTable(ExtendedDataInput in, Connection connection, IDBTable table, OMMonitor monitor,
+ DeserializeRowHandler handler) throws IOException
+ {
int size = in.readInt();
if (size == 0)
{
@@ -888,6 +935,7 @@ public final class DBUtil
String sql = trace(builder.toString());
PreparedStatement statement = null;
+ boolean successful = false;
monitor.begin(1 + 2 * size);
@@ -896,6 +944,8 @@ public final class DBUtil
statement = connection.prepareStatement(sql);
monitor.worked();
+ Object[] values = handler != null ? new Object[fields.length] : null;
+
for (int row = 0; row < size; row++)
{
for (int i = 0; i < fields.length; i++)
@@ -903,10 +953,19 @@ public final class DBUtil
IDBField field = fields[i];
DBType type = field.getType();
boolean canBeNull = !field.isNotNull();
- type.readValue(in, statement, i + 1, canBeNull);
+ Object value = type.readValueWithResult(in, statement, i + 1, canBeNull);
+ if (values != null)
+ {
+ values[i] = value;
+ }
}
statement.addBatch();
+ if (handler != null)
+ {
+ handler.handleRow(in, connection, fields, values);
+ }
+
monitor.worked();
}
@@ -920,6 +979,8 @@ public final class DBUtil
{
async.stop();
}
+
+ successful = true;
}
catch (SQLException ex)
{
@@ -927,8 +988,22 @@ public final class DBUtil
}
finally
{
- close(statement);
- monitor.done();
+ try
+ {
+ if (handler != null)
+ {
+ handler.done(successful);
+ }
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ close(statement);
+ monitor.done();
+ }
}
}
@@ -944,4 +1019,33 @@ public final class DBUtil
return sql;
}
+
+ /**
+ * @author Eike Stepper
+ * @since 4.1
+ */
+ public interface RowHandler
+ {
+ public void done(boolean successful) throws SQLException, IOException;
+ }
+
+ /**
+ * @author Eike Stepper
+ * @since 4.1
+ */
+ public interface SerializeRowHandler extends RowHandler
+ {
+ public void handleRow(ExtendedDataOutput out, Connection connection, IDBField[] fields, Object[] values)
+ throws SQLException, IOException;
+ }
+
+ /**
+ * @author Eike Stepper
+ * @since 4.1
+ */
+ public interface DeserializeRowHandler extends RowHandler
+ {
+ public void handleRow(ExtendedDataInput in, Connection connection, IDBField[] fields, Object[] values)
+ throws SQLException, IOException;
+ }
}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java
index c9c007a899..e9dbbce7a5 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java
@@ -143,7 +143,11 @@ public abstract class AbstractOMTest extends TestCase
testName = getClass().getName() + "." + getName() + "()";
codeLink = null;
+ PrintTraceHandler.CONSOLE.setShortContext(true);
+ OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
+ OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
enableConsole();
+
if (!SUPPRESS_OUTPUT)
{
IOUtil.OUT().println("*******************************************************"); //$NON-NLS-1$
@@ -287,9 +291,6 @@ public abstract class AbstractOMTest extends TestCase
{
if (!SUPPRESS_OUTPUT)
{
- PrintTraceHandler.CONSOLE.setShortContext(true);
- OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
- OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
OMPlatform.INSTANCE.setDebugging(true);
consoleEnabled = true;
}
@@ -301,8 +302,8 @@ public abstract class AbstractOMTest extends TestCase
{
consoleEnabled = false;
OMPlatform.INSTANCE.setDebugging(false);
- OMPlatform.INSTANCE.removeTraceHandler(PrintTraceHandler.CONSOLE);
- OMPlatform.INSTANCE.removeLogHandler(PrintLogHandler.CONSOLE);
+ // OMPlatform.INSTANCE.removeTraceHandler(PrintTraceHandler.CONSOLE);
+ // OMPlatform.INSTANCE.removeLogHandler(PrintLogHandler.CONSOLE);
}
}

Back to the top