cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Donald Ball <ba...@webslingerZ.com>
Subject Re: sql tag-library
Date Mon, 08 May 2000 21:49:07 GMT
On Mon, 8 May 2000, Brian P Millett wrote:

> > I had initially decided that it was silly to provide an inheritance
> > function specifically for the SQL taglib since a generic XML inheritance
> > mechanism would be more comprehensive. Unfortunately, no one has stepped
> > up to bat to write an XInclude processor for cocoon, nor does Xerces
> > support it directly, which I'd hoped would be the case sooner or later. I
> > agree, writing database connection information repeatedly is foolish; but
> > you don't want to write it once in each file, but have to write it in each
> > of your files; you want that information stored in _one_ place and _one_
> > place only. XInclude gets you that, but the SQLProcessor's inheritance
> > methods (and Brian's revisitation of them for the SQL taglib) don't.
> 
> Interesting.  You mean with the XInclude to create a new tag processor that
> say is called <pool> that handles the pool creation, etc.  Then the sql tag
> would then just be modifued to use a connection in the <sql:execute-query
> poolname="foo">??  Or do you need to explain better to me.

Even simpler. A fully qualified SQL, uh, paragraph looks like this:

<execute-query xmlns="http://www.apache.org/1999/SQL">
 <driver>org.gjt.mm.mysql.Driver</driver>
 <dburl>jdbc:mysql://localhost/test</dburl>
 <query>select * from employee_table</query>
</execute-query>

Now, driver and dburl (and probably other things as well) are likely to be
shared amongst multiple queries, both on the given page and on other
pages. So what we could do is write them in a master database.xml file:

<defs>
<database name="test" xmlns="http://www.apache.org/1999/SQL">
 <driver>org.gjt.mm.mysql.Driver</driver>
 <dburl>jdbc:mysql://localhost/test</dburl>
</database> 
</defs>

and include the appropriate section in the SQL queries like so:

<execute-query xmlns="http://www.apache.org/1999/SQL">
 <xinclude:include
  href="/protected/database.xml#xptr(/defs/database[@name='test']/*)"/>
 <query>select * from employee_table</query>
</execute-query>

Note this doesn't address connection pooling. For pooling across multiple
queries on the same page, we could simply make our taglib more
intelligent, in that it would reuse existing connections if it came across
another reference to the same database on the same page. Persisting across
multiple pages is a little trickier, but we could just add another element
to the execute-query block:

<execute-query xmlns="http://www.apache.org/1999/SQL">
 <driver>org.gjt.mm.mysql.Driver</driver>
 <dburl>jdbc:mysql://localhost/test</dburl>
 <persist>true</persist>
 <query>select * from employee_table</query>
</execute-query>

that would indicate to the taglib that the connection should be retrieved
from a pool if possible, and stored in a pool if it's not already there.
Note this addition is completely independent of the inclusion mechanism;
it would be entirely possible to pool connections that aren't included
from a central data source but are manually written in each of the various
query tags.

Comments?

- donald


Mime
View raw message