Class Binary<T extends Serializable>
- Type Parameters:
T- the serializable type
- All Implemented Interfaces:
Serializable, Cloneable, Freezable
Uses Java Object Serialization (JOS) under the hood.
It uses the XXXBinaryStream-methods of ResultSet to read and write the data avoiding
the transactional limits of blobs, because blobs usually are only valid within a transaction.
Binary instead provides a blob-like interface while remaining valid outside transactions.
Furthermore, binaries can be frozen, i.e., made immutable.
Keep in mind that the wrapped object is serialized when the Binary is created or setObject is invoked. Any further changes to the object are not reflected in the internal byte array.
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionBinary()Creates an empty binary.Binary(InputStream stream, int bufSize, boolean frozen) Creates a binary from anInputStream.
Used to read a binary from the database.Creates a Binary from aSerializable. -
Method Summary
Modifier and TypeMethodDescriptionclone()static <T extends Serializable>
Binary<T> create(InputStream stream, int bufSize, boolean frozen) Creates aBinaryout of an InputStream.Retrieves the object encapsulated by theBinary.
The object is deserialized on first invocation and cached afterward.voidSets the object.
The object is serialized immediately.Methods inherited from class AbstractBinary
assertNotFrozen, equals, freeze, getData, getInputStream, getLength, hashCode, isEmpty, isFrozen
-
Constructor Details
-
Binary
Creates a Binary from aSerializable.- Parameters:
object- theSerializableto be stored in the database- Throws:
IOException- if serialization failed
-
Binary
Creates a binary from anInputStream.
Used to read a binary from the database. The stream is closed after creating the binary.- Parameters:
stream- the InputStream (associated with the database) to read from, never null (seecreate)bufSize- the initial buffer size, values below 128 select the default size of 1024frozen- true if binary is frozen- Throws:
IOException- if reading from the input stream failed
-
Binary
public Binary()Creates an empty binary.
-
-
Method Details
-
create
public static <T extends Serializable> Binary<T> create(InputStream stream, int bufSize, boolean frozen) throws IOException Creates aBinaryout of an InputStream. Used to read aBinaryfrom the database. Notice thatstream.available()cannot be used according to theInputStreamcontract. The stream is closed after creating theBinary.- Type Parameters:
T- the serializable type- Parameters:
stream- the InputStream (associated with the database) to read from, may be nullbufSize- the initial buffer size, values below 128 select the default size of 1024frozen- true ifBinaryis frozen- Returns:
- the new
Binaryor null if the stream is null - Throws:
IOException- if reading from the input stream failed
-
clone
Cloned binaries are always not frozen.
Cloned binaries are always not frozen.
- Overrides:
clonein classAbstractBinary<T extends Serializable>
-
getObject
Retrieves the object encapsulated by theBinary.
The object is deserialized on first invocation and cached afterward.The bytes are deserialized through the filter created by
Settings.createDeserializationFilter(long). Since they usually come from the database or a remote peer, applications should configure an allowlist viaSettings.setDeserializationFilter(ObjectInputFilter)or the system property "tentackle.serialFilter".- Specified by:
getObjectin classAbstractBinary<T extends Serializable>- Returns:
- the deserialized object (retrieved from the db), or null if NULL-value
- Throws:
IOException- if reading the object failed, or it was rejected by the filter (InvalidClassException)ClassNotFoundException- if the class of a serialized object cannot be found.
-
setObject
Sets the object.
The object is serialized immediately.- Specified by:
setObjectin classAbstractBinary<T extends Serializable>- Parameters:
object- the object, null to clear the binary- Throws:
IOException- if the object could not be serializedTentackleRuntimeException- if the binary is frozen
-