HOME

TheInfoList



OR:

XQuery API for Java (XQJ) refers to the common
Java API There are two types of Java programming language application programming interfaces (APIs): * The official core Java API, contained in the Android (Google), SE (OpenJDK and Oracle), MicroEJ. These packages (java.* packages) are the core Java la ...
for the
W3C The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web. Founded in 1994 and led by Tim Berners-Lee, the consortium is made up of member organizations that maintain full-time staff working to ...
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, bin ...
1.0 specification. The XQJ API enables Java programmers to execute
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, bin ...
against an
XML Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. T ...
data source (e.g. an
XML database An XML database is a data persistence software system that allows data to be specified, and sometimes stored, in XML format. This data can be queried, transformed, exported and returned to a calling system. XML databases are a flavor of document- ...
) while reducing or eliminating vendor lock in. The XQJ API provides Java developers with an interface to the XQuery Data Model.XQuery 1.0 and XPath 2.0 Data Model (XDM)
/ref> Its design is similar to the JDBC API which has a client/server feel and as such lends itself well to Server-based
XML Databases An XML database is a data persistence software system that allows data to be specified, and sometimes stored, in XML format. This data can be queried, transformed, exported and returned to a calling system. XML databases are a flavor of document- ...
and less well to client-side
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, bin ...
processors, although the " connection" part is a very minor part of the entire API. Users of the XQJ API can bind
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
values to
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, bin ...
expressions, preventing code injection attacks. Also, multiple
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, bin ...
expressions can be executed as part of an
atomic transaction In database systems, atomicity (; from grc, ἄτομος, átomos, undividable) is one of the ACID (''Atomicity, Consistency, Isolation, Durability'') transaction properties. An atomic transaction is an ''indivisible'' and ''irreducible'' se ...
.


History and implementation

The XQuery API for Java was developed at the
Java Community Process The Java Community Process (JCP), established in 1998, is a formalized mechanism that allows interested parties to develop standard technical specifications for Java technology. Anyone can become a JCP Member by filling a form available at thJCP w ...
as JSR 225. It had some big technology backers such as
Oracle An oracle is a person or agency considered to provide wise and insightful counsel or prophetic predictions, most notably including precognition of the future, inspired by deities. As such, it is a form of divination. Description The word '' ...
,XQJ - XQuery Java API is Completed, Marc Van Cappellen, Zhen Hua Liu, Jim Melton and Maxim Orgiyan

/ref>An Early Look at XQuery API for Java (XQJ) - Andrew Eisenberg, IBM and Jim Melton, Oracle
IBM,
BEA Systems BEA Systems, Inc. was a company that specialized in enterprise infrastructure software products which was wholly acquired by Oracle Corporation on April 29, 2008. History BEA began as a software company, founded in 1995 and headquartered in ...
,
Software AG Founded in 1969, Software AG is an enterprise software company with over 10,000 enterprise customers in over 70 countries. The company is the second largest software vendor in Germany, and the seventh largest in Europe. Software AG is traded on t ...
,
Intel Intel Corporation is an American multinational corporation and technology company headquartered in Santa Clara, California. It is the world's largest semiconductor chip manufacturer by revenue, and is one of the developers of the x86 seri ...
,
Nokia Nokia Corporation (natively Nokia Oyj, referred to as Nokia) is a Finnish multinational corporation, multinational telecommunications industry, telecommunications, technology company, information technology, and consumer electronics corporatio ...
and DataDirect. Version 1.0 of the XQuery API for Java Specification was released on June 24, 2009, along with JavaDocs, a
reference implementation In the software development process, a reference implementation (or, less frequently, sample implementation or model implementation) is a program that implements all requirements from a corresponding specification. The reference implementation o ...
and a TCK (Technology Compatibility Kit) which implementing vendors must conform to. The XQJ classes are contained in the
Java package A Java package organizes Java classes into namespaces, providing a unique namespace for each type it contains. Classes in the same package can access each other's package-private and protected members. In general, a package can contain the follo ...
javax.xml.xquery
/code> There is no (visible) activity to create a version of XQJ that provides support for XQuery 3.0 or 3.1, for example by providing Java bindings for additions to the data model such as functions, arrays, or maps.


Functionality

XQJ allows multiple implementations to exist and be used by the same application. XQJ connections support creating and executing
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, bin ...
expressions. Expressions may be updating
XQuery Update Facility XQuery Update Facility is an extension to the XML Query language, XQuery. It provides expressions that can be used to make changes to instances of the XQuery 1.0 and XPath 2.0 Data Model. It became a W3C Candidate Recommendation on 31 July 2009 ...
and may include full text searches. XQJ represents
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, bin ...
expressions using one of the following classes: * XQExpression
/code> – the expression is sent to the XQuery processor every time. *
/code> – the expression is cached and the execution path is pre-determined allowing it to be executed multiple times in an efficient manner.
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, bin ...
expressions return a result sequence of XDM items which in XQJ are represented through the XQResultSequence
/code> interface. The programmer can use an
/code> to walk over individual XDM items in the result sequence. Each item in the sequence has XDM type information associated with it, such as its node type e.g. , or an XDM atomic type such as , or . XDM type information in XQJ can be retrieved via the
/code> interface. Atomic
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, bin ...
items can be easily cast to
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
primitives via XQItemAccessor
/code> methods such as
/code> and
/code>. Also
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, bin ...
items and sequences can be serialized to
DOM Dom or DOM may refer to: People and fictional characters * Dom (given name), including fictional characters * Dom (surname) * Dom La Nena (born 1989), stage name of Brazilian-born cellist, singer and songwriter Dominique Pinto * Dom people, an et ...
, SAX ,
StAX Streaming API for XML (StAX) is an application programming interface (API) to read and write XML documents, originating from the Java programming language community. Traditionally, XML APIs are either: * DOM based - the entire document is read in ...
and the generic IO and classes.


Examples


Basic example

The following example illustrates creating a connection to an
XML Database An XML database is a data persistence software system that allows data to be specified, and sometimes stored, in XML format. This data can be queried, transformed, exported and returned to a calling system. XML databases are a flavor of document- ...
, submitting an
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, bin ...
expression, then processing the results in
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
. Once all of the results have been processed, the connection is closed to free up all resources associated with it. // Create a new connection to an XML database XQConnection conn = vendorDataSource.getConnection("myUser", "myPassword"); XQExpression expr = conn.createExpression(); // Create a reusable XQuery Expression object XQResultSequence result = expr.executeQuery( "for $n in fn:collection('catalog')//item " + "return fn:data($n/name)"); // execute an XQuery expression // Process the result sequence iteratively while (result.next()) // Free all resources created by the connection conn.close();


Binding a value to an external variable

The following example illustrates how a
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
value can be bound to an external variable in an
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, bin ...
expression. Assume that the connection already exists: XQExpression expr = conn.createExpression(); // The XQuery expression to be executed String es = "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(new QName("x"), 21, null); // Execute the XQuery expression XQResultSequence result = expr.executeQuery(es); // Process the result (sequence) iteratively while (result.next())


Default data type mapping

Mapping between
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
and
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, bin ...
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 Java XML Binding (JAXB; formerly Java Architecture for XML Binding) is a software framework that allows Java EE developers to map Java classes to XML representations. JAXB provides two main features: the ability to ''marshal'' Java objects in ...
. The following table illustrates the default mapping rules for when binding
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
values to external variables in
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, bin ...
expressions.


Known implementations


Native XML databases

The following is a list of Native XML Databases which are known to have XQuery API for Java implementations. *
MarkLogic MarkLogic Corporation is an American software business that develops and provides an enterprise NoSQL database, also named ''MarkLogic''. The company was founded in 2001 and is based in San Carlos, California. MarkLogic is a privately held compa ...
*
eXist eXist-db (or eXist for short) is an open source software project for NoSQL databases built on XML technology. It is classified as both a NoSQL document-oriented database system and a native XML database (and it provides support for XML, JSON, HTM ...
*
BaseX BaseX is a native and light-weight XML database management system and XQuery processor, developed as a community project on GitHub. It is specialized in storing, querying, and visualizing large XML documents and collections. BaseX is platform-in ...
* Sedna *
Oracle An oracle is a person or agency considered to provide wise and insightful counsel or prophetic predictions, most notably including precognition of the future, inspired by deities. As such, it is a form of divination. Description The word '' ...
br>XDB
* Tamino *
TigerLogic TigerLogic Corporation was an American internet and software development company that designed, developed, sold and supported software infrastructure products. This software was categorized into the following product lines: Yolink search enhance ...


Relational databases

DataDirect provide XQJ adapters for
relational database A relational database is a (most commonly digital) database based on the relational model of data, as proposed by E. F. Codd in 1970. A system used to maintain relational databases is a relational database management system (RDBMS). Many relatio ...
s, by translating
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, bin ...
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. * Oracle DB (Not XDB) *
IBM Db2 Db2 is a family of data management products, including database servers, developed by IBM. It initially supported the relational model, but was extended to support object–relational features and non-relational structures like JSON a ...
*
Microsoft SQL Server Microsoft SQL Server is a relational database management system developed by Microsoft. As a database server, it is a software product with the primary function of storing and retrieving data as requested by other software applications—which ma ...
* Sybase ASE *
Informix IBM Informix is a product family within IBM's Information Management division that is centered on several relational database management system (RDBMS) offerings. The Informix products were originally developed by Informix Corporation, whose I ...
*
MySQL MySQL () is an open-source relational database management system (RDBMS). Its name is a combination of "My", the name of co-founder Michael Widenius's daughter My, and "SQL", the acronym for Structured Query Language. A relational database o ...
*
PostgreSQL PostgreSQL (, ), also known as Postgres, is a free and open-source relational database management system (RDBMS) emphasizing extensibility and SQL compliance. It was originally named POSTGRES, referring to its origins as a successor to the In ...


Non-database implementations

The following is a list of non-database
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, bin ...
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). * Saxon XSLT and XQuery processor * Zorba * MXQuery * Oracle XQuery Processor


License

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 ''The Open Source Definition'' is a document published by the Open Source Initiative, to determine whether a software license can be labeled with the open-source certification mark. The definition was taken from the exact text of the Debian Free ...
), 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

{{reflist


External links


Javadoc for XQJ

XQJ Tutorial

Building Bridges from Java to XQuery, Charles Foster. XML Prague 2012Prezi Presentation


* ttp://wiki.orbeon.com/forms/doc/developer-guide/processors-xquery-generator#TOC-XQuery-processor-implementations Orbeon Forms using XQJ
Spring Integration XQuery Support

XQS: XQuery for Scala (Sits on top of XQJ)

IntelliJ XQuery Support plugin
Java APIs Java specification requests XML data access Java API for XML Database APIs