Class TBinary<T>
java.lang.Object
org.tentackle.common.AbstractBinary<T>
org.tentackle.common.TBinary<T>
- Type Parameters:
T- the object type
- All Implemented Interfaces:
Serializable, Cloneable, Freezable
Datatype for storing an object in a database.
Same as
Same as
Binary, but uses the application-specific ObjectSerializer implementation.
If tentackle-core is present, as in any multi-tier Tentackle application,
org.tentackle.trip.impl.TripObjectSerializer is used. Otherwise, the DefaultObjectSerializer
applies, which requires the objects to be Serializable.
With TRIP, the objects are not required to implement Serializable.
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionTBinary()Creates an empty binary.TBinary(InputStream stream, int bufSize, boolean frozen) Creates a binary from anInputStream.
Used to read a binary from the database.Creates aTBinaryfrom an object. -
Method Summary
Modifier and TypeMethodDescriptionclone()static <T> TBinary<T> create(InputStream stream, int bufSize, boolean frozen) Creates aTBinaryout of an InputStream.Retrieves the object encapsulated by theTBinary.
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
-
TBinary
Creates aTBinaryfrom an object.- Parameters:
object- the object to be stored in the database- Throws:
IOException- if serialization failed
-
TBinary
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
-
TBinary
public TBinary()Creates an empty binary.
-
-
Method Details
-
create
public static <T> TBinary<T> create(InputStream stream, int bufSize, boolean frozen) throws IOException Creates aTBinaryout of an InputStream. Used to read aTBinaryfrom the database. The stream is closed after creating theTBinary.- Type Parameters:
T- the object 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 ifTBinaryis frozen- Returns:
- the new
TBinaryor 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>
-
getObject
Retrieves the object encapsulated by theTBinary.
The object is deserialized on first invocation and cached afterward.- Specified by:
getObjectin classAbstractBinary<T>- 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.TentackleRuntimeException- if theObjectSerializerfailed
-
setObject
Sets the object.
The object is serialized immediately.- Specified by:
setObjectin classAbstractBinary<T>- Parameters:
object- the object, null to clear the binary- Throws:
IOException- if the object could not be serializedTentackleRuntimeException- if the binary is frozen
-