This is a VTI designed to read XML files which are structured like row sets.
XML files parsed by this VTI are always processed with external entity expansion disabled and secure parser processing enabled.
There are two invocation formats provided by this VTI.
One form of this VTI takes the following arguments. This form is useful when all of the columns in the row can be constructed from data nested INSIDE the row Element.
Here is a sample declaration of this first form of the XmlVTI:
create function findbugs( xmlResourceName varchar( 32672 ), rowTag varchar( 32672 ), childTags varchar( 32672 )... )
returns table
(
className varchar( 32672 ),
bugCount int
)
language java parameter style derby_jdbc_result_set no sql
external name 'org.apache.derby.vti.XmlVTI.xmlVTI';
...and here is a sample invocation:
create view findbugs as
select *
from table
(
findbugs
(
'findbugs.xml',
'ClassStats',
'class', 'bugs'
)
) v;
select * from findbugs where bugCount != 0;
A second form of this VTI takes the following arguments. This form is useful when some of the columns in the row are "inherited" from outer elements inside which the row element nests:
Here is a sample declaration of this second form of the XmlVTI. Using the second form involves declaring an ArrayList type and a factory method too:
create type ArrayList external name 'java.util.ArrayList' language java;
create function asList( cell varchar( 32672 ) ... ) returns ArrayList
language java parameter style derby no sql
external name 'org.apache.derby.vti.XmlVTI.asList';
create function optTrace
(
xmlResourceName varchar( 32672 ),
rowTag varchar( 32672 ),
parentTags ArrayList,
childTags ArrayList
)
returns table
(
stmtID int,
queryID int,
complete boolean,
summary varchar( 32672 ),
type varchar( 50 ),
estimatedCost double,
estimatedRowCount int
)
language java parameter style derby_jdbc_result_set no sql
external name 'org.apache.derby.vti.XmlVTI.xmlVTI';
create view optTrace as
select *
from table
(
optTrace
(
'/Users/me/derby/mainline/z.xml',
'planCost',
asList( 'stmtID', 'queryID', 'complete' ),
asList( 'summary', 'type', 'estimatedCost', 'estimatedRowCount' )
)
) v
;
select * from optTrace
where stmtID = 6 and complete
order by estimatedCost;
| Modifier and Type | Class and Description |
|---|---|
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private DocumentBuilder | |
| private String[] | |
| private int | |
| private NodeList | |
| private int | |
| private int | |
| private String | |
| private InputStream |
| Access | Constructor and Description |
|---|---|
| public | XmlVTI(InputStream
The xml source as an InputStream. xmlResource, String The tag of the master row Element. rowTag, int The first (0-based) tag from columnTags which is a child tag. firstChildTagIdx, String... The tags which supply column data; all of the tag positions less than firstChildTagIdx come from Elements which are outer to the rowTag element; the remaining tags, starting at firstChildTagIdx, are tags of attributes or Elements inside the rowTag Element. columnTags)Build an XmlVTI. |
| Modifier and Type | Method and Description |
|---|---|
| public static ArrayList | |
| public void | close()
Implements java. Releases this |
| private String | |
| public ResultSetMetaData | getMetaData()
Overrides org. Implements java. Retrieves the number, types and properties of
this |
| protected String | Returns: the column value as a stringThe 1-based column index in the row columnNumber)Implements abstract org. Get the string value of the column in the current row identified by the 1-based columnNumber. |
| public boolean | next()
Implements java. Moves the cursor forward one row from its current position. |
| private void | |
| private void | |
| private String | |
| public static XmlVTI | Returns: a VTI to turn the XML text into rowsThe file containing the XML text fileName, String The tag on the outermost element defining the row rowTag, String... The nested attributes and elements corresponding to columns in the row childTags)This is the static method for creating functions from a file name and child tags |
| public static XmlVTI | Returns: a VTI to turn the XML text into rowsName of file which holds the XML text fileName, String The base element for the row rowTag, ArrayList<String> The names of parent tags parentTags, ArrayList<String> The names of child tags childTags)This is the static method for creating functions from a file name and both parent and child tags |
| private static XmlVTI | Returns: a VTI to turn the XML text into rowsThe XML text as a stream xmlResource, String The base element for the row rowTag, ArrayList<String> The names of parent tags parentTags, ArrayList<String> The names of child tags childTags)This is the static method for creating functions from an URL and both parent and child tags |
| public static XmlVTI | Returns: a VTI to turn the XML text into rowsAn URL which locates the XML text urlString, String The tag on the outermost element defining the row rowTag, String... The nested attributes and elements corresponding to columns in the row childTags)This is the static method for creating functions from an url and child tags |
| public static XmlVTI | Returns: a VTI to turn the XML text into rowsAn URL which locates the XML text urlString, String The base element for the row rowTag, ArrayList<String> The names of parent tags parentTags, ArrayList<String> The names of child tags childTags)This is the static method for creating functions from an URL and both parent and child tags |
| _builder | back to summary |
|---|---|
| private DocumentBuilder _builder | |
| _currentRow | back to summary |
|---|---|
| private String[] _currentRow | |
| _firstChildTagIdx | back to summary |
|---|---|
| private int _firstChildTagIdx | |
| _rawRows | back to summary |
|---|---|
| private NodeList _rawRows | |
| _rowCount | back to summary |
|---|---|
| private int _rowCount | |
| _rowIdx | back to summary |
|---|---|
| private int _rowIdx | |
| _rowTag | back to summary |
|---|---|
| private String _rowTag | |
| _xmlResource | back to summary |
|---|---|
| private InputStream _xmlResource | |
| XmlVTI | back to summary |
|---|---|
| public XmlVTI(InputStream xmlResource, String rowTag, int firstChildTagIdx, String... columnTags) Build an XmlVTI.
| |
| asList | back to summary |
|---|---|
| public static ArrayList Factory method to create an ArrayList<String> | |
| close | back to summary |
|---|---|
| public void close() throws SQLException Implements java. Doc from java. Releases this The closing of a
When a Note A
Calling the method
| |
| findColumnValue | back to summary |
|---|---|
| private String findColumnValue(Element rawRow, int columnNumber) throws Exception Find the value of a column inside an element. The columnNumber is 0-based. | |
| getMetaData | back to summary |
|---|---|
| public ResultSetMetaData getMetaData() throws SQLException Overrides org. Implements java. Doc from java. Retrieves the number, types and properties of
this
| |
| getRawColumn | back to summary |
|---|---|
| protected String getRawColumn(int columnNumber) throws SQLException Implements abstract org. Get the string value of the column in the current row identified by the 1-based columnNumber.
| |
| next | back to summary |
|---|---|
| public boolean next() throws SQLException Implements java. Doc from java. Moves the cursor forward one row from its current position.
A
When a call to the If an input stream is open for the current row, a call
to the method
| |
| parseRow | back to summary |
|---|---|
| private void parseRow(int rowNumber) throws Exception Parse a row into columns. | |
| readRows | back to summary |
|---|---|
| private void readRows() throws Exception Fault in the list of rows. | |
| squeezeText | back to summary |
|---|---|
| private String squeezeText(Element node) throws Exception Squeeze the text out of an Element. | |
| xmlVTI | back to summary |
|---|---|
| public static XmlVTI xmlVTI(String fileName, String rowTag, String... childTags) throws Exception This is the static method for creating functions from a file name and child tags | |
| xmlVTI | back to summary |
|---|---|
| public static XmlVTI xmlVTI(final String fileName, String rowTag, ArrayList<String> parentTags, ArrayList<String> childTags) throws Exception This is the static method for creating functions from a file name and both parent and child tags | |
| xmlVTI | back to summary |
|---|---|
| private static XmlVTI xmlVTI(InputStream xmlResource, String rowTag, ArrayList<String> parentTags, ArrayList<String> childTags) throws Exception This is the static method for creating functions from an URL and both parent and child tags | |
| xmlVTIFromURL | back to summary |
|---|---|
| public static XmlVTI xmlVTIFromURL(String urlString, String rowTag, String... childTags) throws Exception This is the static method for creating functions from an url and child tags | |
| xmlVTIFromURL | back to summary |
|---|---|
| public static XmlVTI xmlVTIFromURL(final String urlString, String rowTag, ArrayList<String> parentTags, ArrayList<String> childTags) throws Exception This is the static method for creating functions from an URL and both parent and child tags | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public void | error(SAXParseException
The error information encapsulated in a
SAX parse exception. exception)Implements org. Receive notification of a recoverable error. |
| public void | fatalError(SAXParseException
The error information encapsulated in a
exception)SAXParseException.Implements org. Receive notification of a non-recoverable, fatal error. |
| public void | warning(SAXParseException
The warning information encapsulated in a
SAX parse exception. exception)Implements org. Receive notification of a warning. |
| XMLErrorHandler | back to summary |
|---|---|
| private XMLErrorHandler() | |
| closeInput | back to summary |
|---|---|
| private void closeInput() | |
| error | back to summary |
|---|---|
| public void error(SAXParseException exception) throws SAXException Implements org. Doc from org. Receive notification of a recoverable error. This corresponds to the definition of "error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a validating parser would use this callback to report the violation of a validity constraint. The default behaviour is to take no action. The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end. If the application cannot do so, then the parser should report a fatal error even if the XML recommendation does not require it to do so. Filters may use this method to report other, non-XML errors as well.
| |
| fatalError | back to summary |
|---|---|
| public void fatalError(SAXParseException exception) throws SAXException Implements org. Doc from org. Receive notification of a non-recoverable, fatal error. As defined in section 1.2 of the W3C XML 1.0 Recommendation, fatal errors are those that would make it impossible for a parser to continue normal processing. These include violation of a well-formedness constraint, invalid encoding, and forbidden structural errors as described in the W3C XML 1.0 Recommendation.
| |
| warning | back to summary |
|---|---|
| public void warning(SAXParseException exception) throws SAXException Implements org. Doc from org. Receive notification of a warning. SAX parsers will use this method to report conditions that are not errors or fatal errors as defined by the XML recommendation. The default behaviour is to take no action. The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end. Filters may use this method to report other, non-XML warnings as well.
| |