FazBrowse Wikipedia Viewer | Main Page |
Search Wikipedia:
|
Viewing: https://en.wikipedia.org/wiki/XQuery_API_for_Java

XQuery API for Java

Contents
Examples
    Basic example
Default data type mapping
Known implementations
    Native XML databases
    Relational databases
    Non-database implementations
License
References

XQJ
DeveloperJava Community Process
element(), xs:integer or ContentHandler, StAX InputStream classes.

Examples

edit

Basic example

edit

The following example illustrates creating a connection to an XML Database, submitting an XQuery expression, then processing the results in Java. Once all of the results have been processed, the connection is closed to free up all resources associated with it.

XQExpressionexpr=conn.createExpression(); // The XQuery expression to be executed Stringes="declare variable $x as xs:integer external;"+ " for $n in fn:collection('catalog')//item"+ " where $n/price <= $x"+ " return fn:data($n/name)"; // Bind a value (21) to an external variable with the QName x expr.bindInt(newQName("x"),21,null); // Execute the XQuery expression XQResultSequenceresult=expr.executeQuery(es); // Process the result (sequence) iteratively while(result.next()){ // Process the result ... }

Default data type mapping

edit

Mapping between Java and XQuery data types is largely flexible, however the XQJ 1.0 specification does have default mapping rules mapping data types when they are not specified by the user. These mapping rules bear great similarities to the mapping rules found in JAXB.

The following table illustrates the default mapping rules for when binding Java values to external variables in XQuery expressions.

Default conversion rules when mapping from Java data types to XQuery data types
Java Datatype Default XQuery Data Type(s)
byte xs:hexBinary
float xs:int
short xs:boolean
Float xs:double
Long xs:short
BigDecimal xs:integer
Duration Object's state is Duration Object's state is Duration Object's state is xs:date if the xs:dateTime if the xs:gDay if the xs:gMonth if the xs:gMonthDay if the xs:gYear if the xs:gYearMonth if the xs:time if the QName document-node(element(*, xs:untyped))
Element attribute(*, xs:untypedAtomic)
ProcessingInstruction text()

Known implementations

edit

Native XML databases

edit

The following is a list of Native XML Databases which are known to have XQuery API for Java implementations.

Relational databases

edit

DataDirect provide XQJ adapters for relational databases, by translating XQuery code into SQL on the fly, then converting SQL result sets into a format suitable for XQJ to process further. The following is a couple of known implementations.

Non-database implementations

edit

The following is a list of non-database XQuery processors which provide an XQuery API for Java interface (typically allowing query against documents parsed from XML in filestore, and held in memory as DOM or similar trees).

License

edit

The specification is marked as "Copyright © 2003, 2006 - 2009 Oracle. All rights reserved."

The specification contains two separate licenses: a "specification license" and a "reference implementation license".

The specification license allows free copying of the specification provided that copyright notices are retained; it also grants a license to create and distribute an implementation of the specification provided that it fully implements the entire specification, that it does not modify or extend any interfaces, and that it passes the compatibility tests.

This provision has caused some controversy. Firstly, it is not universally accepted that implementing a published specification is something that requires a license (that is, that copyright law would disallow this in the absence of a license). Secondly, the license does not meet the criteria to qualify as an open source license (see Open Source Definition), because of the ban on making extensions and modifications. This has led some open source enthusiasts to challenge whether XQJ implementations can ever be considered truly open source.

The license for the reference implementation is a fairly conventional BSD-style open source license.

References

edit