Top Description Inners Fields Constructors Methods
org.h2.mvstore.db

public final Class LobStorageMap

extends Object
implements LobStorageInterface
Class Inheritance
All Implemented Interfaces
org.h2.store.LobStorageInterface
Imports
java.io.FilterInputStream, .IOException, .InputStream, .Reader, java.nio.ByteBuffer, java.nio.charset.StandardCharsets, java.util.ArrayList, .Arrays, .Iterator, .Map.Entry, .Queue, java.util.concurrent.ConcurrentLinkedQueue, .RejectedExecutionException, .SynchronousQueue, .ThreadPoolExecutor, java.util.concurrent.atomic.AtomicLong, org.h2.api.ErrorCode, org.h2.engine.Database, org.h2.message.DbException, org.h2.mvstore.DataUtils, .MVMap, .MVStore, .MVStoreException, .StreamStore, .WriteBuffer, org.h2.mvstore.tx.TransactionStore, org.h2.mvstore.type.BasicDataType, .ByteArrayDataType, .LongDataType, org.h2.store.CountingReaderInputStream, .LobStorageFrontend, .LobStorageInterface, .RangeInputStream, org.h2.util.IOUtils, .StringUtils, .Utils, org.h2.value.Value, .ValueBlob, .ValueClob, .ValueLob, .ValueNull, org.h2.value.lob.LobData, .LobDataDatabase

This class stores LOB objects in the database, in maps. This is the back-end i.e. the server side of the LOB storage.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class
private class
private static class

Field Summary

Modifier and TypeField and Description
private final ThreadPoolExecutor
private final Database
private final MVMap<Long, LobStorageMap.BlobMeta>
lobMap

The lob metadata map.

pack-priv final MVStore
private final AtomicLong
private final Queue<LobStorageMap.LobRemovalInfo>
private final MVMap<LobStorageMap.BlobReference, Value>
refMap

The reference map.

private final StreamStore
private final MVMap<Long, byte[]>
tempLobMap

The lob metadata map for temporary lobs.

private static final boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
cleanup(long oldestVersionToKeep)

public void
close()

Overrides default org.h2.store.LobStorageInterface.close.

Close LobStorage and release all resources

public ValueLob
copyLob(ValueLob
the old lob
old
,
int
the new table id
tableId
)

Implements org.h2.store.LobStorageInterface.copyLob.

Copy a lob.

public ValueBlob
createBlob(InputStream
the input stream
in
,
long
the maximum length (-1 if not known)
maxLength
)

Implements org.h2.store.LobStorageInterface.createBlob.

Create a BLOB object.

private ValueBlob
public ValueClob
createClob(Reader
the reader
reader
,
long
the maximum length (-1 if not known)
maxLength
)

Implements org.h2.store.LobStorageInterface.createClob.

Create a CLOB object.

private void
doRemoveLob(int tableId, long lobId)

private long
public InputStream
getInputStream(long
the lob id
lobId
,
long
the number of bytes to read, or -1 if not known
byteCount
)

Implements org.h2.store.LobStorageInterface.getInputStream.

Get the input stream for the given lob, only called on server side of a TCP connection.

public InputStream
getInputStream(long
the lob id
lobId
,
int
the able id
tableId
,
long
the number of bytes to read, or -1 if not known
byteCount
)

Implements org.h2.store.LobStorageInterface.getInputStream.

Get the input stream for the given lob

public boolean
isReadOnly()

Implements org.h2.store.LobStorageInterface.isReadOnly.

Whether the storage is read-only

private static boolean
isTemporaryLob(int tableId)

private boolean
public static MVMap<Long, byte[]>

Returns:

MVMap instance
openLobDataMap
(TransactionStore
containing map
txStore
)

Open map used to store LOB data

public static MVMap<Long, LobStorageMap.BlobMeta>

Returns:

MVMap instance
openLobMap
(TransactionStore
containing map
txStore
)

Open map used to store LOB metadata

public void
removeAllForTable(int
the table id
tableId
)

Implements org.h2.store.LobStorageInterface.removeAllForTable.

Remove all LOBs for this table.

public void
removeLob(ValueLob
the lob
lob
)

Implements org.h2.store.LobStorageInterface.removeLob.

Delete a LOB (from the database, if it is stored there).

private void
requestLobRemoval(int tableId, long lobId)

private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cleanupExecutorback to summary
private final ThreadPoolExecutor cleanupExecutor
databaseback to summary
private final Database database
lobMapback to summary
private final MVMap<Long, LobStorageMap.BlobMeta> lobMap

The lob metadata map. It contains the mapping from the lob id (which is a long) to the blob metadata, including stream store id (which is a byte array).

mvStoreback to summary
pack-priv final MVStore mvStore
nextLobIdback to summary
private final AtomicLong nextLobId
pendingLobRemovalsback to summary
private final Queue<LobStorageMap.LobRemovalInfo> pendingLobRemovals
refMapback to summary
private final MVMap<LobStorageMap.BlobReference, Value> refMap

The reference map. It is used to remove data from the stream store: if no more entries for the given streamStoreId exist, the data is removed from the stream store.

streamStoreback to summary
private final StreamStore streamStore
tempLobMapback to summary
private final MVMap<Long, byte[]> tempLobMap

The lob metadata map for temporary lobs. It contains the mapping from the lob id (which is a long) to the stream store id (which is a byte array). Key: lobId (long) Value: streamStoreId (byte[])

TRACEback to summary
private static final boolean TRACE

Constructor Detail

LobStorageMapback to summary
public LobStorageMap(Database database)

Method Detail

cleanupback to summary
private void cleanup(long oldestVersionToKeep)
closeback to summary
public void close()

Overrides default org.h2.store.LobStorageInterface.close.

Doc from org.h2.store.LobStorageInterface.close.

Close LobStorage and release all resources

Annotations
@Override
copyLobback to summary
public ValueLob copyLob(ValueLob old, int tableId)

Implements org.h2.store.LobStorageInterface.copyLob.

Doc from org.h2.store.LobStorageInterface.copyLob.

Copy a lob.

Parameters
old:ValueLob

the old lob

tableId:int

the new table id

Returns:ValueLob

the new lob

Annotations
@Override
createBlobback to summary
public ValueBlob createBlob(InputStream in, long maxLength)

Implements org.h2.store.LobStorageInterface.createBlob.

Doc from org.h2.store.LobStorageInterface.createBlob.

Create a BLOB object.

Parameters
in:InputStream

the input stream

maxLength:long

the maximum length (-1 if not known)

Returns:ValueBlob

the LOB

Annotations
@Override
createBlobback to summary
private ValueBlob createBlob(InputStream in) throws IOException
createClobback to summary
public ValueClob createClob(Reader reader, long maxLength)

Implements org.h2.store.LobStorageInterface.createClob.

Doc from org.h2.store.LobStorageInterface.createClob.

Create a CLOB object.

Parameters
reader:Reader

the reader

maxLength:long

the maximum length (-1 if not known)

Returns:ValueClob

the LOB

Annotations
@Override
doRemoveLobback to summary
private void doRemoveLob(int tableId, long lobId)
generateLobIdback to summary
private long generateLobId()
getInputStreamback to summary
public InputStream getInputStream(long lobId, long byteCount) throws IOException

Implements org.h2.store.LobStorageInterface.getInputStream.

Doc from org.h2.store.LobStorageInterface.getInputStream.

Get the input stream for the given lob, only called on server side of a TCP connection.

Parameters
lobId:long

the lob id

byteCount:long

the number of bytes to read, or -1 if not known

Returns:InputStream

the stream

Annotations
@Override
Exceptions
IOException:
on failure
getInputStreamback to summary
public InputStream getInputStream(long lobId, int tableId, long byteCount) throws IOException

Implements org.h2.store.LobStorageInterface.getInputStream.

Doc from org.h2.store.LobStorageInterface.getInputStream.

Get the input stream for the given lob

Parameters
lobId:long

the lob id

tableId:int

the able id

byteCount:long

the number of bytes to read, or -1 if not known

Returns:InputStream

the stream

Annotations
@Override
Exceptions
IOException:
on failure
isReadOnlyback to summary
public boolean isReadOnly()

Implements org.h2.store.LobStorageInterface.isReadOnly.

Doc from org.h2.store.LobStorageInterface.isReadOnly.

Whether the storage is read-only

Returns:boolean

true if yes

Annotations
@Override
isTemporaryLobback to summary
private static boolean isTemporaryLob(int tableId)
needCleanupback to summary
private boolean needCleanup()
openLobDataMapback to summary
public static MVMap<Long, byte[]> openLobDataMap(TransactionStore txStore)

Open map used to store LOB data

Parameters
txStore:TransactionStore

containing map

Returns:MVMap<Long, byte[]>

MVMap instance

openLobMapback to summary
public static MVMap<Long, LobStorageMap.BlobMeta> openLobMap(TransactionStore txStore)

Open map used to store LOB metadata

Parameters
txStore:TransactionStore

containing map

Returns:MVMap<Long, LobStorageMap.BlobMeta>

MVMap instance

removeAllForTableback to summary
public void removeAllForTable(int tableId)

Implements org.h2.store.LobStorageInterface.removeAllForTable.

Doc from org.h2.store.LobStorageInterface.removeAllForTable.

Remove all LOBs for this table.

Parameters
tableId:int

the table id

Annotations
@Override
removeLobback to summary
public void removeLob(ValueLob lob)

Implements org.h2.store.LobStorageInterface.removeLob.

Doc from org.h2.store.LobStorageInterface.removeLob.

Delete a LOB (from the database, if it is stored there).

Parameters
lob:ValueLob

the lob

Annotations
@Override
requestLobRemovalback to summary
private void requestLobRemoval(int tableId, long lobId)
traceback to summary
private static void trace(String op)
org.h2.mvstore.db back to summary

public final Class LobStorageMap.BlobMeta

extends Object
Class Inheritance

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
pack-priv final long
pack-priv final long
public final byte[]
streamStoreId

Stream identifier.

pack-priv final int

Constructor Summary

AccessConstructor and Description
public
BlobMeta(byte[] streamStoreId, int tableId, long byteCount, long hash)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

byteCountback to summary
pack-priv final long byteCount
hashback to summary
pack-priv final long hash
streamStoreIdback to summary
public final byte[] streamStoreId

Stream identifier. It is used as a key in LOB data map.

tableIdback to summary
pack-priv final int tableId

Constructor Detail

BlobMetaback to summary
public BlobMeta(byte[] streamStoreId, int tableId, long byteCount, long hash)
org.h2.mvstore.db back to summary

public final Class LobStorageMap.BlobMeta.Type

extends BasicDataType<LobStorageMap.BlobMeta>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final LobStorageMap.BlobMeta.Type

Constructor Summary

AccessConstructor and Description
private
Type()

Method Summary

Modifier and TypeMethod and Description
public LobStorageMap.BlobMeta[]
createStorage(int
number of values to hold
size
)

Implements org.h2.mvstore.type.DataType.createStorage.

Create storage object of array type to hold values

public int
getMemory(LobStorageMap.BlobMeta
the object
blobMeta
)

Implements abstract org.h2.mvstore.type.BasicDataType.getMemory.

Implements org.h2.mvstore.type.DataType.getMemory.

Calculates the amount of used memory in bytes.

public LobStorageMap.BlobMeta
read(ByteBuffer
the source buffer
buff
)

Implements abstract org.h2.mvstore.type.BasicDataType.read.

Implements org.h2.mvstore.type.DataType.read.

Read an object.

public void
write(WriteBuffer
the target buffer
buff
,
LobStorageMap.BlobMeta
the value
blobMeta
)

Implements abstract org.h2.mvstore.type.BasicDataType.write.

Implements org.h2.mvstore.type.DataType.write.

Write an object.

Inherited from org.h2.mvstore.type.BasicDataType:
binarySearchcastcompareequalshashCodeisMemoryEstimationAllowedreadwrite

Field Detail

INSTANCEback to summary
public static final LobStorageMap.BlobMeta.Type INSTANCE

Constructor Detail

Typeback to summary
private Type()

Method Detail

createStorageback to summary
public LobStorageMap.BlobMeta[] createStorage(int size)

Implements org.h2.mvstore.type.DataType.createStorage.

Doc from org.h2.mvstore.type.DataType.createStorage.

Create storage object of array type to hold values

Parameters
size:int

number of values to hold

Returns:LobStorageMap.BlobMeta[]

storage object

Annotations
@Override
getMemoryback to summary
public int getMemory(LobStorageMap.BlobMeta blobMeta)

Implements abstract org.h2.mvstore.type.BasicDataType.getMemory.

Implements org.h2.mvstore.type.DataType.getMemory.

Doc from org.h2.mvstore.type.DataType.getMemory.

Calculates the amount of used memory in bytes.

Parameters
blobMeta:LobStorageMap.BlobMeta

the object

Returns:int

the used memory

Annotations
@Override
readback to summary
public LobStorageMap.BlobMeta read(ByteBuffer buff)

Implements abstract org.h2.mvstore.type.BasicDataType.read.

Implements org.h2.mvstore.type.DataType.read.

Doc from org.h2.mvstore.type.DataType.read.

Read an object.

Parameters
buff:ByteBuffer

the source buffer

Returns:LobStorageMap.BlobMeta

the object

Annotations
@Override
writeback to summary
public void write(WriteBuffer buff, LobStorageMap.BlobMeta blobMeta)

Implements abstract org.h2.mvstore.type.BasicDataType.write.

Implements org.h2.mvstore.type.DataType.write.

Doc from org.h2.mvstore.type.DataType.write.

Write an object.

Parameters
buff:WriteBuffer

the target buffer

blobMeta:LobStorageMap.BlobMeta

the value

Annotations
@Override
org.h2.mvstore.db back to summary

public final Class LobStorageMap.BlobReference

extends Object
implements Comparable<LobStorageMap.BlobReference>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
public final long
public final byte[]

Constructor Summary

AccessConstructor and Description
public
BlobReference(byte[] streamStoreId, long lobId)

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(LobStorageMap.BlobReference
the object to be compared.
other
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lobIdback to summary
public final long lobId
streamStoreIdback to summary
public final byte[] streamStoreId

Constructor Detail

BlobReferenceback to summary
public BlobReference(byte[] streamStoreId, long lobId)

Method Detail

compareToback to summary
public int compareTo(LobStorageMap.BlobReference other)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
other:LobStorageMap.BlobReference

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
org.h2.mvstore.db back to summary

public final Class LobStorageMap.BlobReference.Type

extends BasicDataType<LobStorageMap.BlobReference>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final LobStorageMap.BlobReference.Type

Constructor Summary

AccessConstructor and Description
private
Type()

Method Summary

Modifier and TypeMethod and Description
public int
public LobStorageMap.BlobReference[]
createStorage(int
number of values to hold
size
)

Implements org.h2.mvstore.type.DataType.createStorage.

Create storage object of array type to hold values

public int
getMemory(LobStorageMap.BlobReference
the object
blobReference
)

Implements abstract org.h2.mvstore.type.BasicDataType.getMemory.

Implements org.h2.mvstore.type.DataType.getMemory.

Calculates the amount of used memory in bytes.

public LobStorageMap.BlobReference
read(ByteBuffer
the source buffer
buff
)

Implements abstract org.h2.mvstore.type.BasicDataType.read.

Implements org.h2.mvstore.type.DataType.read.

Read an object.

public void
write(WriteBuffer
the target buffer
buff
,
LobStorageMap.BlobReference
the value
blobReference
)

Implements abstract org.h2.mvstore.type.BasicDataType.write.

Implements org.h2.mvstore.type.DataType.write.

Write an object.

Inherited from org.h2.mvstore.type.BasicDataType:
binarySearchcastequalshashCodeisMemoryEstimationAllowedreadwrite

Field Detail

INSTANCEback to summary
public static final LobStorageMap.BlobReference.Type INSTANCE

Constructor Detail

Typeback to summary
private Type()

Method Detail

compareback to summary
public int compare(LobStorageMap.BlobReference one, LobStorageMap.BlobReference two)

Overrides org.h2.mvstore.type.BasicDataType.compare.

Implements org.h2.mvstore.type.DataType.compare.

Doc from org.h2.mvstore.type.DataType.compare.

Compare two keys.

Parameters
one:LobStorageMap.BlobReference

the first key

two:LobStorageMap.BlobReference

the second key

Returns:int

-1 if the first key is smaller, 1 if larger, and 0 if equal

Annotations
@Override
createStorageback to summary
public LobStorageMap.BlobReference[] createStorage(int size)

Implements org.h2.mvstore.type.DataType.createStorage.

Doc from org.h2.mvstore.type.DataType.createStorage.

Create storage object of array type to hold values

Parameters
size:int

number of values to hold

Returns:LobStorageMap.BlobReference[]

storage object

Annotations
@Override
getMemoryback to summary
public int getMemory(LobStorageMap.BlobReference blobReference)

Implements abstract org.h2.mvstore.type.BasicDataType.getMemory.

Implements org.h2.mvstore.type.DataType.getMemory.

Doc from org.h2.mvstore.type.DataType.getMemory.

Calculates the amount of used memory in bytes.

Parameters
blobReference:LobStorageMap.BlobReference

the object

Returns:int

the used memory

Annotations
@Override
readback to summary
public LobStorageMap.BlobReference read(ByteBuffer buff)

Implements abstract org.h2.mvstore.type.BasicDataType.read.

Implements org.h2.mvstore.type.DataType.read.

Doc from org.h2.mvstore.type.DataType.read.

Read an object.

Parameters
buff:ByteBuffer

the source buffer

Returns:LobStorageMap.BlobReference

the object

Annotations
@Override
writeback to summary
public void write(WriteBuffer buff, LobStorageMap.BlobReference blobReference)

Implements abstract org.h2.mvstore.type.BasicDataType.write.

Implements org.h2.mvstore.type.DataType.write.

Doc from org.h2.mvstore.type.DataType.write.

Write an object.

Parameters
buff:WriteBuffer

the target buffer

blobReference:LobStorageMap.BlobReference

the value

Annotations
@Override
org.h2.mvstore.db back to summary

private final Class LobStorageMap.LobInputStream

extends FilterInputStream
Class Inheritance

Field Summary

Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
read(byte[]
the buffer into which the data is read.
b
,
int
the start offset in array b at which the data is written.
off
,
int
the maximum number of bytes to read.
len
)

Overrides java.io.FilterInputStream.read.

Reads up to len bytes of data from this input stream into an array of bytes.

public int
read()

Overrides java.io.FilterInputStream.read.

Reads the next byte of data from the input stream.

Inherited from java.io.FilterInputStream:
availableclosemarkmarkSupportedreadresetskip

Constructor Detail

LobInputStreamback to summary
public LobInputStream(InputStream in)

Method Detail

readback to summary
public int read(byte[] b, int off, int len) throws IOException

Overrides java.io.FilterInputStream.read.

Doc from java.io.FilterInputStream.read.

Reads up to len bytes of data from this input stream into an array of bytes. If len is not zero, the method blocks until some input is available; otherwise, no bytes are read and 0 is returned.

Parameters
b:byte[]

the buffer into which the data is read.

off:int

the start offset in array b at which the data is written.

len:int

the maximum number of bytes to read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read() throws IOException

Overrides java.io.FilterInputStream.read.

Doc from java.io.FilterInputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
org.h2.mvstore.db back to summary

private final Class LobStorageMap.LobRemovalInfo

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final long
pack-priv final int
pack-priv final long

Constructor Summary

AccessConstructor and Description
pack-priv
LobRemovalInfo(long version, long lobId, int mapId)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lobIdback to summary
pack-priv final long lobId
mapIdback to summary
pack-priv final int mapId
versionback to summary
pack-priv final long version

Constructor Detail

LobRemovalInfoback to summary
pack-priv LobRemovalInfo(long version, long lobId, int mapId)