org.apache.james.mailrepository
Class JDBCMailRepository

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.james.mailrepository.AbstractMailRepository
          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.logger.LogEnabled, org.apache.avalon.framework.service.Serviceable, MailRepository
Direct Known Subclasses:
JDBCSpoolRepository

public class JDBCMailRepository
extends AbstractMailRepository

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: 684816 $ $Date: 2008-08-11 18:03:27 +0100 (Mon, 11 Aug 2008) $

Field Summary
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 class org.apache.james.mailrepository.AbstractMailRepository
DEEP_DEBUG, store
 
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)
           
 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.
protected  void internalRemove(java.lang.String key)
           
protected  void internalStore(org.apache.mailet.Mail mc)
           
 java.util.Iterator list()
          List string keys of messages in repository.
 org.apache.mailet.Mail retrieve(java.lang.String key)
          Retrieves a message given a key.
 void service(org.apache.avalon.framework.service.ServiceManager componentManager)
           
 void setDatasources(org.apache.avalon.cornerstone.services.datasources.DataSourceSelector datasources)
           
 
Methods inherited from class org.apache.james.mailrepository.AbstractMailRepository
lock, remove, remove, remove, store, unlock
 
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

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

setDatasources

public void setDatasources(org.apache.avalon.cornerstone.services.datasources.DataSourceSelector datasources)

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
Overrides:
service in class AbstractMailRepository
Throws:
org.apache.avalon.framework.service.ServiceException
See Also:
Serviceable.service(ServiceManager)

configure

public void configure(org.apache.avalon.framework.configuration.Configuration conf)
               throws org.apache.avalon.framework.configuration.ConfigurationException
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
Overrides:
initialize in class AbstractMailRepository
Throws:
java.lang.Exception - if an error occurs
See Also:
Initializable.initialize()

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

internalStore

protected void internalStore(org.apache.mailet.Mail mc)
                      throws java.io.IOException,
                             javax.mail.MessagingException
Specified by:
internalStore in class AbstractMailRepository
Throws:
java.io.IOException
javax.mail.MessagingException
See Also:
AbstractMailRepository.internalStore(Mail)

retrieve

public org.apache.mailet.Mail retrieve(java.lang.String key)
                                throws javax.mail.MessagingException
Description copied from interface: MailRepository
Retrieves a message given a key. At the moment, keys can be obtained from list() in superinterface Store.Repository

Parameters:
key - the key of the message to retrieve
Returns:
the mail corresponding to this key, null if none exists
Throws:
javax.mail.MessagingException
See Also:
MailRepository.retrieve(String)

internalRemove

protected void internalRemove(java.lang.String key)
                       throws javax.mail.MessagingException
Specified by:
internalRemove in class AbstractMailRepository
Throws:
javax.mail.MessagingException
See Also:
AbstractMailRepository.internalRemove(String)

list

public java.util.Iterator list()
                        throws javax.mail.MessagingException
Description copied from interface: MailRepository
List string keys of messages in repository.

Returns:
an Iterator over the list of keys in the repository
Throws:
javax.mail.MessagingException
See Also:
MailRepository.list()

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-2009 The Apache Software Foundation. All Rights Reserved.