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. Since tentackle-core is part of any Tentackle application, org.tentackle.trip.impl.TripObjectSerializer will be used by default.

Does not require the objects to be serializable implement Serializable.

See Also:
  • Constructor Details

    • TBinary

      public TBinary(T object) throws IOException
      Creates a Binary from an object.
      Parameters:
      object - the object to be stored in the database
      Throws:
      IOException - if some serialization error.
    • 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 may be null
      bufSize - the initial buffer size, 0 = default size
      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 serializable type
      Parameters:
      stream - the InputStream (associated with the database) to read from may be null
      bufSize - the initial buffer size, 0 = default size
      frozen - true if TBinary is frozen
      Returns:
      the new TBinary or null if the stream is null or empty.
      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 Binary.
      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.
    • setObject

      public void setObject(T object) throws IOException
      Sets the serializable.
      Specified by:
      setObject in class AbstractBinary<T>
      Parameters:
      object - the serializable object.
      Throws:
      IOException - if the object could not be serialized