diff options
author | Egidijus Vaishnora | 2011-07-08 15:04:33 +0000 |
---|---|---|
committer | Egidijus Vaishnora | 2011-07-08 15:04:33 +0000 |
commit | 8bbdb7bdc2e42bd43ebed5834b86f586a9ecd732 (patch) | |
tree | 3182210d9ef236214e76dfa92ba265bc9696066e | |
parent | a4a75cb10703c987fcfc583eddc1607717508c0b (diff) | |
download | cdo-8bbdb7bdc2e42bd43ebed5834b86f586a9ecd732.tar.gz cdo-8bbdb7bdc2e42bd43ebed5834b86f586a9ecd732.tar.xz cdo-8bbdb7bdc2e42bd43ebed5834b86f586a9ecd732.zip |
351200: [DB][Derby] Adding two blobs at the same time, derby throws exception
https://bugs.eclipse.org/bugs/show_bug.cgi?id=351200
4 files changed, 210 insertions, 2 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/LimitedInputStream.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/LimitedInputStream.java new file mode 100644 index 0000000000..1bff17c5bc --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/LimitedInputStream.java @@ -0,0 +1,101 @@ +package org.eclipse.emf.cdo.internal.server; + +import java.io.IOException; +import java.io.InputStream; + +/** + * @author Eike Stepper + */ +public class LimitedInputStream extends InputStream +{ + private InputStream in; + + private long remaining; + + private long remainingAtMark = 0; + + public LimitedInputStream(InputStream in, long length) + { + this.in = in; + remaining = length; + } + + @Override + public int read() throws IOException + { + if ((remaining -= 1) < 0) + { + return -1; + } + + return in.read(); + } + + @Override + public int read(byte[] cbuf, int off, int len) throws IOException + { + if (remaining <= 0) + { + return -1; + } + + if (len > remaining) + { + len = (int)remaining; + } + + len = in.read(cbuf, off, len); + if (len > 0) + { + remaining -= len; + } + else + { + remaining -= remaining; + } + + return len; + } + + @Override + public long skip(long n) throws IOException + { + if (n > remaining) + { + n = remaining; + } + + remaining -= n = in.skip(n); + return n; + } + + @Override + public boolean markSupported() + { + return in.markSupported(); + } + + @Override + public synchronized void mark(int readlimit) + { + if (markSupported()) + { + in.mark(readlimit); + remainingAtMark = remaining; + } + } + + @Override + public synchronized void reset() throws IOException + { + in.reset(); + remaining = remainingAtMark; + } + + @Override + public void close() throws IOException + { + remaining = 0; + in.close(); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreAccessor.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreAccessor.java index 5625d151d7..67108d94f3 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreAccessor.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreAccessor.java @@ -14,6 +14,7 @@ package org.eclipse.emf.cdo.spi.server; import org.eclipse.emf.cdo.common.branch.CDOBranch; import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.internal.server.LimitedInputStream; import org.eclipse.emf.cdo.server.ISession; import org.eclipse.emf.cdo.server.IStore; import org.eclipse.emf.cdo.server.ITransaction; @@ -112,11 +113,11 @@ public abstract class StoreAccessor extends StoreAccessorBase long size = in.readLong(); if (size > 0) { - writeBlob(id, size, in); + writeBlob(id, size, new LimitedInputStream(in, size)); } else { - writeClob(id, -size, new InputStreamReader(in)); + writeClob(id, -size, new InputStreamReader(new LimitedInputStream(in, -size))); } } } 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 250f2ea4a6..379d496a33 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 @@ -230,5 +230,6 @@ public abstract class AllConfigs extends ConfigTestSuite testClasses.add(Bugzilla_343471_Test.class); testClasses.add(Bugzilla_351195_Test.class); testClasses.add(Bugzilla_351198_Test.class); + testClasses.add(Bugzilla_351200_Test.class); } } diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_351200_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_351200_Test.java new file mode 100644 index 0000000000..494d3606f2 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_351200_Test.java @@ -0,0 +1,105 @@ +/** + * 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.common.lob.CDOClob; +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.File; +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.ByteArrayInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; + +/** + * @author Egidijus Vaisnora + */ +public class Bugzilla_351200_Test extends AbstractCDOTest +{ + public void testCommit2Blob() 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); + + inputStream = new ByteArrayInputStream("Just another stream".getBytes()); + blob = new CDOBlob(inputStream); + + image = getModel3Factory().createImage(); + image.setWidth(320); + image.setHeight(200); + image.setData(blob); + + resource.getContents().add(image); + + transaction.commit(); + } + finally + { + IOUtil.close(inputStream); + } + } + + public void testCommit2Clob() 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"); + CDOClob clob = new CDOClob(new InputStreamReader(inputStream)); + File file = getModel3Factory().createFile(); + file.setName("copyright.txt"); + file.setData(clob); + + resource.getContents().add(file); + + inputStream = new ByteArrayInputStream("Just another stream".getBytes()); + clob = new CDOClob(new InputStreamReader(inputStream)); + file = getModel3Factory().createFile(); + file.setName("xxx.txt"); + file.setData(clob); + + resource.getContents().add(file); + + transaction.commit(); + } + finally + { + IOUtil.close(inputStream); + } + } +}
\ No newline at end of file |