Class XmlVTI
- All Implemented Interfaces:
AutoCloseable
,ResultSet
,Wrapper
,AwareVTI
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.
- xmlResourceName - The name of an xml file.
- rowTag - The tag of the element which contains the row-structured content.
- childTags - The attributes and descendant elements inside the row element which should be treated as columns.
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:
- xmlResourceName - The name of an xml file.
- rowTag - The tag of the element which contains the row-structured content.
- parentTags - Attributes and elements (to be treated as columns) from outer elements in which the rowTag is nested.
- childTags - Attributes and elements (to be treated as columns) inside the row element.
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;
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.apache.derby.vti.VTITemplate
VTITemplate.ColumnDescriptor
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DocumentBuilder
private String[]
private int
private NodeList
private int
private int
private String
private InputStream
Fields inherited from interface java.sql.ResultSet
CLOSE_CURSORS_AT_COMMIT, CONCUR_READ_ONLY, CONCUR_UPDATABLE, FETCH_FORWARD, FETCH_REVERSE, FETCH_UNKNOWN, HOLD_CURSORS_OVER_COMMIT, TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, TYPE_SCROLL_SENSITIVE
-
Constructor Summary
ConstructorsConstructorDescriptionXmlVTI
(InputStream xmlResource, String rowTag, int firstChildTagIdx, String... columnTags) Build an XmlVTI. -
Method Summary
Modifier and TypeMethodDescriptionFactory method to create an ArrayListvoid
close()
private String
findColumnValue
(Element rawRow, int columnNumber) Find the value of a column inside an element.protected String
getRawColumn
(int columnNumber) Get the string value of the column in the current row identified by the 1-based columnNumber.boolean
next()
private void
parseRow
(int rowNumber) Parse a row into columns.private void
readRows()
Fault in the list of rows.private String
squeezeText
(Element node) Squeeze the text out of an Element.private static XmlVTI
xmlVTI
(InputStream xmlResource, String rowTag, ArrayList<String> parentTags, ArrayList<String> childTags) This is the static method for creating functions from an URL and both parent and child tagsstatic XmlVTI
This is the static method for creating functions from a file name and child tagsstatic XmlVTI
This is the static method for creating functions from a file name and both parent and child tagsstatic XmlVTI
xmlVTIFromURL
(String urlString, String rowTag, String... childTags) This is the static method for creating functions from an url and child tagsstatic XmlVTI
xmlVTIFromURL
(String urlString, String rowTag, ArrayList<String> parentTags, ArrayList<String> childTags) This is the static method for creating functions from an URL and both parent and child tagsMethods inherited from class org.apache.derby.vti.StringColumnVTI
findColumn, getAsciiStream, getBigDecimal, getBinaryStream, getBlob, getBoolean, getByte, getBytes, getClob, getColumnCount, getColumnName, getDate, getDouble, getFloat, getInt, getLong, getShort, getString, getTime, getTimestamp, setColumnNames, wasNull
Methods inherited from class org.apache.derby.vti.VTITemplate
absolute, afterLast, beforeFirst, cancelRowUpdates, clearWarnings, deleteRow, first, getArray, getArray, getAsciiStream, getBigDecimal, getBigDecimal, getBigDecimal, getBinaryStream, getBlob, getBoolean, getByte, getBytes, getCharacterStream, getCharacterStream, getClob, getConcurrency, getContext, getCursorName, getDate, getDate, getDate, getDouble, getFetchDirection, getFetchSize, getFloat, getHoldability, getInt, getLong, getNCharacterStream, getNCharacterStream, getNClob, getNClob, getNString, getNString, getObject, getObject, getObject, getObject, getObject, getObject, getRef, getRef, getReturnTableSignature, getRow, getRowId, getRowId, getShort, getSQLXML, getSQLXML, getStatement, getString, getTime, getTime, getTime, getTimestamp, getTimestamp, getTimestamp, getType, getUnicodeStream, getUnicodeStream, getURL, getURL, getWarnings, insertRow, isAfterLast, isBeforeFirst, isClosed, isFirst, isLast, isWrapperFor, last, moveToCurrentRow, moveToInsertRow, notImplemented, previous, refreshRow, relative, rowDeleted, rowInserted, rowUpdated, setContext, setFetchDirection, setFetchSize, unwrap, updateArray, updateArray, updateAsciiStream, updateAsciiStream, updateAsciiStream, updateAsciiStream, updateAsciiStream, updateAsciiStream, updateBigDecimal, updateBigDecimal, updateBinaryStream, updateBinaryStream, updateBinaryStream, updateBinaryStream, updateBinaryStream, updateBinaryStream, updateBlob, updateBlob, updateBlob, updateBlob, updateBlob, updateBlob, updateBoolean, updateBoolean, updateByte, updateByte, updateBytes, updateBytes, updateCharacterStream, updateCharacterStream, updateCharacterStream, updateCharacterStream, updateCharacterStream, updateCharacterStream, updateClob, updateClob, updateClob, updateClob, updateClob, updateClob, updateDate, updateDate, updateDouble, updateDouble, updateFloat, updateFloat, updateInt, updateInt, updateLong, updateLong, updateNCharacterStream, updateNCharacterStream, updateNCharacterStream, updateNCharacterStream, updateNClob, updateNClob, updateNClob, updateNClob, updateNClob, updateNClob, updateNString, updateNString, updateNull, updateNull, updateObject, updateObject, updateObject, updateObject, updateRef, updateRef, updateRow, updateRowId, updateRowId, updateShort, updateShort, updateSQLXML, updateSQLXML, updateString, updateString, updateTime, updateTime, updateTimestamp, updateTimestamp
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.sql.ResultSet
updateObject, updateObject, updateObject, updateObject
-
Field Details
-
_rowTag
-
_xmlResource
-
_rowIdx
private int _rowIdx -
_rowCount
private int _rowCount -
_currentRow
-
_builder
-
_rawRows
-
_firstChildTagIdx
private int _firstChildTagIdx
-
-
Constructor Details
-
XmlVTI
Build an XmlVTI.
- Parameters:
xmlResource
- The xml source as an InputStream.rowTag
- The tag of the master row Element.firstChildTagIdx
- The first (0-based) tag from columnTags which is a child tag.columnTags
- 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.
-
-
Method Details
-
xmlVTI
This is the static method for creating functions from a file name and child tags- Throws:
Exception
-
xmlVTIFromURL
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- Throws:
Exception
-
xmlVTI
public static XmlVTI xmlVTI(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- Throws:
Exception
-
xmlVTIFromURL
public static XmlVTI xmlVTIFromURL(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- Throws:
Exception
-
xmlVTI
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- Throws:
Exception
-
asList
Factory method to create an ArrayList -
getRawColumn
Get the string value of the column in the current row identified by the 1-based columnNumber.
- Specified by:
getRawColumn
in classStringColumnVTI
- Throws:
SQLException
-
close
- Throws:
SQLException
-
getMetaData
- Specified by:
getMetaData
in interfaceResultSet
- Overrides:
getMetaData
in classVTITemplate
- Throws:
SQLException
-
next
- Throws:
SQLException
-
readRows
Fault in the list of rows.
- Throws:
Exception
-
parseRow
Parse a row into columns.
- Throws:
Exception
-
findColumnValue
Find the value of a column inside an element. The columnNumber is 0-based.
- Throws:
Exception
-
squeezeText
Squeeze the text out of an Element.
- Throws:
Exception
-