AnyData Class

The AnyData class models self-descriptive data by encapsulating the type information with the actual data. AnyData is used primarily with OCCI Advanced Queuing feature, to represent and enqueue data and to receive messages from queues as AnyData instances.

Most SQL and user-defined types can be converted into an AnyData type using the setFromxxx() methods. An AnyData object can be converted into most SQL and user-defined types using getAsxxx() methods. SYS.ANYDATA type models AnyData both in SQL and PL/SQL. See Table 13-4, "OCCI Data Types supported by AnyData Class" for supported data types.

The getType() call returns the TypeCode represented by an AnyData object, while the isNull() call determines if AnyData contains a NULL value. The setNull() method sets the value of AnyData to NULL.

To use the OCCI AnyData type, the environment has to be initiated in OBJECT mode.

Example 13-1 Converting From an SQL Pre-Defined Type To AnyData Type

This example demonstrates how to convert types from string to AnyData.

Connection *conn;
...
AnyData any(conn);
string str("Hello World");
any.setFromString(str);
...

Example 13-2 Creating an SQL Pre-Defined Type From AnyData Type

This example demonstrates how to convert an AnyData object back to a string object. Note the use of getType() and isNull() methods to validate AnyData before conversion.

Connection *conn;
string str;
...
if(!any.isNULL())
{   if(any.getType()==OCCI_TYPECODE_VARCHAR2)
   {
      str = any.getAsString();
      cout<<str;
   }
}
...

Example 13-3 Converting From a User-Defined Type To AnyData Type

This example demonstrates how to convert from a user-defined type to AnyData type.

Connection *conn;
...
// Assume an OBJECT of type Person with the following defined fields
// CREATE TYPE person as OBJECT (
//    FRIST_NAME VARCHAR2(20),
//    LAST_NAME VARCHAR2(25),
//    EMAIL VARCHAR2(25),
//    SALARY NUMBER(8,2)
//   );
// Assume relevant classes have been generated by OTT.
...
Person *pers new Person( "Steve", "Addams",
                         "steve.addams@anycompany.com", 50000.00);
AnyData anyObj(conn);
anyObj.setFromObject(pers);
...

Example 13-4 Converting From a User-Defined Type To AnyData Type

This example demonstrates how to convert an AnyData object back to a user-defined type. Note the use of getType() and isNull() methods to validate AnyData before conversion.

Connection *conn;
// Assume an OBJECT of type Person with the following defined fields
// CREATE TYPE person as OBJECT (
//    FRIST_NAME VARCHAR2(20),
//    LAST_NAME VARCHAR2(25),
//    EMAIL VARCHAR2(25),
//    SALARY NUMBER(8,2)
//   );
// Assume relevant classes have been generated by OTT.
Person *pers = new Person();
...
If(!anyObj.isNull())
{   if(anyObj.getType()==OCCI_TYPECODE_OBJECT)
      pers = anyObj.getAsObject();
}
...

Table 13-4 OCCI Data Types supported by AnyData Class

Data Type TypeCode
BDouble
OCCI_TYPECODE_BDOUBLE
BFile
OCCI_TYPECODE_BFILE
BFloat
OCCI_TYPECODE_BFLOAT
Bytes
OCCI_TYPECODE_RAW
Date
OCCI_TYPECODE_DATE
IntervalDS
OCCI_TYPECODE_INTERVAL_DS
IntervalYM
OCCI_TYPECODE_INTERVAL_YM
Number
OCCI_TYPECODE_NUMBERB
PObject
OCCI_TYPECODE_OBJECT
Ref
OCCI_TYPECODE_REF
string
OCCI_TYPECODE_VARCHAR2
TimeStamp
OCCI_TYPECODE_TIMESTAMP

Table 13-5 Summary of AnyData Methods

Method Summary

AnyData()

AnyData class constructor.

getAsBDouble()

Converts an AnyData object into BDouble.

getAsBfile()

Converts an AnyData object into Bfile.

getAsBFloat()

Converts an AnyData object into BFloat.

getAsBytes()

Converts an AnyData object into Bytes.

getAsDate()

Converts an AnyData object into Date.

getAsIntervalDS()

Converts an AnyData object into IntervalDS.

getAsIntervalYM()

Converts an AnyData object into IntervalYM.

getAsNumber()

Converts an AnyData object into Number.

getAsObject()

Converts an AnyData object into PObject.

getAsRef()

Converts an AnyData object into RefAny.

getAsString()

Converts an AnyData object into a namespace string.

getAsTimestamp()

Converts an AnyData object into Timestamp.

getType()

Retrieves the DataType held by the AnyData object. See Table 13-4.

isNull()

Tests whether AnyData object is NULL.

setFromBDouble()

Converts a BDouble into Anydata.

setFromBfile()

Converts a Bfile into Anydata.

setFromBFloat()

Converts a BFloat into Anydata.

setFromBytes()

Converts a Bytes into Anydata.

setFromDate()

Converts a Date into Anydata.

setFromIntervalDS()

Converts an IntervalDS into Anydata.

setFromIntervalYM()

Converts an IntervalYM into Anydata.

setFromNumber()

Converts a Number into Anydata.

setFromObject()

Converts a PObject into Anydata.

setFromRef()

Converts a RefAny into Anydata.

setFromString()

Converts a namespace string into Anydata.

setFromTimestamp()

Converts a Timestamp into Anydata.

setNull()

Sets AnyData object to NULL.



AnyData()

AnyData constructor.

Syntax

AnyData(
   const Connection *conn); 
Parameter Description
conn
The connection.


getAsBDouble()

Converts an AnyData object into BDouble.

Syntax

BDouble getAsBDouble() const;

getAsBfile()

Converts an AnyData object into Bfile.

Syntax

Bfile getAsBfile() const;

getAsBFloat()

Converts an AnyData object into BFloat.

Syntax

BFloat getAsBFloat() const;

getAsBytes()

Converts an AnyData object into Bytes.

Syntax

Bytes getAsBytes() const;

getAsDate()

Converts an AnyData object into Date.

Syntax

Date getAsDate() const;

getAsIntervalDS()

Converts an AnyData object into IntervalDS.

Syntax

IntervalDS getAsIntervalDS() const;

getAsIntervalYM()

Converts an AnyData object into IntervalYM.

Syntax

IntervalYS getAsIntervalYM() const;

getAsNumber()

Converts an AnyData object into Number.

Syntax

Number getAsNumber() const;

getAsObject()

Converts an AnyData object into PObject.

Syntax

PObject* getAsObject() const;

getAsRef()

Converts an AnyData object into RefAny.

Syntax

RefAny getAsRef() const;

getAsString()

Converts an AnyData object into a namespace string.

Syntax

string getAsString() const;

getAsTimestamp()

Converts an AnyData object into Timestamp.

Syntax

Timestamp getAsTimestamp() const;

getType()

Retrieves the data type held by the AnyData object. Refer to Table 13-4 for valid values for TypeCode.

Syntax

TypeCode getType();

isNull()

Tests whether the AnyData object is NULL. If the AnyData object is NULL, then TRUE is returned; otherwise, FALSE is returned.

Syntax

bool isNull() const;

setFromBDouble()

Converts a BDouble into AnyData.

Syntax

void setFromBDouble(
   const BDouble& bdouble);
Parameter Description
bdouble
The BDouble that is converted into AnyData.


setFromBfile()

Converts a Bfile into AnyData.

Syntax

void setFromBfile(
   const Bfile& bfile);
Parameter Description
bfile
The Bfile that is converted into AnyData.


setFromBFloat()

Converts a BFloat into AnyData.

Syntax

void setFromBFloat(
   const BFloat& bfloat);
Parameter Description
bfloat
The BFloat that is converted into AnyData.


setFromBytes()

Converts a Bytes into AnyData.

Syntax

void setFromBytes(
   const Bytes& bytes);
Parameter Description
bytes
The Bytes that is converted into AnyData.


setFromDate()

Converts a Date into AnyData.

Syntax

void setFromDate(
   const Date& date);
Parameter Description
date
The Date that is converted into AnyData.


setFromIntervalDS()

Converts an IntervalDS into AnyData.

Syntax

void setFromIntervalDS(
   const IntervalDS& intervalds);
Parameter Description
invtervalds
The IntervalDS that is converted into AnyData.


setFromIntervalYM()

Converts an IntervalYM into AnyData.

Syntax

void setFromIntervalYM(
   const IntervalYM& intervalym);
Parameter Description
invalym
The IntervalYM that is converted into AnyData.


setFromNumber()

Converts a Number into AnyData.

Syntax

void setFromNumber(
   const Number& num);
Parameter Description
num
The Number that is converted into AnyData.


setFromObject()

Converts a PObject into AnyData.

Syntax

void setFromObject(
   const PObject* objptr);
Parameter Description
objptr
The PObject that is converted into AnyData.


setFromRef()

Converts a PObject into AnyData.

Syntax

void setFromRef(
   const RefAny& ref
   const string &typeName,
   const string &schema);
Parameter Description
ref
The RefAny that is converted into AnyData.
typeName
The name of the type.
schema
The name of the schema where the type is defined.


setFromString()

Converts a namespace string into AnyData.

Syntax

void setFromString(
   string& str);
Parameter Description
str
The namespace string that is converted into AnyData.


setFromTimestamp()

Converts a Timestamp into AnyData.

Syntax

void setFromTimestamp(
   const Timestamp& timestamp);
Parameter Description
timestamp
The Timestamp that is converted into AnyData.


setNull()

Sets AnyData object to NULL.

Syntax

void setNull();