org.apache.james.mailrepository.jdbc
Class JDBCMailRepository

java.lang.Object
  extended by org.apache.james.mailrepository.lib.AbstractMailRepository
      extended by org.apache.james.mailrepository.jdbc.JDBCMailRepository
All Implemented Interfaces:
Configurable, LogEnabled, MailRepository

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: 1088657 $ $Date: 2010-12-29 21:47:46 +0100 (Wed, 29 Dec 2010) $

Field Summary
protected  DataSource datasource
          The JDBC datasource that provides the JDBC connection
protected  String datasourceName
          The name of the datasource used by this repository
protected  boolean jdbcMailAttributesReady
          "Support for Mail Attributes under JDBC repositories is ready" indicator.
protected  String repositoryName
          The repository name parsed from the destination URL
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 class org.apache.james.mailrepository.lib.AbstractMailRepository
DEEP_DEBUG
 
Constructor Summary
JDBCMailRepository()
           
 
Method Summary
protected  void checkJdbcAttributesSupport(DatabaseMetaData dbMetaData)
          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".
protected  void doConfigure(org.apache.commons.configuration.HierarchicalConfiguration configuration)
           
 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 init()
          Initialises the JDBC repository.
protected  void internalRemove(String key)
           
protected  void internalStore(org.apache.mailet.Mail mc)
           
 Iterator list()
           
 org.apache.mailet.Mail retrieve(String key)
           
 void setDatasource(DataSource datasource)
           
 void setFileSystem(FileSystem fileSystem)
           
 
Methods inherited from class org.apache.james.mailrepository.lib.AbstractMailRepository
configure, getLogger, lock, remove, remove, remove, setLog, store, unlock
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tableName

protected String tableName
The table name parsed from the destination URL


repositoryName

protected String repositoryName
The repository name parsed from the destination URL


datasource

protected DataSource 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


jdbcMailAttributesReady

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

Constructor Detail

JDBCMailRepository

public JDBCMailRepository()
Method Detail

setDatasource

public void setDatasource(DataSource datasource)

setFileSystem

public void setFileSystem(FileSystem fileSystem)

doConfigure

protected void doConfigure(org.apache.commons.configuration.HierarchicalConfiguration configuration)
                    throws org.apache.commons.configuration.ConfigurationException
Overrides:
doConfigure in class AbstractMailRepository
Throws:
org.apache.commons.configuration.ConfigurationException

init

@PostConstruct
public void init()
          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.

Throws:
Exception - if an error occurs

checkJdbcAttributesSupport

protected void checkJdbcAttributesSupport(DatabaseMetaData dbMetaData)
                                   throws 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:
SQLException - if a fatal situation is met

internalStore

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

retrieve

public org.apache.mailet.Mail retrieve(String key)
                                throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException
See Also:
MailRepository.retrieve(String)

internalRemove

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

list

public Iterator list()
              throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException
See Also:
MailRepository.list()

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