Class BytesDataType

Direct Known Subclasses:
BinaryStreamDataType, BlobDataType, PostgreSQLOidDataType, UuidAwareBytesDataType

public class BytesDataType extends AbstractDataType
DataType mapping a binary SQL column type to a Java byte[].
Since:
1.0 (Mar 20, 2002)
Version:
$Revision$ $Date$
Author:
Manuel Laflamme, Last changed by: $Author$
  • Constructor Details

    • BytesDataType

      public BytesDataType(String name, int sqlType)
      Constructs a data type with the given SQL type mapping.
      Parameters:
      name - the data type name.
      sqlType - the Types constant this data type maps to.
  • Method Details

    • loadFile

      public byte[] loadFile(String filename) throws IOException
      Reads the entire contents of the given file into a byte array.
      Parameters:
      filename - the path of the file to read.
      Returns:
      the file's contents.
      Throws:
      IOException - if the file cannot be read.
    • loadURL

      public byte[] loadURL(String urlAsString) throws IOException
      Reads the entire contents at the given URL into a byte array.
      Parameters:
      urlAsString - the URL to read from.
      Returns:
      the URL content.
      Throws:
      IOException - if the URL cannot be read.
    • typeCast

      public Object typeCast(Object value) throws TypeCastException
      Casts the given value into a byte[] using different strategies. Note that this might sometimes result in undesired behavior when character data (Strings) are used.
      Specified by:
      typeCast in class DataType
      Parameters:
      value - the value to typecast.
      Returns:
      the typecast value.
      Throws:
      TypeCastException - if the value cannot be typecast to this DataType.
      See Also:
    • compareNonNulls

      protected int compareNonNulls(Object value1, Object value2) throws TypeCastException
      Description copied from class: AbstractDataType
      Compares non-null values to each other. Both objects are guaranteed to be not null and to implement the interface Comparable. The two given objects are the results of the DataType.typeCast(Object) method call which is usually implemented by a specialized DataType implementation.
      Overrides:
      compareNonNulls in class AbstractDataType
      Parameters:
      value1 - First value resulting from the DataType.typeCast(Object) method call
      value2 - Second value resulting from the DataType.typeCast(Object) method call
      Returns:
      The result of the Comparable.compareTo(Object) invocation.
      Throws:
      TypeCastException - if either value cannot be cast to a Comparable.
    • compare

      public int compare(byte[] v1, byte[] v2) throws TypeCastException
      Lexicographically compares two byte arrays.
      Parameters:
      v1 - the first byte array.
      v2 - the second byte array.
      Returns:
      a negative, zero, or positive value if v1 is less than, equal to, or greater than v2, respectively.
      Throws:
      TypeCastException - never thrown by this implementation.
    • getSqlValue

      public Object getSqlValue(int column, ResultSet resultSet) throws SQLException, TypeCastException
      Description copied from class: DataType
      Returns the specified column value from the specified resultset object.
      Overrides:
      getSqlValue in class AbstractDataType
      Parameters:
      column - the column index to read, starting at 1.
      resultSet - the result set to read the column value from.
      Returns:
      the column value.
      Throws:
      SQLException - if a database access error occurs.
      TypeCastException - if the value cannot be typecast to this DataType.
    • setSqlValue

      public void setSqlValue(Object value, int column, PreparedStatement statement) throws SQLException, TypeCastException
      Description copied from class: DataType
      Set the specified value to the specified prepared statement object.
      Overrides:
      setSqlValue in class AbstractDataType
      Parameters:
      value - the value to bind.
      column - the parameter index to bind to, starting at 1.
      statement - the prepared statement to bind the value on.
      Throws:
      SQLException - if a database access error occurs.
      TypeCastException - if the value cannot be typecast to this DataType.