提交 4675d719 authored 作者: Noel Grandin's avatar Noel Grandin

document ValueLob.type a little

上级 d4ed1a5d
...@@ -109,7 +109,10 @@ public class ValueLob extends Value { ...@@ -109,7 +109,10 @@ public class ValueLob extends Value {
*/ */
private static int dirCounter; private static int dirCounter;
private final int type; /**
* either Value.BLOB or Value.CLOB
*/
private final int valueType;
private long precision; private long precision;
private DataHandler handler; private DataHandler handler;
private int tableId; private int tableId;
...@@ -124,7 +127,7 @@ public class ValueLob extends Value { ...@@ -124,7 +127,7 @@ public class ValueLob extends Value {
private ValueLob(int type, DataHandler handler, String fileName, private ValueLob(int type, DataHandler handler, String fileName,
int tableId, int objectId, boolean linked, long precision, int tableId, int objectId, boolean linked, long precision,
boolean compressed) { boolean compressed) {
this.type = type; this.valueType = type;
this.handler = handler; this.handler = handler;
this.fileName = fileName; this.fileName = fileName;
this.tableId = tableId; this.tableId = tableId;
...@@ -135,7 +138,7 @@ public class ValueLob extends Value { ...@@ -135,7 +138,7 @@ public class ValueLob extends Value {
} }
private ValueLob(int type, byte[] small) { private ValueLob(int type, byte[] small) {
this.type = type; this.valueType = type;
this.small = small; this.small = small;
if (small != null) { if (small != null) {
if (type == Value.BLOB) { if (type == Value.BLOB) {
...@@ -147,7 +150,7 @@ public class ValueLob extends Value { ...@@ -147,7 +150,7 @@ public class ValueLob extends Value {
} }
private static ValueLob copy(ValueLob lob) { private static ValueLob copy(ValueLob lob) {
ValueLob copy = new ValueLob(lob.type, lob.handler, lob.fileName, ValueLob copy = new ValueLob(lob.valueType, lob.handler, lob.fileName,
lob.tableId, lob.objectId, lob.linked, lob.precision, lob.compressed); lob.tableId, lob.objectId, lob.linked, lob.precision, lob.compressed);
copy.small = lob.small; copy.small = lob.small;
copy.hash = lob.hash; copy.hash = lob.hash;
...@@ -178,7 +181,7 @@ public class ValueLob extends Value { ...@@ -178,7 +181,7 @@ public class ValueLob extends Value {
/** /**
* Create a LOB value with the given parameters. * Create a LOB value with the given parameters.
* *
* @param type the data type * @param type the data type, either Value.BLOB or Value.CLOB
* @param handler the file handler * @param handler the file handler
* @param tableId the table object id * @param tableId the table object id
* @param objectId the object id * @param objectId the object id
...@@ -196,7 +199,7 @@ public class ValueLob extends Value { ...@@ -196,7 +199,7 @@ public class ValueLob extends Value {
/** /**
* Create a LOB value with the given parameters. * Create a LOB value with the given parameters.
* *
* @param type the data type * @param type the data type, either Value.BLOB or Value.CLOB
* @param handler the file handler * @param handler the file handler
* @param tableId the table object id * @param tableId the table object id
* @param objectId the object id * @param objectId the object id
...@@ -454,7 +457,7 @@ public class ValueLob extends Value { ...@@ -454,7 +457,7 @@ public class ValueLob extends Value {
this.precision = 0; this.precision = 0;
this.small = null; this.small = null;
this.hash = 0; this.hash = 0;
String compressionAlgorithm = h.getLobCompressionAlgorithm(type); String compressionAlgorithm = h.getLobCompressionAlgorithm(valueType);
this.compressed = compressionAlgorithm != null; this.compressed = compressionAlgorithm != null;
synchronized (h) { synchronized (h) {
String path = h.getDatabasePath(); String path = h.getDatabasePath();
...@@ -507,7 +510,7 @@ public class ValueLob extends Value { ...@@ -507,7 +510,7 @@ public class ValueLob extends Value {
*/ */
@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) {
return ValueLob.createClob(getReader(), -1, handler); return ValueLob.createClob(getReader(), -1, handler);
...@@ -593,7 +596,7 @@ public class ValueLob extends Value { ...@@ -593,7 +596,7 @@ public class ValueLob extends Value {
@Override @Override
public int getType() { public int getType() {
return type; return valueType;
} }
@Override @Override
...@@ -606,7 +609,7 @@ public class ValueLob extends Value { ...@@ -606,7 +609,7 @@ public class ValueLob extends Value {
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);
} }
...@@ -626,7 +629,7 @@ public class ValueLob extends Value { ...@@ -626,7 +629,7 @@ public class ValueLob extends Value {
@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();
} }
...@@ -636,7 +639,7 @@ public class ValueLob extends Value { ...@@ -636,7 +639,7 @@ public class ValueLob extends Value {
@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();
} }
...@@ -659,7 +662,7 @@ public class ValueLob extends Value { ...@@ -659,7 +662,7 @@ public class ValueLob extends Value {
// 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());
...@@ -670,7 +673,7 @@ public class ValueLob extends Value { ...@@ -670,7 +673,7 @@ public class ValueLob extends Value {
@Override @Override
protected int compareSecure(Value v, CompareMode mode) { protected int compareSecure(Value v, CompareMode mode) {
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();
...@@ -679,7 +682,7 @@ public class ValueLob extends Value { ...@@ -679,7 +682,7 @@ public class ValueLob extends Value {
@Override @Override
public Object getObject() { public Object getObject() {
if (type == Value.CLOB) { if (valueType == Value.CLOB) {
return getReader(); return getReader();
} }
return getInputStream(); return getInputStream();
...@@ -692,7 +695,7 @@ public class ValueLob extends Value { ...@@ -692,7 +695,7 @@ public class ValueLob extends Value {
@Override @Override
public Reader getReader(long oneBasedOffset, long length) { public Reader getReader(long oneBasedOffset, long length) {
return rangeReader(getReader(), oneBasedOffset, length, type == Value.CLOB ? precision : -1); return rangeReader(getReader(), oneBasedOffset, length, valueType == Value.CLOB ? precision : -1);
} }
@Override @Override
...@@ -727,7 +730,7 @@ public class ValueLob extends Value { ...@@ -727,7 +730,7 @@ public class ValueLob extends Value {
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);
...@@ -737,7 +740,7 @@ public class ValueLob extends Value { ...@@ -737,7 +740,7 @@ public class ValueLob extends Value {
@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);
} }
...@@ -752,7 +755,7 @@ public class ValueLob extends Value { ...@@ -752,7 +755,7 @@ public class ValueLob extends Value {
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");
...@@ -790,10 +793,10 @@ public class ValueLob extends Value { ...@@ -790,10 +793,10 @@ public class ValueLob extends Value {
public void convertToFileIfRequired(DataHandler h) { public void convertToFileIfRequired(DataHandler h) {
try { try {
if (small != null && small.length > h.getMaxLengthInplaceLob()) { if (small != null && small.length > h.getMaxLengthInplaceLob()) {
boolean compress = h.getLobCompressionAlgorithm(type) != null; boolean compress = h.getLobCompressionAlgorithm(valueType) != null;
int len = getBufferSize(h, compress, Long.MAX_VALUE); int len = getBufferSize(h, compress, Long.MAX_VALUE);
int tabId = tableId; int tabId = tableId;
if (type == Value.BLOB) { if (valueType == Value.BLOB) {
createFromStream( createFromStream(
Utils.newBytes(len), 0, getInputStream(), Long.MAX_VALUE, h); Utils.newBytes(len), 0, getInputStream(), Long.MAX_VALUE, h);
} else { } else {
...@@ -863,7 +866,7 @@ public class ValueLob extends Value { ...@@ -863,7 +866,7 @@ public class ValueLob extends Value {
@Override @Override
public ValueLob copyToTemp() { public ValueLob copyToTemp() {
ValueLob lob; ValueLob lob;
if (type == CLOB) { if (valueType == CLOB) {
lob = ValueLob.createClob(getReader(), precision, handler); lob = ValueLob.createClob(getReader(), precision, handler);
} else { } else {
lob = ValueLob.createBlob(getInputStream(), precision, handler); lob = ValueLob.createBlob(getInputStream(), precision, handler);
...@@ -877,7 +880,7 @@ public class ValueLob extends Value { ...@@ -877,7 +880,7 @@ public class ValueLob extends Value {
return this; return this;
} }
ValueLob lob; ValueLob lob;
if (type == CLOB) { if (valueType == CLOB) {
lob = ValueLob.createClob(getReader(), precision, handler); lob = ValueLob.createClob(getReader(), precision, handler);
} else { } else {
lob = ValueLob.createBlob(getInputStream(), precision, handler); lob = ValueLob.createBlob(getInputStream(), precision, handler);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论