Search in sources :

Example 1 with LobDataDatabase

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);
    }
}
Also used : MVStore(org.h2.mvstore.MVStore) LobDataDatabase(org.h2.value.lob.LobDataDatabase) ValueLob(org.h2.value.ValueLob) ValueBlob(org.h2.value.ValueBlob) ValueClob(org.h2.value.ValueClob)

Example 2 with LobDataDatabase

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;
}
Also used : LobDataDatabase(org.h2.value.lob.LobDataDatabase) ValueBlob(org.h2.value.ValueBlob) DbException(org.h2.message.DbException) IOException(java.io.IOException)

Example 3 with LobDataDatabase

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;
}
Also used : LobDataDatabase(org.h2.value.lob.LobDataDatabase) ValueBigint(org.h2.value.ValueBigint) ValueTinyint(org.h2.value.ValueTinyint) ValueSmallint(org.h2.value.ValueSmallint)

Example 4 with LobDataDatabase

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();
    }
}
Also used : LobDataInMemory(org.h2.value.lob.LobDataInMemory) LobStorageInterface(org.h2.store.LobStorageInterface) LobDataDatabase(org.h2.value.lob.LobDataDatabase)

Example 5 with LobDataDatabase

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);
}
Also used : LobData(org.h2.value.lob.LobData) LobDataInMemory(org.h2.value.lob.LobDataInMemory) LobDataDatabase(org.h2.value.lob.LobDataDatabase) LobDataFetchOnDemand(org.h2.value.lob.LobDataFetchOnDemand)

Aggregations

LobDataDatabase (org.h2.value.lob.LobDataDatabase)41 LobDataInMemory (org.h2.value.lob.LobDataInMemory)22 LobData (org.h2.value.lob.LobData)17 ValueBlob (org.h2.value.ValueBlob)10 ValueBigint (org.h2.value.ValueBigint)7 ValueClob (org.h2.value.ValueClob)7 ValueSmallint (org.h2.value.ValueSmallint)7 ValueTinyint (org.h2.value.ValueTinyint)7 LobStorageInterface (org.h2.store.LobStorageInterface)6 ValueLob (org.h2.value.ValueLob)6 LobDataFetchOnDemand (org.h2.value.lob.LobDataFetchOnDemand)6 MVStore (org.h2.mvstore.MVStore)5 Constraint (org.h2.constraint.Constraint)4 Value (org.h2.value.Value)4 ValueInterval (org.h2.value.ValueInterval)4 ValueTimeTimeZone (org.h2.value.ValueTimeTimeZone)4 ValueTimestamp (org.h2.value.ValueTimestamp)4 ValueTimestampTimeZone (org.h2.value.ValueTimestampTimeZone)4 ValueUuid (org.h2.value.ValueUuid)4 IOException (java.io.IOException)3