提交 900c76bb authored 作者: noelgrandin's avatar noelgrandin

There is no need to store both LobStorageInterface and DataHandler as fields in ValueLobDb.

Simplify the code and only store DataHandler.
上级 6aba2a41
......@@ -25,7 +25,6 @@ import org.h2.result.SortOrder;
import org.h2.store.Data;
import org.h2.store.DataHandler;
import org.h2.store.LobStorageFrontend;
import org.h2.store.LobStorageInterface;
import org.h2.tools.SimpleResultSet;
import org.h2.util.DateTimeUtils;
import org.h2.value.CompareMode;
......@@ -613,8 +612,7 @@ public class ValueDataType implements DataType {
int tableId = readVarInt(buff);
long lobId = readVarLong(buff);
long precision = readVarLong(buff);
LobStorageInterface lobStorage = handler.getLobStorage();
ValueLobDb lob = ValueLobDb.create(type, lobStorage, tableId, lobId, null, precision);
ValueLobDb lob = ValueLobDb.create(type, handler, tableId, lobId, null, precision);
return lob;
} else {
int tableId = readVarInt(buff);
......
......@@ -805,8 +805,7 @@ public class Data {
int tableId = readVarInt();
long lobId = readVarLong();
long precision = readVarLong();
LobStorageInterface lobStorage = handler.getLobStorage();
ValueLobDb lob = ValueLobDb.create(type, lobStorage, tableId, lobId, null, precision);
ValueLobDb lob = ValueLobDb.create(type, handler, tableId, lobId, null, precision);
return lob;
} else {
int tableId = readVarInt();
......
......@@ -406,7 +406,7 @@ public class LobStorageBackend implements LobStorageInterface {
prep.setInt(3, tableId);
prep.execute();
reuse(sql, prep);
ValueLobDb v = ValueLobDb.create(type, this, tableId, lobId, null, byteCount);
ValueLobDb v = ValueLobDb.create(type, database, tableId, lobId, null, byteCount);
return v;
} catch (SQLException e) {
throw DbException.convert(e);
......@@ -439,7 +439,7 @@ public class LobStorageBackend implements LobStorageInterface {
prep.executeUpdate();
reuse(sql, prep);
ValueLobDb v = ValueLobDb.create(type, this, tableId, lobId, null, length);
ValueLobDb v = ValueLobDb.create(type, database, tableId, lobId, null, length);
return v;
} catch (SQLException e) {
throw DbException.convert(e);
......
......@@ -206,8 +206,7 @@ public class Recover extends Tool implements DataHandler {
*/
public static Value.ValueBlob readBlobDb(Connection conn, long lobId, long precision) {
DataHandler h = ((JdbcConnection) conn).getSession().getDataHandler();
LobStorageInterface lobStorage = h.getLobStorage();
return ValueLobDb.create(Value.BLOB, lobStorage, LobStorageFrontend.TABLE_TEMP, lobId, null, precision);
return ValueLobDb.create(Value.BLOB, h, LobStorageFrontend.TABLE_TEMP, lobId, null, precision);
}
/**
......@@ -215,8 +214,7 @@ public class Recover extends Tool implements DataHandler {
*/
public static Value.ValueClob readClobDb(Connection conn, long lobId, long precision) {
DataHandler h = ((JdbcConnection) conn).getSession().getDataHandler();
LobStorageInterface lobStorage = h.getLobStorage();
return ValueLobDb.create(Value.CLOB, lobStorage, LobStorageFrontend.TABLE_TEMP, lobId, null, precision);
return ValueLobDb.create(Value.CLOB, h, LobStorageFrontend.TABLE_TEMP, lobId, null, precision);
}
private void trace(String message) {
......
......@@ -592,7 +592,7 @@ public class Transfer {
hmac = null;
}
long precision = readLong();
return ValueLobDb.create(Value.BLOB, session.getDataHandler().getLobStorage(), tableId, id, hmac, precision);
return ValueLobDb.create(Value.BLOB, session.getDataHandler(), tableId, id, hmac, precision);
}
int len = (int) length;
byte[] small = new byte[len];
......@@ -623,7 +623,7 @@ public class Transfer {
hmac = null;
}
long precision = readLong();
return ValueLobDb.create(Value.CLOB, session.getDataHandler().getLobStorage(), tableId, id, hmac, precision);
return ValueLobDb.create(Value.CLOB, session.getDataHandler(), tableId, id, hmac, precision);
}
DataReader reader = new DataReader(in);
int len = (int) length;
......
......@@ -37,29 +37,25 @@ import org.h2.util.Utils;
public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlob {
private final int type;
private long precision;
private int tableId;
private int hash;
private LobStorageInterface lobStorage;
private final long lobId;
private final byte[] hmac;
private final byte[] small;
private final DataHandler handler;
private long precision;
private int tableId;
private int hash;
private FileStore tempFile;
private String fileName;
private ValueLobDb(int type, LobStorageInterface lobStorage, int tableId, long lobId, byte[] hmac, long precision) {
private ValueLobDb(int type, DataHandler handler, int tableId, long lobId, byte[] hmac, long precision) {
this.type = type;
this.lobStorage = lobStorage;
this.handler = handler;
this.tableId = tableId;
this.lobId = lobId;
this.hmac = hmac;
this.precision = precision;
this.small = null;
this.handler = null;
}
private ValueLobDb(int type, byte[] small, long precision) {
......@@ -84,16 +80,16 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
* Create a LOB value.
*
* @param type the type
* @param lobStorage the storage
* @param handler the data handler
* @param tableId the table id
* @param id the lob id
* @param hmac the message authentication code
* @param precision the precision (number of bytes / characters)
* @return the value
*/
public static ValueLobDb create(int type, LobStorageInterface lobStorage,
public static ValueLobDb create(int type, DataHandler handler,
int tableId, long id, byte[] hmac, long precision) {
return new ValueLobDb(type, lobStorage, tableId, id, hmac, precision);
return new ValueLobDb(type, handler, tableId, id, hmac, precision);
}
/**
......@@ -120,15 +116,15 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
if (t == type) {
return this;
} else if (t == Value.CLOB) {
if (lobStorage != null) {
Value copy = lobStorage.createClob(getReader(), -1);
if (handler != null) {
Value copy = handler.getLobStorage().createClob(getReader(), -1);
return copy;
} else if (small != null) {
return LobStorageFrontend.createSmallLob(t, small);
}
} else if (t == Value.BLOB) {
if (lobStorage != null) {
Value copy = lobStorage.createBlob(getInputStream(), -1);
if (handler != null) {
Value copy = handler.getLobStorage().createBlob(getInputStream(), -1);
return copy;
} else if (small != null) {
return LobStorageFrontend.createSmallLob(t, small);
......@@ -159,9 +155,8 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
FileUtils.delete(fileName);
}
}
if (lobStorage != null) {
lobStorage.removeLob(lobId);
lobStorage = null;
if (handler != null) {
handler.getLobStorage().removeLob(lobId);
}
}
......@@ -180,7 +175,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
database.getLobStorage().setTable(lobId, tabId);
this.tableId = tabId;
} else {
return lobStorage.copyLob(type, lobId, tabId, getPrecision());
return handler.getLobStorage().copyLob(type, lobId, tabId, getPrecision());
}
} else if (small.length > database.getMaxLengthInplaceLob()) {
LobStorageInterface s = database.getLobStorage();
......@@ -323,7 +318,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
}
long byteCount = (type == Value.BLOB) ? precision : -1;
try {
return lobStorage.getInputStream(lobId, hmac, byteCount);
return handler.getLobStorage().getInputStream(lobId, hmac, byteCount);
} catch (IOException e) {
throw DbException.convertIOException(e, toString());
}
......@@ -543,7 +538,6 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
private FileStoreOutputStream initTemp() throws IOException {
this.precision = 0;
this.lobStorage = this.handler.getLobStorage();
String path = this.handler.getDatabasePath();
if (path.length() == 0) {
path = SysProperties.PREFIX_TEMP_FILE;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论