Author: norman
Date: Thu Sep 7 15:26:31 2006
New Revision: 441263
URL: http://svn.apache.org/viewvc?view=rev&rev=441263
Log:
Add functionality of reseting the trained data of BayesianAnalysis. JAMES-608
Modified:
james/server/trunk/src/conf/sqlResources.xml
james/server/trunk/src/java/org/apache/james/management/BayesianAnalyzerManagement.java
james/server/trunk/src/java/org/apache/james/management/BayesianAnalyzerManagementMBean.java
james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
james/server/trunk/src/java/org/apache/james/services/BayesianAnalyzerManagementService.java
james/server/trunk/src/java/org/apache/james/util/JDBCBayesianAnalyzer.java
Modified: james/server/trunk/src/conf/sqlResources.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/conf/sqlResources.xml?view=diff&rev=441263&r1=441262&r2=441263
==============================================================================
--- james/server/trunk/src/conf/sqlResources.xml (original)
+++ james/server/trunk/src/conf/sqlResources.xml Thu Sep 7 15:26:31 2006
@@ -674,6 +674,16 @@
<!-- Statements used to update the spam token counts. -->
<sql name="updateSpamToken">UPDATE bayesiananalysis_spam SET
OCCURRENCES=(OCCURRENCES + ?) WHERE (TOKEN=?)</sql>
+ <!-- Statements used to delete ham tokens. -->
+ <sql name="deleteHamTokens">DELETE FROM bayesiananalysis_ham</sql>
+
+ <!-- Statements used to delete spam tokens. -->
+ <sql name="deleteSpamTokens">DELETE FROM bayesiananalysis_spam</sql>
+
+ <!-- Statements used to delete message counts. -->
+ <sql name="deleteMessageCounts">DELETE FROM
bayesiananalysis_messagecounts</sql>
+
+
<!-- Statements used to create the "ham" table (the 'token' field must be
case sensitive). -->
<sql name="createHamTable" db="mysql">
CREATE TABLE bayesiananalysis_ham (
Modified:
james/server/trunk/src/java/org/apache/james/management/BayesianAnalyzerManagement.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/BayesianAnalyzerManagement.java?view=diff&rev=441263&r1=441262&r2=441263
==============================================================================
---
james/server/trunk/src/java/org/apache/james/management/BayesianAnalyzerManagement.java
(original)
+++
james/server/trunk/src/java/org/apache/james/management/BayesianAnalyzerManagement.java
Thu Sep 7 15:26:31 2006
@@ -369,7 +369,22 @@
protected void delegatedLog(String logString) {
// no logging
}
- };
+ };
+
+
+ /**
+ * @see
org.apache.james.services.BayesianAnalyzerManagementService#resetData()
+ */
+ public void resetData() throws BayesianAnalyzerManagementException {
+ synchronized(JDBCBayesianAnalyzer.DATABASE_LOCK) {
+ try {
+ analyzer.resetData(component.getConnection());
+ } catch (SQLException e) {
+ throw new BayesianAnalyzerManagementException(e.getMessage());
+ }
+ }
+
+ }
/**
* Inner class to represent the data in an xml file
@@ -404,4 +419,5 @@
}
}
+
}
Modified:
james/server/trunk/src/java/org/apache/james/management/BayesianAnalyzerManagementMBean.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/BayesianAnalyzerManagementMBean.java?view=diff&rev=441263&r1=441262&r2=441263
==============================================================================
---
james/server/trunk/src/java/org/apache/james/management/BayesianAnalyzerManagementMBean.java
(original)
+++
james/server/trunk/src/java/org/apache/james/management/BayesianAnalyzerManagementMBean.java
Thu Sep 7 15:26:31 2006
@@ -103,4 +103,14 @@
* @throws BayesianAnalyzerManagementException
*/
void importData(String file) throws BayesianAnalyzerManagementException;
+
+ /**
+ * reset trained data
+ *
+ * @phoenix:mx-operation
+ * @phoenix:mx-description reset trained data
+ *
+ * @throws BayesianAnalyzerManagementException
+ */
+ void resetData() throws BayesianAnalyzerManagementException;
}
Modified:
james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java?view=diff&rev=441263&r1=441262&r2=441263
==============================================================================
---
james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
(original)
+++
james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
Thu Sep 7 15:26:31 2006
@@ -159,6 +159,8 @@
private static final String COMMAND_IMPORTBAYESIANDATA =
"IMPORTBAYESIANDATA";
+ private static final String COMMAND_RESETBAYESIANDATA =
"RESETBAYESIANDATA";
+
/**
* The text string for the QUIT command
*/
@@ -353,6 +355,8 @@
return doEXPORTBAYESIANDATA(argument);
} else if (command.equals(COMMAND_IMPORTBAYESIANDATA)) {
return doIMPORTBAYESIANDATA(argument);
+ } else if (command.equals(COMMAND_RESETBAYESIANDATA)) {
+ return doRESETBAYESIANDATA(argument);
} else if (command.equals(COMMAND_MEMSTAT)) {
return doMEMSTAT(argument);
} else if (command.equals(COMMAND_QUIT)) {
@@ -618,7 +622,8 @@
out.println("addham dir/mbox [directory/mbox]
feed the BayesianAnalysisFeeder with the content of the directory
or mbox file as HAM");
out.println("addspam dir/mbox [directory/mbox]
feed the BayesianAnalysisFeeder with the content of the directory
or mbox file as SPAM");
out.println("exportbayesiandata [file]
export the BayesianAnalysis data to a xml file");
- out.println("importbayesiandata [file]
import the BayesianAnalysis data from a xml file");
+ out.println("resetbayesiandata
reset trained BayesianAnalysis data");
+ out.println("memstat ([-gc])
shows memory usage. When called with -gc the garbage collector
get called");
out.println("memstat ([-gc])
shows memory usage. When called with -gc the garbage collector
get called");
out.println("shutdown
kills the current JVM (convenient when James is run as a
daemon)");
out.println("quit
close connection");
@@ -1256,7 +1261,7 @@
getLogger().error("Error on exporting BayesianAnalysis data: " +
e);
out.println("Error on exporting BayesianAnalysis data: " + e);
out.flush();
- return false;
+ return true;
} finally {
theWatchdog.start();
}
@@ -1285,7 +1290,29 @@
getLogger().error("Error on importing BayesianAnalysis data: " +
e);
out.println("Error on importing BayesianAnalysis data: " + e);
out.flush();
- return false;
+ return true;
+ } finally {
+ theWatchdog.start();
+ }
+
+ return true;
+ }
+
+ private boolean doRESETBAYESIANDATA(String argument) {
+
+ try {
+ // stop watchdog cause feeding can take some time
+ theWatchdog.stop();
+
+ theConfigData.getBayesianAnalyzerManagement().resetData();
+ out.println("Reseted the BayesianAnalysis data");
+ out.flush();
+
+ } catch (BayesianAnalyzerManagementException e) {
+ getLogger().error("Error on reseting BayesianAnalysis data: " + e);
+ out.println("Error on reseting BayesianAnalysis data: " + e);
+ out.flush();
+ return true;
} finally {
theWatchdog.start();
}
Modified:
james/server/trunk/src/java/org/apache/james/services/BayesianAnalyzerManagementService.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/services/BayesianAnalyzerManagementService.java?view=diff&rev=441263&r1=441262&r2=441263
==============================================================================
---
james/server/trunk/src/java/org/apache/james/services/BayesianAnalyzerManagementService.java
(original)
+++
james/server/trunk/src/java/org/apache/james/services/BayesianAnalyzerManagementService.java
Thu Sep 7 15:26:31 2006
@@ -103,4 +103,11 @@
* @throws SQLException
*/
public void importData(String file) throws
BayesianAnalyzerManagementException;
+
+ /**
+ * Reset the trained data
+ *
+ * @throws BayesianAnalyzerManagementException
+ */
+ public void resetData() throws BayesianAnalyzerManagementException;
}
Modified:
james/server/trunk/src/java/org/apache/james/util/JDBCBayesianAnalyzer.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/util/JDBCBayesianAnalyzer.java?view=diff&rev=441263&r1=441262&r2=441263
==============================================================================
--- james/server/trunk/src/java/org/apache/james/util/JDBCBayesianAnalyzer.java
(original)
+++ james/server/trunk/src/java/org/apache/james/util/JDBCBayesianAnalyzer.java
Thu Sep 7 15:26:31 2006
@@ -259,6 +259,18 @@
setMessageCount(conn,
sqlQueries.getSqlString("updateSpamMessageCounts", true),
getSpamMessageCount());
}
+ /**
+ * Reset all trained data
+ *
+ * @param conn The connection for accessing the database
+ * @throws SQLException If a dtabase error occours
+ */
+ public void resetData(Connection conn) throws SQLException {
+ deleteData(conn,sqlQueries.getSqlString("deleteHamTokens",true));
+ deleteData(conn,sqlQueries.getSqlString("deleteSpamTokens",true));
+ deleteData(conn,sqlQueries.getSqlString("deleteMessageCounts",true));
+ }
+
private void setMessageCount(Connection conn, String sqlStatement, int
count)
throws java.sql.SQLException {
PreparedStatement init = null;
@@ -420,4 +432,22 @@
return true;
}
+ private void deleteData(Connection conn, String deleteSqlStatement) throws
SQLException {
+ PreparedStatement delete = null;
+
+ try {
+ //Used to delete ham tokens
+ delete = conn.prepareStatement(deleteSqlStatement);
+ delete.executeUpdate();
+ } finally {
+ if (delete != null) {
+ try {
+ delete.close();
+ } catch (java.sql.SQLException ignore) {
+ }
+
+ delete = null;
+ }
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]