org.apache.james.mailrepository
Class JDBCMailRepository

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.james.mailrepository.JDBCMailRepository
All Implemented Interfaces:
org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.logger.LogEnabled, org.apache.avalon.framework.service.Serviceable, MailRepository
Direct Known Subclasses:
JDBCSpoolRepository

public class JDBCMailRepository
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements MailRepository, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.service.Serviceable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Initializable

Implementation of a MailRepository on a database.

Requires a configuration element in the .conf.xml file of the form:
<repository destinationURL="db://<datasource>/<table_name>/<repository_name>"
type="MAIL"
model="SYNCHRONOUS"/>
</repository>

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

Requires a logger called MailRepository.

Version:
CVS $Revision: 494012 $ $Date: 2007-01-08 10:23:58 +0000 (lun, 08 gen 2007) $

Field Summary
protected  org.apache.avalon.framework.context.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  java.lang.String datasourceName
          The name of the datasource used by this repository
protected  org.apache.avalon.cornerstone.services.datasources.DataSourceSelector datasources
          The selector used to obtain the JDBC datasource
protected  boolean jdbcMailAttributesReady
          "Support for Mail Attributes under JDBC repositories is ready" indicator.
protected  java.lang.String repositoryName
          The repository name parsed from the destination URL
protected  SqlResources sqlQueries
          Contains all of the sql strings for this component.
protected  java.lang.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, ROLE
 
Constructor Summary
JDBCMailRepository()
           
 
Method Summary
protected  void checkJdbcAttributesSupport(java.sql.DatabaseMetaData dbMetaData)
          Checks whether support for JDBC Mail atributes is activated for this repository and if everything is consistent.
 void configure(org.apache.avalon.framework.configuration.Configuration conf)
           
 void contextualize(org.apache.avalon.framework.context.Context context)
           
 boolean equals(java.lang.Object obj)
           
protected  java.sql.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.
 java.util.Iterator list()
          Gets a list of message keys stored in this repository.
 boolean lock(java.lang.String key)
          Obtains a lock on a message identified by a key
 void remove(java.util.Collection mails)
          Removes a Collection of mails from the repository
 void remove(Mail mail)
          Removes a specified message
 void remove(java.lang.String key)
          Removes a message identified by a key.
 Mail retrieve(java.lang.String key)
          Retrieves a message given a key.
 void service(org.apache.avalon.framework.service.ServiceManager componentManager)
           
 void store(Mail mc)
          Store this message to the database.
 boolean unlock(java.lang.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 org.apache.avalon.framework.context.Context context
The Avalon context used by the instance


tableName

protected java.lang.String tableName
The table name parsed from the destination URL


repositoryName

protected java.lang.String repositoryName
The repository name parsed from the destination URL


datasources

protected org.apache.avalon.cornerstone.services.datasources.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 java.lang.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


jdbcMailAttributesReady

protected boolean jdbcMailAttributesReady
"Support for Mail Attributes under JDBC repositories is ready" indicator.

Constructor Detail

JDBCMailRepository

public JDBCMailRepository()
Method Detail

contextualize

public void contextualize(org.apache.avalon.framework.context.Context context)
                   throws org.apache.avalon.framework.context.ContextException
Specified by:
contextualize in interface org.apache.avalon.framework.context.Contextualizable
Throws:
org.apache.avalon.framework.context.ContextException
See Also:
Contextualizable.contextualize(Context)

service

public void service(org.apache.avalon.framework.service.ServiceManager componentManager)
             throws org.apache.avalon.framework.service.ServiceException
Specified by:
service in interface org.apache.avalon.framework.service.Serviceable
Throws:
org.apache.avalon.framework.service.ServiceException
See Also:
org.apache.avalon.framework.service.Servicable#service(ServiceManager)

configure

public void configure(org.apache.avalon.framework.configuration.Configuration conf)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Throws:
org.apache.avalon.framework.configuration.ConfigurationException
See Also:
Configurable.configure(Configuration)

initialize

public void initialize()
                throws java.lang.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 org.apache.avalon.framework.activity.Initializable
Throws:
java.lang.Exception - if an error occurs

checkJdbcAttributesSupport

protected void checkJdbcAttributesSupport(java.sql.DatabaseMetaData dbMetaData)
                                   throws java.sql.SQLException
Checks whether support for JDBC Mail atributes is activated for this repository and if everything is consistent. Looks for both the "updateMessageAttributesSQL" and "retrieveMessageAttributesSQL" statements in sqlResources and for a table column named "message_attributes".

Parameters:
dbMetaData - the database metadata to be used to look up the column
Throws:
java.sql.SQLException - if a fatal situation is met

unlock

public boolean unlock(java.lang.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(java.lang.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(Mail mc)
           throws javax.mail.MessagingException
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
Throws:
javax.mail.MessagingException

retrieve

public Mail retrieve(java.lang.String key)
              throws javax.mail.MessagingException
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
Throws:
javax.mail.MessagingException

remove

public void remove(Mail mail)
            throws javax.mail.MessagingException
Removes a specified message

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

remove

public void remove(java.util.Collection mails)
            throws javax.mail.MessagingException
Removes a Collection of mails from the repository

Specified by:
remove in interface MailRepository
Parameters:
mails - The Collection of MailImpl's to delete
Throws:
javax.mail.MessagingException
Since:
2.2.0

remove

public void remove(java.lang.String key)
            throws javax.mail.MessagingException
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
Throws:
javax.mail.MessagingException

list

public java.util.Iterator list()
                        throws javax.mail.MessagingException
Gets a list of message keys stored in this repository.

Specified by:
list in interface MailRepository
Returns:
an Iterator of the message keys
Throws:
javax.mail.MessagingException

getConnection

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

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

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.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 java.lang.Object
Returns:
the hash code


Copyright © 2002-2007 The Apache Software Foundation. All Rights Reserved.