Oracle9i XML API Reference - XDK and Oracle XML DB Release 2 (9.2) Part Number A96616-01 |
|
XML SQL Utility for Java (XSU) generates and stores XML from SQL queries.
This chapter contains descriptions of the following XSU classes:
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.
Parameter | Description |
---|---|
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.
Parameter | Description |
---|---|
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 String getXMLMetaData( int metaType, boolean withVer);
Parameter | Description |
---|---|
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);
Parameter | Description |
---|---|
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.
Parameter | Description |
---|---|
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);
Parameter | Description |
---|---|
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);
Parameter | Description |
---|---|
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);
Parameter | Description |
---|---|
attrName |
Attribute Name |
Sets the XML data header, the XML entity which is appended at the beginning of the query-generated XML entity, the rowset. The two entities are enclosed by the tag specified through 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, String docTag);
Parameter | Description |
---|---|
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, 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( String mask);
Parameter | Description |
---|---|
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( String enc)
Parameter | Description |
---|---|
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( String tag);
Parameter | Description |
---|---|
tag |
Tag name |
Allows the user to pass in an exception, and have the XSU handle it.
public void setException( java.lang.Exception e);
Parameter | Description |
---|---|
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);
Parameter | Description |
---|---|
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);
Parameter | Description |
---|---|
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);
Parameter | Description |
---|---|
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);
Parameter | Description |
---|---|
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.
public void setRowIdAttrName( String attrName);
Parameter | Description |
---|---|
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, such as 0, 1, 2, and so on.
public void setRowIdAttrValue( String colName);
Parameter | Description |
---|---|
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( String tag);
Parameter | Description |
---|---|
tag |
Tag name |
Sets the tag to be used to enclose the XML element corresponding to a db. record.
public void setRowTag( String tag);
Parameter | Description |
---|---|
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);
Parameter | Description |
---|---|
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);
Parameter | Description |
---|---|
flag |
Whether to turn on SQL to XML identifier escaping. |
Sets the stylesheet header, which contains 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.
Parameter | Description |
---|---|
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.
Syntax | Description |
---|---|
String ref); |
The stylesheet parameter is passed in as the data. |
String ref); |
The stylesheet parameter is passed in as a URI to the document. |
Parameter | Description |
---|---|
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( String name, String value);
Parameter | Description |
---|---|
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);
Parameter | Description |
---|---|
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);
Parameter | Description |
---|---|
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();
OracleXMLSave class supports canonical mapping from XML to object-relational tables or views. It supports inserts, updates and deletes. The user first creates the class by passing in the table name on which these DML operations need to be done. After that, the user is free to use the insert/update/delete on this table.
Many useful functions are provided in this class to help in identifying the key columns for update or delete and to restrict the columns being updated.
public class OracleXMLSave extends java.lang.Object java.lang.Object | +--oracle.xml.sql.dml.OracleXMLSave
The public constructor for the OracleXMLSave class.
public OracleXMLSave( java.sql.Connection oconn, String tabName;
Parameter | Description |
---|---|
oconn |
Connection object (connection to the database) |
tableName |
The name of the table that should be updated |
Closes/deallocates all the context associated with this object.
public void close();
Deletes the rows in the table based on the XML document. Returns the number of XML ROW elements processed. This may or may not be equal to the number of database rows deleted based on whether the rows selected through the XML document uniquely identified the rows in the table.
By default, the delete processing matches all the element values with the corresponding column names. Each ROW element in the input document is taken as a separate delete statement on the table. By using the setKeyColumnList()
, the list of columns that must be matched to identify the row to be deleted is set, and other elements are ignored. This is an efficient method for deleting more than one row in the table if matching is employed (since the delete statement is cached). Otherwise, a new delete statement has to be created for each ROW element in the input document. The options are described in the following table.
Returns a URL object identifying the target entity, given a file name or a URL. If the argument passed is not in a valid URL format, such as "http://..." or "file://...", then this method attempts to correct the argument by pre-pending "file://". If a NULL
or an empty string are passed to it, NULL
is returned.
public static java.net.URL getURL( String target);
Parameter | Description |
---|---|
target |
File name or URL string. |
Inserts an XML document into the specified table. Returns the number of rows inserted.
NULL
value for all elements that are missing in the input document. By using the setUpdateColumnList()
, no NULL
values would be inserted for the rest of the columns; instead, default values would be used.setKeyColumnList()
.setUpdateColumnList()
.The options are described in the following table.
Removes the value of a top-level stylesheet parameter. If no stylesheet is registered, this method is a no op.
public void removeXSLTParam( String name);
Parameter | Description |
---|---|
name |
Parameter name |
Changes the batch size used during DML operations. When performing inserts, updates or deletes, it is recommended to batch the operations to minimize I/O cycles; however, this requires more cache for storing the bind values while the operations are executing. When batching is used, the commits occur only in terms of batches. If a single statement inside a batch fails, the entire batch is rolled back. If this behavior is undesirable, set batch size to 1. The default batch size is DEFAULT_BATCH_SIZE
.
public void setBatchSize( int size);
Parameter | Description |
---|---|
size |
The batch size to use for all DML. |
Sets the commit batch size, which refers to the number of records inserted after which a commit must follow. If size < 1,
or the session is in "auto-commit" mode, the XSU does not make any explicit commits. Default commit-batch size is 0
.
public void setCommitBatch( int size);
Parameter | Description |
---|---|
size |
Commit batch size. |
Describes to the XSU the format of the dates in the XML document. By default, OracleXMLSave assumes that the date is in format 'MM/dd/yyyy HH:mm:ss'. You can override this default format by calling this function. The syntax of the date format pattern, the date mask, should conform to the requirements of the java.text.SimpleDateFormat class. Setting the mask to NULL
or an empty string, causes the use of the default mask -- OracleXMLSave.DATE_FORMAT.
public void setDateFormat( String mask);
Parameter | Description |
---|---|
mask |
The date mask. |
The XSU performs mapping of XML elements to database columns or attributes based on the element names (XML tags). This function instructs the XSU to perform a case-insensitive match. This may affect the metadata caching performed when creating the Save object.
public void setIgnoreCase( boolean ignore);
Parameter | Description |
---|---|
flag |
Should the tag case in the XML doc be ignored? |
Sets the list of columns to be used for identifying a particular row in the database table during update or delete. This call is ignored for the insert case. The key columns must be set before updates can be done. It is optional for deletes. When this key columns is set, then the values from these tags in the XML document is used to identify the database row for update or delete. Currently, there is no way to update the values of the key columns themselves, since there is no way in the XML document to specify that case.
public void setKeyColumnList( String[] keyColNames);
Parameter | Description |
---|---|
keyColNames |
The names of the list of columns that are used as keys. |
Instructs the XSU whether to preserve whitespaces.
public void setPreserveWhitespace( boolean flag);
Parameter | Description |
---|---|
flag |
Should the whitespaces be preserved? |
Names the tag used in the XML doc so to enclose the XML elements corresponding to each row value. Setting the value of this to NULL
implies that there is no row tag present, and the top level elements of the document correspond to the rows themselves.
public void setRowTag( String rowTag);
Parameter | Description |
---|---|
tag |
Tag name. |
This turns on or off escaping of XML tags when the SQL object name, which is mapped to a XML identifier, is not a valid XML identifier.
public void setSQLToXMLNameEscaping( boolean flag);
Parameter | Description |
---|---|
flag |
Should the SQL to XML escaping be turned on? |
Set the column values to be updated. Applies to inserts and updates, not deletes.
public void setUpdateColumnList( String[] updColNames);
Parameter | Description |
---|---|
updColNmaes |
The string list of columns to be updated. |
Registers a XSL transform to be applied to generated XML. If a stylesheet was already registered, it gets replaced by the new one. To un-register the stylesheet pass in a NULL
for the stylesheet
argument. The options are described in the following table.
Syntax | Description |
---|---|
String ref); |
The stylesheet parameter is passed in as the data. |
String ref); |
The stylesheet parameter is passed in as a URI to the document. |
Parameter | Description |
---|---|
stylesheet |
The stylesheet URI. |
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 (note that string literal values would therefore have to be explicitly quoted). If no stylesheet is registered, this method is a no op.
public void setXSLTParam( String name, String value);
Parameter | Description |
---|---|
name |
Parameter name. |
value |
Parameter value as an XPATH expression. |
Updates the table given the XML document. Returns the number of XML elements processed. This may or may not be equal to the number of database rows modified, depending on whether the rows selected through the XML document uniquely identify the rows in the table.
setKeyColumnList()
.setUpdateColumnList()
.The options are described in the following table.
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.
Parameter | Description |
---|---|
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 String getXMLErrorString();
Prints the SQL parameters as well in the error message.
public String getXMLSQLErrorString();
Sets the error tag name, which is then used by getXMLErrorString()
and getXMLSQLErrorString()
to generate XML error reports.
public void setErrorTag( String tagName);
Parameter | Description |
---|---|
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( String errorTag); |
Sets the error tag as the passed in argument. |
Parameter | Description |
---|---|
errorTag |
The error tag. |
|
Copyright © 2001, 2002 Oracle Corporation. All Rights Reserved. |
|