cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ricardo Rocha <rica...@apache.org>
Subject Re: sql tag-library
Date Mon, 08 May 2000 13:16:11 GMT
On Mon, 08 May 2000, MIchele Bianchi wrote:
> i'm wondering about 2 ideas on the sql tag-library.  the first to specify the
> driver name in the config file (or smth like that) so it could be really easy
> to change the dbms.  the second one to have a choice specify a dbconnection
> or the dburl.  the db connection it's a really expensive operation it seems
> imho to create a global var and reuse it.  please tell me if it is stupid, cos
> i'm new in servlet programming.

During an improvised "Intro to XSP" course held in the tropical jungles of
Colombia (South America), we came up with an example logicsheet that
uses externally defined, named connection pools.

Note: while useful right out of the box, this logicsheet is meant to be just
an example of logicsheet authoring principles. Translated: it still requires
some polishing, :-)

This logicsheet allows you to execute any arbritrary SQL statement against
a named connection pool:

  <!-- Get KING's data. 'myEmp' is mapped to a Hashtable -->
  <xsql:select-into name="myEmp" use-connection="scott">
    <xsql:statement>
      SELECT * FROM emp WHERE ename = 'KING'
    </xsql:statement>
  </xsql:select-into>

  <!-- List all employees working with KING -->
  <xsql:execute-query id="coworkers" use-connection="scott">
    <xsql:statement>
      SELECT *
      FROM emp
      WHERE deptno = <xsql:get-column from="myEmp" name="deptno"/>
    </xsql:statement>
   </xsl:execute-query>

  <!-- Raise salaries for KING's colleagues -->
  </xsql:execute-update use-connection="scott">
    <xsql:statement>
      UPDATE emp
      SET        sal = sal * 1.1
      WHERE   job = '<xsql:get-column from="myEmp" name="deptno"/>'
    </xsql:statement>
  </xsql:execute-update>

This logicsheet simply wraps calls to static methods in a "library class"
(XSQL.java) which is, in turn, based on Gefion Software's
DBConnectionManager.

A simple live demo can be checked at:

    http://www.plenix.com/xsp/logicsheets/emp.xml

This page contains a link to a zip file containing the source code and
an Oracle-based example which can be easily "ported" to other
RDBMS's.

Mime
View raw message