提交 d263ba28 authored 作者: Thomas Mueller's avatar Thomas Mueller

New experimental LOB storage mechanism.

上级 1de0bbf7
...@@ -32,7 +32,7 @@ import org.h2.value.ValueFloat; ...@@ -32,7 +32,7 @@ import org.h2.value.ValueFloat;
import org.h2.value.ValueInt; import org.h2.value.ValueInt;
import org.h2.value.ValueJavaObject; import org.h2.value.ValueJavaObject;
import org.h2.value.ValueLob; import org.h2.value.ValueLob;
import org.h2.value.ValueLob2; import org.h2.value.ValueLobDb;
import org.h2.value.ValueLong; import org.h2.value.ValueLong;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
import org.h2.value.ValueShort; import org.h2.value.ValueShort;
...@@ -565,10 +565,11 @@ public class Data { ...@@ -565,10 +565,11 @@ public class Data {
write(small, 0, small.length); write(small, 0, small.length);
} }
} else { } else {
ValueLob2 lob = (ValueLob2) v; ValueLobDb lob = (ValueLobDb) v;
byte[] small = lob.getSmall(); byte[] small = lob.getSmall();
if (small == null) { if (small == null) {
writeVarInt(-3); writeVarInt(-3);
writeVarInt(lob.getTableId());
writeVarLong(lob.getLobId()); writeVarLong(lob.getLobId());
writeVarLong(lob.getPrecision()); writeVarLong(lob.getPrecision());
} else { } else {
...@@ -697,10 +698,11 @@ public class Data { ...@@ -697,10 +698,11 @@ public class Data {
read(small, 0, smallLen); read(small, 0, smallLen);
return LobStorage.createSmallLob(type, small); return LobStorage.createSmallLob(type, small);
} else if (smallLen == -3) { } else if (smallLen == -3) {
int tableId = readVarInt();
long lobId = readVarLong(); long lobId = readVarLong();
long precision = readVarLong(); long precision = readVarLong();
LobStorage lobStorage = handler.getLobStorage(); LobStorage lobStorage = handler.getLobStorage();
ValueLob2 lob = ValueLob2.create(type, lobStorage, null, lobId, precision); ValueLobDb lob = ValueLobDb.create(type, lobStorage, null, tableId, lobId, precision);
return lob; return lob;
} else { } else {
int tableId = readVarInt(); int tableId = readVarInt();
...@@ -890,10 +892,11 @@ public class Data { ...@@ -890,10 +892,11 @@ public class Data {
len += small.length; len += small.length;
} }
} else { } else {
ValueLob2 lob = (ValueLob2) v; ValueLobDb lob = (ValueLobDb) v;
byte[] small = lob.getSmall(); byte[] small = lob.getSmall();
if (small == null) { if (small == null) {
len += getVarIntLen(-3); len += getVarIntLen(-3);
len += getVarIntLen(lob.getTableId());
len += getVarLongLen(lob.getLobId()); len += getVarLongLen(lob.getLobId());
len += getVarLongLen(lob.getPrecision()); len += getVarLongLen(lob.getPrecision());
} else { } else {
......
...@@ -770,6 +770,10 @@ public class DataType { ...@@ -770,6 +770,10 @@ public class DataType {
} }
if (ResultSet.class.isAssignableFrom(x)) { if (ResultSet.class.isAssignableFrom(x)) {
return Value.RESULT_SET; return Value.RESULT_SET;
} else if (Value.ValueBlob.class.isAssignableFrom(x)) {
return Value.BLOB;
} else if (Value.ValueClob.class.isAssignableFrom(x)) {
return Value.CLOB;
} else if (String.class.isAssignableFrom(x)) { } else if (String.class.isAssignableFrom(x)) {
return Value.STRING; return Value.STRING;
} else if (BigDecimal.class.isAssignableFrom(x)) { } else if (BigDecimal.class.isAssignableFrom(x)) {
...@@ -836,6 +840,12 @@ public class DataType { ...@@ -836,6 +840,12 @@ public class DataType {
} }
if (x instanceof String) { if (x instanceof String) {
return ValueString.get((String) x); return ValueString.get((String) x);
} else if (x instanceof Value) {
return (Value) x;
} else if (x instanceof Long) {
return ValueLong.get(((Long) x).longValue());
} else if (x instanceof Integer) {
return ValueInt.get(((Integer) x).intValue());
} else if (x instanceof BigDecimal) { } else if (x instanceof BigDecimal) {
return ValueDecimal.get((BigDecimal) x); return ValueDecimal.get((BigDecimal) x);
} else if (x instanceof Boolean) { } else if (x instanceof Boolean) {
...@@ -844,10 +854,6 @@ public class DataType { ...@@ -844,10 +854,6 @@ public class DataType {
return ValueByte.get(((Byte) x).byteValue()); return ValueByte.get(((Byte) x).byteValue());
} else if (x instanceof Short) { } else if (x instanceof Short) {
return ValueShort.get(((Short) x).shortValue()); return ValueShort.get(((Short) x).shortValue());
} else if (x instanceof Integer) {
return ValueInt.get(((Integer) x).intValue());
} else if (x instanceof Long) {
return ValueLong.get(((Long) x).longValue());
} else if (x instanceof Float) { } else if (x instanceof Float) {
return ValueFloat.get(((Float) x).floatValue()); return ValueFloat.get(((Float) x).floatValue());
} else if (x instanceof Double) { } else if (x instanceof Double) {
......
...@@ -1007,4 +1007,18 @@ public abstract class Value { ...@@ -1007,4 +1007,18 @@ public abstract class Value {
return this; return this;
} }
/**
* A "binary large object".
*/
public interface ValueClob {
// this is a marker interface
}
/**
* A "character large object".
*/
public interface ValueBlob {
// this is a marker interface
}
} }
...@@ -29,7 +29,7 @@ import org.h2.util.Utils; ...@@ -29,7 +29,7 @@ import org.h2.util.Utils;
/** /**
* An alternate LOB implementation. * An alternate LOB implementation.
*/ */
public class ValueLob2 extends Value { public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlob {
private final int type; private final int type;
private long precision; private long precision;
...@@ -45,7 +45,7 @@ public class ValueLob2 extends Value { ...@@ -45,7 +45,7 @@ public class ValueLob2 extends Value {
private FileStore tempFile; private FileStore tempFile;
private String fileName; private String fileName;
private ValueLob2(int type, LobStorage lobStorage, String fileName, int tableId, long lobId, long precision) { private ValueLobDb(int type, LobStorage lobStorage, String fileName, int tableId, long lobId, long precision) {
this.type = type; this.type = type;
this.lobStorage = lobStorage; this.lobStorage = lobStorage;
this.fileName = fileName; this.fileName = fileName;
...@@ -54,7 +54,7 @@ public class ValueLob2 extends Value { ...@@ -54,7 +54,7 @@ public class ValueLob2 extends Value {
this.precision = precision; this.precision = precision;
} }
private ValueLob2(int type, byte[] small, long precision) { private ValueLobDb(int type, byte[] small, long precision) {
this.type = type; this.type = type;
this.small = small; this.small = small;
this.precision = precision; this.precision = precision;
...@@ -66,12 +66,13 @@ public class ValueLob2 extends Value { ...@@ -66,12 +66,13 @@ public class ValueLob2 extends Value {
* @param type the type * @param type the type
* @param lobStorage the storage * @param lobStorage the storage
* @param fileName the file name (may be null) * @param fileName the file name (may be null)
* @param tableId the table id
* @param id the lob id * @param id the lob id
* @param precision the precision (number of bytes / characters) * @param precision the precision (number of bytes / characters)
* @return the value * @return the value
*/ */
public static ValueLob2 create(int type, LobStorage lobStorage, String fileName, long id, long precision) { public static ValueLobDb create(int type, LobStorage lobStorage, String fileName, int tableId, long id, long precision) {
return new ValueLob2(type, lobStorage, fileName, LobStorage.TABLE_ID_SESSION_VARIABLE, id, precision); return new ValueLobDb(type, lobStorage, fileName, tableId, id, precision);
} }
/** /**
...@@ -82,8 +83,8 @@ public class ValueLob2 extends Value { ...@@ -82,8 +83,8 @@ public class ValueLob2 extends Value {
* @param precision the precision * @param precision the precision
* @return the lob value * @return the lob value
*/ */
public static ValueLob2 createSmallLob(int type, byte[] small, long precision) { public static ValueLobDb createSmallLob(int type, byte[] small, long precision) {
return new ValueLob2(type, small, precision); return new ValueLobDb(type, small, precision);
} }
/** /**
...@@ -141,12 +142,21 @@ public class ValueLob2 extends Value { ...@@ -141,12 +142,21 @@ public class ValueLob2 extends Value {
public Value link(DataHandler h, int tabId) { public Value link(DataHandler h, int tabId) {
if (small == null) { if (small == null) {
if (tabId != tableId) { if (tabId != tableId) {
if (tableId != LobStorage.TABLE_ID_SESSION_VARIABLE) { if (tableId != LobStorage.TABLE_TEMP) {
throw DbException.throwInternalError(); return lobStorage.copyLob(type, lobId, tabId, getPrecision());
} }
lobStorage.setTable(lobId, tabId); lobStorage.setTable(lobId, tabId);
this.tableId = tabId; this.tableId = tabId;
} }
} else if (small.length > h.getMaxLengthInplaceLob()) {
LobStorage s = h.getLobStorage();
Value v;
if (type == Value.BLOB) {
v = s.createBlob(getInputStream(), getPrecision());
} else {
v = s.createClob(getReader(), getPrecision());
}
return v.link(h, tabId);
} }
return this; return this;
} }
...@@ -335,7 +345,7 @@ public class ValueLob2 extends Value { ...@@ -335,7 +345,7 @@ public class ValueLob2 extends Value {
* *
* @return the value * @return the value
*/ */
public ValueLob2 copyToTemp() { public ValueLobDb copyToTemp() {
return this; return this;
} }
...@@ -359,7 +369,7 @@ public class ValueLob2 extends Value { ...@@ -359,7 +369,7 @@ public class ValueLob2 extends Value {
* @param handler the data handler * @param handler the data handler
* @return the lob value * @return the lob value
*/ */
public static ValueLob2 createTempClob(Reader in, long length, DataHandler handler) { public static ValueLobDb createTempClob(Reader in, long length, DataHandler handler) {
try { try {
boolean compress = handler.getLobCompressionAlgorithm(Value.CLOB) != null; boolean compress = handler.getLobCompressionAlgorithm(Value.CLOB) != null;
long remaining = Long.MAX_VALUE; long remaining = Long.MAX_VALUE;
...@@ -379,9 +389,9 @@ public class ValueLob2 extends Value { ...@@ -379,9 +389,9 @@ public class ValueLob2 extends Value {
} }
if (len <= handler.getMaxLengthInplaceLob()) { if (len <= handler.getMaxLengthInplaceLob()) {
byte[] small = StringUtils.utf8Encode(new String(buff, 0, len)); byte[] small = StringUtils.utf8Encode(new String(buff, 0, len));
return ValueLob2.createSmallLob(Value.CLOB, small, len); return ValueLobDb.createSmallLob(Value.CLOB, small, len);
} }
ValueLob2 lob = new ValueLob2(Value.CLOB, null, 0); ValueLobDb lob = new ValueLobDb(Value.CLOB, null, 0);
lob.createTempFromReader(buff, len, in, remaining, handler); lob.createTempFromReader(buff, len, in, remaining, handler);
return lob; return lob;
} catch (IOException e) { } catch (IOException e) {
...@@ -397,7 +407,7 @@ public class ValueLob2 extends Value { ...@@ -397,7 +407,7 @@ public class ValueLob2 extends Value {
* @param handler the data handler * @param handler the data handler
* @return the lob value * @return the lob value
*/ */
public static ValueLob2 createTempBlob(InputStream in, long length, DataHandler handler) { public static ValueLobDb createTempBlob(InputStream in, long length, DataHandler handler) {
try { try {
long remaining = Long.MAX_VALUE; long remaining = Long.MAX_VALUE;
boolean compress = handler.getLobCompressionAlgorithm(Value.BLOB) != null; boolean compress = handler.getLobCompressionAlgorithm(Value.BLOB) != null;
...@@ -416,9 +426,9 @@ public class ValueLob2 extends Value { ...@@ -416,9 +426,9 @@ public class ValueLob2 extends Value {
if (len <= handler.getMaxLengthInplaceLob()) { if (len <= handler.getMaxLengthInplaceLob()) {
byte[] small = Utils.newBytes(len); byte[] small = Utils.newBytes(len);
System.arraycopy(buff, 0, small, 0, len); System.arraycopy(buff, 0, small, 0, len);
return ValueLob2.createSmallLob(Value.BLOB, small, small.length); return ValueLobDb.createSmallLob(Value.BLOB, small, small.length);
} }
ValueLob2 lob = new ValueLob2(Value.BLOB, null, 0); ValueLobDb lob = new ValueLobDb(Value.BLOB, null, 0);
lob.createTempFromStream(buff, len, in, remaining, handler); lob.createTempFromStream(buff, len, in, remaining, handler);
return lob; return lob;
} catch (IOException e) { } catch (IOException e) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论