Package org.h2.mvstore.type
Class ObjectDataType
- java.lang.Object
-
- org.h2.mvstore.type.BasicDataType<java.lang.Object>
-
- org.h2.mvstore.type.ObjectDataType
-
- All Implemented Interfaces:
java.util.Comparator<java.lang.Object>,DataType<java.lang.Object>
public class ObjectDataType extends BasicDataType<java.lang.Object>
A data type implementation for the most common data types, including serializable objects.
-
-
Constructor Summary
Constructors Constructor Description ObjectDataType()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompare(java.lang.Object a, java.lang.Object b)Compare two keys.static intcompareNotNull(byte[] data1, byte[] data2)Compare the contents of two byte arrays.java.lang.Object[]createStorage(int size)Create storage object of array type to hold valuesstatic java.lang.Objectdeserialize(byte[] data)De-serialize the byte array to an object.intgetMemory(java.lang.Object obj)Calculates the amount of used memory in bytes.java.lang.Objectread(java.nio.ByteBuffer buff)Read an object.static byte[]serialize(java.lang.Object obj)Serialize the object to a byte array.voidwrite(WriteBuffer buff, java.lang.Object obj)Write an object.-
Methods inherited from class org.h2.mvstore.type.BasicDataType
binarySearch, cast, equals, hashCode, isMemoryEstimationAllowed, read, write
-
-
-
-
Method Detail
-
createStorage
public java.lang.Object[] createStorage(int size)
Description copied from interface:DataTypeCreate storage object of array type to hold values- Parameters:
size- number of values to hold- Returns:
- storage object
-
compare
public int compare(java.lang.Object a, java.lang.Object b)Description copied from interface:DataTypeCompare two keys.- Specified by:
comparein interfacejava.util.Comparator<java.lang.Object>- Specified by:
comparein interfaceDataType<java.lang.Object>- Overrides:
comparein classBasicDataType<java.lang.Object>- Parameters:
a- the first keyb- the second key- Returns:
- -1 if the first key is smaller, 1 if larger, and 0 if equal
-
getMemory
public int getMemory(java.lang.Object obj)
Description copied from interface:DataTypeCalculates the amount of used memory in bytes.- Specified by:
getMemoryin interfaceDataType<java.lang.Object>- Specified by:
getMemoryin classBasicDataType<java.lang.Object>- Parameters:
obj- the object- Returns:
- the used memory
-
write
public void write(WriteBuffer buff, java.lang.Object obj)
Description copied from interface:DataTypeWrite an object.- Specified by:
writein interfaceDataType<java.lang.Object>- Specified by:
writein classBasicDataType<java.lang.Object>- Parameters:
buff- the target bufferobj- the value
-
read
public java.lang.Object read(java.nio.ByteBuffer buff)
Description copied from interface:DataTypeRead an object.- Specified by:
readin interfaceDataType<java.lang.Object>- Specified by:
readin classBasicDataType<java.lang.Object>- Parameters:
buff- the source buffer- Returns:
- the object
-
serialize
public static byte[] serialize(java.lang.Object obj)
Serialize the object to a byte array.- Parameters:
obj- the object to serialize- Returns:
- the byte array
-
deserialize
public static java.lang.Object deserialize(byte[] data)
De-serialize the byte array to an object.- Parameters:
data- the byte array- Returns:
- the object
-
compareNotNull
public static int compareNotNull(byte[] data1, byte[] data2)Compare the contents of two byte arrays. If the content or length of the first array is smaller than the second array, -1 is returned. If the content or length of the second array is smaller than the first array, 1 is returned. If the contents and lengths are the same, 0 is returned.This method interprets bytes as unsigned.
- Parameters:
data1- the first byte array (must not be null)data2- the second byte array (must not be null)- Returns:
- the result of the comparison (-1, 1 or 0)
-
-