提交 c3e89b0c authored 作者: Noel Grandin's avatar Noel Grandin

document type in ValueLobDb a little

上级 4675d719
...@@ -42,7 +42,10 @@ import org.h2.util.Utils; ...@@ -42,7 +42,10 @@ import org.h2.util.Utils;
public class ValueLobDb extends Value implements Value.ValueClob, public class ValueLobDb extends Value implements Value.ValueClob,
Value.ValueBlob { Value.ValueBlob {
private final int type; /**
* the value type (Value.BLOB or CLOB)
*/
private final int valueType;
private final long lobId; private final long lobId;
private final byte[] hmac; private final byte[] hmac;
private final byte[] small; private final byte[] small;
...@@ -66,7 +69,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -66,7 +69,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
private ValueLobDb(int type, DataHandler handler, int tableId, long lobId, private ValueLobDb(int type, DataHandler handler, int tableId, long lobId,
byte[] hmac, long precision) { byte[] hmac, long precision) {
this.type = type; this.valueType = type;
this.handler = handler; this.handler = handler;
this.tableId = tableId; this.tableId = tableId;
this.lobId = lobId; this.lobId = lobId;
...@@ -78,7 +81,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -78,7 +81,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
} }
private ValueLobDb(int type, byte[] small, long precision) { private ValueLobDb(int type, byte[] small, long precision) {
this.type = type; this.valueType = type;
this.small = small; this.small = small;
this.precision = precision; this.precision = precision;
this.lobId = 0; this.lobId = 0;
...@@ -94,7 +97,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -94,7 +97,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
*/ */
private ValueLobDb(DataHandler handler, Reader in, long remaining) private ValueLobDb(DataHandler handler, Reader in, long remaining)
throws IOException { throws IOException {
this.type = Value.CLOB; this.valueType = Value.CLOB;
this.handler = handler; this.handler = handler;
this.small = null; this.small = null;
this.lobId = 0; this.lobId = 0;
...@@ -126,7 +129,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -126,7 +129,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
*/ */
private ValueLobDb(DataHandler handler, byte[] buff, int len, InputStream in, private ValueLobDb(DataHandler handler, byte[] buff, int len, InputStream in,
long remaining) throws IOException { long remaining) throws IOException {
this.type = Value.BLOB; this.valueType = Value.BLOB;
this.handler = handler; this.handler = handler;
this.small = null; this.small = null;
this.lobId = 0; this.lobId = 0;
...@@ -167,7 +170,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -167,7 +170,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
/** /**
* Create a LOB value. * Create a LOB value.
* *
* @param type the type * @param type the type (Value.BLOB or CLOB)
* @param handler the data handler * @param handler the data handler
* @param tableId the table id * @param tableId the table id
* @param id the lob id * @param id the lob id
...@@ -194,7 +197,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -194,7 +197,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
*/ */
@Override @Override
public Value convertTo(int t, int precision, Mode mode, Object column, String[] enumerators) { public Value convertTo(int t, int precision, Mode mode, Object column, String[] enumerators) {
if (t == type) { if (t == valueType) {
return this; return this;
} else if (t == Value.CLOB) { } else if (t == Value.CLOB) {
if (handler != null) { if (handler != null) {
...@@ -248,7 +251,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -248,7 +251,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
} else if (small.length > database.getMaxLengthInplaceLob()) { } else if (small.length > database.getMaxLengthInplaceLob()) {
LobStorageInterface s = database.getLobStorage(); LobStorageInterface s = database.getLobStorage();
Value v; Value v;
if (type == Value.BLOB) { if (valueType == Value.BLOB) {
v = s.createBlob(getInputStream(), getPrecision()); v = s.createBlob(getInputStream(), getPrecision());
} else { } else {
v = s.createClob(getReader(), getPrecision()); v = s.createClob(getReader(), getPrecision());
...@@ -272,7 +275,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -272,7 +275,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
@Override @Override
public int getType() { public int getType() {
return type; return valueType;
} }
@Override @Override
...@@ -285,7 +288,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -285,7 +288,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
int len = precision > Integer.MAX_VALUE || precision == 0 ? int len = precision > Integer.MAX_VALUE || precision == 0 ?
Integer.MAX_VALUE : (int) precision; Integer.MAX_VALUE : (int) precision;
try { try {
if (type == Value.CLOB) { if (valueType == Value.CLOB) {
if (small != null) { if (small != null) {
return new String(small, StandardCharsets.UTF_8); return new String(small, StandardCharsets.UTF_8);
} }
...@@ -305,7 +308,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -305,7 +308,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
@Override @Override
public byte[] getBytes() { public byte[] getBytes() {
if (type == CLOB) { if (valueType == CLOB) {
// convert hex to string // convert hex to string
return super.getBytes(); return super.getBytes();
} }
...@@ -315,7 +318,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -315,7 +318,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
@Override @Override
public byte[] getBytesNoCopy() { public byte[] getBytesNoCopy() {
if (type == CLOB) { if (valueType == CLOB) {
// convert hex to string // convert hex to string
return super.getBytesNoCopy(); return super.getBytesNoCopy();
} }
...@@ -337,7 +340,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -337,7 +340,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
// it in the database file // it in the database file
return (int) (precision ^ (precision >>> 32)); return (int) (precision ^ (precision >>> 32));
} }
if (type == CLOB) { if (valueType == CLOB) {
hash = getString().hashCode(); hash = getString().hashCode();
} else { } else {
hash = Utils.getByteArrayHash(getBytes()); hash = Utils.getByteArrayHash(getBytes());
...@@ -357,7 +360,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -357,7 +360,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
return 0; return 0;
} }
} }
if (type == Value.CLOB) { if (valueType == Value.CLOB) {
return Integer.signum(getString().compareTo(v.getString())); return Integer.signum(getString().compareTo(v.getString()));
} }
byte[] v2 = v.getBytesNoCopy(); byte[] v2 = v.getBytesNoCopy();
...@@ -366,7 +369,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -366,7 +369,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
@Override @Override
public Object getObject() { public Object getObject() {
if (type == Value.CLOB) { if (valueType == Value.CLOB) {
return getReader(); return getReader();
} }
return getInputStream(); return getInputStream();
...@@ -379,7 +382,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -379,7 +382,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
@Override @Override
public Reader getReader(long oneBasedOffset, long length) { public Reader getReader(long oneBasedOffset, long length) {
return ValueLob.rangeReader(getReader(), oneBasedOffset, length, type == Value.CLOB ? precision : -1); return ValueLob.rangeReader(getReader(), oneBasedOffset, length, valueType == Value.CLOB ? precision : -1);
} }
@Override @Override
...@@ -392,7 +395,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -392,7 +395,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
return new BufferedInputStream(new FileStoreInputStream(store, return new BufferedInputStream(new FileStoreInputStream(store,
handler, false, alwaysClose), Constants.IO_BUFFER_SIZE); handler, false, alwaysClose), Constants.IO_BUFFER_SIZE);
} }
long byteCount = (type == Value.BLOB) ? precision : -1; long byteCount = (valueType == Value.BLOB) ? precision : -1;
try { try {
return handler.getLobStorage().getInputStream(this, hmac, byteCount); return handler.getLobStorage().getInputStream(this, hmac, byteCount);
} catch (IOException e) { } catch (IOException e) {
...@@ -413,7 +416,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -413,7 +416,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
inputStream = new BufferedInputStream(new FileStoreInputStream(store, inputStream = new BufferedInputStream(new FileStoreInputStream(store,
handler, false, alwaysClose), Constants.IO_BUFFER_SIZE); handler, false, alwaysClose), Constants.IO_BUFFER_SIZE);
} else { } else {
byteCount = (type == Value.BLOB) ? precision : -1; byteCount = (valueType == Value.BLOB) ? precision : -1;
try { try {
inputStream = handler.getLobStorage().getInputStream(this, hmac, byteCount); inputStream = handler.getLobStorage().getInputStream(this, hmac, byteCount);
} catch (IOException e) { } catch (IOException e) {
...@@ -430,7 +433,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -430,7 +433,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
if (p > Integer.MAX_VALUE || p <= 0) { if (p > Integer.MAX_VALUE || p <= 0) {
p = -1; p = -1;
} }
if (type == Value.BLOB) { if (valueType == Value.BLOB) {
prep.setBinaryStream(parameterIndex, getInputStream(), (int) p); prep.setBinaryStream(parameterIndex, getInputStream(), (int) p);
} else { } else {
prep.setCharacterStream(parameterIndex, getReader(), (int) p); prep.setCharacterStream(parameterIndex, getReader(), (int) p);
...@@ -440,7 +443,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -440,7 +443,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
@Override @Override
public String getSQL() { public String getSQL() {
String s; String s;
if (type == Value.CLOB) { if (valueType == Value.CLOB) {
s = getString(); s = getString();
return StringUtils.quoteStringSQL(s); return StringUtils.quoteStringSQL(s);
} }
...@@ -455,7 +458,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -455,7 +458,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
return getSQL(); return getSQL();
} }
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
if (type == Value.CLOB) { if (valueType == Value.CLOB) {
buff.append("SPACE(").append(getPrecision()); buff.append("SPACE(").append(getPrecision());
} else { } else {
buff.append("CAST(REPEAT('00', ").append(getPrecision()).append(") AS BINARY"); buff.append("CAST(REPEAT('00', ").append(getPrecision()).append(") AS BINARY");
...@@ -650,13 +653,13 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -650,13 +653,13 @@ public class ValueLobDb extends Value implements Value.ValueClob,
return this; return this;
} }
ValueLobDb lob; ValueLobDb lob;
if (type == CLOB) { if (valueType == CLOB) {
if (handler == null) { if (handler == null) {
try { try {
int p = MathUtils.convertLongToInt(precision); int p = MathUtils.convertLongToInt(precision);
String s = IOUtils.readStringAndClose(getReader(), p); String s = IOUtils.readStringAndClose(getReader(), p);
byte[] data = s.getBytes(StandardCharsets.UTF_8); byte[] data = s.getBytes(StandardCharsets.UTF_8);
lob = ValueLobDb.createSmallLob(type, data, s.length()); lob = ValueLobDb.createSmallLob(valueType, data, s.length());
} catch (IOException e) { } catch (IOException e) {
throw DbException.convertIOException(e, null); throw DbException.convertIOException(e, null);
} }
...@@ -668,7 +671,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, ...@@ -668,7 +671,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
try { try {
int p = MathUtils.convertLongToInt(precision); int p = MathUtils.convertLongToInt(precision);
byte[] data = IOUtils.readBytesAndClose(getInputStream(), p); byte[] data = IOUtils.readBytesAndClose(getInputStream(), p);
lob = ValueLobDb.createSmallLob(type, data, data.length); lob = ValueLobDb.createSmallLob(valueType, data, data.length);
} catch (IOException e) { } catch (IOException e) {
throw DbException.convertIOException(e, null); throw DbException.convertIOException(e, null);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论