diff options
author | Eike Stepper | 2012-05-03 12:07:17 +0000 |
---|---|---|
committer | Stefan Winkler | 2012-05-03 12:07:17 +0000 |
commit | 10f1b0c0e6929b50bc818c609736a6c48ddc8601 (patch) | |
tree | f26fb08bf333c1fd0525d18260435efa6220dde6 | |
parent | 1962c1f5fb57cecb27c26955ef1dd0eadbc524ce (diff) | |
download | cdo-10f1b0c0e6929b50bc818c609736a6c48ddc8601.tar.gz cdo-10f1b0c0e6929b50bc818c609736a6c48ddc8601.tar.xz cdo-10f1b0c0e6929b50bc818c609736a6c48ddc8601.zip |
[377727] [DB] rawReplication of BLOB in mySQL wrong
https://bugs.eclipse.org/bugs/show_bug.cgi?id=377727
Write LOBs to file to buffer them.
3 files changed, 69 insertions, 46 deletions
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 683c91576c..82673f0bd9 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 @@ -14,11 +14,17 @@ package org.eclipse.net4j.db; import org.eclipse.net4j.util.io.ExtendedDataInput;
import org.eclipse.net4j.util.io.ExtendedDataOutput;
import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.io.TMPUtil;
import java.io.ByteArrayInputStream;
-import java.io.EOFException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.Reader;
import java.sql.Blob;
import java.sql.Clob;
@@ -28,7 +34,7 @@ import java.sql.SQLException; /**
* Enumerates the SQL data types that are compatible with the DB framework.
- *
+ *
* @author Eike Stepper
* @noextend This interface is not intended to be extended by clients.
*/
@@ -511,34 +517,7 @@ public enum DBType long length = in.readLong();
if (length > 0)
{
- reader = new Reader()
- {
- @Override
- public int read(char[] cbuf, int off, int len) throws IOException
- {
- int read = 0;
-
- try
- {
- while (read < len)
- {
- cbuf[off++] = in.readChar();
- read++;
- }
- }
- catch (EOFException ex)
- {
- read = -1;
- }
-
- return read;
- }
-
- @Override
- public void close() throws IOException
- {
- }
- };
+ reader = createFileReader(in, length);
}
else
{
@@ -553,6 +532,7 @@ public enum DBType @Override
public void close() throws IOException
{
+ // Do nothing
}
};
}
@@ -561,6 +541,34 @@ public enum DBType reader.close();
return null;
}
+
+ private FileReader createFileReader(final ExtendedDataInput in, long length) throws IOException
+ {
+ FileWriter fw = null;
+
+ try
+ {
+ final File tempFile = TMPUtil.createTempFile("lob-", ".tmp");
+ tempFile.deleteOnExit();
+
+ fw = new FileWriter(tempFile);
+ IOUtil.copyCharacter(new InputStreamReader(new ExtendedDataInput.Stream(in)), fw, length);
+
+ return new FileReader(tempFile)
+ {
+ @Override
+ public void close() throws IOException
+ {
+ super.close();
+ tempFile.delete();
+ }
+ };
+ }
+ finally
+ {
+ IOUtil.close(fw);
+ }
+ }
},
DATE(91)
@@ -824,11 +832,7 @@ public enum DBType try
{
out.writeLong(length);
- while (length-- > 0)
- {
- int b = stream.read();
- out.writeByte(b + Byte.MIN_VALUE);
- }
+ IOUtil.copyBinary(stream, new ExtendedDataOutput.Stream(out), length);
}
finally
{
@@ -855,14 +859,7 @@ public enum DBType {
if (length > 0)
{
- value = new InputStream()
- {
- @Override
- public int read() throws IOException
- {
- return in.readByte() - Byte.MIN_VALUE;
- }
- };
+ value = createFileInputStream(in, length);
}
else
{
@@ -878,6 +875,34 @@ public enum DBType return null;
}
+
+ private FileInputStream createFileInputStream(final ExtendedDataInput in, long length) throws IOException
+ {
+ FileOutputStream fos = null;
+
+ try
+ {
+ final File tempFile = TMPUtil.createTempFile("lob-", ".tmp");
+ tempFile.deleteOnExit();
+
+ fos = new FileOutputStream(tempFile);
+ IOUtil.copyBinary(new ExtendedDataInput.Stream(in), fos, length);
+
+ return new FileInputStream(tempFile)
+ {
+ @Override
+ public void close() throws IOException
+ {
+ super.close();
+ tempFile.delete();
+ }
+ };
+ }
+ finally
+ {
+ IOUtil.close(fos);
+ }
+ }
};
private static final int BOOLEAN_NULL = -1;
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInput.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInput.java index fd731d5f04..89c24ed610 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInput.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInput.java @@ -168,7 +168,6 @@ public interface ExtendedDataInput extends DataInput * @author Eike Stepper
* @since 2.0
*/
- @Deprecated
public static class Stream extends InputStream
{
private ExtendedDataInput delegate;
@@ -188,7 +187,7 @@ public interface ExtendedDataInput extends DataInput {
try
{
- return delegate.readUnsignedByte();
+ return delegate.readByte() - Byte.MIN_VALUE;
}
catch (EOFException ex)
{
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutput.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutput.java index fdf50ae47d..7b6feaa3e5 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutput.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutput.java @@ -146,7 +146,6 @@ public interface ExtendedDataOutput extends DataOutput * @author Eike Stepper
* @since 2.0
*/
- @Deprecated
public static class Stream extends OutputStream
{
private ExtendedDataOutput delegate;
|