public class JDBCRepository extends AbstractDataSourceComponentBackedRepository
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.
JDBC.QueryExecutor, JDBC.Template
Repository.ConfigurationNode
Modifier and Type | Field and Description |
---|---|
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 |
FIELD_ID, isDefault, PARAM_INDEX_FIELD_ID
ATTRIBUTE_DSI, dbSelector, dsi
_configuration, _context, _description, _encoding, _id, _locale, _logger, _manager, _xmlizable_objects, _xmlLang, isToSaxInitialized
CLASS_NAME_SUFFIX, PACKAGE_QUALNAME
DEFAULT_ENCODING
ALL_SAVE_ATTRIB, PATH_ATTRIB, SAVE_DIRECTORY_PARAM
Constructor and Description |
---|
JDBCRepository()
Creates a repository.
|
Modifier and Type | Method and Description |
---|---|
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.
|
checkConnection, checkEncoding, exists, getClassNameSuffix, getDocumentGetQuery, isDefault, loadBaseConfiguration, optimize, setIsDefault
finalize, getDataSourceComponent, releaseDataSourceComponent, service
createTable, getTableName, handleUnsupportedTokens
configureDescription, contextualize, enableLogging, getBaseAttributes, getConfiguration, getContext, getDescription, getEncoding, getId, getLocale, getLog, getServiceManager, getXmlLang, setDescription, setEncoding, setId, setLocale, setUpSdxObject, setUpSdxObject, setXmlLang, toSAX, verifyConfigurationResources
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getId, setId
getDescription, setDescription
getEncoding, setEncoding
getLocale, getXmlLang, setLocale, setXmlLang
public static final int NO_SPECIFIC_TYPE
protected static final java.lang.String FIELD_DATA
protected final int PARAM_INDEX_FIELD_DATA_ORIGINAL
public JDBCRepository()
A super.getLog() must be set and then this repository must be configured and initialized.
public RepositoryConnection getConnection() throws SDXException
SDXException
public void releaseConnection(RepositoryConnection c) throws SDXException
c
- A connection.SDXException
public void configure(org.apache.avalon.framework.configuration.Configuration configuration) throws org.apache.avalon.framework.configuration.ConfigurationException
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)
configure
in interface org.apache.avalon.framework.configuration.Configurable
configure
in class DataSourceComponentBacked
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"/>
org.apache.avalon.framework.configuration.ConfigurationException
public void init() throws SDXException
SDXException
public long size() throws SDXException
SDXException
public void lists(org.xml.sax.ContentHandler hdl) throws SDXException
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.
hdl
- A SAX content handler to feed with events.SDXException
public void add(Document doc, RepositoryConnection c) throws SDXException
add
in interface Repository
add
in class AbstractDataSourceComponentBackedRepository
doc
- A document.c
- A connection to the repository.SDXException
public void empty() throws SDXException
SDXException
public void delete(Document doc, RepositoryConnection c) throws SDXException
delete
in interface Repository
delete
in class AbstractDataSourceComponentBackedRepository
doc
- A document.c
- A connection to the repository.SDXException
public void toSAX(ParsableDocument doc, org.apache.cocoon.xml.XMLConsumer consumer, RepositoryConnection c) throws SDXException
toSAX
in interface Repository
toSAX
in class AbstractDataSourceComponentBackedRepository
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.SDXException
public java.io.InputStream openStream(Document doc, java.lang.String encoding, RepositoryConnection c) throws SDXException
openStream
in interface Repository
openStream
in class AbstractDataSourceComponentBackedRepository
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.SDXException
public void get(Document doc, java.io.OutputStream os, RepositoryConnection c) throws SDXException
get
in interface Repository
get
in class AbstractDataSourceComponentBackedRepository
doc
- A document.os
- An output stream.c
- A connection to the repository.SDXException
protected java.lang.String getTableCreationQuery()
This query should not have any parameter.
getTableCreationQuery
in class JDBC
protected java.lang.String getDocumentAddQuery()
This query should have three parameters, the first for the id, the second for the doctype and the third for the data.
protected java.lang.String getDocumentDeleteQuery()
This query should have one parameter for the document's id.
protected java.lang.String getDeleteAllQuery()
This query should not have any parameter.
protected java.lang.String getEntriesWithLimitQuery(long offset, long number)
offset
- number
- protected boolean initToSax()
AbstractSdxObject
initToSax
in class AbstractSdxObject
protected void initVolatileObjectsToSax()
initVolatileObjectsToSax
in class JDBC
public void backup(SaveParameters save_config) throws SDXException
public void restore(SaveParameters save_config) throws SDXException
Copyright © 2000-2010 Ministere de la culture et de la communication / AJLSM. All Rights Reserved.