org.apache.james.mailrepository
Class JDBCMailRepository

java.lang.Object
  |
  +--org.apache.avalon.framework.logger.AbstractLogEnabled
        |
        +--org.apache.james.mailrepository.JDBCMailRepository
All Implemented Interfaces:
Component, Composable, Configurable, Contextualizable, Initializable, LogEnabled, MailRepository
Direct Known Subclasses:
JDBCSpoolRepository

public class JDBCMailRepository
extends AbstractLogEnabled
implements MailRepository, Component, Contextualizable, Composable, Configurable, Initializable

Implementation of a MailRepository on a database.

Requires a configuration element in the .conf.xml file of the form:
type="MAIL"
model="SYNCHRONOUS"/>

destinationURL specifies..(Serge??)
Type can be SPOOL or MAIL
Model is currently not used and may be dropped

Requires a logger called MailRepository.

Version:
1.0.0, 24/04/1999
Author:
Serge Knystautas , Darrell DeBoer

Field Summary
protected  Context context
          The Avalon context used by the instance
protected  org.apache.avalon.excalibur.datasource.DataSourceComponent datasource
          The JDBC datasource that provides the JDBC connection
protected  String datasourceName
          The name of the datasource used by this repository
protected  DataSourceSelector datasources
          The selector used to obtain the JDBC datasource
protected  String destination
          Destination URL for the repository.
protected  String filestore
          The name of the filestore to be used to store mail when configured to use dbfile mode.
protected  String repositoryName
          The repository name parsed from the destination URL
protected  String sqlFileName
          The name of the SQL configuration file to be used to configure this repository.
protected  SqlResources sqlQueries
          Contains all of the sql strings for this component.
protected  String tableName
          The table name parsed from the destination URL
protected  JDBCUtil theJDBCUtil
          The JDBCUtil helper class
 
Fields inherited from interface org.apache.james.services.MailRepository
MAIL
 
Constructor Summary
JDBCMailRepository()
           
 
Method Summary
 void compose(ComponentManager componentManager)
           
 void configure(Configuration conf)
           
 void contextualize(Context context)
           
 boolean equals(Object obj)
           
protected  Connection getConnection()
          Gets the SQL connection to be used by this JDBCMailRepository
 int hashCode()
          Provide a hash code that is consistent with equals for this class
 void initialize()
          Initialises the JDBC repository. 1) Tests the connection to the database. 2) Loads SQL strings from the SQL definition file, choosing the appropriate SQL for this connection, and performing paramter substitution, 3) Initialises the database with the required tables, if necessary.
 Iterator list()
          Gets a list of message keys stored in this repository.
 boolean lock(String key)
          Obtains a lock on a message identified by a key
 void remove(MailImpl mail)
          Removes a specified message
 void remove(String key)
          Removes a message identified by a key.
 MailImpl retrieve(String key)
          Retrieves a message given a key.
 void store(MailImpl mc)
          Store this message to the database.
 boolean unlock(String key)
          Releases a lock on a message identified by a key
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected Context context
The Avalon context used by the instance


destination

protected String destination
Destination URL for the repository. See class description for more info


tableName

protected String tableName
The table name parsed from the destination URL


repositoryName

protected String repositoryName
The repository name parsed from the destination URL


filestore

protected String filestore
The name of the filestore to be used to store mail when configured to use dbfile mode.


sqlFileName

protected String sqlFileName
The name of the SQL configuration file to be used to configure this repository.


datasources

protected DataSourceSelector datasources
The selector used to obtain the JDBC datasource


datasource

protected org.apache.avalon.excalibur.datasource.DataSourceComponent datasource
The JDBC datasource that provides the JDBC connection


datasourceName

protected String datasourceName
The name of the datasource used by this repository


sqlQueries

protected SqlResources sqlQueries
Contains all of the sql strings for this component.


theJDBCUtil

protected JDBCUtil theJDBCUtil
The JDBCUtil helper class

Constructor Detail

JDBCMailRepository

public JDBCMailRepository()
Method Detail

contextualize

public void contextualize(Context context)
                   throws ContextException
Specified by:
contextualize in interface Contextualizable
ContextException
See Also:
Contextualizable.contextualize(Context)

compose

public void compose(ComponentManager componentManager)
             throws ComponentException
Specified by:
compose in interface Composable
ComponentException
See Also:
Composable.compose(ComponentManager)

configure

public void configure(Configuration conf)
               throws ConfigurationException
Specified by:
configure in interface Configurable
ConfigurationException
See Also:
Configurable.configure(Configuration)

initialize

public void initialize()
                throws Exception
Initialises the JDBC repository. 1) Tests the connection to the database. 2) Loads SQL strings from the SQL definition file, choosing the appropriate SQL for this connection, and performing paramter substitution, 3) Initialises the database with the required tables, if necessary.

Specified by:
initialize in interface Initializable
Throws:
Exception - if an error occurs

unlock

public boolean unlock(String key)
Releases a lock on a message identified by a key

Specified by:
unlock in interface MailRepository
Parameters:
key - the key of the message to be unlocked
Returns:
true if successfully released the lock, false otherwise

lock

public boolean lock(String key)
Obtains a lock on a message identified by a key

Specified by:
lock in interface MailRepository
Parameters:
key - the key of the message to be locked
Returns:
true if successfully obtained the lock, false otherwise

store

public void store(MailImpl mc)
Store this message to the database. Optionally stores the message body to the filesystem and only writes the headers to the database.

Specified by:
store in interface MailRepository
Parameters:
mc - the mail message to store

retrieve

public MailImpl retrieve(String key)
Retrieves a message given a key. At the moment, keys can be obtained from list()

Specified by:
retrieve in interface MailRepository
Parameters:
key - the key of the message to retrieve
Returns:
the mail corresponding to this key, null if none exists

remove

public void remove(MailImpl mail)
Removes a specified message

Specified by:
remove in interface MailRepository
Parameters:
mail - the message to be removed from the repository

remove

public void remove(String key)
Removes a message identified by a key.

Specified by:
remove in interface MailRepository
Parameters:
key - the key of the message to be removed from the repository

list

public Iterator list()
Gets a list of message keys stored in this repository.

Specified by:
list in interface MailRepository
Returns:
an Iterator of the message keys

getConnection

protected Connection getConnection()
                            throws SQLException
Gets the SQL connection to be used by this JDBCMailRepository

Returns:
the connection
Throws:
SQLException - if there is an issue with getting the connection

equals

public boolean equals(Object obj)
Overrides:
equals in class Object
See Also:
Object.equals(Object)

hashCode

public int hashCode()
Provide a hash code that is consistent with equals for this class

Overrides:
hashCode in class Object
Returns:
the hash code


"Copyright © 1999-2002 Apache Jakarta Project. All Rights Reserved."