Class Binary<T extends Serializable>
java.lang.Object
org.tentackle.common.AbstractBinary<T>
org.tentackle.common.Binary<T>
- Type Parameters:
T- the serializable type
- All Implemented Interfaces:
Serializable, Cloneable, Freezable
Datatype for storing an object in a database.
Uses Java Object Serialization (JOS) under the hood.
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.voidSets the serializable.Methods inherited from class AbstractBinary
assertNotFrozen, equals, freeze, getData, getInputStream, getLength, hashCode, isFrozen
-
Constructor Details
-
Binary
Creates a Binary from aSerializable.- Parameters:
object- theSerializableto be stored in the database- Throws:
IOException- if some serialization error.
-
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 may be nullbufSize- the initial buffer size, 0 = default sizefrozen- 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 that stream.available() cannot be used according to sun's spec. 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, 0 = default sizefrozen- true ifBinaryis frozen- Returns:
- the new
Binaryor null if the stream is null or empty. - 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.- 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 failedClassNotFoundException- if the class of a serialized object cannot be found.
-
setObject
Sets the serializable.- Specified by:
setObjectin classAbstractBinary<T extends Serializable>- Parameters:
object- the serializable object.- Throws:
IOException- if the object could not be serialized
-