com.informix.lang

## Class JavaToIfxType

- java.lang.Object
- - com.informix.lang.JavaToIfxType

    public final class JavaToIfxType
    extends java.lang.Object

This static class handles all the Java to Informix data conversion. A separate method is provided for each conversion. All the conversion fns return a byte array for writing to output stream to an extrnal server. For variable length types (DECIMAL, TIMESTAMP, VARCHAR) the first two bytes are the length of the "data bytes" Note: If a padding byte is needed to make the sequence even in length that must be done by the fns that actually write the bytes to the stream.

### Field Summary

Fields
`static int` `BYTEMASK`
`static int` `BYTESHIFT`
`static int` `DefDblScale`
`static int` `DefFltScale`
`static int` `IFX_DOUBLE_SIZE`
`static int` `IFX_INT_SIZE`
`static int` `IFX_LGINT_SIZE`
`static int` `IFX_LONG_SIZE`
`static int` `IFX_SMFLOAT_SIZE`
`static int` `IFX_SMINT_SIZE`
`static java.lang.String` `NO_ENCODING`
`protected static boolean` `TruncateFractSec` if false then rounds up fractional seconds, possibly upto year In order to do rounding, set this to false and uncomment the series of ifs inside convertTimestampToDecimal() below.

### Constructor Summary

Constructors
Constructor and Description
`JavaToIfxType()`

### Method Summary

Methods
`static Decimal` `convertIntervalToDecimal(IntervalDF intrvl)`
`static Decimal` `convertIntervalToDecimal(IntervalYM intrvl)`
`static java.lang.String` `convertIntervalToString(IntervalDF intrvl)`
`static java.lang.String` `convertIntervalToString(IntervalYM intrvl)`
`static java.lang.String` `convertNanosToFract(int nano)` Converts first to a number that retains high 5 digits and reduces to a string.
`static Decimal` `convertTimestampToDecimal(java.sql.Timestamp t)` Creates a Decimal from the Timestamp that represents its value as a decimal number of the form: yyyymmddhhmmss.fffff Note: For now truncates fractional digits 6-9 instead of rounding Since rounding could in worst case propagate all the way to year we will hold off on doing it until need is clearly expressed.
`static Decimal` `convertTimestampToDecimal(java.sql.Timestamp t, java.util.Calendar cal)`
`static Decimal` `convertTimeToDecimal(java.sql.Time t)` Creates Decimal from the Time that represents its value as a decimal number of the form: hhmmss.0
`byte[]` `JavaToIfx4BytesChar(java.lang.String s, boolean usestrenc)`
`byte[]` `JavaToIfx4BytesChar(java.lang.String s, java.lang.String dbEnc, boolean usestrenc)`
`byte[]` `JavaToIfxChar(java.lang.String s, boolean usestrenc)` Converts a Java String to an Informix Char (n) (in a byte array) The first 2 bytes encode the length of the string.
`byte[]` `JavaToIfxChar(java.lang.String s, java.lang.String dbEnc, boolean usestrenc)`
`static byte[]` `JavaToIfxDate(java.sql.Date d)` Converts a Java java.sql.Date to an Informix date (in a byte array)
`static byte[]` `JavaToIfxDateTime(java.sql.Time t)` Converts a Java dateTime (java.sql.Time) to an Informix datetime (in a byte array)
`static byte[]` `JavaToIfxDateTime(java.sql.Timestamp t)` Converts a Java dateTime (java.sql.Timestamp) to an Informix datetime (in a byte array)
`static byte[]` `JavaToIfxDateTime(java.sql.Timestamp t, java.util.Calendar cal)`
`static byte[]` `JavaToIfxDecimal(java.math.BigDecimal n)` Converts a Java Bignum to an Informix decimal (in a byte array)
`static byte[]` `JavaToIfxDecimalNull(short qual)`
`static byte[]` `JavaToIfxDouble(double d)` Converts a Java double to an Informix double
`static byte[]` `JavaToIfxDouble(java.lang.Double d)` Converts a Java Double to an Informix double
`static byte[]` `JavaToIfxInt(int i)` Converts a Java int to an Informix int (in a byte array) Conversion method: Shifts the int into 4 bytes
`static byte[]` `JavaToIfxInterval(IntervalDF t)` Converts a Java interval (IntervalDF) to an Informix interval (in a byte array) Conversion path: IntervalDF->String->Decimal->Interval
`static byte[]` `JavaToIfxInterval(IntervalYM t)` Converts a Java interval (IntervalYM) to an Informix interval (in a byte array) Conversion path: IntervalYM->String->Decimal->Interval
`static byte[]` `JavaToIfxLongBigInt(long val)` Converts a Java long to an Informix bigint (in a byte array)
`static byte[]` `JavaToIfxLongInt(long l)` Converts a Java long to an Informix int8 (in a byte array)
`byte[]` `JavaToIfxLvarchar(java.lang.String s, java.lang.String dbEnc, boolean usestrenc)`
`static byte[]` `JavaToIfxReal(float f)` Converts a Java float to an Informix real
`static byte[]` `JavaToIfxReal(java.lang.Float f)` Converts a Java Float to an Informix real
`static byte[]` `JavaToIfxSmallInt(short s)` Converts a Java short to an Informix smallint (in a byte array)
`byte[]` `JavaToIfxVarChar(java.lang.String s, java.lang.String dbEnc, int leng, boolean usestrenc)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### IFX_INT_SIZE

    public static final int IFX_INT_SIZE

See Also:
  Constant Field Values

#### BYTESHIFT

    public static final int BYTESHIFT

See Also:
  Constant Field Values

#### BYTEMASK

    public static final int BYTEMASK

See Also:
  Constant Field Values

#### IFX_LGINT_SIZE

    public static final int IFX_LGINT_SIZE

See Also:
  Constant Field Values

#### IFX_SMINT_SIZE

    public static final int IFX_SMINT_SIZE

See Also:
  Constant Field Values

#### IFX_SMFLOAT_SIZE

    public static final int IFX_SMFLOAT_SIZE

See Also:
  Constant Field Values

#### IFX_LONG_SIZE

    public static final int IFX_LONG_SIZE

See Also:
  Constant Field Values

#### IFX_DOUBLE_SIZE

    public static final int IFX_DOUBLE_SIZE

See Also:
  Constant Field Values

#### DefDblScale

    public static final int DefDblScale

See Also:
  Constant Field Values

#### DefFltScale

    public static final int DefFltScale

See Also:
  Constant Field Values

#### NO_ENCODING

    public static final java.lang.String NO_ENCODING

See Also:
  Constant Field Values

#### TruncateFractSec

    protected static final boolean TruncateFractSec

if false then rounds up fractional seconds, possibly upto year In order to do rounding, set this to false and uncomment the series of ifs inside convertTimestampToDecimal() below. Of course, the code has to be recompiled too.

See Also:
  Constant Field Values

### Constructor Detail

#### JavaToIfxType

    public JavaToIfxType()

### Method Detail

#### JavaToIfxInt

    public static byte[] JavaToIfxInt(int i)

Converts a Java int to an Informix int (in a byte array) Conversion method: Shifts the int into 4 bytes

Parameters:
  `i` - int to be converted

#### JavaToIfxChar

    public byte[] JavaToIfxChar(java.lang.String s,
                       boolean usestrenc)
                         throws java.io.UnsupportedEncodingException,
                                java.sql.SQLException

Converts a Java String to an Informix Char (n) (in a byte array) The first 2 bytes encode the length of the string. Remaining bytes encode the characters in the string

Parameters:
  `s` - String to be converted TBD ??? Shouldnt we use 2 bytes per char due to Unicode?
Throws:
  `java.io.UnsupportedEncodingException`
  `java.sql.SQLException`

#### JavaToIfxChar

    public byte[] JavaToIfxChar(java.lang.String s,
                       java.lang.String dbEnc,
                       boolean usestrenc)
                         throws java.io.UnsupportedEncodingException,
                                java.sql.SQLException

Throws:
  `java.io.UnsupportedEncodingException`
  `java.sql.SQLException`

#### JavaToIfx4BytesChar

    public byte[] JavaToIfx4BytesChar(java.lang.String s,
                             boolean usestrenc)
                               throws java.io.UnsupportedEncodingException,
                                      java.sql.SQLException

Throws:
  `java.io.UnsupportedEncodingException`
  `java.sql.SQLException`

#### JavaToIfx4BytesChar

    public byte[] JavaToIfx4BytesChar(java.lang.String s,
                             java.lang.String dbEnc,
                             boolean usestrenc)
                               throws java.io.UnsupportedEncodingException,
                                      java.sql.SQLException

Throws:
  `java.io.UnsupportedEncodingException`
  `java.sql.SQLException`

#### JavaToIfxVarChar

    public byte[] JavaToIfxVarChar(java.lang.String s,
                          java.lang.String dbEnc,
                          int leng,
                          boolean usestrenc)
                            throws java.io.UnsupportedEncodingException,
                                   java.sql.SQLException

Throws:
  `java.io.UnsupportedEncodingException`
  `java.sql.SQLException`

#### JavaToIfxLvarchar

    public byte[] JavaToIfxLvarchar(java.lang.String s,
                           java.lang.String dbEnc,
                           boolean usestrenc)
                             throws java.io.UnsupportedEncodingException,
                                    java.sql.SQLException

Throws:
  `java.io.UnsupportedEncodingException`
  `java.sql.SQLException`

#### JavaToIfxDate

    public static byte[] JavaToIfxDate(java.sql.Date d)

Converts a Java java.sql.Date to an Informix date (in a byte array)

#### convertNanosToFract

    public static java.lang.String convertNanosToFract(int nano)

Converts first to a number that retains high 5 digits and reduces to a string. Truncates or rounds based on static flag TruncateFractSec.

Parameters:
  `nano` - number representing nano seconds

#### convertTimestampToDecimal

    public static Decimal convertTimestampToDecimal(java.sql.Timestamp t)

Creates a Decimal from the Timestamp that represents its value as a decimal number of the form: yyyymmddhhmmss.fffff Note: For now truncates fractional digits 6-9 instead of rounding Since rounding could in worst case propagate all the way to year we will hold off on doing it until need is clearly expressed. However, code is already there to do rounding. It only needs to be made activ e.

#### convertTimestampToDecimal

    public static Decimal convertTimestampToDecimal(java.sql.Timestamp t,
                                    java.util.Calendar cal)

#### convertTimeToDecimal

    public static Decimal convertTimeToDecimal(java.sql.Time t)

Creates Decimal from the Time that represents its value as a decimal number of the form: hhmmss.0

#### convertIntervalToString

    public static java.lang.String convertIntervalToString(IntervalDF intrvl)

#### convertIntervalToDecimal

    public static Decimal convertIntervalToDecimal(IntervalDF intrvl)

#### convertIntervalToString

    public static java.lang.String convertIntervalToString(IntervalYM intrvl)

#### convertIntervalToDecimal

    public static Decimal convertIntervalToDecimal(IntervalYM intrvl)

#### JavaToIfxDateTime

    public static byte[] JavaToIfxDateTime(java.sql.Timestamp t)

Converts a Java dateTime (java.sql.Timestamp) to an Informix datetime (in a byte array)

Parameters:
  `t` - Timestamp to be converted

#### JavaToIfxDateTime

    public static byte[] JavaToIfxDateTime(java.sql.Timestamp t,
                           java.util.Calendar cal)

#### JavaToIfxDateTime

    public static byte[] JavaToIfxDateTime(java.sql.Time t)

Converts a Java dateTime (java.sql.Time) to an Informix datetime (in a byte array)

Parameters:
  `t` - Time to be converted

#### JavaToIfxInterval

    public static byte[] JavaToIfxInterval(IntervalDF t)

Converts a Java interval (IntervalDF) to an Informix interval (in a byte array) Conversion path: IntervalDF->String->Decimal->Interval

Parameters:
  `t` - Interval to be converted

#### JavaToIfxInterval

    public static byte[] JavaToIfxInterval(IntervalYM t)

Converts a Java interval (IntervalYM) to an Informix interval (in a byte array) Conversion path: IntervalYM->String->Decimal->Interval

Parameters:
  `t` - Interval to be converted

#### JavaToIfxDecimalNull

    public static final byte[] JavaToIfxDecimalNull(short qual)

#### JavaToIfxDecimal

    public static final byte[] JavaToIfxDecimal(java.math.BigDecimal n)

Converts a Java Bignum to an Informix decimal (in a byte array)

#### JavaToIfxDouble

    public static final byte[] JavaToIfxDouble(java.lang.Double d)

Converts a Java Double to an Informix double

#### JavaToIfxDouble

    public static final byte[] JavaToIfxDouble(double d)

Converts a Java double to an Informix double

#### JavaToIfxReal

    public static final byte[] JavaToIfxReal(java.lang.Float f)

Converts a Java Float to an Informix real

#### JavaToIfxReal

    public static byte[] JavaToIfxReal(float f)

Converts a Java float to an Informix real

#### JavaToIfxSmallInt

    public static byte[] JavaToIfxSmallInt(short s)

Converts a Java short to an Informix smallint (in a byte array)

#### JavaToIfxLongInt

    public static byte[] JavaToIfxLongInt(long l)

Converts a Java long to an Informix int8 (in a byte array)

#### JavaToIfxLongBigInt

    public static byte[] JavaToIfxLongBigInt(long val)

Converts a Java long to an Informix bigint (in a byte array)