Class ByteArrayType

java.lang.Object
org.apache.cayenne.access.types.ByteArrayType
All Implemented Interfaces:
ExtendedType<byte[]>
Direct Known Subclasses:
OracleByteArrayType

public class ByteArrayType
extends Object
implements ExtendedType<byte[]>
Handles byte[], mapping it as either of JDBC types - BLOB or (VAR)BINARY. Can be configured to trim trailing zero bytes.
  • Field Details

    • trimmingBytes

      protected boolean trimmingBytes
    • usingBlobs

      protected boolean usingBlobs
  • Constructor Details

    • ByteArrayType

      public ByteArrayType​(boolean trimmingBytes, boolean usingBlobs)
  • Method Details

    • logBytes

      public static void logBytes​(StringBuilder buffer, byte[] bytes)
    • trimBytes

      public static byte[] trimBytes​(byte[] bytes)
      Strips null bytes from the byte array, returning a potentially smaller array that contains no trailing zero bytes.
    • getClassName

      public String getClassName()
      Description copied from interface: ExtendedType
      Returns a full name of Java class that this ExtendedType supports.
      Specified by:
      getClassName in interface ExtendedType<byte[]>
    • materializeObject

      public byte[] materializeObject​(ResultSet rs, int index, int type) throws Exception
      Description copied from interface: ExtendedType
      Reads an object from JDBC ResultSet column, converting it to class returned by 'getClassName' method.
      Specified by:
      materializeObject in interface ExtendedType<byte[]>
      Throws:
      Exception - if read error occurred, or an object can't be converted to a target Java class.
    • materializeObject

      public byte[] materializeObject​(CallableStatement cs, int index, int type) throws Exception
      Description copied from interface: ExtendedType
      Reads an object from a stored procedure OUT parameter, converting it to class returned by 'getClassName' method.
      Specified by:
      materializeObject in interface ExtendedType<byte[]>
      Throws:
      Exception - if read error occurred, or an object can't be converted to a target Java class.
    • setJdbcObject

      public void setJdbcObject​(PreparedStatement st, byte[] val, int pos, int type, int scale) throws Exception
      Description copied from interface: ExtendedType
      Initializes a single parameter of a PreparedStatement with object value.
      Specified by:
      setJdbcObject in interface ExtendedType<byte[]>
      Throws:
      Exception
    • toString

      public String toString​(byte[] value)
      Description copied from interface: ExtendedType
      Converts value of the supported type to a human-readable String representation.
      Specified by:
      toString in interface ExtendedType<byte[]>
      Parameters:
      value - a value to convert to String.
    • writeBlob

      protected Blob writeBlob​(byte[] bytes)
    • readBlob

      protected byte[] readBlob​(Blob blob) throws IOException, SQLException
      Throws:
      IOException
      SQLException
    • readBinaryStream

      protected byte[] readBinaryStream​(ResultSet rs, int index) throws IOException, SQLException
      Throws:
      IOException
      SQLException
    • readValueStream

      protected byte[] readValueStream​(InputStream in, int streamSize, int bufSize) throws IOException
      Throws:
      IOException
    • isUsingBlobs

      public boolean isUsingBlobs()
      Returns true if byte columns are handled as BLOBs internally.
    • setUsingBlobs

      public void setUsingBlobs​(boolean usingBlobs)
    • isTrimmingBytes

      public boolean isTrimmingBytes()
    • setTrimmingBytes

      public void setTrimmingBytes​(boolean trimingBytes)