Oracle9i Supplied Java Packages Reference Release 2 (9.2) Part Number A96609-01 |
|
This chapter describes the Java classes for XML SQL Utility for Java, which are contained in the oracle.xml.sql.query package. XML SQL Utility for Java (XSU) generates and stores XML from SQL queries.
This chapter contains these sections:
The Java classes for XML SQL Utility for Java are contained in the oracle.xml.sql.query package. XML SQL Utility for Java (XSU) generates and stores XML data to and from the database from SQL queries or result sets or tables. It achieves data transformation by mapping canonically any SQL query result to XML, and vice versa.
The OracleXMLQuery class generates XML given an SQL query.
public class OracleXMLQuery extends java.lang.Object java.lang.Object | +--oracle.xml.sql.query.OracleXMLQuery
Class constructor for the OracleXMLQueryObject. The options are described in the following table.
conn |
database connection |
rset |
jdbc result set object |
query |
the SQL query string |
dset |
dataset |
Closes any open resource, created by the OracleXML engine. This will not close for instance result set supplied by the user.
public void close();
Returns the number of rows processed.
public long getNumRowsProcessed();
Transforms the object-relational data, specified in the constructor, into XML. Returns a representation of the XML document. The options are described in the following table.
metaType |
the type of XML metadata (NONE, SCHEMA) |
root |
root node to which to append the new XML |
This functions returns the DTD or the XMLSchema for the XML document which would have been generated by a getXML*()
call, such as getXMLDOM()
, getXMLSAX()
, getXMLSchema()
, or getXMLString()
.
public java.lang.String getXMLMetaData( int metaType,
boolean withVer);
metaType |
Specifies the type of XML metadata to be generated (NONE or DTD). |
withVer |
Specifies whether to generate the version processing instruction |
Transforms the object-relational data, specified in the constructor, into an XML document.
public void getXMLSAX(org.xml.sax.ContentHandler sax);
sax |
ContentHandler object to be registered. |
This methods generates the XML Schema(s) corresponding to the specified query; returns the XML Schema(s).
public org.w3c.dom.Document[] getXMLSchema();
Transforms the object-relational data, specified in the constructor, into a XML document. Returns the string representation of the XML document. The options are described in the following table.
metaType |
The type of XML metadata (NONE, DTD, or SCHEMA, static fields of this class) |
root |
root node to which to append the new XML |
The default behavior for all the getXML*()
functions which DO NOT TAKE in a ResultSet object, such as getXMLDOM()
, getXMLSAX()
, getXMLSchema()
, or getXMLString()
, is to close the ResultSet object and Statement objects at the end of the call. If the persistent feature is needed, where by calling getXML()
repeatedly the next set of rows is obtained, this behavior must be turned off by calling this function with value TRUE. OracleXMLQuery
would not close the ResultSet
and Statement
objects after the getXML()
calls. To close the cursor state, the close()
function must be called explicitly.
public void keepObjectOpen( boolean alive);
alive |
Should the object be kept open? |
Removes the value of a top-level stylesheet parameter. NOTE: if no stylesheet is registered, this method is a no op.
public void removeXSLTParam( String name);
name |
Parameter name |
Sets the name of the id
attribute of the collection element's separator tag. Passing NULL
or an empty string causes the row id
attribute to be omitted.
public void setCollIdAttrName( String attrName);
attrName |
Attribute Name |
Sets the XML data header, the XML entity which is appended at the beginning of the query-generated XML entity (i.e., rowset). The two entities are enclosed by the tag specified via the docTag
argument. The last data header specified is the one that is used. Passing in NULL
for the header
parameter unsets the data header.
public void setDataHeader( java.io.Reader header,
java.lang.String docTag);
header |
Header |
docTag |
Tag used to enclose the data header and the rowset |
Sets the format of the generated dates in the XML doc. The syntax of the date format pattern (i.e. the date mask), should conform to the requirements of the java.text.SimpleDateFormat class. Setting the mask to NULL
or an empty string, unsets the date mask.
public void setDateFormat( java.lang.String mask);
mask |
The data mask |
Sets the encoding processing instruction (PI) in the XML doc. If NULL
or an empty string are specified as the encoding, then the default characterset is specified in the encoding PI.
public void setEncoding(java.lang.String enc)
enc |
Encoding of the CML doc (IANA name of encoding) |
Sets the tag to be used to enclose the XML error docs.
public void setErrorTag( java.lang.String tag);
tag |
Tag name |
Allows the user to pass in an exception, and have the XSU handle it.
public void setException( java.lang.Exception e);
e |
The exception to be processed by XSU |
Sets the maximum number of rows to be converted to XML. By default there is no maximum set. To explicitly specify no max, see MAXROWS_ALL
field.
public void setMaxRows( int rows);
rows |
Maximum number of rows to generate |
Sets the XML meta header. When set, the header is inserted at the beginning of the metadata part (DTD or XMLSchema) of each XML document generated by this object. The last meta header specified is the one that is used. Setting the header
to NULL
or an empty string unsets the meta header.
public void setMetaHeader( java.io.Reader header);
header |
Header |
Instructs the XSU whether to throw the raised exceptions. If this call isn't made, or if FALSE
is passed to the flag
argument, the XSU catches the SQL exceptions and generates an XML doc from the exception message.
public void setRaiseException(boolean flag);
flag |
Should the raised exception be thrown? |
Instructs the XSU whether to throw an OracleXMLNoRowsException
when the generated XML doc is empty. By default, the exception is not thrown.
public void setRaiseNoRowsException( boolean flag);
flag |
Should the |
Sets the name of the id attribute of the row enclosing tag. Passing NULL
or an empty string causes the row id attribute to be omitted.
attrName |
Attribute name |
Specifies the scalar column whose value is to be assigned to the id attribute of the row enclosing tag. Passing NULL
or an empty string causes the row id attribute to be assigned the row count value (i.e. 0, 1, 2, ...).
public void setRowIdAttrValue( java.lang.String colName);
colName |
Column whose value will be assigned to the row id attribute |
Sets the tag to be used to enclose the XML dataset.
public void setRowsetTag( java.lang.String tag);
tag |
Tag name |
Sets the tag to be used to enclose the XML element corresponding to a db. record.
public void setRowTag( java.lang.String tag);
tag |
Tag name |
Sets the number of rows to skip. By default 0 rows are skipped. To skip all the rows use SKIPROWS_ALL.
public void setSkipRows(int rows);
rows |
Number of rows to skip. |
This turns on or off escaping of XML tags in the case that the SQL object name, which is mapped to a XML identifier, is not a valid XML identifier.
public void setSQLToXMLNameEscaping( boolean flag);
flag |
Whether to turn on SQL to XML identifier escaping. |
Sets the stylesheet header (i.e. stylesheet processing instructions) in the generated XML doc. Passing NULL
in the argument will unset the stylesheet header and the stylesheet type. The options are described in the following table.
uri |
Stylesheet URI |
type |
Stylesheet type; defaults to 'text/xsl' |
Registers a XSL transform to be applied to generated XML. If a stylesheet is already registered, it is replaced by the new one. To un-register the stylesheet, pass in NULL
value for the argument. The options are described in the following table.
stylesheet |
The stylesheet. |
ref |
URL for include, import and external entities. |
Sets the value of a top-level stylesheet parameter. The parameter value is expected to be a valid XPath expression; therefore the string literal values have to be explicitly quoted). If no stylesheet is registered, this method is a no op.
public void setXSLTParam( java.lang.String name,
java.lang.String value);
name |
Parameter name |
value |
Parameter value as an XPATH expression |
This will set the case to be lower for all tag names. Note, make this call after all the desired tags have been set.
public void useLowerCaseTagNames();
Specifies if NULL
ness is indicated by a special XML attribute or by omitting the entity from the XML document.
public void useNullAttributeIndicator(boolean flag);
flag |
Should the attribute be used to indicate |
By default, the tag name for elements of a collection is the collection's tag name followed by "_item". This method, when called with argument value of TRUE
, instructs the XSU to use the collection element's type name as the collection element's tag name.
public void useTypeForCollElemTag( boolean flag);
flag |
Should the column element type be used to indicate its tag name? |
Sets all tag names to upper case. This call should be made only after all the desired tags have been set.
public void useUpperCaseTagNames();
Class for managing all exceptions thrown by the XSU.
public class OracleXMLSQLException extends java.lang.RuntimeException java.lang.Object | +--java.lang.Throwable | +--java.lang.Exception | +--java.lang.RuntimeException | +--oracle.xml.sql.OracleXMLSQLException
Creates a new OracleXMLSQLException. The options are described in the following table.
e |
The exception. |
errorTagName |
The error tag name. |
message |
The error message. |
errorCode |
the SQL error code. |
Returns the SQL error code thrown.
public int getErrorCode();
Returns the original exception, if there was one; otherwise, returns NULL
.
public java.lang.Exception getParentException();
Prints the XML error string with the given error tag name.
public java.lang.String getXMLErrorString();
Prints the SQL parameters as well in the error message.
public java.lang.String getXMLSQLErrorString();
Sets the error tag name, which is then used by getXMLErrorString()
and getXMLSQLErrorString()
to generate XML error reports.
public void setErrorTag(java.lang.String tagName);
tagName |
The tag name of the error |
The exception that can be thrown when no rows are found.
public class OracleXMLSQLNoRowsException extends OracleXMLSQLException java.lang.Object | +--java.lang.Throwable | +--java.lang.Exception | +--java.lang.RuntimeException | +--OracleXMLSQLException | +--oracle.xml.sql.OracleXMLSQLNoRowsException
java.io.Serializable
Creates a new OracleXMLSQLNoRowsException
. The options are described in the following table.
Syntax | Description |
---|---|
public OracleXMLSQLNoRowsException(); |
Default class constructor. |
public OracleXMLSQLNoRowsException( java.lang.String errorTag); |
Sets the error tag as the passed in argument. |
errorTag |
The error tag. |
Member | Inherited from |
---|---|
|
Copyright © 1996, 2002 Oracle Corporation. All Rights Reserved. |
|