com.informix.jdbc

## Class IfxBSONObject

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

All Implemented Interfaces:
  java.sql.SQLData, java.util.Map<java.lang.String,java.lang.Object>

    public class IfxBSONObject
    extends IfxUDT
    implements java.sql.SQLData, java.util.Map<java.lang.String,java.lang.Object>

The IfxBSONObject is a hybrid of both the `SQLData` interface necessary to read and write BSON data with the Informix JDBC driver and the supporting API's for users to create/read/manipulate BSON documents This class is a split between the Raw BSON document (data stays as a byte array) and an editble document (data is

### Nested Class Summary

### Nested classes/interfaces inherited from interface java.util.Map

`java.util.Map.Entry<K,V>`

### Field Summary

Fields
`protected Document` `bsonObject` The decoded BSON object.
`protected RawBsonDocument` `rawDocument`

### Constructor Summary

Constructors
Constructor and Description
`IfxBSONObject()` A no-arg constructor is required for SQLData to work.
`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.
`IfxBSONObject(Document bsonObject)` Constructs a new object from the specified `BSONObject`.
`IfxBSONObject(RawBsonDocument document)`
`IfxBSONObject(java.lang.String key, java.lang.Object value)` Constructs a new object with an initial key/value pair

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`IfxBSONObject` `append(java.lang.String key, java.lang.Object value)` Append the key/value pair to this document Similar to {`put(String, Object)` but this method returns the class reference to make multiple appends easier to write
`boolean` `containsField(java.lang.String s)`
`boolean` `containsKey(java.lang.Object key)`
`boolean` `containsKey(java.lang.String s)`
`boolean` `containsValue(java.lang.Object value)`
`protected void` `ensureBsonObject()`
`static IfxBSONObject` `ensureIfxBSONObject(java.lang.Object o)` Ensures that the specified object is an `IfxBSONObject`.
`protected void` `ensureRawDocument()`
`java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>>` `entrySet()`
`boolean` `equals(java.lang.Object o)`
`java.lang.Object` `get(java.lang.Object key)`
`java.lang.Object` `get(java.lang.String key)`
`boolean` `getBoolean(java.lang.String key)` Returns the boolean value of the key in the document
`byte[]` `getBytes()`
`Document` `getDocument()` Return the Map version of the Bson document This version takes more memory but is completely manipulatable as you would a Map This returns a reference to the document object contained in this object.
`IfxBSONObject` `getDocument(java.lang.String key)` Returns a subdocument from this document
`double` `getDouble(java.lang.String key)` Returns the double value of the key in the document
`java.lang.String` `getFirstKey()` Return the first key from the document
`int` `getInt(java.lang.String key)` Returns the int value of the key in the document
`long` `getLong(java.lang.String key)` Returns the long value of the key in the document
`RawBsonDocument` `getRawDocument()` Return the reference to the raw document If you get this object, this is a reference only, if you decided to modify this object later or the raw document take care as they can become out of sync.
`java.lang.String` `getSQLTypeName()`
`java.lang.String` `getString(java.lang.String key)` Returns the string value of the key in the document
`int` `hashCode()`
`boolean` `isEmpty()`
`boolean` `isRawDocument()` Returns whether we are currently a raw document or a fully exploded java map
`java.util.Set<java.lang.String>` `keySet()`
`java.lang.Object` `put(java.lang.String key, java.lang.Object v)`
`void` `putAll(BSONObject o)`
`void` `putAll(java.util.Map m)`
`void` `readSQL(java.sql.SQLInput stream, java.lang.String typeName)`
`java.lang.Object` `remove(java.lang.Object key)`
`java.lang.Object` `removeField(java.lang.String key)`
`void` `setBSONObject(org.bson.BSONObject bsonObject)`
`void` `setBytes(byte[] bytes)` Assigns the BSON-encoded byte array representation of a document.
`void` `setDocument(Document bsonObject)` Assigns the BSONObject this object represents.
`void` `setRawDocument(RawBsonDocument doc)`
`int` `size()`
`java.util.Map<java.lang.String,java.lang.Object>` `toMap()`
`java.lang.String` `toString()`
`java.util.Collection<java.lang.Object>` `values()`
`void` `writeSQL(java.sql.SQLOutput stream)`

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

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

### Methods inherited from interface java.util.Map

`clear, compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll`

### Field Detail

#### rawDocument

    protected RawBsonDocument rawDocument

#### bsonObject

    protected Document 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).

### 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(java.lang.String key,
                         java.lang.Object value)

Constructs a new object with an initial key/value pair

Parameters:
  `key` - String key
  `value` - Object value

#### 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(RawBsonDocument 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(Document 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`

#### ensureRawDocument

    protected void ensureRawDocument()

#### ensureBsonObject

    protected void ensureBsonObject()

#### 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

#### setRawDocument

    public void setRawDocument(RawBsonDocument doc)

#### setDocument

    public void setDocument(Document 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

#### setBSONObject

    public void setBSONObject(org.bson.BSONObject 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()

#### put

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

Specified by:
  `put` in interface `java.util.Map<java.lang.String,java.lang.Object>`

#### toMap

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

#### containsKey

    public boolean containsKey(java.lang.String s)

#### containsField

    public boolean containsField(java.lang.String s)

#### keySet

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

Specified by:
  `keySet` in interface `java.util.Map<java.lang.String,java.lang.Object>`

#### hashCode

    public int hashCode()

Specified by:
  `hashCode` in interface `java.util.Map<java.lang.String,java.lang.Object>`

#### equals

    public boolean equals(java.lang.Object o)

Specified by:
  `equals` in interface `java.util.Map<java.lang.String,java.lang.Object>`

#### size

    public int size()

Specified by:
  `size` in interface `java.util.Map<java.lang.String,java.lang.Object>`

#### isEmpty

    public boolean isEmpty()

Specified by:
  `isEmpty` in interface `java.util.Map<java.lang.String,java.lang.Object>`

#### containsKey

    public boolean containsKey(java.lang.Object key)

Specified by:
  `containsKey` in interface `java.util.Map<java.lang.String,java.lang.Object>`

#### containsValue

    public boolean containsValue(java.lang.Object value)

Specified by:
  `containsValue` in interface `java.util.Map<java.lang.String,java.lang.Object>`

#### get

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

Specified by:
  `get` in interface `java.util.Map<java.lang.String,java.lang.Object>`

#### get

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

#### remove

    public java.lang.Object remove(java.lang.Object key)

Specified by:
  `remove` in interface `java.util.Map<java.lang.String,java.lang.Object>`

#### values

    public java.util.Collection<java.lang.Object> values()

Specified by:
  `values` in interface `java.util.Map<java.lang.String,java.lang.Object>`

#### entrySet

    public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()

Specified by:
  `entrySet` in interface `java.util.Map<java.lang.String,java.lang.Object>`

#### putAll

    public void putAll(java.util.Map m)

Specified by:
  `putAll` in interface `java.util.Map<java.lang.String,java.lang.Object>`

#### getDocument

    public Document getDocument()

Return the Map version of the Bson document This version takes more memory but is completely manipulatable as you would a Map This returns a reference to the document object contained in this object. If you manipulate this document outside of the object you might need to create a new IfxBSONOBject

Returns:
  Document this

#### getDocument

    public IfxBSONObject getDocument(java.lang.String key)

Returns a subdocument from this document

Parameters:
  `key` - field to search for
Returns:
  IfxBSONObject the resulting document

#### getRawDocument

    public RawBsonDocument getRawDocument()

Return the reference to the raw document If you get this object, this is a reference only, if you decided to modify this object later or the raw document take care as they can become out of sync. The best practice is to create a new IfxBSONObject later if you modify the raw document outside of this class

Returns:
  RawBsonDocument Raw document underlying object

#### append

    public IfxBSONObject append(java.lang.String key,
                                java.lang.Object value)

Append the key/value pair to this document Similar to {`put(String, Object)` but this method returns the class reference to make multiple appends easier to write

Parameters:
  `key` - Key to set
  `value` - Object to set
Returns:
  IfxBSONObject this object

#### getInt

    public int getInt(java.lang.String key)

Returns the int value of the key in the document

Parameters:
  `key` - Key to lookup
Returns:
  int the value of the key

#### getLong

    public long getLong(java.lang.String key)

Returns the long value of the key in the document

Parameters:
  `key` - Key to lookup
Returns:
  long the value of the key

#### getDouble

    public double getDouble(java.lang.String key)

Returns the double value of the key in the document

Parameters:
  `key` - Key to lookup
Returns:
  double the value of the key

#### getString

    public java.lang.String getString(java.lang.String key)

Returns the string value of the key in the document

Parameters:
  `key` - Key to lookup
Returns:
  string the value of the key

#### getBoolean

    public boolean getBoolean(java.lang.String key)

Returns the boolean value of the key in the document

Parameters:
  `key` - Key to lookup
Returns:
  boolean the value of the key

#### isRawDocument

    public boolean isRawDocument()

Returns whether we are currently a raw document or a fully exploded java map

Returns:
  boolean `true` if we are are a raw document

#### getFirstKey

    public java.lang.String getFirstKey()

Return the first key from the document

Returns:
  String the first key in the document

#### putAll

    public void putAll(BSONObject o)

Specified by:
  `putAll` in interface `java.util.Map<java.lang.String,java.lang.Object>`

#### removeField

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