|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--oracle.xml.sql.dml.OracleXMLSave
OracleXMLSave - This class supports canonical mapping from XML
to object-relational tables and views. You must initially create a
class by passing in the table name to which DML operations apply. You
can subsequently use any of the insertion, update, and deletion
methods of OracleXMLSave
class on the table. Many useful
functions are provided to help identify key columns for update or
delete, and to restrict columns being updated.
A typical sequence might look like this:
OracleXMLSave sav = new OracleXMLSave(conn, "emp");
sav.insertXML(xmlDoc);
String[]tempArr = new String[2];
tempArr[0] = EMPNO";
sav.setKeyColumnList(tempArray);
sav.updateXML(xmlDoc);
sav.deleteXML(xmlDoc);
sav.close();
Field Summary | |
static java.lang.String |
DATE_FORMAT
The date format for use in setDateFormat . |
static int |
DEFAULT_BATCH_SIZE
The default insert batch size is 17 records |
boolean |
xDocIsEsc
|
Constructor Summary | |
OracleXMLSave(java.sql.Connection oconn,
java.lang.String tabName)
Constructor for the OracleXMLSave class. |
Method Summary | |
void |
cleanLobList()
This function frees all temporary LOBs |
void |
close()
Closes the OracleXMLSave object and deallocates all
context associated with it. |
java.net.URL |
createURL(java.lang.String fileName)
Returns the URL object for a specified file or URL. |
int |
deleteXML(Document doc)
Deletes the rows in the table based on the XML document By default, matches all XML element values with corresponding column names. |
int |
deleteXML(java.io.InputStream xmlStream)
Deletes the rows in the table based on the XML document. |
int |
deleteXML(java.io.Reader xmlStream)
Deletes the rows in the table based on the XML document. |
int |
deleteXML(java.lang.String xmlDoc)
Deletes the rows in the table based on the XML document. |
int |
deleteXML(java.net.URL url)
Deletes rows from a table based on element values of the input XML document. |
protected void |
finalize()
|
static java.net.URL |
getURL(java.lang.String target)
Given a file name or a URL it return a URL object. |
int |
insertXML(Document doc)
|
int |
insertXML(java.io.InputStream xmlStream)
|
int |
insertXML(java.io.Reader xmlStream)
|
int |
insertXML(java.lang.String xmlDoc)
|
int |
insertXML(java.net.URL url)
Inserts an XML document from a specified URL into a table, By default, matches element names to column names, and sets columns with missing elements in input to null. |
void |
removeXSLTParam(java.lang.String name)
Removes the value of a top-level stylesheet parameter. |
void |
setBatchSize(int size)
Changes the batch size used during DML operations. |
void |
setCommitBatch(int size)
Sets the commit batch size, or the number of records inserted before a commit. |
void |
setDateFormat(java.lang.String mask)
Specifies the format of dates used in the XML document. |
void |
setIgnoreCase(boolean ignore)
Sets XML element names, based on XML tags, to be case insensitive when converting to database columns and attributes. |
void |
setKeyColumnList(java.lang.String[] keyColNames)
Sets the list of columns used to identify table rows against XML input document elements prior to UPDATE and
DELETE operations. |
void |
setPreserveWhitespace(boolean flag)
Specifies whether to preserve whitespace.. |
void |
setRowTag(java.lang.String rowTag)
Names the tag for the row enclosing XML element. |
void |
setSQLToXMLNameEscaping(boolean flag)
Determines whether to turn on XML tag escaping for SQL object names, to ensure conversion to valid XML identifiers. |
void |
setUpdateColumnList(java.lang.String[] updColNames)
Sets and limits the list of columns for INSERT and
UPDATE operations. |
void |
setXSLT(java.io.Reader stylesheet,
java.lang.String ref)
Registers an XSL transformation that should be applied to generated XML. |
void |
setXSLT(java.lang.String stylesheet,
java.lang.String ref)
Registers an XSL transformation that should be applied to generated XML. |
void |
setXSLTParam(java.lang.String name,
java.lang.String value)
Sets the value of the top-level stylesheet parameter. |
int |
updateXML(Document doc)
Updates the table given the XML document in a DOM tree form. |
int |
updateXML(java.io.InputStream xmlStream)
Updates the table given the XML document in a stream form. |
int |
updateXML(java.io.Reader xmlStream)
Updates the table given the XML document in a stream form. |
int |
updateXML(java.lang.String xmlDoc)
Updates the table given the XML document in a string form. |
int |
updateXML(java.net.URL url)
Updates the columns in a database table, based on the element values in the input XML document. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static int DEFAULT_BATCH_SIZE
public static final java.lang.String DATE_FORMAT
setDateFormat
.
public boolean xDocIsEsc
Constructor Detail |
public OracleXMLSave(java.sql.Connection oconn, java.lang.String tabName)
OracleXMLSave
class.
oconn
- Connection
object for accessing the databasetabName
- The name of the table that should be updatedMethod Detail |
public void setPreserveWhitespace(boolean flag)
flag
- TRUE
to preserve whitespacepublic void setXSLT(java.lang.String stylesheet, java.lang.String ref)
null
in the
stylesheet
parameter.
stylesheet
- the stylesheet URIref
- URL for include, import and external entitiespublic void setXSLT(java.io.Reader stylesheet, java.lang.String ref)
null
in the
stylesheet
parameter.
stylesheet
- the stylesheetref
- URL for include, import and external entitiespublic void setXSLTParam(java.lang.String name, java.lang.String value)
name
- parameter namevalue
- parameter value as an XPATH
expressionpublic void removeXSLTParam(java.lang.String name)
name
- parameter namepublic void setCommitBatch(int size)
size < 1
or the session is in
"auto-commit" mode, no explicit commits are made. The default
size
is 0
.
size
- commit batch sizepublic void setSQLToXMLNameEscaping(boolean flag)
flag
- TRUE
to turn on SQL to XML escapingpublic void setIgnoreCase(boolean ignore)
OracleXMLSave
object.
ignore
- ignore tag case in the XML doc? 0-false 1-truepublic void setRowTag(java.lang.String rowTag)
rowTag
to null
means that top level
elements of the document correspond to table rows.
rowTag
- tag namepublic void setDateFormat(java.lang.String mask)
MM/dd/yyyy
HH:mm:ss
. The defualt override should conform to
requirements of the java.text.SimpleDateFormat
class.
Setting the mask
parameter to null or
empty string sets the default mask
OracleXMLSave.DATE_FORMAT
.
- Parameters:
mask
- the date mask
public java.net.URL createURL(java.lang.String fileName)
target
parameter is not a valid URL format,
"http://..." or "file://...", tries to create a URL object of the
form "file://target
". Returns null
if the
target
parameter is null
or an empty
string.
fileName
- The name of the file
target entity
public static java.net.URL getURL(java.lang.String target)
null
or an empty string are passed to it, null
is returned.
target
- file name or URL string
target entity
protected void finalize()
finalize
in class java.lang.Object
public void close()
OracleXMLSave
object and deallocates all
context associated with it.
public void cleanLobList()
public int insertXML(java.net.URL url)
null. To
restrict insertion to a subset of a table's columns and allow the
other columns to hold a default value, use the
setUpdateColumnList()
method. Set the key column by a
setKeyColumnList()
call.
For example, consider the employee table emp:
TABLE emp( empno NUMBER, ename VARCHAR2(20), hiredate DATE);
Now, assume that you want to insert the table using an XML document.
OracleXMLSave save = new OracleXMLSave(conn, "emp");
save.insertXML(xmlDoc); // xmlDoc supplied..
save.close();
If you want to insert values only into EMPNO, HIREDATE, and SALARY
and let the default values handle the rest of the columns:
String insArray = new String[3];
insArray[0] = "EMPNO";
insArray[1] = "HIREDATE";
insArray[2] = "SALARY";
save.setUpdateColumnList(insArray);
save.insertXML(xmlDoc); // will only insert values into EMPNO, HIREDATE,
// and SALARY columns
- Parameters:
url
- URL to the input XML document used to populate the
table
- Returns:
- The number of rows inserted.
public int insertXML(java.lang.String xmlDoc) throws java.io.IOException
java.io.IOException
public int insertXML(java.io.Reader xmlStream)
public int insertXML(java.io.InputStream xmlStream)
public int insertXML(Document doc)
public int updateXML(java.net.URL url)
UPDATE
transaction. To
restrict update to a subset of columns and allow the other columns
to hold previous values, use the
setUpdateColumnList()
method. This has the added
benefit of improving performance by caching the UPDATE
statement and batching transactions.
For example, consider the employee table emp:
TABLE emp( empno NUMBER, ename VARCHAR2(20), hiredate DATE);
Now, assume that you want to update the table using an XML document
and you want to use the values of the element EMPNO to match the right
row and then only update the HIREDATE column.
You can send in an XML document containing the HIREDATE value and the
EMPNO value and call the updateXML() routine with the setKeyColumnList()
containing the EMPNO string.
OracleXMLSave save = new OracleXMLSave(conn, "emp");
String[] keyArray = new String[1];
keyArray[0] = "EMPNO"; // Set EMPNO as key column.
save.setKeyColumnList(keyArray); // Set the key column names.
String[] updArray = new String[1];
updArray[0] = "HIREDATE"; // Set hiredate as column to update.
save.setUpdateColumnList(updArray);
save.updateXML(xmlDoc); // xmlDoc supplied..
save.close();
url
- URL to the input XML document used to update the table
public int updateXML(java.lang.String xmlDoc) throws java.io.IOException
UPDATE
transaction. To
restrict update to a subset of columns and allow the other columns
to hold previous values, use the
setUpdateColumnList()
method. This has the added
benefit of improving performance by caching the UPDATE
statement and batching transactions.
xmlDoc
- The string form of the XML document
java.io.IOException
public int updateXML(java.io.Reader xmlStream)
UPDATE
transaction. To
restrict update to a subset of columns and allow the other columns
to hold previous values, use the
setUpdateColumnList()
method. This has the added
benefit of improving performance by caching the UPDATE
statement and batching transactions.
public int updateXML(java.io.InputStream xmlStream)
UPDATE
transaction. To
restrict update to a subset of columns and allow the other columns
to hold previous values, use the
setUpdateColumnList()
method. This has the added
benefit of improving performance by caching the UPDATE
statement and batching transactions.
public int updateXML(Document doc)
UPDATE
transaction. To
restrict update to a subset of columns and allow the other columns
to hold previous values, use the
setUpdateColumnList()
method. This has the added
benefit of improving performance by caching the UPDATE
statement and batching transactions.
public int deleteXML(java.net.URL url)
DELETE
transaction. You can use a partial
matching approach and limit the number of elements used to identify
a row by using the setKeyColumnList()
method. This has
the added benefit of improving performance by caching the
DELETE
statement and batching transactions.
For example, consider the employee table emp:
TABLE emp( empno NUMBER, ename VARCHAR2(20), hiredate DATE);
Now, you want to delete the rows in the table using an XML document
and you want to identify the row based on the EMPNO value.
You can send in an XML document containing the EMPNO value
and call the deleteXML() routine with the setKeyColumnList()
containing the EMPNO string.
OracleXMLSave save = new OracleXMLSave(conn, "emp");
save.deleteXML(xmlDoc); // Deletes rows by matching all columns with the
// element values in the input document.
String[] deleteArray = new String[1];
deleteArray[0] = "EMPNO";
save.setKeyColumnList(deleteArray); // Set the key columns.
save.deleteXML(xmlDoc); // only deletes rows by matching the EMPNO values
url
- URL to the XML document used to identify rows for
deletion from the table
public int deleteXML(java.lang.String xmlDoc) throws java.io.IOException
DELETE
transaction. You can use a partial
matching approach and limit the number of elements used to identify
a row by using the setKeyColumnList()
method. This has
the added benefit of improving performance by caching the
DELETE
statement and batching transactions.
xmlDoc
- The XML document in String form
java.io.IOException
public int deleteXML(java.io.Reader xmlStream)
DELETE
transaction. You can use a partial
matching approach and limit the number of elements used to identify
a row by using the setKeyColumnList()
method. This has
the added benefit of improving performance by caching the
DELETE
statement and batching transactions.
public int deleteXML(java.io.InputStream xmlStream)
DELETE
transaction. You can use a partial
matching approach and limit the number of elements used to identify
a row by using the setKeyColumnList()
method. This has
the added benefit of improving performance by caching the
DELETE
statement and batching transactions.
public int deleteXML(Document doc)
DELETE
transaction. You can use a partial
matching approach and limit the number of elements used to identify
a row by using the setKeyColumnList()
method. This has
the added benefit of improving performance by caching the
DELETE
statement and batching transactions.
public void setBatchSize(int size)
size
to 1
. The default batch size is
DEFAULT_BATCH_SIZE
.
size
- The batch size used for all DMLs.public void setKeyColumnList(java.lang.String[] keyColNames)
UPDATE
and
DELETE
operations. This call is mandatory for
UPDATE
s and optional for DELETE
s. Update
and deletion based on key column values is a no-op.
keyColNames
- The names of the list of columns that are used as keys.public void setUpdateColumnList(java.lang.String[] updColNames)
INSERT
and
UPDATE
operations. Only these columns will be updated,
leaving other values in the record in their previous states. Only
values of these columns will be added when inserting a new record,
setting other values to the pre-defined table default.
updColNames
- The string list of columns to be updated.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |