summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEgidijus Vaishnora2011-07-08 11:09:56 (EDT)
committerEgidijus Vaishnora2011-07-08 11:09:56 (EDT)
commit9b23d1939c2cf0ceaebb4519483d0030a6d8f6b1 (patch)
treea48e1773c93c9f23c93448f2e27d4ff8a9271d4f
parent8bbdb7bdc2e42bd43ebed5834b86f586a9ecd732 (diff)
downloadcdo-9b23d1939c2cf0ceaebb4519483d0030a6d8f6b1.zip
cdo-9b23d1939c2cf0ceaebb4519483d0030a6d8f6b1.tar.gz
cdo-9b23d1939c2cf0ceaebb4519483d0030a6d8f6b1.tar.bz2
351202: Exception adding the same Blob data
https://bugs.eclipse.org/bugs/show_bug.cgi?id=351202
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_351202_Test.java75
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/ByteArrayWrapper.java77
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java12
5 files changed, 160 insertions, 7 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java
index 6afe13c..5685062 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java
@@ -809,7 +809,7 @@ public class MEMStore extends LongIDStore implements IMEMStore, BranchLoader, Du
{
byte[] id = it.next();
String key = HexUtil.bytesToHex(id);
- if (lobs.containsKey(key))
+ if (!lobs.containsKey(key))
{
it.remove();
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
index 379d496..180f90c 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
@@ -231,5 +231,6 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_351195_Test.class);
testClasses.add(Bugzilla_351198_Test.class);
testClasses.add(Bugzilla_351200_Test.class);
+ testClasses.add(Bugzilla_351202_Test.class);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_351202_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_351202_Test.java
new file mode 100644
index 0000000..a0e8b04
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_351202_Test.java
@@ -0,0 +1,75 @@
+/**
+ * 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.bugzilla;
+
+import org.eclipse.emf.cdo.common.lob.CDOBlob;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.bundle.OM;
+import org.eclipse.emf.cdo.tests.model3.Image;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+
+import org.eclipse.net4j.util.io.IOUtil;
+
+import java.io.InputStream;
+
+/**
+ * @author Egidijus Vaisnora
+ */
+public class Bugzilla_351202_Test extends AbstractCDOTest
+{
+ public void testCommitBlob() throws Exception
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("res"));
+
+ InputStream inputStream = null;
+
+ try
+ {
+ inputStream = OM.BUNDLE.getInputStream("copyright.txt");
+ CDOBlob blob = new CDOBlob(inputStream);
+
+ Image image = getModel3Factory().createImage();
+ image.setWidth(320);
+ image.setHeight(200);
+ image.setData(blob);
+
+ resource.getContents().add(image);
+
+ transaction.commit();
+ }
+ finally
+ {
+ IOUtil.close(inputStream);
+ }
+
+ try
+ {
+ inputStream = OM.BUNDLE.getInputStream("copyright.txt");
+ CDOBlob blob = new CDOBlob(inputStream);
+
+ Image image = getModel3Factory().createImage();
+ image.setWidth(320);
+ image.setHeight(200);
+ image.setData(blob);
+ resource.getContents().add(image);
+
+ transaction.commit();
+ }
+ finally
+ {
+ IOUtil.close(inputStream);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/ByteArrayWrapper.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/ByteArrayWrapper.java
new file mode 100644
index 0000000..a9f5fe0
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/ByteArrayWrapper.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.internal.cdo.transaction;
+
+import org.eclipse.net4j.util.CheckUtil;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Starting with 4.1 use org.eclipse.net4j.util.collection.ByteArrayWrapper!
+ *
+ * @author Eike Stepper
+ */
+public final class ByteArrayWrapper
+{
+ private final byte[] data;
+
+ public ByteArrayWrapper(byte[] data)
+ {
+ CheckUtil.checkArg(data, "data");
+ this.data = data;
+ }
+
+ public byte[] getData()
+ {
+ return data;
+ }
+
+ @Override
+ public boolean equals(Object other)
+ {
+ if (other instanceof ByteArrayWrapper)
+ {
+ return Arrays.equals(data, ((ByteArrayWrapper)other).data);
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Arrays.hashCode(data);
+ }
+
+ @Override
+ public String toString()
+ {
+ return data.toString();
+ }
+
+ public static Set<byte[]> toByteArray(Set<ByteArrayWrapper> wrappers)
+ {
+ if (wrappers == null)
+ {
+ return null;
+ }
+
+ Set<byte[]> result = new HashSet<byte[]>();
+ for (ByteArrayWrapper wrapper : wrappers)
+ {
+ result.add(wrapper.getData());
+ }
+
+ return result;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
index 4446f30..3ef76dd 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
@@ -2262,7 +2262,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
*/
private boolean isPartialCommit;
- private Map<byte[], CDOLob<?>> lobs = new HashMap<byte[], CDOLob<?>>();
+ private Map<ByteArrayWrapper, CDOLob<?>> lobs = new HashMap<ByteArrayWrapper, CDOLob<?>>();
public CDOCommitContextImpl(InternalCDOTransaction transaction)
{
@@ -2425,11 +2425,11 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
if (!lobs.isEmpty())
{
CDOSessionProtocol sessionProtocol = getSession().getSessionProtocol();
- List<byte[]> alreadyKnown = sessionProtocol.queryLobs(lobs.keySet());
+ List<byte[]> alreadyKnown = sessionProtocol.queryLobs(ByteArrayWrapper.toByteArray(lobs.keySet()));
for (byte[] id : alreadyKnown)
{
- lobs.remove(id);
+ lobs.remove(new ByteArrayWrapper(id));
}
}
}
@@ -2563,7 +2563,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
return commitInfoManager.createCommitInfo(branch, timeStamp, previousTimeStamp, userID, comment, commitData);
}
- private void preCommit(Map<CDOID, CDOObject> objects, Map<byte[], CDOLob<?>> lobs)
+ private void preCommit(Map<CDOID, CDOObject> objects, Map<ByteArrayWrapper, CDOLob<?>> lobs)
{
if (!objects.isEmpty())
{
@@ -2581,7 +2581,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
}
}
- private void collectLobs(InternalCDORevision revision, Map<byte[], CDOLob<?>> lobs)
+ private void collectLobs(InternalCDORevision revision, Map<ByteArrayWrapper, CDOLob<?>> lobs)
{
EStructuralFeature[] features = revision.getClassInfo().getAllPersistentFeatures();
for (int i = 0; i < features.length; i++)
@@ -2592,7 +2592,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
CDOLob<?> lob = (CDOLob<?>)revision.getValue(feature);
if (lob != null)
{
- lobs.put(lob.getID(), lob);
+ lobs.put(new ByteArrayWrapper(lob.getID()), lob);
}
}
}