xmlxsltjndisaxonsmooks

How to access database connection from JNDI and is there XA transaction support using saxonica(Saxon) sql extension?


I am using Saxon 9.5 EE and following the official documentation where examples for using saxon sql is given. In that to connect to db following snippet is mentioned

<xsl:stylesheet
xmlns:sql="http://saxon.sf.net/sql"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:saxon="http://saxon.sf.net/"
extension-element-prefixes="saxon sql">

<!-- insert your database details here, or supply them in parameters -->
<xsl:param name="driver" select="'sun.jdbc.odbc.JdbcOdbcDriver'"/>
<xsl:param name="database" select="'jdbc:odbc:test'"/>  
<xsl:param name="user"/>
<xsl:param name="password"/>

but i don't want to mention IP, url password here and I want to use existing connection pool from jndi datasource. I also want to know if this all database activity can be made a part of XA transaction.

This way I am not able to achieve desired performance. Alternate to this I have tried using smooks and FTL using jndi datasource which is 3-4 times faster but I loose xslt advanced capabilities and large community.

If anyone has done something similar please help.


Solution

  • The SQL extension for Saxon was largely user-contributed code, it's open source and you are welcome to extend it or use it as a starting point for something more ambitious.

    But you may not need to: for example you can certainly pass in a JDBC connection as a parameter to the stylesheet (wrapped as an ExternalObject) rather than getting the connection using Saxon's sql:connect.

    If I were doing the SQL extension today I don't think I would use extension elements, I would do it all with functions. That's easier than it used to be because we now have maps and higher-order functions so one can design more complex parameter and result structures. For example, I would have sql:query() return an array of maps, each representing one row of the result.