use of org.h2.value.lob.LobDataDatabase in project h2database by h2database.
the class LobStorageMap method copyLob.
@Override
public ValueLob copyLob(ValueLob old, int tableId) {
MVStore.TxCounter txCounter = mvStore.registerVersionUsage();
try {
final LobDataDatabase lobData = (LobDataDatabase) old.getLobData();
final int type = old.getValueType();
final long oldLobId = lobData.getLobId();
long octetLength = old.octetLength();
// get source lob
final byte[] streamStoreId;
if (isTemporaryLob(lobData.getTableId())) {
streamStoreId = tempLobMap.get(oldLobId);
} else {
BlobMeta value = lobMap.get(oldLobId);
streamStoreId = value.streamStoreId;
}
// create destination lob
final long newLobId = generateLobId();
if (isTemporaryLob(tableId)) {
tempLobMap.put(newLobId, streamStoreId);
} else {
BlobMeta value = new BlobMeta(streamStoreId, tableId, type == Value.CLOB ? old.charLength() : octetLength, 0);
lobMap.put(newLobId, value);
}
BlobReference refMapKey = new BlobReference(streamStoreId, newLobId);
refMap.put(refMapKey, ValueNull.INSTANCE);
LobDataDatabase newLobData = new LobDataDatabase(database, tableId, newLobId);
ValueLob lob = type == Value.BLOB ? new ValueBlob(newLobData, octetLength) : new ValueClob(newLobData, octetLength, old.charLength());
if (TRACE) {
trace("copy " + lobData.getTableId() + "/" + lobData.getLobId() + " > " + tableId + "/" + newLobId);
}
return lob;
} finally {
mvStore.deregisterVersionUsage(txCounter);
}
}
use of org.h2.value.lob.LobDataDatabase in project h2database by h2database.
the class LobStorageMap method createBlob.
private ValueBlob createBlob(InputStream in) throws IOException {
byte[] streamStoreId;
try {
streamStoreId = streamStore.put(in);
} catch (Exception e) {
throw DataUtils.convertToIOException(e);
}
long lobId = generateLobId();
long length = streamStore.length(streamStoreId);
final int tableId = LobStorageFrontend.TABLE_TEMP;
tempLobMap.put(lobId, streamStoreId);
BlobReference key = new BlobReference(streamStoreId, lobId);
refMap.put(key, ValueNull.INSTANCE);
ValueBlob lob = new ValueBlob(new LobDataDatabase(database, tableId, lobId), length);
if (TRACE) {
trace("create " + tableId + "/" + lobId);
}
return lob;
}
use of org.h2.value.lob.LobDataDatabase in project h2database by h2database.
the class ValueDataType method readLobDataDatabase.
private LobDataDatabase readLobDataDatabase(ByteBuffer buff) {
int tableId = readVarInt(buff);
long lobId = readVarLong(buff);
LobDataDatabase lobData = new LobDataDatabase(handler, tableId, lobId);
return lobData;
}
use of org.h2.value.lob.LobDataDatabase in project h2database by h2database.
the class ValueClob method copy.
@Override
public ValueLob copy(DataHandler database, int tableId) {
if (lobData instanceof LobDataInMemory) {
byte[] small = ((LobDataInMemory) lobData).getSmall();
if (small.length > database.getMaxLengthInplaceLob()) {
LobStorageInterface s = database.getLobStorage();
ValueClob v = s.createClob(getReader(), charLength);
ValueLob v2 = v.copy(database, tableId);
v.remove();
return v2;
}
return this;
} else if (lobData instanceof LobDataDatabase) {
return database.getLobStorage().copyLob(this, tableId);
} else {
throw new UnsupportedOperationException();
}
}
use of org.h2.value.lob.LobDataDatabase in project h2database by h2database.
the class ValueClob method compareTypeSafe.
@Override
public int compareTypeSafe(Value v, CompareMode mode, CastDataProvider provider) {
if (v == this) {
return 0;
}
ValueClob v2 = (ValueClob) v;
LobData lobData = this.lobData, lobData2 = v2.lobData;
if (lobData.getClass() == lobData2.getClass()) {
if (lobData instanceof LobDataInMemory) {
return Integer.signum(getString().compareTo(v2.getString()));
} else if (lobData instanceof LobDataDatabase) {
if (((LobDataDatabase) lobData).getLobId() == ((LobDataDatabase) lobData2).getLobId()) {
return 0;
}
} else if (lobData instanceof LobDataFetchOnDemand) {
if (((LobDataFetchOnDemand) lobData).getLobId() == ((LobDataFetchOnDemand) lobData2).getLobId()) {
return 0;
}
}
}
return compare(this, v2);
}
Aggregations