InfoQ

News

XQuery Java API JSR 225 Available for Public Review

Posted by Abhay Bakshi on Jul 03, 2007

Community
Java
Topics
Data Access
Tags
XQuery
The first public review draft of JSR 225: XQuery API for Java has been posted for review.  The spec (being led by Oracle) aims to provide standard programmatic access for XQuery implementations in Java.  XQJ is a generic XQuery data access framework, which provides a uniform interface on top of a variety of different XQuery implementations.

The W3C XQuery is a query language for XML. Wikipedia defines it's function as providing the means to extract and manipulate data from XML documents or any data source that can be viewed as XML, such as relational databases or office documents.XQuery uses XPath expression syntax to address specific parts of an XML document. One of the language syntax requirements for XQuery is that the Query language MUST be convenient for humans to read and write. The XQuery language now has both a human-readable syntax and an XML-based syntax. The XML-based syntax for XQuery is available at XQueryX 1.0.

A basic XQJ expression in Java looks like (from the spec):
...
// establish a connection to the XQuery engine
XQConnection conn = xqds.getConnection();

// create an expression object that is later used
// to execute an XQuery expression
XQExpression expr = conn.createExpression();

// the XQuery expression to be executed
String es = "for $n in fn:doc('catalog.xml')//item " +
"return fn:data($n/name)";

// execute the XQuery expression
XQResultSequence result = expr.executeQuery(es);

// process the result (sequence) iteratively
while (result.next()) {
// retrieve the current item of the sequence as a String
String str = result.getAtomicValue();
System.out.println("Product name: " + str);
}

// free all resources allocated for the result
result.close();

// free all resources allocated for the expression
expr.close();

// free all resources allocated for the connection
conn.close();
...
While the XQJ spec has been led by Jim Melton (Oracle), its JCP expert group involves members including Jason Hunter, DataDirect , BEA Systems et al. Industry leaders outside of JCP have also been following the XQJ specification, contributing ideas, and improving their own products for conformity. Michael Kay - creator of Saxon and author of XPath 2.0 Programmer's Reference - writes:
It's the first new version for about a year, and the spec is developed under conditions of absolute secrecy, so I was interested to see what was going to be in it. I wasn't expecting too much, because most of my comments on the previous draft had been politely rejected (about 8 months after I submitted them, with no open discussion). Sure enough, they've tidied up quite a lot of little things, but the overall design hasn't changed much. (It's sufficiently incompatible, however, that most applications will have to be tweaked: not rewritten, but amended here and there.)
It's still uncompromisingly based on a client-server, connection-oriented model where the application lives on a different machine from the database (so 1980s!). ... prepared expressions are not thread-safe - you can't compile an expression and then run it in multiple threads simultaneously, because the XQPreparedExpression holds its own dynamic execution context.
Are there any good points? Yes, quite a few. The mapping of XPath values (the 19 primitive data types) to equivalent objects in Java is done reasonably well - much better than JAXP ... This version also has a full representation in Java terms of all XPath types ...
Still, I think one can do better. ...
The W3C XQuery specification and 8 related specifications (including XSLT 2.0 and XPath 2.0) were submitted to the W3C on June 8 2006. Many of them were updated on 23 January 2007. The industry has already begun embracing XQuery in their products, even JSR 170/Java Content Repositories use it as their standard query mechanism. InfoQ has been tracking development of XQuery specification, XQJ specification, and the implementations.
article by Tomek Górski Posted Oct 13, 2007 5:48 AM
Article by Andrew News Posted Feb 3, 2008 10:39 AM
  1. Back to top

    article

    Oct 13, 2007 5:48 AM by Tomek Górski

    Thanks for another very interesting article. Keep up the good work. Regards
    Pozycjonowanie Tom

  2. Back to top

    Article

    Feb 3, 2008 10:39 AM by Andrew News

    Interesting Article, thank you for sharing your thoughts.

Educational Content

Brian Marick on 4 Challenges and 5 Guiding Values of Agile Software Development

Brian Marick takes us through a quick tour of the most important values and challenges to adopting Agile successfully (they aren't the typical challenges and values we hear in the community).

Are You a Software Architect?

The line between development and architecture is tricky. Does it exist at all? Is an ivory tower actually needed? There's a balance in the middle, but how do you move from developer to architect?

Agile – A Way of Life and Pragmatic Use of Authority

The word 'authority' sometimes produces an allergic response in hard-line agilists. Freedom and authority – both are bad if misused and both are good if used in right spirit for a noble cause.

Getting Started with Grails, Second Edition

"Getting Started with Grails" brings you up to speed on this modern web framework. Companies as varied as LinkedIn, Wired, and Taco Bell are all using Grails. Are you ready to get started as well?

Using ITIL V3 as a Foundation for SOA Governance

Those familiar with only ITIL V2 often scoff at the thought that ITIL could serve as a governance framework for SOA. With ITIL V3, the focus of the framework shifted towards service-orientation.

Adrian Colyer on AspectJ, tc Server and dm Server

SpringSource CTO Adrian Colyer discusses AspectJ, SpringSource's dm Server and tc Server products, OSGi and Scrum.

Adam Wiggins on Heroku

Heroku's Adam Wiggins talks about Rails, Background Jobs, Add-Ons, Ruby, and how Heroku manages to work around Ruby's inefficiencies using Erlang and other languages.

SOA as an Architectural Pattern: Best Practices in Software Architecture

For Grady Booch the foundation of a good architecture is patterns, SOA being just one of many patterns. In this Second Life presentation, Booch attempts to bring more clarity on what architecture is.