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

Friday, September 2, 2011

Quartz Jobscheduler dashboard

I have a little project running at my customers site which basically is nothing more then a bunch of CRON jobs deployed as a Webapplication. As 1 Cron job seemed to fail from time to time I wanted to get some more insight into what triggers are defined, a way to pause or resume those triggers and check which jobs are currently running.

Here are some screenshots of my first prototype dashboard:









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.

Tuesday, June 28, 2011

Finished some restyling of this blog

Ok.. I just received news of Google's +1 button which is kinda cool to get noticed so I decided to hack it in. Because i again played around with the template designer of my blog my previous customizations got lost. Nothing to worry really, only SyntaxHighLighter was not working anymore and my code snippets magically vanished. So I decided to switch to using the latest and greatest version of SyntaxHighLighter and use the autoloader which was a new feature. I also am using the hosted version of the css and js files which is easier.

One side note: I had to make sure syntaxhighlighter got bootstrapped only after the dom was loaded. So I used YUI3's onDomReady event to call a bootstrapSyntaxHighLighter function i wrote.

Tuesday, June 14, 2011

Mimicking the Switch Expression in XQuery1.0

Here follows a little trick I picked up. Sometimes you want just like in many other programming languages to handle several use cases depending on a switch expression. This is not possible for XQuery1.0 by default but that does not mean you can't mimic it using the typeswitch expression ;-)



Output:

Complex Grouping with Xquery ...the general pattern

Testdata:


The idea is that we group all items so we get combinations of chapter with resp. paragraphs. However, some paragraphs don't have a parent (chapter). In this case those paragraphs should be handled first.


Expected output:


Well, here is kind of a generic solution (read solution pattern). You need 1 function that extracts the groupingkey from an item. The getGroupingKeys function just takes the distinct values of all grouping keys. So when you have the groupingkeys, you can determine the items belonging to each group using this predicate [local:getGroupingKey(.) = $grouping_key]. Next you handle the items for each group the way you want.

Generic Join function (XSLT/ Xquery)

In case you need a very high level join function for a sequence of items, I just wrote one which works very nicely.