Author: norman
Date: Fri Jan 8 18:48:56 2010
New Revision: 897295
URL: http://svn.apache.org/viewvc?rev=897295&view=rev
Log:
Move torque configuration to an extra file
Added:
james/server/trunk/spring-deployment/src/main/config/james/torque.properties
Modified:
james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServerProtocolHandlerFactory.java
james/server/trunk/imapserver-function/src/main/java/org/apache/james/mailboxmanager/torque/DefaultMailboxManager.java
james/server/trunk/spring-deployment/src/main/config/james/james-config.xml
Modified:
james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServerProtocolHandlerFactory.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServerProtocolHandlerFactory.java?rev=897295&r1=897294&r2=897295&view=diff
==============================================================================
---
james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServerProtocolHandlerFactory.java
(original)
+++
james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServerProtocolHandlerFactory.java
Fri Jan 8 18:48:56 2010
@@ -44,8 +44,6 @@
import org.apache.jsieve.mailet.Poster;
/**
- * TODO: this is a quick cut-and-paste hack from POP3Server. Should probably be
- * rewritten from scratch, together with ImapHandler.
*
* <p>Accepts IMAP connections on a server socket and dispatches them to
IMAPHandlers.</p>
*
@@ -175,6 +173,16 @@
}
}
+ /**
+ * Post mail to mailbox
+ *
+ * @param username
+ * @param mail
+ * @param destination
+ * @param session
+ * @param mailboxManager
+ * @throws MessagingException
+ */
public void postToMailbox(String username, MimeMessage mail, String
destination, final MailboxSession session, final MailboxManager mailboxManager)
throws MessagingException {
if (destination == null || "".equals(destination)) {
destination = "INBOX";
Modified:
james/server/trunk/imapserver-function/src/main/java/org/apache/james/mailboxmanager/torque/DefaultMailboxManager.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/mailboxmanager/torque/DefaultMailboxManager.java?rev=897295&r1=897294&r2=897295&view=diff
==============================================================================
---
james/server/trunk/imapserver-function/src/main/java/org/apache/james/mailboxmanager/torque/DefaultMailboxManager.java
(original)
+++
james/server/trunk/imapserver-function/src/main/java/org/apache/james/mailboxmanager/torque/DefaultMailboxManager.java
Fri Jan 8 18:48:56 2010
@@ -19,19 +19,16 @@
package org.apache.james.mailboxmanager.torque;
-import java.io.File;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
-import java.util.List;
import java.util.Locale;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
-import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.PropertiesConfiguration;
@@ -59,12 +56,10 @@
MessageHeaderPeer.TABLE_NAME, MessageBodyPeer.TABLE_NAME,
MessageFlagsPeer.TABLE_NAME };
- private BaseConfiguration torqueConf;
-
- private boolean initialized;
-
private FileSystem fileSystem;
private String configFile;
+
+ private String torqueFile;
public DefaultMailboxManager(UserManager userManager) {
super(userManager);
@@ -77,95 +72,55 @@
@PostConstruct
public void init() throws Exception {
- if (!initialized) {
- if (torqueConf == null) {
- throw new RuntimeException("must be configured first!");
- }
- if (Torque.isInit()) {
- throw new RuntimeException("Torque is already initialized!");
- }
- Connection conn = null;
- try {
- Torque.init(torqueConf);
- conn = Transaction.begin(MailboxRowPeer.DATABASE_NAME);
- SqlResources sqlResources = new SqlResources();
- sqlResources.init(fileSystem.getResource(configFile),
- DefaultMailboxManager.class.getName(), conn,
- new HashMap<String,String>());
-
- DatabaseMetaData dbMetaData = conn.getMetaData();
-
- for (int i = 0; i < tableNames.length; i++) {
- if (!tableExists(dbMetaData, tableNames[i])) {
- BasePeer.executeStatement(sqlResources
- .getSqlString("createTable_" + tableNames[i]),
- conn);
- System.out.println("Created table " + tableNames[i]);
- getLog().info("Created table " + tableNames[i]);
- }
+ if (Torque.isInit()) {
+ throw new RuntimeException("Torque is already initialized!");
+ }
+ Connection conn = null;
+ try {
+ Torque.init(new
PropertiesConfiguration(fileSystem.getFile(torqueFile)));
+ conn = Transaction.begin(MailboxRowPeer.DATABASE_NAME);
+ SqlResources sqlResources = new SqlResources();
+ sqlResources.init(fileSystem.getResource(configFile),
+ DefaultMailboxManager.class.getName(), conn,
+ new HashMap<String,String>());
+
+ DatabaseMetaData dbMetaData = conn.getMetaData();
+
+ for (int i = 0; i < tableNames.length; i++) {
+ if (!tableExists(dbMetaData, tableNames[i])) {
+ BasePeer.executeStatement(sqlResources
+ .getSqlString("createTable_" + tableNames[i]),
+ conn);
+ System.out.println("Created table " + tableNames[i]);
+ getLog().info("Created table " + tableNames[i]);
}
+ }
- Transaction.commit(conn);
- initialized = true;
- System.out.println("MailboxManager has been initialized");
- getLog().info("MailboxManager has been initialized");
- } catch (Exception e) {
- System.err
-
.println("============================================");
- e.printStackTrace();
- System.err
-
.println("--------------------------------------------");
- Transaction.safeRollback(conn);
- try {
- Torque.shutdown();
- } catch (TorqueException e1) {
-
- }
- throw new MailboxException(new
HumanReadableText("org.apache.james.imap.INIT_FAILED", "Initialisation
failed"), e);
+ Transaction.commit(conn);
+ System.out.println("MailboxManager has been initialized");
+ getLog().info("MailboxManager has been initialized");
+ } catch (Exception e) {
+ Transaction.safeRollback(conn);
+ try {
+ Torque.shutdown();
+ } catch (TorqueException e1) {
+ // ignore on shutdown
}
+ throw new MailboxException(new
HumanReadableText("org.apache.james.imap.INIT_FAILED", "Initialisation
failed"), e);
}
}
- public void configureDefaults()
- throws org.apache.commons.configuration.ConfigurationException {
- File torqueConfigFile = new File("torque.properties");
- if (torqueConfigFile.canRead()) {
- getLog().info("reading torque.properties...");
- torqueConf = new PropertiesConfiguration(torqueConfigFile);
- } else {
- torqueConf = new BaseConfiguration();
- torqueConf.addProperty("torque.database.default",
"mailboxmanager");
- torqueConf.addProperty("torque.database.mailboxmanager.adapter",
- "derby");
- torqueConf.addProperty("torque.dsfactory.mailboxmanager.factory",
- "org.apache.torque.dsfactory.SharedPoolDataSourceFactory");
- torqueConf.addProperty(
- "torque.dsfactory.mailboxmanager.connection.driver",
- "org.apache.derby.jdbc.EmbeddedDriver");
- torqueConf.addProperty(
- "torque.dsfactory.mailboxmanager.connection.url",
- "jdbc:derby:target/testdb;create=true");
- torqueConf.addProperty(
- "torque.dsfactory.mailboxmanager.connection.user", "app");
- torqueConf.addProperty(
- "torque.dsfactory.mailboxmanager.connection.password",
- "app");
- torqueConf.addProperty(
- "torque.dsfactory.mailboxmanager.pool.maxActive", "100");
- }
- configFile = "file://conf/mailboxManagerSqlResources.xml";
- }
- @SuppressWarnings("unchecked")
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.lifecycle.Configurable#configure(org.apache.commons.configuration.HierarchicalConfiguration)
+ */
public void configure(HierarchicalConfiguration conf)
throws ConfigurationException {
- torqueConf = new BaseConfiguration();
- List<HierarchicalConfiguration> tps =
conf.configurationsAt("torque-properties.property");
- for (int i = 0; i < tps.size(); i++) {
- torqueConf.addProperty(tps.get(i).getString("[...@name]"),
tps.get(i).getString("[...@value]"));
- }
configFile = conf.getString("configFile",null);
if (configFile == null) configFile =
"file://conf/mailboxManagerSqlResources.xml";
+ torqueFile = conf.getString("torqueConfigFile",null);
+ if (torqueFile == null) torqueFile = "file://conf/torque.properties";
}
private boolean tableExists(DatabaseMetaData dbMetaData, String tableName)
Modified:
james/server/trunk/spring-deployment/src/main/config/james/james-config.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/config/james/james-config.xml?rev=897295&r1=897294&r2=897295&view=diff
==============================================================================
--- james/server/trunk/spring-deployment/src/main/config/james/james-config.xml
(original)
+++ james/server/trunk/spring-deployment/src/main/config/james/james-config.xml
Fri Jan 8 18:48:56 2010
@@ -1126,31 +1126,8 @@
</handler>
<configFile>file://conf/mailboxManagerSqlResources.xml</configFile>
- <torque-properties>
- <property name="torque.database.default"
- value="mailboxmanager"/>
- <property
- name="torque.database.mailboxmanager.adapter"
- value="derby"/>
- <property
- name="torque.dsfactory.mailboxmanager.factory"
-
value="org.apache.torque.dsfactory.SharedPoolDataSourceFactory"/>
- <property
- name="torque.dsfactory.mailboxmanager.connection.driver"
- value="org.apache.derby.jdbc.EmbeddedDriver"/>
- <property
- name="torque.dsfactory.mailboxmanager.connection.url"
-
value="jdbc:derby:../var/mailboxmanager-derbydb;create=true"/>
- <property
- name="torque.dsfactory.mailboxmanager.connection.user"
- value="app"/>
- <property
- name="torque.dsfactory.mailboxmanager.connection.password"
- value="app"/>
- <property
- name="torque.dsfactory.mailboxmanager.pool.maxActive"
- value="100"/>
- </torque-properties>
+ <!-- File which holds the torque configuration -->
+ <torqueConfigFile>file://conf/torque.properties</torqueConfigFile>
</imapserver>
<!-- The NNTP server is enabled by default -->
Added:
james/server/trunk/spring-deployment/src/main/config/james/torque.properties
URL:
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/config/james/torque.properties?rev=897295&view=auto
==============================================================================
---
james/server/trunk/spring-deployment/src/main/config/james/torque.properties
(added)
+++
james/server/trunk/spring-deployment/src/main/config/james/torque.properties
Fri Jan 8 18:48:56 2010
@@ -0,0 +1,8 @@
+torque.database.default=mailboxmanager
+torque.database.mailboxmanager.adapter=derby
+torque.dsfactory.mailboxmanager.factory=org.apache.torque.dsfactory.SharedPoolDataSourceFactory
+torque.dsfactory.mailboxmanager.connection.driver=org.apache.derby.jdbc.EmbeddedDriver
+torque.dsfactory.mailboxmanager.connection.url=jdbc:derby:../var/mailboxmanager-derbydb;create=true
+torque.dsfactory.mailboxmanager.connection.user=app
+torque.dsfactory.mailboxmanager.connection.password=app
+torque.dsfactory.mailboxmanager.pool.maxActive=100
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]