com.informix.jdbc

## Class IfxBSONObject

- java.lang.Object
- - com.informix.jdbc.IfxObject
  - - com.informix.jdbc.IfxBSONObject

All Implemented Interfaces:
  java.sql.SQLData, org.bson.BSONObject

    public class IfxBSONObject
    extends IfxObject
    implements java.sql.SQLData, org.bson.BSONObject

The IfxBSONObject is a hybrid of both the `SQLData` interface necessary to read and write BSON data with the Informix JDBC driver and the `BSONObject` interface necessary to work with BSON objects that returned by or sent to Informix.

Note: This class is not thread safe.

### Field Summary

Fields
`protected org.bson.BSONObject` `bsonObject` The decoded BSON object.
`protected byte[]` `bsonObjectBytes` Stores `BSONObject` as a BSON-encoded representation of the byte array.
`protected int` `bsonObjectHashCode` Stores the hashCode of the `bsonObject` whenever it is assigned.
`protected IfxUDTInput` `inputStream`
`protected IfxUDTOutput` `outputStream`
`protected static int` `UDT_FLAG_SIZE`
`protected static int` `UDT_LENGTH_SIZE`

### Fields inherited from class com.informix.jdbc.IfxObject

`conn, encodedLength, extendedID, extendedName, extendedOwner, ifxType, isNull, jdbcType, sourceType, trace, typeMap, used_in_update`

### Constructor Summary

Constructors
Constructor and Description
`IfxBSONObject()` A no-arg constructor is required for SQLData to work.
`IfxBSONObject(org.bson.BSONObject bsonObject)` Constructs a new object from the specified `BSONObject`.
`IfxBSONObject(byte[] bytes)` Constructs a new object from the specified BSON-encoded byte array.
`IfxBSONObject(byte[] bytes, boolean copyBytes)` Constructs a new object from the specified BSON-encoded byte array.

### Method Summary

Methods
`void` `clear()` Clear the instance states
`boolean` `containsField(java.lang.String s)`
`boolean` `containsKey(java.lang.String s)` Deprecated.
`protected void` `ensureBsonObject()` Ensures that the `bsonObject` field is non-null.
`protected void` `ensureBsonObjectBytes()` Ensures that the `bsonObjectBytes` field is non-null.
`static IfxBSONObject` `ensureIfxBSONObject(java.lang.Object o)` Ensures that the specified object is an `IfxBSONObject`.
`boolean` `equals(java.lang.Object o)` Find out whether two objects are equal.
`void` `fromBytes(byte[] b)`
`void` `fromIfx(byte[] b)`
`void` `fromIfx(byte[] b, int offset, int blength)`
`void` `fromInputStream(java.io.InputStream x, int length)`
`void` `fromObject(java.lang.Object data)` Initialize IfxObject with the value in obj.
`java.lang.Object` `get(java.lang.String key)`
`byte[]` `getBytes()`
`java.lang.String` `getSQLTypeName()`
`int` `hashCode()`
`java.util.Set<java.lang.String>` `keySet()`
`java.lang.Object` `put(java.lang.String key, java.lang.Object v)`
`void` `putAll(org.bson.BSONObject o)`
`void` `putAll(java.util.Map m)`
`void` `readSQL(java.sql.SQLInput stream, java.lang.String typeName)`
`java.lang.Object` `removeField(java.lang.String key)`
`void` `setBSONObject(org.bson.BSONObject bsonObject)` Assigns the BSONObject this object represents.
`void` `setBytes(byte[] bytes)` Assigns the BSON-encoded byte array representation of a document.
`void` `setConnection(IfxConnection conn)` GENERIC
`java.io.InputStream` `toBinaryStream()`
`byte[]` `toBytes()`
`byte[]` `toIfx()`
`byte[]` `toIfxTuple()`
`java.util.Map<java.lang.String,java.lang.Object>` `toMap()`
`java.lang.Object` `toObject()`
`java.lang.Object` `toObject(boolean fromComplexType)` This version of toObject has a parameter that indicates if we are doing a toObject for a complex type.
`java.lang.String` `toString()` Convert to string.
`protected void` `unsafeSetBSONObject(org.bson.BSONObject bsonObject)` WARNING:This method should not be made public.
`void` `writeSQL(java.sql.SQLOutput stream)`

### Methods inherited from class com.informix.jdbc.IfxObject

`clearWarning, fromAsciiStream, fromAsciiStream, fromBinaryStream, fromBinaryStream, fromBlob, fromBoolean, fromBoolean, fromByte, fromByte, fromCharacterStream, fromCharacterStream, fromClob, fromDate, fromDecimal, fromDecimal, fromDouble, fromDouble, fromFloat, fromFloat, fromIfx, fromIfx, fromIfx, fromIfx, fromInputStream, fromInt, fromInt, fromIntervalDF, fromIntervalYM, fromLong, fromLong, fromNClob, fromObject, fromObject, fromRowId, fromShort, fromShort, fromSQLXML, fromString, fromString, fromTime, fromTimestamp, get_used_in_update, getEncodedLength, getWarning, isNull, nullify, set_used_in_update, setExtendedTypeName, setIfxType, setTypeMap, toAsciiStream, toBlob, toBoolean, toByte, toCharacterStream, toClob, toDate, toDecimal, toDouble, toFloat, toIfxBSONObject, toInputStream, toInt, toInterval, toIntervalDF, toIntervalYM, toLong, toNClob, toRowId, toShort, toSQLXML, toTime, toTimestamp, toUnloadString, unnullify`

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

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### bsonObjectBytes

    protected byte[] bsonObjectBytes

Stores `BSONObject` as a BSON-encoded representation of the byte array. At any given time either the bsonObject is null or the bsonObjectBytes are null. At no time are both non-null.

#### bsonObject

    protected org.bson.BSONObject bsonObject

The decoded BSON object. When a method from BSONObject is called against an IfxBSONObject, the bsonObjectBytes are decoded and the bsonObject is created. If a BSONObject method that modifies the document is called, the bsonObjectBytes are set to null to indicate that they are no longer in-sync with the state of the document. If a BSONObject method that only reads from the document is called, the bsonObject is created and the bsonObjectBytes are left as-is (both will remain non-null as long as a BSONObject write method is not subsequently called).

#### bsonObjectHashCode

    protected int bsonObjectHashCode

Stores the hashCode of the `bsonObject` whenever it is assigned. When fetching the bytes, if the `Object.hashCode()` of the current `bsonObject` does not match that saved when the bsonObject was initially assigned, the `bsonObjectBytes` must be re-computed.

#### UDT_FLAG_SIZE

    protected static final int UDT_FLAG_SIZE

See Also:
  Constant Field Values

#### UDT_LENGTH_SIZE

    protected static final int UDT_LENGTH_SIZE

See Also:
  Constant Field Values

#### inputStream

    protected IfxUDTInput inputStream

#### outputStream

    protected IfxUDTOutput outputStream

### Constructor Detail

#### IfxBSONObject

    public IfxBSONObject()

A no-arg constructor is required for SQLData to work. Broadly speaking, this constructor should not be called.

#### IfxBSONObject

    public IfxBSONObject(byte[] bytes)

Constructs a new object from the specified BSON-encoded byte array.

Parameters:
  `bytes` - the BSON-encoded document

#### IfxBSONObject

    public IfxBSONObject(byte[] bytes,
                 boolean copyBytes)

Constructs a new object from the specified BSON-encoded byte array. Optionally, copies the input byte array to a new byte array.

Parameters:
  `bytes` - the BSON-encoded document
  `copyBytes` - if `true` the byte array is copied

#### IfxBSONObject

    public IfxBSONObject(org.bson.BSONObject bsonObject)

Constructs a new object from the specified `BSONObject`. It is generally preferable to use the method `ensureIfxBSONObject(Object)` as it inspects the object to see if it is already of type `IfxBSONObject`.

Parameters:
  `bsonObject` -

### Method Detail

#### getSQLTypeName

    public java.lang.String getSQLTypeName()
                                    throws java.sql.SQLException

Specified by:
  `getSQLTypeName` in interface `java.sql.SQLData`
Throws:
  `java.sql.SQLException`

#### readSQL

    public void readSQL(java.sql.SQLInput stream,
               java.lang.String typeName)
                 throws java.sql.SQLException

Specified by:
  `readSQL` in interface `java.sql.SQLData`
Throws:
  `java.sql.SQLException`

#### writeSQL

    public void writeSQL(java.sql.SQLOutput stream)
                  throws java.sql.SQLException

Specified by:
  `writeSQL` in interface `java.sql.SQLData`
Throws:
  `java.sql.SQLException`

#### ensureBsonObjectBytes

    protected void ensureBsonObjectBytes()

Ensures that the `bsonObjectBytes` field is non-null.

#### ensureBsonObject

    protected void ensureBsonObject()

Ensures that the `bsonObject` field is non-null.

#### getBytes

    public byte[] getBytes()

#### setBytes

    public void setBytes(byte[] bytes)

Assigns the BSON-encoded byte array representation of a document. The bsonObject representation is assigned the value `null`.

Parameters:
  `bytes` - the BSON-encoded byte array representation of a document

#### setBSONObject

    public void setBSONObject(org.bson.BSONObject bsonObject)

Assigns the BSONObject this object represents. The BSON-encoded byte array representation is assigned the value `null`.

Parameters:
  `bsonObject` - the document
Throws:
  `java.lang.NullPointerException` - if the bsonObject is null

#### unsafeSetBSONObject

    protected void unsafeSetBSONObject(org.bson.BSONObject bsonObject)

WARNING:This method should not be made public.

Assigns the `bsonObject` and `bsonObjectHashCode` fields. If the bsonObject is `null`, the hash code is assigned the value `0`. No exception is thrown when a null bsonObject is specified.

Parameters:
  `bsonObject` -

#### ensureIfxBSONObject

    public static IfxBSONObject ensureIfxBSONObject(java.lang.Object o)

Ensures that the specified object is an `IfxBSONObject`. If the object is already of type `IfxBSONObject`, the object is simply cast and returned. If the object implements the `BSONObject` interface, the appropriate constructor is called and the new object is returned.

Parameters:
  `o` -
Returns:
Throws:
  `java.lang.NullPointerException` - if the specified object is null
  `java.lang.IllegalArgumentException` - if the object is not of type `IfxBSONObject` and does not implement the interface `BSONObject`

#### toString

    public java.lang.String toString()

Description copied from class: `IfxObject`
Convert to string.

Returns:
  the converted String object, or null on error

#### put

    public java.lang.Object put(java.lang.String key,
                       java.lang.Object v)

Specified by:
  `put` in interface `org.bson.BSONObject`

#### putAll

    public void putAll(org.bson.BSONObject o)

Specified by:
  `putAll` in interface `org.bson.BSONObject`

#### putAll

    public void putAll(java.util.Map m)

Specified by:
  `putAll` in interface `org.bson.BSONObject`

#### get

    public java.lang.Object get(java.lang.String key)

Specified by:
  `get` in interface `org.bson.BSONObject`

#### toMap

    public java.util.Map<java.lang.String,java.lang.Object> toMap()

Specified by:
  `toMap` in interface `org.bson.BSONObject`

#### removeField

    public java.lang.Object removeField(java.lang.String key)

Specified by:
  `removeField` in interface `org.bson.BSONObject`

#### containsKey

    @Deprecated
    public boolean containsKey(java.lang.String s)

Deprecated.

Specified by:
  `containsKey` in interface `org.bson.BSONObject`

#### containsField

    public boolean containsField(java.lang.String s)

Specified by:
  `containsField` in interface `org.bson.BSONObject`

#### keySet

    public java.util.Set<java.lang.String> keySet()

Specified by:
  `keySet` in interface `org.bson.BSONObject`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `java.lang.Object`

#### equals

    public boolean equals(java.lang.Object o)

Description copied from class: `IfxObject`
Find out whether two objects are equal.

Overrides:
  `equals` in class `IfxObject`
Parameters:
  `o` - the other object to compare with
Returns:
  true if the objects are equal

#### fromObject

    public void fromObject(java.lang.Object data)
                    throws java.sql.SQLException

Description copied from class: `IfxObject`
Initialize IfxObject with the value in obj. It does the data conversion automatically from the obj type to IfxObject type. For example: In IfxInteger(), fromObject(Object obj) { if (obj instanceof Short) fromShort((Short) obj); }

Overrides:
  `fromObject` in class `IfxObject`
Parameters:
  `data` - Convert the data value from obj to IfxObject
Throws:
  `java.sql.SQLException`

#### toObject

    public java.lang.Object toObject()
                              throws java.sql.SQLException

Overrides:
  `toObject` in class `IfxObject`
Throws:
  `java.sql.SQLException`

#### toObject

    public java.lang.Object toObject(boolean fromComplexType)
                              throws java.sql.SQLException

This version of toObject has a parameter that indicates if we are doing a toObject for a complex type. If so, don't do the isDirect return udtClass, as elements 2-N need to be instantiated and returned, not just the first one over and over again.

Overrides:
  `toObject` in class `IfxObject`
Throws:
  `java.sql.SQLException`

#### fromBytes

    public void fromBytes(byte[] b)
                   throws java.sql.SQLException

Overrides:
  `fromBytes` in class `IfxObject`
Throws:
  `java.sql.SQLException`

#### toBytes

    public byte[] toBytes()
                   throws java.sql.SQLException

Overrides:
  `toBytes` in class `IfxObject`
Throws:
  `java.sql.SQLException`

#### fromInputStream

    public void fromInputStream(java.io.InputStream x,
                       int length)
                         throws java.sql.SQLException

Overrides:
  `fromInputStream` in class `IfxObject`
Throws:
  `java.sql.SQLException`

#### toBinaryStream

    public java.io.InputStream toBinaryStream()
                                       throws java.sql.SQLException

Overrides:
  `toBinaryStream` in class `IfxObject`
Throws:
  `java.sql.SQLException`

#### clear

    public void clear()

Description copied from class: `IfxObject`
Clear the instance states

Overrides:
  `clear` in class `IfxObject`

#### setConnection

    public void setConnection(IfxConnection conn)
                       throws java.sql.SQLException

Description copied from class: `IfxObject`
GENERIC

Overrides:
  `setConnection` in class `IfxObject`
Throws:
  `java.sql.SQLException`

#### fromIfx

    public void fromIfx(byte[] b)
                 throws java.sql.SQLException

Overrides:
  `fromIfx` in class `IfxObject`
Throws:
  `java.sql.SQLException`

#### fromIfx

    public void fromIfx(byte[] b,
               int offset,
               int blength)
                 throws java.sql.SQLException

Overrides:
  `fromIfx` in class `IfxObject`
Throws:
  `java.sql.SQLException`

#### toIfx

    public byte[] toIfx()
                 throws java.sql.SQLException

Overrides:
  `toIfx` in class `IfxObject`
Throws:
  `java.sql.SQLException`

#### toIfxTuple

    public byte[] toIfxTuple()
                      throws java.sql.SQLException

Overrides:
  `toIfxTuple` in class `IfxObject`
Throws:
  `java.sql.SQLException`