org.apache.james.ai.classic
Class JDBCBayesianAnalyzer

java.lang.Object
  extended by org.apache.james.ai.classic.BayesianAnalyzer
      extended by org.apache.james.ai.classic.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

Field Summary
static String DATABASE_LOCK
          Public object representing a lock on database activity.
 
Constructor Summary
JDBCBayesianAnalyzer()
          Default constructor.
 
Method Summary
protected abstract  void delegatedLog(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.
 String getSqlFileName()
          Getter for property sqlFileName.
 Map<String,String> getSqlParameters()
          Getter for property sqlParameters.
 void initSqlQueries(Connection conn, Document sqlConfiguration)
          Initializes the sql query environment from the SqlResources file.
 void loadHamNSpam(Connection conn)
          Loads the token frequencies from the database.
 void resetData(Connection conn)
          Reset all trained data
 void setSqlFileName(String sqlFileName)
          Setter for property sqlFileName.
 void setSqlParameters(Map<String,String> sqlParameters)
          Setter for property sqlParameters.
static void touchLastDatabaseUpdateTime()
          Sets static lastDatabaseUpdateTime to System.currentTimeMillis().
 void updateHamTokens(Connection conn)
          Updates the database with new "ham" token frequencies.
 void updateSpamTokens(Connection conn)
          Updates the database with new "spam" token frequencies.
 
Methods inherited from class org.apache.james.ai.classic.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 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(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 String getSqlFileName()
Getter for property sqlFileName.

Returns:
Value of property sqlFileName.

setSqlFileName

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

Parameters:
sqlFileName - New value of property sqlFileName.

getSqlParameters

public Map<String,String> getSqlParameters()
Getter for property sqlParameters.

Returns:
Value of property sqlParameters.

setSqlParameters

public void setSqlParameters(Map<String,String> 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(Connection conn)
                  throws SQLException
Loads the token frequencies from the database.

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

updateHamTokens

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

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

updateSpamTokens

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

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

resetData

public void resetData(Connection conn)
               throws SQLException
Reset all trained data

Parameters:
conn - The connection for accessing the database
Throws:
SQLException - If a database error occours

initSqlQueries

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

Parameters:
conn - The connection for accessing the database
sqlConfiguration - The sqlResources configuration document
Throws:
Exception - If any error occurs


Copyright © 2011 The Apache Software Foundation. All Rights Reserved.