fr.gouv.culture.sdx.repository
Class JDBCRepository

java.lang.Object
  extended by fr.gouv.culture.sdx.utils.AbstractSdxObject
      extended by fr.gouv.culture.sdx.utils.rdbms.JDBC
          extended by fr.gouv.culture.sdx.utils.rdbms.DataSourceComponentBacked
              extended by fr.gouv.culture.sdx.repository.AbstractDataSourceComponentBackedRepository
                  extended by fr.gouv.culture.sdx.repository.JDBCRepository
All Implemented Interfaces:
Repository, Describable, Encodable, Identifiable, Localizable, Saveable, SdxObject, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.logger.LogEnabled, org.apache.avalon.framework.service.Serviceable, org.apache.excalibur.xml.sax.XMLizable
Direct Known Subclasses:
HSQLRepository, MSSQLRepository, MYSQLRepository, ORACLERepository, 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/interfaces inherited from class fr.gouv.culture.sdx.utils.rdbms.JDBC
JDBC.QueryExecutor, JDBC.Template
 
Nested classes/interfaces inherited from interface fr.gouv.culture.sdx.repository.Repository
Repository.ConfigurationNode
 
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
 
Fields inherited from class fr.gouv.culture.sdx.utils.rdbms.DataSourceComponentBacked
ATTRIBUTE_DSI, dbSelector, dsi
 
Fields inherited from class fr.gouv.culture.sdx.utils.rdbms.JDBC
tableName
 
Fields inherited from class fr.gouv.culture.sdx.utils.AbstractSdxObject
_configuration, _context, _description, _encoding, _id, _locale, _logger, _manager, _xmlizable_objects, _xmlLang, isToSaxInitialized
 
Fields inherited from interface fr.gouv.culture.sdx.repository.Repository
CLASS_NAME_SUFFIX, PACKAGE_QUALNAME
 
Fields inherited from interface fr.gouv.culture.sdx.utils.Encodable
DEFAULT_ENCODING
 
Fields inherited from interface fr.gouv.culture.sdx.utils.save.Saveable
ALL_SAVE_ATTRIB, PATH_ATTRIB, SAVE_DIRECTORY_PARAM
 
Constructor Summary
JDBCRepository()
          Creates a repository.
 
Method Summary
 void add(Document doc, RepositoryConnection c)
          Adds a document to the repository.
 void backup(SaveParameters save_config)
          Save the repository
 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 getEntriesWithLimitQuery(long offset, long number)
          Implementation of statement with a limit parameter No limit there, implementation is done in the subclasses.
protected  java.lang.String getTableCreationQuery()
          Returns an SQL query that could create the table.
 void init()
          Initializes the repository.
protected  boolean initToSax()
          Init the LinkedHashMap _xmlizable_objects with the objects in order to describ them in XML
protected  void initVolatileObjectsToSax()
          Init the LinkedHashMap _xmlizable_volatile_objects with the objects in order to describ them in XML Some objects need to be refresh each time a toSAX is called
 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.
 void restore(SaveParameters save_config)
          Restore the repository
 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, getClassNameSuffix, getDocumentGetQuery, isDefault, loadBaseConfiguration, optimize, setIsDefault
 
Methods inherited from class fr.gouv.culture.sdx.utils.rdbms.DataSourceComponentBacked
finalize, getDataSourceComponent, releaseDataSourceComponent, service
 
Methods inherited from class fr.gouv.culture.sdx.utils.rdbms.JDBC
createTable, getTableName, handleUnsupportedTokens
 
Methods inherited from class fr.gouv.culture.sdx.utils.AbstractSdxObject
configureDescription, contextualize, enableLogging, getBaseAttributes, getConfiguration, getContext, getDescription, getEncoding, getId, getLocale, getLog, getServiceManager, getXmlLang, setDescription, setEncoding, setId, setLocale, setUpSdxObject, setUpSdxObject, setXmlLang, toSAX, verifyConfigurationResources
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface fr.gouv.culture.sdx.utils.SdxObject
getLog
 
Methods inherited from interface org.apache.avalon.framework.logger.LogEnabled
enableLogging
 
Methods inherited from interface org.apache.avalon.framework.context.Contextualizable
contextualize
 
Methods inherited from interface org.apache.avalon.framework.service.Serviceable
service
 
Methods inherited from interface fr.gouv.culture.sdx.utils.Identifiable
getId, setId
 
Methods inherited from interface fr.gouv.culture.sdx.utils.Describable
getDescription, setDescription
 
Methods inherited from interface fr.gouv.culture.sdx.utils.Encodable
getEncoding, setEncoding
 
Methods inherited from interface fr.gouv.culture.sdx.utils.Localizable
getLocale, getXmlLang, setLocale, setXmlLang
 
Methods inherited from interface org.apache.excalibur.xml.sax.XMLizable
toSAX
 

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 super.getLog() must be set and then this repository must be configured and initialized.

See Also:
AbstractSdxObject.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 service connection from cocoon's database selector service.

Parameters:
c - A connection.
Throws:
SDXException

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 DataSourceComponentBacked
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.

getEntriesWithLimitQuery

protected java.lang.String getEntriesWithLimitQuery(long offset,
                                                    long number)
Implementation of statement with a limit parameter No limit there, implementation is done in the subclasses.

Parameters:
offset -
number -
Returns:
the query

initToSax

protected boolean initToSax()
Description copied from class: AbstractSdxObject
Init the LinkedHashMap _xmlizable_objects with the objects in order to describ them in XML

Specified by:
initToSax in class AbstractSdxObject

initVolatileObjectsToSax

protected void initVolatileObjectsToSax()
Init the LinkedHashMap _xmlizable_volatile_objects with the objects in order to describ them in XML Some objects need to be refresh each time a toSAX is called

Overrides:
initVolatileObjectsToSax in class JDBC

backup

public void backup(SaveParameters save_config)
            throws SDXException
Save the repository

Throws:
SDXException
See Also:
Saveable.backup(fr.gouv.culture.sdx.utils.save.SaveParameters)

restore

public void restore(SaveParameters save_config)
             throws SDXException
Restore the repository

Throws:
SDXException
See Also:
Saveable.restore(fr.gouv.culture.sdx.utils.save.SaveParameters)


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