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.
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 12-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 12-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 prior to conversion.
Connection *conn; string str; ... if(!any.isNULL()) { if(any.getType()==OCCI_TYPECODE_VARCHAR2) { str = any.getAsString(); cout<<str; } } ...
Example 12-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 12-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 prior to 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 12-4 OCCI Datatypes supported by AnyData Class
| Datatype | 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 12-5 Summary of AnyData Methods
| Method | Summary |
|---|---|
|
|
|
|
Converts an |
|
|
Converts an |
|
|
Converts an |
|
|
Converts an |
|
|
Converts an |
|
|
Converts an |
|
|
Converts an |
|
|
Converts an |
|
|
Converts an |
|
|
Converts an |
|
|
Converts an |
|
|
Converts an |
|
|
Retrieves the DataType held by the |
|
|
Tests whether |
|
|
Converts a |
|
|
Converts a |
|
|
Converts a |
|
|
Converts a |
|
|
Converts a |
|
|
Converts an |
|
|
Converts an |
|
|
Converts a |
|
|
Converts a |
|
|
Converts a |
|
|
Converts a namespace |
|
|
Converts a |
|
|
Sets |
AnyData constructor.
AnyData( const Connection *conn);
| Parameter | Description |
|---|---|
conn |
The connection. |
Converts an AnyData object into BDouble.
BDouble getAsBDouble() const;
Converts an AnyData object into Bfile.
Bfile getAsBfile() const;
Converts an AnyData object into BFloat.
BFloat getAsBFloat() const;
Converts an AnyData object into Bytes.
Bytes getAsBytes() const;
Converts an AnyData object into Date.
Date getAsDate() const;
Converts an AnyData object into IntervalDS.
IntervalDS getAsIntervalDS() const;
Converts an AnyData object into IntervalYM.
IntervalYS getAsIntervalYM() const;
Converts an AnyData object into Number.
Number getAsNumber() const;
Converts an AnyData object into PObject.
PObject* getAsObject() const;
Converts an AnyData object into RefAny.
RefAny getAsRef() const;
Converts an AnyData object into a namespace string.
string getAsString() const;
Converts an AnyData object into Timestamp.
Timestamp getAsTimestamp() const;
Retrieves the data type held by the AnyData object. Refer to Table 12-4 for valid values for TypeCode.
TypeCode getType();
Tests whether the AnyData object is NULL. If the AnyData object is NULL, then TRUE is returned; otherwise, FALSE is returned.
bool isNull() const;
Converts a BDouble into AnyData.
void setFromBDouble( const BDouble& bdouble);
| Parameter | Description |
|---|---|
bdouble |
The BDouble that will be converted into AnyData. |
Converts a Bfile into AnyData.
void setFromBfile( const Bfile& bfile);
| Parameter | Description |
|---|---|
bfile |
The Bfile that will be converted into AnyData. |
Converts a BFloat into AnyData.
void setFromBFloat( const BFloat& bfloat);
| Parameter | Description |
|---|---|
bfloat |
The BFloat that will be converted into AnyData. |
Converts a Bytes into AnyData.
void setFromBytes( const Bytes& bytes);
| Parameter | Description |
|---|---|
bytes |
The Bytes that will be converted into AnyData. |
Converts a Date into AnyData.
void setFromDate( const Date& date);
| Parameter | Description |
|---|---|
date |
The Date that will be converted into AnyData. |
Converts an IntervalDS into AnyData.
void setFromIntervalDS( const IntervalDS& intervalds);
| Parameter | Description |
|---|---|
invtervalds |
The IntervalDS that will be converted into AnyData. |
Converts an IntervalYM into AnyData.
void setFromIntervalYM( const IntervalYM& intervalym);
| Parameter | Description |
|---|---|
invalym |
The IntervalYM that will be converted into AnyData. |
Converts a Number into AnyData.
void setFromNumber( const Number& num);
| Parameter | Description |
|---|---|
num |
The Number that will be converted into AnyData. |
Converts a PObject into AnyData.
void setFromObject( const PObject* objptr);
| Parameter | Description |
|---|---|
objptr |
The PObject that will be converted into AnyData. |
Converts a PObject into AnyData.
void setFromRef( const RefAny& ref const string &typeName, const string &schema);
| Parameter | Description |
|---|---|
ref |
The RefAny that will be converted into AnyData. |
typeName |
The name of the type. |
schema |
Th name of the schema where the type is defined. |
Converts a namespace string into AnyData.
void setFromString( string& str);
| Parameter | Description |
|---|---|
str |
The namespace string that will be converted into AnyData. |
Converts a Timestamp into AnyData.
void setFromTimestamp( const Timestamp& timestamp);
| Parameter | Description |
|---|---|
timestamp |
The Timestamp that will be converted into AnyData. |
Sets AnyData object to NULL.
void setNull();