home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- Copyright 1999-2004 The Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
- <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.0//EN" "document-v10.dtd">
-
- <document>
- <header>
- <title>DatabaseReader</title>
- <version>0.9</version>
- <type>Technical document</type>
- <authors>
- <person name="Bernhard Huber" email="huber@apache.org"/>
- </authors>
- <abstract>This document describes the DatabaseReader of Cocoon.</abstract>
- </header>
- <body>
- <s1 title="DatabaseReader">
- <table>
- <tr>
- <td>NAME</td><td>databasereader</td>
- </tr>
- <tr>
- <td>WHAT</td><td>The <code>DatabaseReader</code> component is used
- to serve data from a database
- </td>
- </tr>
- <tr>
- <td>TYPE</td><td>Reader, Sitemap Component</td>
- </tr>
- <tr>
- <td>BLOCK</td><td>Database</td>
- </tr>
- <tr>
- <td>CLASS</td><td>org.apache.cocoon.reading.DatabaseReader</td>
- </tr>
- <!--tr>
- <td>DEPRECATED</td><td>Cocoon 2.0, 2.1</td>
- </tr-->
- <tr>
- <td>SINCE</td><td>Cocoon 2.1</td>
- </tr>
- <tr>
- <td>CACHEABLE</td><td>yes</td>
- </tr>
- </table>
- </s1>
- <s1 title="Description">
- <p>
- This Reader pulls a resource from a database. It is configured with
- the Connection to use, parameters specify the table and column
- to pull the image from, and source specifies the source key information.
- </p>
- </s1>
- <s1 title="Usage">
- <p>
- </p>
- <s2 title="Sitemap pipeline examples">
- <p>
- The following pipeline snippet uses a <code>Database Reader</code>
- for serving <em>PNG</em> images from a database.
- </p>
- <source><![CDATA[
- <map:match pattern="images/*.png">
- <map:read type="databasereader"
- src="{1}"
- mime-type="image/png">
- <!-- option sitemap parameters -->
- <map:parameter name="table" value="images"/>
- <map:parameter name="image" value="image"/>
- <map:parameter name="key" value="name"/>
- <map:parameter name="where" value="publishing = 1"/>
- <map:parameter name="order-by" value="created"/>
- <map:parameter name="last-modified" value="last-modified"/>
- </map:read>
- </map:match>
- ]]></source>
- <p>
- The snippet above make following assumption about the database
- </p>
- <ul>
- <li>A database table <code>images</code> holds the <em>PNG</em> image data.</li>
- <li>The database table has <code>image</code> column storing the image data as <code>BLOB</code>.
- </li>
- <li>The database table has <code>key</code> column which must match the value of
- of <code>{1}</code>.
- </li>
- <li>The database table has <code>publishing</code> column indicating by value <code>1</code>
- that the image data is allowed to get published.
- </li>
- <li>The database table has <code>created</code> column, indicating the creation date of
- the image data, and used if the <code>key</code> is not a primary key, serving
- images in a LIFO fashion.
- </li>
- <li>The database table has <code>last-modified</code> column of type <code>TIMESTAMP</code>
- indicating the last modification date of the image data.
- </li>
- </ul>
- </s2>
- <s2 title="Sitemap component configuration example">
- <p></p>
- <source><![CDATA[
- <map:readers...
- <map:reader name="databasereader"
- src="org.apache.cocoon.reading.DatabaseReader"
- logger="sitemap.reader.databasereader"
- pool-max="32" pool-min="1" pool-grow="4"/>
- <!-- optional reader configuration -->
- ...
- </map:readers>
- ...
- ]]></source>
- </s2>
- <s2 title="Configuration">
- <p>
- In the <code>Database Reader</code> declaration section following configuration
- options are available
- </p>
- <table>
- <tr><th>Configurationname</th><th>Type</th><th>Comment</th></tr>
- <tr><td>use-connection</td><td>Data source name</td>
- <td>The name of a database selector, configured in the
- <code>cocoon.xconf</code> file.
- </td>
- </tr>
- <tr><td>invalidate</td><td> never | always </td>
- <td>
- This option configures the caching behaviour if lastModifed
- has value of <code>-1</code>.
- </td>
- </tr>
- </table>
- </s2>
- <s2 title="Setup">
- <p>
- The <code>DatabaseReader</code> accepts following setup parameters
- </p>
- <table>
- <tr><th>Parametername</th><th>Type</th><th>Comment</th></tr>
- <tr><td>table</td><td>database table name</td>
- <td>The database table name</td>
- </tr>
- <tr><td>image</td><td>database column name</td>
- <td>The column name of the image data</td>
- </tr>
- <tr><td>key</td><td>database key column name</td>
- <td>The key column name of the image data matching the src attribute of
- the <map:read> sitemap usage.
- </td>
- </tr>
- <tr><td>where</td><td>database where expression</td>
- <td>Optional parameter specifying SQL where expression.</td>
- </tr>
- <tr><td>order-by</td><td>database order-by expression</td>
- <td>Optional parameter specifying an SQL order-by expression.
- </td>
- </tr>
- <tr><td>last-modified</td><td>timestamp column name</td>
- <td>Optional parameter a <code>TIMESTAMP</code> column name, added
- to the <code>SELECT</code> clause of the SQL query.
- </td>
- </tr>
- <tr><td>content-type</td><td>database column name</td>
- <td>Optional parameter a column name, if specified the column
- value overrides the <code>mime-type</code> attribute of the
- <map:read> sitemap usage.
- </td>
- </tr>
- </table>
- <p>
- The key value is derived from the <code>src</code> attribute
- of the <code>Database Reader</code> usage..
- </p>
- <p>
- The <code>Database Reader</code> builds internally following SQL query:
- </p>
- <source><![CDATA[
- SELECT {image} [, last-modified] [, {order-by-column} ] from {table}
- WHERE {key} = {src} [ AND {where} ]
- [ORDER BY {order-by}]
- ]]></source>
- </s2>
- <s2 title="Effect on Object Model and Sitemap Parameters">
- <p>
- </p>
- </s2>
- </s1>
- <s1 title="Bugs/Caveats">
- <p>
- The <code>Database Reader</code> needs a datasource name, it is referenced
- by the configuration element <code>use-connection</code>. The datasource name
- has to be configured in the Cocoon database configuration <code>cocoon.xconf</code>.
- </p>
- <p>
- If the parameter <code>last-modified</code> ends with <code>" DESC"</code> this
- suffix is truncated as it is appended to the SQL clause, noted as {order-by-column}
- in the SQL query snippet above.
- </p>
- </s1>
- <s1 title="History">
- <p>
- 12-25-02: created initial version by Bernhard Huber
- </p>
- </s1>
- <s1 title="See also">
- <p>
- <!-- Links to related components pages -->
- </p>
- </s1>
- </body>
- </document>
-
-