org.apache.james.util
Class JDBCBayesianAnalyzer

java.lang.Object
  extended by org.apache.james.util.BayesianAnalyzer
      extended by org.apache.james.util.JDBCBayesianAnalyzer

public abstract class JDBCBayesianAnalyzer
extends BayesianAnalyzer

Manages the persistence of the spam bayesian analysis corpus using a JDBC database.

This class is abstract to allow implementations to take advantage of different logging capabilities/interfaces in different parts of the code.

Since:
2.3.0
Version:
CVS $Revision: $ $Date: $

Field Summary
static java.lang.String DATABASE_LOCK
          Public object representing a lock on database activity.
 
Constructor Summary
JDBCBayesianAnalyzer()
          Default constructor.
 
Method Summary
protected abstract  void delegatedLog(java.lang.String errorString)
          An abstract method which child classes override to handle logging of errors in their particular environments.
static long getLastDatabaseUpdateTime()
          Getter for static lastDatabaseUpdateTime.
 java.lang.String getSqlFileName()
          Getter for property sqlFileName.
 java.util.Map getSqlParameters()
          Getter for property sqlParameters.
 void initSqlQueries(java.sql.Connection conn, MailetContext mailetContext)
          Initializes the sql query environment from the SqlResources file.
 void loadHamNSpam(java.sql.Connection conn)
          Loads the token frequencies from the database.
 void setSqlFileName(java.lang.String sqlFileName)
          Setter for property sqlFileName.
 void setSqlParameters(java.util.Map sqlParameters)
          Setter for property sqlParameters.
static void touchLastDatabaseUpdateTime()
          Sets static lastDatabaseUpdateTime to System.currentTimeMillis().
 void updateHamTokens(java.sql.Connection conn)
          Updates the database with new "ham" token frequencies.
 void updateSpamTokens(java.sql.Connection conn)
          Updates the database with new "spam" token frequencies.
 
Methods inherited from class org.apache.james.util.BayesianAnalyzer
addHam, addSpam, buildCorpus, clear, computeSpamProbability, getCorpus, getHamMessageCount, getHamTokenCounts, getSpamMessageCount, getSpamTokenCounts, setCorpus, setHamMessageCount, setHamTokenCounts, setSpamMessageCount, setSpamTokenCounts, tokenCountsClear
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATABASE_LOCK

public static final java.lang.String DATABASE_LOCK
Public object representing a lock on database activity.

See Also:
Constant Field Values
Constructor Detail

JDBCBayesianAnalyzer

public JDBCBayesianAnalyzer()
Default constructor.

Method Detail

delegatedLog

protected abstract void delegatedLog(java.lang.String errorString)
An abstract method which child classes override to handle logging of errors in their particular environments.

Parameters:
errorString - the error message generated

getSqlFileName

public java.lang.String getSqlFileName()
Getter for property sqlFileName.

Returns:
Value of property sqlFileName.

setSqlFileName

public void setSqlFileName(java.lang.String sqlFileName)
Setter for property sqlFileName.

Parameters:
sqlFileName - New value of property sqlFileName.

getSqlParameters

public java.util.Map getSqlParameters()
Getter for property sqlParameters.

Returns:
Value of property sqlParameters.

setSqlParameters

public void setSqlParameters(java.util.Map sqlParameters)
Setter for property sqlParameters.

Parameters:
sqlParameters - New value of property sqlParameters.

getLastDatabaseUpdateTime

public static long getLastDatabaseUpdateTime()
Getter for static lastDatabaseUpdateTime.

Returns:
Value of property lastDatabaseUpdateTime.

touchLastDatabaseUpdateTime

public static void touchLastDatabaseUpdateTime()
Sets static lastDatabaseUpdateTime to System.currentTimeMillis().


loadHamNSpam

public void loadHamNSpam(java.sql.Connection conn)
                  throws java.sql.SQLException
Loads the token frequencies from the database.

Parameters:
conn - The connection for accessing the database
Throws:
java.sql.SQLException - If a database error occurs

updateHamTokens

public void updateHamTokens(java.sql.Connection conn)
                     throws java.sql.SQLException
Updates the database with new "ham" token frequencies.

Parameters:
conn - The connection for accessing the database
Throws:
java.sql.SQLException - If a database error occurs

updateSpamTokens

public void updateSpamTokens(java.sql.Connection conn)
                      throws java.sql.SQLException
Updates the database with new "spam" token frequencies.

Parameters:
conn - The connection for accessing the database
Throws:
java.sql.SQLException - If a database error occurs

initSqlQueries

public void initSqlQueries(java.sql.Connection conn,
                           MailetContext mailetContext)
                    throws java.lang.Exception
Initializes the sql query environment from the SqlResources file. Will look for conf/sqlResources.xml.

Parameters:
conn - The connection for accessing the database
mailetContext - The current mailet context, for finding the conf/sqlResources.xml file
Throws:
java.lang.Exception - If any error occurs


Copyright ? 2002-2009 The Apache Software Foundation. All Rights Reserved.