提交 90dc0db2 authored 作者: noelgrandin's avatar noelgrandin

re-organise LobStorageBackend code a little, so we don't need to correct the…

re-organise LobStorageBackend code a little, so we don't need to correct the precision of a CLOB later on
上级 23fdae21
...@@ -334,7 +334,7 @@ public class LobStorageBackend implements LobStorageInterface { ...@@ -334,7 +334,7 @@ public class LobStorageBackend implements LobStorageInterface {
} }
} }
private ValueLobDb addLob(InputStream in, long maxLength, int type) { private ValueLobDb addLob(InputStream in, long maxLength, int type, CountingReaderInputStream countingReaderForClob) {
try { try {
byte[] buff = new byte[BLOCK_LENGTH]; byte[] buff = new byte[BLOCK_LENGTH];
if (maxLength < 0) { if (maxLength < 0) {
...@@ -380,8 +380,9 @@ public class LobStorageBackend implements LobStorageInterface { ...@@ -380,8 +380,9 @@ public class LobStorageBackend implements LobStorageInterface {
small = new byte[0]; small = new byte[0];
} }
if (small != null) { if (small != null) {
// CLOB: the precision will be fixed later // For a BLOB, precision is length in bytes. For a CLOB, precision is length in chars
ValueLobDb v = ValueLobDb.createSmallLob(type, small, small.length); long precision = countingReaderForClob == null ? small.length : countingReaderForClob.getLength();
ValueLobDb v = ValueLobDb.createSmallLob(type, small, precision);
return v; return v;
} }
return registerLob(type, lobId, LobStorageFrontend.TABLE_TEMP, length); return registerLob(type, lobId, LobStorageFrontend.TABLE_TEMP, length);
...@@ -538,7 +539,7 @@ public class LobStorageBackend implements LobStorageInterface { ...@@ -538,7 +539,7 @@ public class LobStorageBackend implements LobStorageInterface {
public Value createBlob(InputStream in, long maxLength) { public Value createBlob(InputStream in, long maxLength) {
if (SysProperties.LOB_IN_DATABASE) { if (SysProperties.LOB_IN_DATABASE) {
init(); init();
return addLob(in, maxLength, Value.BLOB); return addLob(in, maxLength, Value.BLOB, null);
} }
return ValueLob.createBlob(in, maxLength, database); return ValueLob.createBlob(in, maxLength, database);
} }
...@@ -549,8 +550,7 @@ public class LobStorageBackend implements LobStorageInterface { ...@@ -549,8 +550,7 @@ public class LobStorageBackend implements LobStorageInterface {
init(); init();
long max = maxLength == -1 ? Long.MAX_VALUE : maxLength; long max = maxLength == -1 ? Long.MAX_VALUE : maxLength;
CountingReaderInputStream in = new CountingReaderInputStream(reader, max); CountingReaderInputStream in = new CountingReaderInputStream(reader, max);
ValueLobDb lob = addLob(in, Long.MAX_VALUE, Value.CLOB); ValueLobDb lob = addLob(in, Long.MAX_VALUE, Value.CLOB, in);
lob.setPrecision(in.getLength());
return lob; return lob;
} }
return ValueLob.createClob(reader, maxLength, database); return ValueLob.createClob(reader, maxLength, database);
...@@ -755,6 +755,9 @@ public class LobStorageBackend implements LobStorageInterface { ...@@ -755,6 +755,9 @@ public class LobStorageBackend implements LobStorageInterface {
static class CountingReaderInputStream extends InputStream { static class CountingReaderInputStream extends InputStream {
private final Reader reader; private final Reader reader;
/**
* total length of Reader data in chars
*/
private long length; private long length;
private long remaining; private long remaining;
private int pos; private int pos;
......
...@@ -41,8 +41,13 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo ...@@ -41,8 +41,13 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
private final byte[] hmac; private final byte[] hmac;
private final byte[] small; private final byte[] small;
private final DataHandler handler; private final DataHandler handler;
/**
* For a BLOB, precision is length in bytes.
* For a CLOB, precision is length in chars.
*/
private long precision; private long precision;
private int tableId; private int tableId;
private int hash; private int hash;
private FileStore tempFile; private FileStore tempFile;
...@@ -407,10 +412,6 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo ...@@ -407,10 +412,6 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
return lobId; return lobId;
} }
public void setPrecision(long precision) {
this.precision = precision;
}
@Override @Override
public String toString() { public String toString() {
return "lob: " + fileName + " table: " + tableId + " id: " + lobId; return "lob: " + fileName + " table: " + tableId + " id: " + lobId;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论