com.ibm.as400.access

Class SQLDataBase

  • java.lang.Object
    • com.ibm.as400.access.SQLDataBase


  • public abstract class SQLDataBase
    extends java.lang.Object
    The SQLData interface represents native SQL data. A specific implementation of this interface will implement a specific type of SQL data.

    This base class contains conversion methods usable by the sub classes.

    • Constructor Summary

      Constructors 
      Constructor and Description
      SQLDataBase(com.ibm.as400.access.SQLConversionSettings settings)
      Create a new SQLDataBase object with the specified settings
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      void clearOutOfBounds()
      Clear the out of bounds flag
      void clearTruncated()
      Clears the truncated information
      abstract java.lang.Object clone()
      Returns a clone of the SQLData object.
      void convertFromRawBytes(byte[] rawBytes, int offset, ConvTable converter)
      Loads the contents of the data from raw bytes, as returned in a reply from the system.
      abstract void convertFromRawBytes(byte[] rawBytes, int offset, ConvTable converter, boolean ignoreConversionErrors)
      Loads the contents of the data from raw bytes, as returned in a reply from the system.
      abstract void convertToRawBytes(byte[] rawBytes, int offset, ConvTable ccsidConverter)
      Converts the contents of the data in raw bytes, as needed in a request to the system.
      abstract int getActualSize()
      Returns the actual size of this piece of data in bytes.
      java.sql.Array getArray()
      Converts (returns) the data to a java.sql.Array object.
      java.io.InputStream getAsciiStream()
      Converts the data to a stream of ASCII characters.
      java.lang.Object getBatchableObject()
      Converts the data to a Java object that will be used later when processing a batch.
      java.math.BigDecimal getBigDecimal(int scale)
      Converts the data to a Java BigDecimal object.
      abstract java.io.InputStream getBinaryStream()
      Converts the data to a stream of uninterpreted bytes.
      abstract java.sql.Blob getBlob()
      Converts the data to a java.sql.Blob object.
      boolean getBoolean()
      Converts the data to a Java boolean.
      byte getByte()
      Converts the data to a Java byte.
      abstract byte[] getBytes()
      Converts the data to a Java byte array containing uninterpreted bytes.
      java.io.Reader getCharacterStream()
      Converts the data to a java.io.Reader object.
      java.sql.Clob getClob()
      Converts the data to a java.sql.Clob object.
      abstract java.lang.String getCreateParameters()
      Returns the parameters used in creating the type.
      java.sql.Date getDate(java.util.Calendar calendar)
      Converts the data to a java.sql.Date object.
      abstract int getDisplaySize()
      Returns the display size.
      double getDouble()
      Converts the data to a Java double.
      float getFloat()
      Converts the data to a Java float.
      int getInt()
      Converts the data to a Java int.
      abstract java.lang.String getJavaClassName()
      Returns the Java class name for ParameterMetaData.getParameterClassName().
      abstract java.lang.String getLiteralPrefix()
      Returns the prefix used to quote a literal.
      abstract java.lang.String getLiteralSuffix()
      Returns the suffix used to quote a literal.
      abstract java.lang.String getLocalName()
      Returns the localized version of the name of the data type.
      long getLong()
      Converts the data to a Java long.
      abstract int getMaximumPrecision()
      Returns the maximum precision of the type.
      abstract int getMaximumScale()
      Returns the maximum scale of the type.
      abstract int getMinimumScale()
      Returns the minimum scale of the type.
      abstract int getNativeType()
      Returns the native IBM i identifier for the type.
      java.io.Reader getNCharacterStream()
      Converts the data to a java.io.Reader object.
      java.lang.String getNString()
      Converts the data to String object.
      abstract java.lang.Object getObject()
      Converts the data to a Java object.
      abstract boolean getOutOfBounds()
      Returns true if the last conversion of this piece of data was out of bounds of the range of the requested datatype.
      abstract int getPrecision()
      Returns the precision of the type.
      abstract int getRadix()
      Returns the radix for the type.
      java.lang.Object getSavedValue()
      Obtain the save value.
      abstract int getScale()
      Returns the scale of the type.
      short getShort()
      Converts the data to a Java short.
      abstract int getSQLType()
      Returns the SQL type constant for the implementing class.
      abstract java.lang.String getString()
      Converts the data to a Java String object.
      java.sql.Time getTime(java.util.Calendar calendar)
      Converts the data to a java.sql.Time object.
      java.sql.Timestamp getTimestamp(java.util.Calendar calendar)
      Converts the data to a java.sql.Timestamp object.
      abstract int getTruncated()
      Returns the number of bytes truncated by the last conversion of this piece of data.
      abstract int getType()
      Returns the type constant associated with the type.
      abstract java.lang.String getTypeName()
      Returns the name of the data type.
      java.io.InputStream getUnicodeStream()
      Converts the data to a stream of Unicdoe characters.
      static boolean isCharacterType(int sqlType) 
      abstract boolean isSigned()
      Indicates whether the type is signed.
      abstract boolean isText()
      Indicates whether the type is text.
      void saveValue()
      Save the current value.
      abstract void set(java.lang.Object object, java.util.Calendar calendar, int scale)
      Sets the contents of the data based on a Java object.
      void updateSettings(com.ibm.as400.access.SQLConversionSettings settings) 
      void validateRawTruncatedData(byte[] rawBytes, int offset, ConvTable ccsidConverter)
      validates that raw truncated data is correct.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SQLDataBase

        public SQLDataBase(com.ibm.as400.access.SQLConversionSettings settings)
        Create a new SQLDataBase object with the specified settings
        Parameters:
        settings -
    • Method Detail

      • clone

        public abstract java.lang.Object clone()
        Returns a clone of the SQLData object. Use this sparingly so that we minimize the number of copies.
        Overrides:
        clone in class java.lang.Object
        Returns:
        The clone.
      • convertFromRawBytes

        public void convertFromRawBytes(byte[] rawBytes,
                               int offset,
                               ConvTable converter)
                                 throws java.sql.SQLException
        Loads the contents of the data from raw bytes, as returned in a reply from the system.
        Parameters:
        rawBytes - raw bytes from the system.
        offset - offset.
        converter - the converter.
        Throws:
        java.sql.SQLException - If the raw bytes are not in the expected format.
      • convertFromRawBytes

        public abstract void convertFromRawBytes(byte[] rawBytes,
                               int offset,
                               ConvTable converter,
                               boolean ignoreConversionErrors)
                                          throws java.sql.SQLException
        Loads the contents of the data from raw bytes, as returned in a reply from the system.
        Parameters:
        rawBytes - raw bytes from the system.
        offset - offset.
        converter - the converter.
        ignoreConversionErrors - Should conversion errors be ignored Used when converting packed decimal arrays
        Throws:
        java.sql.SQLException - If the raw bytes are not in the expected format.
      • convertToRawBytes

        public abstract void convertToRawBytes(byte[] rawBytes,
                             int offset,
                             ConvTable ccsidConverter)
                                        throws java.sql.SQLException
        Converts the contents of the data in raw bytes, as needed in a request to the system.
        Parameters:
        rawBytes - the raw bytes for the system.
        offset - the offset into the byte array.
        ccsidConverter - the converter.
        Throws:
        java.sql.SQLException - If a database error occurs.
      • validateRawTruncatedData

        public void validateRawTruncatedData(byte[] rawBytes,
                                    int offset,
                                    ConvTable ccsidConverter)
        validates that raw truncated data is correct. The data is corrected if is not correct. This is only used when converting to MIXED CCSID and UTF-8.
        Parameters:
        rawBytes - the raw bytes for the system.
        offset - the offset into the byte array.
        ccsidConverter - the converter.
      • set

        public abstract void set(java.lang.Object object,
               java.util.Calendar calendar,
               int scale)
                          throws java.sql.SQLException
        Sets the contents of the data based on a Java object. This performs all conversions described in Table 6 of the JDBC specification.
        Parameters:
        object - a Java object.
        calendar - The calendar.
        scale - The scale.
        Throws:
        java.sql.SQLException - If the Java object is not an appropriate type.
      • getSQLType

        public abstract int getSQLType()
        Returns the SQL type constant for the implementing class.
        Returns:
        the SQL type constant.
      • getCreateParameters

        public abstract java.lang.String getCreateParameters()
        Returns the parameters used in creating the type.
        Returns:
        the parameters, separated by commas, or null if none.
      • getDisplaySize

        public abstract int getDisplaySize()
        Returns the display size. This is defined in Appendix D of the ODBC 2.0 Programmer's Reference.
        Returns:
        the display size (in characters).
      • getJavaClassName

        public abstract java.lang.String getJavaClassName()
        Returns the Java class name for ParameterMetaData.getParameterClassName().
        Returns:
        the Java class name.
      • getLiteralPrefix

        public abstract java.lang.String getLiteralPrefix()
        Returns the prefix used to quote a literal.
        Returns:
        the prefix, or null if none.
      • getLiteralSuffix

        public abstract java.lang.String getLiteralSuffix()
        Returns the suffix used to quote a literal.
        Returns:
        the suffix, or null if none.
      • getLocalName

        public abstract java.lang.String getLocalName()
        Returns the localized version of the name of the data type.
        Returns:
        the name, or null.
      • getMaximumPrecision

        public abstract int getMaximumPrecision()
        Returns the maximum precision of the type. This is defined in Appendix D of the ODBC 2.0 Programmer's Reference.
        Returns:
        the maximum precision.
      • getMaximumScale

        public abstract int getMaximumScale()
        Returns the maximum scale of the type. This is defined in Appendix D of the ODBC 2.0 Programmer's Reference.
        Returns:
        the maximum scale.
      • getMinimumScale

        public abstract int getMinimumScale()
        Returns the minimum scale of the type. This is defined in Appendix D of the ODBC 2.0 Programmer's Reference.
        Returns:
        the minimum scale.
      • getNativeType

        public abstract int getNativeType()
        Returns the native IBM i identifier for the type.
        Returns:
        the native type.
      • getPrecision

        public abstract int getPrecision()
        Returns the precision of the type. This is defined in Appendix D of the ODBC 2.0 Programmer's Reference.
        Returns:
        the precision.
      • getRadix

        public abstract int getRadix()
        Returns the radix for the type.
        Returns:
        the radix.
      • getScale

        public abstract int getScale()
        Returns the scale of the type. This is defined in Appendix D of the ODBC 2.0 Programmer's Reference.
        Returns:
        the scale.
      • getType

        public abstract int getType()
        Returns the type constant associated with the type.
        Returns:
        SQL type code defined in java.sql.Types.
      • getTypeName

        public abstract java.lang.String getTypeName()
        Returns the name of the data type.
        Returns:
        the name.
      • isSigned

        public abstract boolean isSigned()
        Indicates whether the type is signed.
        Returns:
        true or false
      • isText

        public abstract boolean isText()
        Indicates whether the type is text. This also indicates that the associated data needs to be converted.
        Returns:
        true or false
      • getActualSize

        public abstract int getActualSize()
        Returns the actual size of this piece of data in bytes.
        Returns:
        the actual size of this piece of data in bytes.
      • getTruncated

        public abstract int getTruncated()
        Returns the number of bytes truncated by the last conversion of this piece of data.
        Returns:
        the number of bytes truncated by the last conversion
      • clearTruncated

        public void clearTruncated()
        Clears the truncated information
      • getOutOfBounds

        public abstract boolean getOutOfBounds()
        Returns true if the last conversion of this piece of data was out of bounds of the range of the requested datatype. This will only happen when requesting conversion to a numeric type.
        Returns:
        out of bounds indicator
      • clearOutOfBounds

        public void clearOutOfBounds()
        Clear the out of bounds flag
      • getAsciiStream

        public java.io.InputStream getAsciiStream()
                                           throws java.sql.SQLException
        Converts the data to a stream of ASCII characters.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getBigDecimal

        public java.math.BigDecimal getBigDecimal(int scale)
                                           throws java.sql.SQLException
        Converts the data to a Java BigDecimal object.
        Parameters:
        scale - scale, or -1 to use full scale.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getBinaryStream

        public abstract java.io.InputStream getBinaryStream()
                                                     throws java.sql.SQLException
        Converts the data to a stream of uninterpreted bytes.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getBlob

        public abstract java.sql.Blob getBlob()
                                       throws java.sql.SQLException
        Converts the data to a java.sql.Blob object.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getBoolean

        public boolean getBoolean()
                           throws java.sql.SQLException
        Converts the data to a Java boolean.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getByte

        public byte getByte()
                     throws java.sql.SQLException
        Converts the data to a Java byte.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getBytes

        public abstract byte[] getBytes()
                                 throws java.sql.SQLException
        Converts the data to a Java byte array containing uninterpreted bytes.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getCharacterStream

        public java.io.Reader getCharacterStream()
                                          throws java.sql.SQLException
        Converts the data to a java.io.Reader object.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getClob

        public java.sql.Clob getClob()
                              throws java.sql.SQLException
        Converts the data to a java.sql.Clob object.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getDate

        public java.sql.Date getDate(java.util.Calendar calendar)
                              throws java.sql.SQLException
        Converts the data to a java.sql.Date object.
        Parameters:
        calendar - The calendar.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getDouble

        public double getDouble()
                         throws java.sql.SQLException
        Converts the data to a Java double.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getFloat

        public float getFloat()
                       throws java.sql.SQLException
        Converts the data to a Java float.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getInt

        public int getInt()
                   throws java.sql.SQLException
        Converts the data to a Java int.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getLong

        public long getLong()
                     throws java.sql.SQLException
        Converts the data to a Java long.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getObject

        public abstract java.lang.Object getObject()
                                            throws java.sql.SQLException
        Converts the data to a Java object. The actual type of the Java object is dictated per section 8, table 2 ("Standard mapping from SQL types to Java types") of the JDBC 1.10 specification
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getBatchableObject

        public java.lang.Object getBatchableObject()
                                            throws java.sql.SQLException
        Converts the data to a Java object that will be used later when processing a batch. In most cases, this will return the same object as getObject(). In the timestamp case, we return an AS400FieldedTimstamp. This is need to permit timestamps that do not exist in the current timezone to be sent to the server.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getShort

        public short getShort()
                       throws java.sql.SQLException
        Converts the data to a Java short.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getString

        public abstract java.lang.String getString()
                                            throws java.sql.SQLException
        Converts the data to a Java String object. This conversion must be provided by the implementation.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If a database error occurs.
      • getTime

        public java.sql.Time getTime(java.util.Calendar calendar)
                              throws java.sql.SQLException
        Converts the data to a java.sql.Time object.
        Parameters:
        calendar - The calendar.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getTimestamp

        public java.sql.Timestamp getTimestamp(java.util.Calendar calendar)
                                        throws java.sql.SQLException
        Converts the data to a java.sql.Timestamp object.
        Parameters:
        calendar - The calendar.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getUnicodeStream

        public java.io.InputStream getUnicodeStream()
                                             throws java.sql.SQLException
        Converts the data to a stream of Unicdoe characters.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getNCharacterStream

        public java.io.Reader getNCharacterStream()
                                           throws java.sql.SQLException
        Converts the data to a java.io.Reader object.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getNString

        public java.lang.String getNString()
                                    throws java.sql.SQLException
        Converts the data to String object.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • getArray

        public java.sql.Array getArray()
                                throws java.sql.SQLException
        Converts (returns) the data to a java.sql.Array object.
        Returns:
        the result of the conversion.
        Throws:
        java.sql.SQLException - If the conversion is not required or not possible.
      • updateSettings

        public void updateSettings(com.ibm.as400.access.SQLConversionSettings settings)
      • isCharacterType

        public static boolean isCharacterType(int sqlType)
      • getSavedValue

        public java.lang.Object getSavedValue()
        Obtain the save value. All values are "wrapped" to the corresponding Java type
      • saveValue

        public void saveValue()
                       throws java.sql.SQLException
        Save the current value. Called before the statement is executed so that the previous value can be restored if the statement needs to be seamlessly re-executed
        Throws:
        java.sql.SQLException