fr.gouv.culture.sdx.repository
Class JDBCRepository

java.lang.Object
  extended byfr.gouv.culture.sdx.utils.SdxObjectImpl
      extended byfr.gouv.culture.sdx.utils.rdbms.JDBC
          extended byfr.gouv.culture.sdx.utils.rdbms.DataSourceComponentBacked
              extended byfr.gouv.culture.sdx.repository.AbstractDataSourceComponentBackedRepository
                  extended byfr.gouv.culture.sdx.repository.JDBCRepository
All Implemented Interfaces:
org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.logger.LogEnabled, Repository, SdxObject
Direct Known Subclasses:
HSQLRepository, MSSQLRepository, MYSQLRepository, POSTGRESQLRepository

public class JDBCRepository
extends AbstractDataSourceComponentBackedRepository

An implementation of a repository using a JDBC datasource.

This repository can be used by itself, or be subclassed for specific RDBMS. A great care has been taken to isolate what could be vendor specific.


Nested Class Summary
 
Nested classes inherited from class fr.gouv.culture.sdx.utils.rdbms.JDBC
JDBC.QueryExecutor, JDBC.Template
 
Field Summary
protected static java.lang.String FIELD_DATA
          Constant for a field name in a table
static int NO_SPECIFIC_TYPE
           
protected  int PARAM_INDEX_FIELD_DATA_ORIGINAL
           
 
Fields inherited from class fr.gouv.culture.sdx.repository.AbstractDataSourceComponentBackedRepository
FIELD_ID, isDefault, PARAM_INDEX_FIELD_ID, props
 
Fields inherited from class fr.gouv.culture.sdx.utils.rdbms.DataSourceComponentBacked
ATTRIBUTE_DSI, dbSelector, dsi, manager
 
Fields inherited from class fr.gouv.culture.sdx.utils.rdbms.JDBC
id, tableName
 
Fields inherited from class fr.gouv.culture.sdx.utils.SdxObjectImpl
encoding, logger
 
Fields inherited from interface fr.gouv.culture.sdx.repository.Repository
ATTRIBUTE_DEFAULT, ATTRIBUTE_ID, ATTRIBUTE_REF, ATTRIBUTE_TYPE, CLASS_NAME_SUFFIX, ELEMENT_NAME_REPOSITORIES, ELEMENT_NAME_REPOSITORY, PACKAGE_QUALNAME
 
Constructor Summary
JDBCRepository()
          Creates a repository.
 
Method Summary
 void add(Document doc, RepositoryConnection c)
          Adds a document to the repository.
 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 configuration)
          Configures this repository.
 void delete(Document doc, RepositoryConnection c)
          Deletes a document from the repository.
 void empty()
          Deletes all documents from the repository.
 void get(Document doc, java.io.OutputStream os, RepositoryConnection c)
          Writes the content of a document to an output stream.
 RepositoryConnection getConnection()
          Gets a connection for manipulating repository's content.
protected  java.lang.String getDeleteAllQuery()
          Returns an SQL query that could delete all documents.
protected  java.lang.String getDocumentAddQuery()
          Returns an SQL query that could add a document.
protected  java.lang.String getDocumentDeleteQuery()
          Returns an SQL query that could delete a document.
protected  java.lang.String getTableCreationQuery()
          Returns an SQL query that could create the table.
 void init()
          Initializes the repository.
 void lists(org.xml.sax.ContentHandler hdl)
          Lists the repository content as SAX events.
 java.io.InputStream openStream(Document doc, java.lang.String encoding, RepositoryConnection c)
          Opens an input stream to read the content of a document.
 void releaseConnection(RepositoryConnection c)
          Releases a previously opened connection.
 long size()
          Returns the number of documents within the repository (all kind of documents).
 void toSAX(ParsableDocument doc, org.apache.cocoon.xml.XMLConsumer consumer, RepositoryConnection c)
          Retrieves an SDX document as SAX events.
 
Methods inherited from class fr.gouv.culture.sdx.repository.AbstractDataSourceComponentBackedRepository
checkConnection, checkEncoding, exists, getDocumentGetQuery, getId, isDefault, loadBaseConfiguration, optimize, setIsDefault, setProperties
 
Methods inherited from class fr.gouv.culture.sdx.utils.rdbms.DataSourceComponentBacked
getDataSourceComponent, releaseDataSourceComponent
 
Methods inherited from class fr.gouv.culture.sdx.utils.rdbms.JDBC
createTable, getTableName, handleUnsupportedTokens
 
Methods inherited from class fr.gouv.culture.sdx.utils.SdxObjectImpl
enableLogging, getChildLogger, setEncoding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.avalon.framework.logger.LogEnabled
enableLogging
 

Field Detail

NO_SPECIFIC_TYPE

public static final int NO_SPECIFIC_TYPE
See Also:
Constant Field Values

FIELD_DATA

protected static final java.lang.String FIELD_DATA
Constant for a field name in a table

See Also:
Constant Field Values

PARAM_INDEX_FIELD_DATA_ORIGINAL

protected final int PARAM_INDEX_FIELD_DATA_ORIGINAL
See Also:
Constant Field Values
Constructor Detail

JDBCRepository

public JDBCRepository()
Creates a repository.

A logger must be set and then this repository must be configured and initialized.

See Also:
SdxObjectImpl.enableLogging(org.apache.avalon.framework.logger.Logger), configure(org.apache.avalon.framework.configuration.Configuration), init()
Method Detail

getConnection

public RepositoryConnection getConnection()
                                   throws SDXException
Gets a connection for manipulating repository's content.

Returns:
The connection.
Throws:
SDXException

releaseConnection

public void releaseConnection(RepositoryConnection c)
                       throws SDXException
Releases a previously opened connection. The releases both the SQL connection to the database and the datasource component connection from cocoon's database selector component.

Parameters:
c - A connection.
Throws:
SDXException

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
Overrides:
compose in class DataSourceComponentBacked
Parameters:
manager - The component manager from Cocoon that allow us to acquire a database selector component.
Throws:
org.apache.avalon.framework.component.ComponentException

configure

public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Configures this repository.

In addition to the parameters needed in the base configuration handled by the parent class, the following parameter is required: data source identifier (dsi), the value of the "name" attribute of the "jdbc" subElement for the "datasources" element in cocoon.xconf (user must create this information in cocoon.xconf)

Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Overrides:
configure in class AbstractDataSourceComponentBackedRepository
Parameters:
configuration - The configuration for this repository (based on a xml file).

Sample configuration entry:

<sdx:repository sdx:type = "JDBC" sdx:id = "myRepoId" dsi = "datasource identifier from cocoon.xconf"/>

Throws:
org.apache.avalon.framework.configuration.ConfigurationException

init

public void init()
          throws SDXException
Initializes the repository. If there are no tables in the database, we create the necessary table

Throws:
SDXException

size

public long size()
          throws SDXException
Returns the number of documents within the repository (all kind of documents). NOT IMPLEMENTED YET!

Returns:
The number.
Throws:
SDXException

lists

public void lists(org.xml.sax.ContentHandler hdl)
           throws SDXException
Lists the repository content as SAX events.

The exact structure is still to be defined, but it should be very simple, with only one element per document and a few properties as attributes.

Parameters:
hdl - A SAX content handler to feed with events.
Throws:
SDXException

add

public void add(Document doc,
                RepositoryConnection c)
         throws SDXException
Adds a document to the repository.

Specified by:
add in interface Repository
Overrides:
add in class AbstractDataSourceComponentBackedRepository
Parameters:
doc - A document.
c - A connection to the repository.
Throws:
SDXException

empty

public void empty()
           throws SDXException
Deletes all documents from the repository.

Throws:
SDXException

delete

public void delete(Document doc,
                   RepositoryConnection c)
            throws SDXException
Deletes a document from the repository.

Specified by:
delete in interface Repository
Overrides:
delete in class AbstractDataSourceComponentBackedRepository
Parameters:
doc - A document.
c - A connection to the repository.
Throws:
SDXException

toSAX

public void toSAX(ParsableDocument doc,
                  org.apache.cocoon.xml.XMLConsumer consumer,
                  RepositoryConnection c)
           throws SDXException
Retrieves an SDX document as SAX events.

Specified by:
toSAX in interface Repository
Overrides:
toSAX in class AbstractDataSourceComponentBackedRepository
Parameters:
doc - A ParsableDocument, ie XMLDocument or HTMLDocument.
consumer - A SAX content handler to feed with events.

The wrapped contentHandler for including events within an XSP page contentHandler should be created using IncludeXMLConsumer stripper = new IncludeXMLConsumer(xspContentHandler);

c - A connection to the repository.
Throws:
SDXException

openStream

public java.io.InputStream openStream(Document doc,
                                      java.lang.String encoding,
                                      RepositoryConnection c)
                               throws SDXException
Opens an input stream to read the content of a document.

Specified by:
openStream in interface Repository
Overrides:
openStream in class AbstractDataSourceComponentBackedRepository
Parameters:
encoding - An encoding (may be null).

If null or invalid we use a default.

TODOImplement use of encoding currently not implemented , will do soon.

doc - A document to read.
c - A connection to the repository.
Returns:
The stream.
Throws:
SDXException

get

public void get(Document doc,
                java.io.OutputStream os,
                RepositoryConnection c)
         throws SDXException
Writes the content of a document to an output stream.

Specified by:
get in interface Repository
Overrides:
get in class AbstractDataSourceComponentBackedRepository
Parameters:
doc - A document.
os - An output stream.
c - A connection to the repository.
Throws:
SDXException

getTableCreationQuery

protected java.lang.String getTableCreationQuery()
Returns an SQL query that could create the table.

This query should not have any parameter.

Specified by:
getTableCreationQuery in class JDBC
Returns:
The query.

getDocumentAddQuery

protected java.lang.String getDocumentAddQuery()
Returns an SQL query that could add a document.

This query should have three parameters, the first for the id, the second for the doctype and the third for the data.

Returns:
The query.

getDocumentDeleteQuery

protected java.lang.String getDocumentDeleteQuery()
Returns an SQL query that could delete a document.

This query should have one parameter for the document's id.

Returns:
The query.

getDeleteAllQuery

protected java.lang.String getDeleteAllQuery()
Returns an SQL query that could delete all documents.

This query should not have any parameter.

Returns:
The query.


Copyright © 2000-2004 Ministere de la culture et de la communication / AJLSM. All Rights Reserved.