提交 b203816d authored 作者: noelgrandin's avatar noelgrandin

the link() and unlink() methods from Value are only called from the backend, so…

the link() and unlink() methods from Value are only called from the backend, so pass in the Database instance.
That lets me remove the removeLob() method from LobStorageInterface.
上级 2f77a60e
......@@ -150,7 +150,7 @@ public class Session extends SessionWithState {
}
if (old != null) {
// close the old value (in case it is a lob)
old.unlink();
old.unlink(database);
old.close();
}
}
......@@ -489,7 +489,7 @@ public class Session extends SessionWithState {
// commit record is not written
database.flush();
for (Value v : unlinkLobMap.values()) {
v.unlink();
v.unlink(database);
v.close();
}
unlinkLobMap = null;
......
......@@ -11,7 +11,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.value.Value;
import org.h2.value.ValueLob;
import org.h2.value.ValueLobDb;
......@@ -101,16 +100,4 @@ public class LobStorageFrontend implements LobStorageInterface {
return ValueLob.createClob(reader, maxLength, handler);
}
/**
* Set the table reference of this lob.
*
* @param lobId the lob
* @param table the table
*/
public void setTable(long lobId, int table) {
// TODO ideally, this should not be called at all, but that's a refactoring for another day
// this should never be called
throw new UnsupportedOperationException();
}
}
......@@ -35,14 +35,6 @@ public interface LobStorageInterface {
*/
Value createBlob(InputStream in, long maxLength);
/**
* Set the table reference of this lob.
*
* @param lobId the lob
* @param table the table
*/
void setTable(long lobId, int table);
/**
* Copy a lob.
*
......
......@@ -19,10 +19,10 @@ import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.engine.Database;
import org.h2.message.DbException;
import org.h2.store.DataHandler;
import org.h2.store.LobStorageBackend;
......@@ -968,11 +968,11 @@ public abstract class Value {
* Link a large value to a given table. For values that are kept fully in
* memory this method has no effect.
*
* @param handler the data handler
* @param database the database
* @param tableId the table to link to
* @return the new value or itself
*/
public Value link(DataHandler handler, int tableId) {
public Value link(Database database, int tableId) {
return this;
}
......@@ -990,7 +990,7 @@ public abstract class Value {
* Mark any underlying resource as 'not linked to any table'. For values
* that are kept fully in memory this method has no effect.
*/
public void unlink() {
public void unlink(Database database) {
// nothing to do
}
......
......@@ -15,6 +15,7 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.engine.Database;
import org.h2.message.DbException;
import org.h2.mvstore.DataUtils;
import org.h2.store.DataHandler;
......@@ -147,30 +148,30 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
}
}
public void unlink() {
public void unlink(Database database) {
if (small == null && tableId != LobStorageBackend.TABLE_ID_SESSION_VARIABLE) {
lobStorage.setTable(lobId, LobStorageBackend.TABLE_ID_SESSION_VARIABLE);
database.getLobStorage().setTable(lobId, LobStorageBackend.TABLE_ID_SESSION_VARIABLE);
tableId = LobStorageBackend.TABLE_ID_SESSION_VARIABLE;
}
}
public Value link(DataHandler h, int tabId) {
public Value link(Database database, int tabId) {
if (small == null) {
if (tableId == LobStorageBackend.TABLE_TEMP) {
lobStorage.setTable(lobId, tabId);
database.getLobStorage().setTable(lobId, tabId);
this.tableId = tabId;
} else {
return lobStorage.copyLob(type, lobId, tabId, getPrecision());
}
} else if (small.length > h.getMaxLengthInplaceLob()) {
LobStorageInterface s = h.getLobStorage();
} else if (small.length > database.getMaxLengthInplaceLob()) {
LobStorageInterface s = database.getLobStorage();
Value v;
if (type == Value.BLOB) {
v = s.createBlob(getInputStream(), getPrecision());
} else {
v = s.createClob(getReader(), getPrecision());
}
return v.link(h, tabId);
return v.link(database, tabId);
}
return this;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论