Class ANYDATA
- java.lang.Object
-
- oracle.sql.ANYDATA
-
- All Implemented Interfaces:
oracle.jdbc.internal.ObjectData
,OracleData
,ORAData
public class ANYDATA extends Object implements ORAData, OracleData
This class is the Java mapping of the SYS.ANYDATA SQL type. Instances of this type are self-descriptive. They contain a type description as well the actual content (also called the embedded object).You can construct an ANYDATA instance from a Datum instance using
ANYDATA.convertDatum(Datum)
. The following example shows how to construct an ANYDATA instance that encapsulates a NUMBER:NUMBER num = new NUMBER(12345); ANYDATA anydt = ANYDATA.convertDatum(num);
TheANYDATA.convertDatum(Datum)
method is the java equivalent of the PLSQLConvertXXX
procedures. In the previous example we could also have used PLSQL to construct the ANYDATA instance and retrieve it in Java:// conn being a JDBC connection Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select ANYDATA.ConvertNUMBER(12345) from dual"); ANYDATA anydt = null; if(rs.next()) anydt = (ANYDATA)rs.getObject(1);
The public method
getTypeDescriptor()
returns an instance ofTypeDescriptor
which provides a description of the type. To retrieve the actual data, useaccessDatum()
which returns an instance ofDatum
. To know what to cast it to, use the type description. For example:Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select anydatacol from foo"); while(rs.next()) { ANYDATA anydt = (ANYDATA)rs.getObject(1); System.out.println(anydt.stringValue()); TypeDescriptor typedesc = anydt.getTypeDescriptor(); Datum embeddedDatum = anydt.accessDatum(); if(typedesc.getTypeCode() == TypeDescriptor.TYPECODE_DATE) { // the embedded object is a DATE: DATE datedatum = (DATE)embeddedDatum; // etc. } else if(typedesc.getTypeCode() == TypeDescriptor.TYPECODE_NUMBER) { // the embedded object is a NUMBER NUMBER numberdatum = (NUMBER)embeddedDatum; // etc. } }
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Datum
accessDatum()
Returns the embedded object.static ANYDATA
convertDatum(Datum datum)
Constructs an ANYDATA instance from any instance ofDatum
.protected oracle.jdbc.internal.OracleConnection
getConnectionDuringExceptionHandling()
byte[]
getData()
Returns the linearized form of the embedded object value.TypeDescriptor
getTypeDescriptor()
Returns the type description of this ANYDATA instance.boolean
isNull()
Returns true if the data part of this ANYDATA instance is null and false otherwise.boolean
isREF()
Returns true if the embedded object is a REF and false otherwise.String
stringValue()
Returns a string representation of this ANYDATA.String
stringValue(Connection _connection)
Returns a string representation of this ANYDATA.Datum
toDatum(Connection c)
Extract an oracle.sql.Datum object.Object
toJDBCObject(Connection c)
Extract a jdbc Object.
-
-
-
Method Detail
-
toDatum
public Datum toDatum(Connection c) throws SQLException
Description copied from interface:ORAData
Extract an oracle.sql.Datum object.This method is invoked by setORAData() to extract a Datum. The implementation of this method must return the correct type of Datum.
Although most implementation will ignore the connection, it is occassionally needed. For example, if the class embeds CHAR attributes, connection may be needed to determine the database character set.
- Specified by:
toDatum
in interfaceORAData
- Parameters:
c
- The connection into which the value is being sent.- Returns:
- a Datum contaning the value to be sent into the connection.
- Throws:
SQLException
- if an error occurred.
-
toJDBCObject
public Object toJDBCObject(Connection c) throws SQLException
Description copied from interface:OracleData
Extract a jdbc Object.This method is invoked by setObject() to extract the jdbc Object. The implementation must return the jdbc Object that correctly represents the underlying SQLType.
Although most implementation will ignore the connection, it is ocassionally needed. for example, if the class embeds CHAR attributes, connection may be needed to determine the database character set.
- Specified by:
toJDBCObject
in interfaceOracleData
- Parameters:
c
- The connection into which the value is being sent.- Returns:
- a jdbc Object contianing the value to be sent into the connection.
- Throws:
SQLException
- if an error occurred.
-
convertDatum
public static ANYDATA convertDatum(Datum datum) throws SQLException
Constructs an ANYDATA instance from any instance ofDatum
.- Throws:
SQLException
-
getTypeDescriptor
public TypeDescriptor getTypeDescriptor()
Returns the type description of this ANYDATA instance.
-
isNull
public boolean isNull()
Returns true if the data part of this ANYDATA instance is null and false otherwise.
-
getData
public byte[] getData()
Returns the linearized form of the embedded object value. This method is an internal method.
-
isREF
public boolean isREF()
Returns true if the embedded object is a REF and false otherwise.
-
stringValue
public String stringValue() throws SQLException
Returns a string representation of this ANYDATA. The string contains both the type code name and a string representation of the embedded object.For example the following code:
String sql = "select anydata.ConvertDate(TO_DATE('Jan 15, 2006, 11:00 AM', " +" 'Mon dd, YYYY, HH:MI AM')) from dual"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); rs.next(); ANYDATA ad = (ANYDATA)rs.getObject(1); System.out.println(ad.stringValue());
will print in stdout the following string:
ANYDATA TypeCode: "TYPECODE_DATE" - ANYDATA Value: "1/15/2006 11:0:0"
- Throws:
SQLException
-
stringValue
public String stringValue(Connection _connection) throws SQLException
Returns a string representation of this ANYDATA. The string contains both the type code name and a string representation of the embedded object.For example the following code:
String sql = "select anydata.ConvertTIMESTAMPTZ(TO_TIMESTAMP_TZ(" +" TIMESTAMP'1997-06-22 08:30:00' AT TIME ZONE 'Asia/Calcutta')) from dual"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); rs.next(); ANYDATA ad = (ANYDATA)rs.getObject(1); // Pass connection to the types that require connection to print // eg: oracle.sql.TIMESTAMPTZ, oracle.sql.TIMESTAMPLTZ System.out.println(ad.stringValue(conn));
will print in stdout the following string:
ANYDATA TypeCode: "TYPECODE_TIMESTAMP_TZ" - ANYDATA Value: "1997-6-22 21.0.0.0 Asia/Calcutta"
- Parameters:
_connection
- OracleConnection object- Throws:
SQLException
-
accessDatum
public Datum accessDatum() throws SQLException
Returns the embedded object. UsegetTypeDescripor()
to retrieve type description of this embedded object. You will then be able to cast it to the rightoracle.sql.
class.- Throws:
SQLException
-
getConnectionDuringExceptionHandling
protected oracle.jdbc.internal.OracleConnection getConnectionDuringExceptionHandling()
-
-