org.apache.cocoon.reading
Class DatabaseReader

java.lang.Object
  |
  +--org.apache.avalon.framework.logger.AbstractLoggable
        |
        +--org.apache.cocoon.reading.AbstractReader
              |
              +--org.apache.cocoon.reading.DatabaseReader
All Implemented Interfaces:
Cacheable, org.apache.avalon.framework.component.Component, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.logger.Loggable, org.apache.avalon.excalibur.pool.Poolable, Reader, org.apache.avalon.excalibur.pool.Recyclable, SitemapModelComponent, SitemapOutputComponent

public class DatabaseReader
extends AbstractReader
implements org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Disposable, Cacheable, org.apache.avalon.excalibur.pool.Poolable

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.

Version:
CVS $Id: DatabaseReader.java,v 1.8 2002/02/22 07:03:54 cziegeler Exp $
Author:
Berin Loritsch

Fields inherited from class org.apache.cocoon.reading.AbstractReader
objectModel, out, parameters, resolver, source
 
Fields inherited from interface org.apache.cocoon.reading.Reader
ROLE
 
Constructor Summary
DatabaseReader()
           
 
Method Summary
 void compose(org.apache.avalon.framework.component.ComponentManager manager)
          Compose the object so that we get the Components we need from the ComponentManager.
 void configure(org.apache.avalon.framework.configuration.Configuration conf)
          Configure the Reader so that we can use the same database for all instances.
 void dispose()
          dispose()
 void generate()
          Generates the resource we need to retrieve verbatim from the database.
 long generateKey()
          Generate the unique key.
 CacheValidity generateValidity()
          Generate the validity object.
 java.lang.String getMimeType()
          Get the mime-type of the output of this Serializer This default implementation returns null to indicate that the mime-type specified in the sitemap is to be used
 java.lang.String getQuery()
          This method builds the query string used for accessing the database.
 boolean modifiedSince(java.sql.ResultSet set, Request request, Response response)
          Tests whether a resource has been modified or not.
 void recycle()
          Recycle the component
 void serialize(Response response)
          This method actually performs the serialization.
 void setup(SourceResolver resolver, java.util.Map objectModel, java.lang.String src, org.apache.avalon.framework.parameters.Parameters par)
          Set the SourceResolver the object model Map, the source and sitemap Parameters used to process the request.
 
Methods inherited from class org.apache.cocoon.reading.AbstractReader
getLastModified, setOutputStream, shouldSetContentLength
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLoggable
getLogger, setLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseReader

public DatabaseReader()
Method Detail

compose

public void compose(org.apache.avalon.framework.component.ComponentManager manager)
             throws org.apache.avalon.framework.component.ComponentException
Compose the object so that we get the Components we need from the ComponentManager.
Specified by:
compose in interface org.apache.avalon.framework.component.Composable

configure

public void configure(org.apache.avalon.framework.configuration.Configuration conf)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Configure the Reader so that we can use the same database for all instances.
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable

setup

public void setup(SourceResolver resolver,
                  java.util.Map objectModel,
                  java.lang.String src,
                  org.apache.avalon.framework.parameters.Parameters par)
           throws ProcessingException,
                  org.xml.sax.SAXException,
                  java.io.IOException
Set the SourceResolver the object model Map, the source and sitemap Parameters used to process the request.
Overrides:
setup in class AbstractReader

generate

public void generate()
              throws ProcessingException,
                     org.xml.sax.SAXException,
                     java.io.IOException
Generates the resource we need to retrieve verbatim from the database. Granted, this can be used for any resource from a database, so we may want to get rid of the bias toward images. This reader requires a number of parameters:
   <parameter name="table" value="database_table_name"/>
   <parameter name="image" value="database_resource_column_name"/>
   <parameter name="key" value="database_lookup_key_column_name"/>
 
Please note that if any of those parameters are missing, this Reader cannot function. There are a number of other parameters that allow you to provide hints for the reader to optimize resource use:
   <parameter name="last-modified" value="database_timestamp_column_name"/>
   <parameter name="content-type" value="content_mime_type"/>
   <parameter name="expires" value="number_of_millis_before_refresh"/>
   <parameter name="where" value="alternate_key = 'foo'"/>
   <parameter name="order-by" value="alternate_key DESC"/>
 
Lastly, the key value is derived from the value of the source string.

getQuery

public java.lang.String getQuery()
                          throws java.lang.Exception
This method builds the query string used for accessing the database. If the required parameters do not exist, then we cannot build a correct query.

modifiedSince

public boolean modifiedSince(java.sql.ResultSet set,
                             Request request,
                             Response response)
                      throws java.sql.SQLException
Tests whether a resource has been modified or not. As Blobs and database columns usually do not have intrinsic dates on them (at least easily accessible), we have to have a database column that holds a date for the resource. Please note, that the database column must be a Timestamp column. In the absence of such a column this method always returns true. This is because databases are much more prone to change than filesystems, and don't have intrinsic timestamps on column updates.

serialize

public void serialize(Response response)
               throws java.io.IOException,
                      java.sql.SQLException
This method actually performs the serialization.

generateKey

public long generateKey()
Generate the unique key. This key must be unique inside the space of this component.
Specified by:
generateKey in interface Cacheable
Returns:
The generated key hashes the src

generateValidity

public CacheValidity generateValidity()
Generate the validity object.
Specified by:
generateValidity in interface Cacheable
Returns:
The generated validity object or null if the component is currently not cacheable.

recycle

public void recycle()
Description copied from class: AbstractReader
Recycle the component
Overrides:
recycle in class AbstractReader

dispose

public void dispose()
dispose()
Specified by:
dispose in interface org.apache.avalon.framework.activity.Disposable

getMimeType

public java.lang.String getMimeType()
Description copied from class: AbstractReader
Get the mime-type of the output of this Serializer This default implementation returns null to indicate that the mime-type specified in the sitemap is to be used
Overrides:
getMimeType in class AbstractReader


Copyright � 1999-2002 Apache Software Foundation. All Rights Reserved.