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

public final class TBinary<T> extends AbstractBinary<T> implements Serializable
Datatype for storing an object in a database.
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:
  • Constructor Details

    • TBinary

      public TBinary(T object) throws IOException
      Creates a TBinary from an object.
      Parameters:
      object - the object to be stored in the database
      Throws:
      IOException - if serialization failed
    • TBinary

      public TBinary(InputStream stream, int bufSize, boolean frozen) throws IOException
      Creates a binary from an InputStream.
      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 (see create)
      bufSize - the initial buffer size, values below 128 select the default size of 1024
      frozen - 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 a TBinary out of an InputStream. Used to read a TBinary from the database. The stream is closed after creating the TBinary.
      Type Parameters:
      T - the object type
      Parameters:
      stream - the InputStream (associated with the database) to read from, may be null
      bufSize - the initial buffer size, values below 128 select the default size of 1024
      frozen - true if TBinary is frozen
      Returns:
      the new TBinary or null if the stream is null
      Throws:
      IOException - if reading from the input stream failed
    • clone

      public TBinary<T> clone()

      Cloned binaries are always not frozen.

      Cloned binaries are always not frozen.

      Overrides:
      clone in class AbstractBinary<T>
    • getObject

      public T getObject() throws IOException, ClassNotFoundException
      Retrieves the object encapsulated by the TBinary.
      The object is deserialized on first invocation and cached afterward.
      Specified by:
      getObject in class AbstractBinary<T>
      Returns:
      the deserialized object (retrieved from the db), or null if NULL-value
      Throws:
      IOException - if reading the object failed
      ClassNotFoundException - if the class of a serialized object cannot be found.
      TentackleRuntimeException - if the ObjectSerializer failed
    • setObject

      public void setObject(T object) throws IOException
      Sets the object.
      The object is serialized immediately.
      Specified by:
      setObject in class AbstractBinary<T>
      Parameters:
      object - the object, null to clear the binary
      Throws:
      IOException - if the object could not be serialized
      TentackleRuntimeException - if the binary is frozen