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