If you're interested in functional programming, you might also want to checkout my second blog which i'm actively working on!!

Wednesday, July 6, 2011

Unit testing XQJ and Saxon

I have to admit that it took me quite a bit of time to get this unit test working. All these namespaces don't make life easier. But let met explain what is going on in the code snippets below. First I wrote a little module which has 1 function that returns the groupId as a string. Luckily saxon did support the "at" hint for importing modules. But it took me quite some time to understand what the base-uri was used by saxon. Default it seems to be "" but it somehow knows how to resolve it to 'file:///c:/development/workspaces/cocoon3/cocoon-xmldb/'.



module containing 1 function that extracts groupId from pom


pom_module.xquery which imports pom.xqlib module and outputs groupId



Tuesday, July 5, 2011

Unit testing XQJGenerator

My first unit tests would only work if I had an xmldb up and running. That was not really convenient. So I looked around for a XQJ implementation that I could use from my unit tests. Saxon9-HE came to the rescue.

I added following dependency to my pom.xml after installing the jar in my local maven repo




test-application-context.xml:


xquery for unit-test: splitting a sentence into words



xquery for unit-test: retrieving all ASF members from pom.xml


unit-test: transform a plain string of words into xml output


unit-test: return the names of all ASF-members of pom.xml

Using XQJ API with Cocoon3

As my research pointed out XMLDB was a bit painfull to use as most xmldb implementations had quite specific API's to accomplish the same result. I instead turned my focus to the newer XQJ API which offers a JDBC alike approach to using XQuery.

Today I wrote a first draft version of an XQJGenerator accompanied from 2 basic unit tests. Although you have to be carefull that not all XQueries can be ported from XMLDB API to XQJ i managed to get the results extracted the way I wanted to.

XQJGenerator.java


XQJGeneratorTest.java


xquery1.xquery


demoboards1.xquery


test-application-context.xml


xquery1.xquery output


demoboards1.xquery output

Friday, July 1, 2011

Comparing usage of XMLDB Services

As I want to be able to use all XMLDB API services from within Cocoon a first task is comparing in what aspect usage differs accross 'Service' and 'XMLDB'.

Any good observer can see that it's possible to abstract this a bit further:

Using XpathQueryService with BaseX:




Using XQueryService with Sedna:

Cocoon 3.0 and XML DB API

Yesterday evening i checked out the latest sources from Cocoon3.0 and started diving into the source code to get a feeling of how things work in this new version. As Jeroen Reijn already pointed out in this article it only takes you half an hour to be up and running building your own custom pipeline.

The company where i'm currently working at recently started using an XML DB (instead of storing files on a filesystem) based upon my advice. We already were using a custom XQueryGenerator for Cocoon2.2 but as a little exercise I quickly hacked some code together based upon Cocoon3. The actual code of the XQueryGenerator is not yet worthy to be shared but I just wanted to share the results of 2 little unit tests.



demoboard module:


demoboards1.xquery:


demoboards2.xquery:


Both Xqueries should return the same result which they do.