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

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

    • Binary

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

      public Binary(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
    • Binary

      public Binary()
      Creates an empty binary.
  • Method Details