james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gabriel Bucher <gabriel.buc...@razor.ch>
Subject [PATCH] fix dir context problem in JDBC store
Date Tue, 11 Sep 2001 20:16:32 GMT
 > 12. Fix dir context problem in JDBC store
This patches fix the dir context problems in the JDBC store!

file://conf/sqlResources.xml means <james_app_home>/conf/sqlResources.xml

Buchi

PS: I will also take a look into the nntp-repository. I think, there is 
the same to do!


Index: build.xml
===================================================================
RCS file: /home/cvspublic/jakarta-james/build.xml,v
retrieving revision 1.75
diff -u -r1.75 build.xml
--- build.xml	2001/08/11 10:31:17	1.75
+++ build.xml	2001/09/11 19:51:05
@@ -326,7 +326,7 @@
          <include name="activation.jar"/>
          <include name="mail_1_2.jar"/>
          <include name="jakarta-oro-2.0.1.jar"/>
-        <include name="mysql-2.0.4.jar"/>
+<!--        <include name="mysql-2.0.4.jar"/> -->
        </zipfileset>

        <zipfileset dir="${build.conf}" fullpath="conf/config.xml">
@@ -341,6 +341,9 @@
          <include name="james-server.xml"/>
        </zipfileset>

+      <zipfileset dir="${build.conf}" prefix="conf">
+        <include name="sqlResources.xml"/>
+      </zipfileset>
      </jar>

    </target>
@@ -374,6 +377,7 @@
          <include name="jmxtools.jar"/>
          <include name="logkit.jar"/>
          <include name="xerces.jar"/>
+        <include name="mysql-2.0.4.jar"/>
        </fileset>
      </copy>

Index: src/conf/james-config.xml
===================================================================
RCS file: /home/cvspublic/jakarta-james/src/conf/james-config.xml,v
retrieving revision 1.10
diff -u -r1.10 james-config.xml
--- src/conf/james-config.xml	2001/09/11 04:29:30	1.10
+++ src/conf/james-config.xml	2001/09/11 19:52:36
@@ -455,7 +455,7 @@
              <type>MAIL</type>
            </types>
            <config>
-            <sqlFile>dist/conf/sqlResources.xml</sqlFile>
+            <sqlFile>file://conf/sqlResources.xml</sqlFile>
            </config>
          </repository>
          <repository
@@ -467,7 +467,7 @@
              <type>SPOOL</type>
            </types>
            <config>
-            <sqlFile>dist/conf/sqlResources.xml</sqlFile>
+            <sqlFile>file://conf/sqlResources.xml</sqlFile>
              <filestore>file://var/dbspool</filestore>
            </config>
          </repository>
@@ -533,27 +533,27 @@
        <repository name="LocalUsers"
 
class="org.apache.james.userrepository.JamesUsersJdbcRepository"
                    destinationURL="db://maildb/users">
-          <sqlFile>dist/conf/sqlResources.xml</sqlFile>
+          <sqlFile>file://conf/sqlResources.xml</sqlFile>
        </repository>
        <!-- The list used by the default ListServ mailet -->
        <repository name="list-james"
 
class="org.apache.james.userrepository.ListUsersJdbcRepository"
                    destinationURL="db://maildb/lists/list-james">
-          <sqlFile>dist/conf/sqlResources.xml</sqlFile>
+          <sqlFile>file://conf/sqlResources.xml</sqlFile>
        </repository>
        <!-- An example mailinglist repository, with no "listName" parameter
             specified. Uses the default value from the sql definition 
file. -->
        <repository name="list-test"
 
class="org.apache.james.userrepository.ListUsersJdbcRepository"
                    destinationURL="db://maildb/lists">
-          <sqlFile>dist/conf/sqlResources.xml</sqlFile>
+          <sqlFile>file://conf/sqlResources.xml</sqlFile>
        </repository>
        <!-- An example UserRepository for DefaultUser implementations. 
Testing purposes
             only. -->
        <repository name="default-users"
 
class="org.apache.james.userrepository.DefaultUsersJdbcRepository"
                    destinationURL="db://maildb/DefaultUsers">
-          <sqlFile>dist/conf/sqlResources.xml</sqlFile>
+          <sqlFile>file://conf/sqlResources.xml</sqlFile>
        </repository>
    </users-store>

@@ -565,23 +565,23 @@
      <data-sources>
          <!-- Example, connecting to a MySQL database called "mail" on 
localhost
          -->
-        <!--
+
          <data-source name="maildb"
- 
type="org.apache.avalon.excalibur.datasource.JdbcDataSource">
+ 
class="org.apache.avalon.excalibur.datasource.JdbcDataSource">
              <driver>org.gjt.mm.mysql.Driver</driver>
-            <dburl>jdbc:mysql://127.0.0.1/mail</dburl>
-            <user>username</user>
-            <password>password</password>
+            <dburl>jdbc:mysql://127.0.0.1/james</dburl>
+            <user>root</user>
+            <password>root</password>
          </data-source>
-        -->
-
+
+<!--
          <data-source name="maildb"
-        			type="org.apache.avalon.excalibur.datasource.JdbcDataSource">
+        			class="org.apache.avalon.excalibur.datasource.JdbcDataSource">
          	<driver>com.inet.tds.TdsDriver</driver>
          	<dburl>jdbc:inetdae7:127.0.0.1?database=James</dburl>
          	<user>sa_james</user>
          	<password>blahblah</password>
-        </data-source>
+        </data-source> -->
      </data-sources>
    </database-connections>

Index: src/conf/sqlResources.xml
===================================================================
RCS file: /home/cvspublic/jakarta-james/src/conf/sqlResources.xml,v
retrieving revision 1.1
diff -u -r1.1 sqlResources.xml
--- src/conf/sqlResources.xml	2001/09/11 04:29:30	1.1
+++ src/conf/sqlResources.xml	2001/09/11 19:52:42
@@ -117,7 +117,7 @@
      <sql name="createTable" db="mysql">
          CREATE TABLE ${table} (
          	message_name varchar (200) NOT NULL PRIMARY KEY,
-        	repository_name varchar (200) NOT NULL PRIMARY KEY,
+        	repository_name varchar (200) NOT NULL ,
          	message_state varchar (30) NOT NULL ,
          	error_message varchar (200) NULL ,
          	sender varchar (200) NULL ,
Index: src/java/org/apache/james/core/AvalonMailStore.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-james/src/java/org/apache/james/core/AvalonMailStore.java,v
retrieving revision 1.6
diff -u -r1.6 AvalonMailStore.java
--- src/java/org/apache/james/core/AvalonMailStore.java	2001/09/11 04:32:44	1.6
+++ src/java/org/apache/james/core/AvalonMailStore.java	2001/09/11 19:52:44
@@ -20,6 +20,9 @@
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.logger.Loggable;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.james.services.MailRepository;
@@ -38,7 +41,7 @@
   */
  public class AvalonMailStore
      extends AbstractLoggable
-    implements Block, Composable, Configurable, MailStore, Initializable {
+    implements Block, Contextualizable, Composable, Configurable, 
Initializable, MailStore {

      private static final String REPOSITORY_NAME = "Repository";
      private static long id;
@@ -51,11 +54,17 @@
      // map of [Repository Class]->default config for repository.
      private HashMap defaultConfigs;

+    protected Context                context;
      protected Configuration          configuration;
      protected ComponentManager       componentManager;

      private SpoolRepository inboundSpool;

+    public void contextualize(final Context context)
+            throws ContextException {
+        this.context = context;
+    }
+
      public void compose( final ComponentManager componentManager )
          throws ComponentException
      {
@@ -189,11 +198,14 @@
                     if (reply instanceof Loggable) {
  		       setupLogger(reply);
                      }
-                    if (reply instanceof Configurable) {
-                        ((Configurable) reply).configure(config);
+                    if (reply instanceof Contextualizable) {
+                        ((Contextualizable) reply).contextualize(context);
                      }
                      if (reply instanceof Composable) {
                          ((Composable) reply).compose( componentManager );
+                    }
+                    if (reply instanceof Configurable) {
+                        ((Configurable) reply).configure(config);
                      }
                      if (reply instanceof Initializable) {
                          ((Initializable) reply).initialize();
Index: src/java/org/apache/james/core/AvalonUsersStore.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-james/src/java/org/apache/james/core/AvalonUsersStore.java,v
retrieving revision 1.2
diff -u -r1.2 AvalonUsersStore.java
--- src/java/org/apache/james/core/AvalonUsersStore.java	2001/06/10 13:19:57	1.2
+++ src/java/org/apache/james/core/AvalonUsersStore.java	2001/09/11 19:52:44
@@ -19,6 +19,9 @@
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.james.services.UsersRepository;
  import org.apache.james.services.UsersStore;
@@ -30,12 +33,19 @@
   */
  public class AvalonUsersStore
      extends AbstractLoggable
-    implements Block, Composable, Configurable, UsersStore, Initializable {
+    implements Block, Contextualizable, Composable, Configurable, 
Initializable, UsersStore {

      private HashMap repositories;
+    protected Context                context;
      protected Configuration          configuration;
      protected ComponentManager       componentManager;

+
+    public void contextualize(final Context context)
+            throws ContextException {
+        this.context = context;
+    }
+
      public void configure( final Configuration configuration )
          throws ConfigurationException {
          this.configuration = configuration;
@@ -64,18 +74,15 @@

              setupLogger((Component)rep);

+            if (rep instanceof Contextualizable) {
+                ((Contextualizable) rep).contextualize(context);
+            }
              if (rep instanceof Composable) {
                  ((Composable) rep).compose( componentManager );
              }
-
              if (rep instanceof Configurable) {
                  ((Configurable) rep).configure(repConf);
              }
-            /*
-              if (rep instanceof Contextualizable) {
-              ((Contextualizable) rep).contextualize(context);
-              }
-            */
              if (rep instanceof Initializable) {
                  ((Initializable) rep).initialize();
              }
Index: src/java/org/apache/james/mailrepository/AvalonMailRepository.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-james/src/java/org/apache/james/mailrepository/AvalonMailRepository.java,v
retrieving revision 1.7
diff -u -r1.7 AvalonMailRepository.java
--- src/java/org/apache/james/mailrepository/AvalonMailRepository.java	2001/09/11 04:33:08
1.7
+++ src/java/org/apache/james/mailrepository/AvalonMailRepository.java	2001/09/11 19:52:50
@@ -13,6 +13,7 @@
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.util.Iterator;
+import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
@@ -46,7 +47,7 @@
   */
  public class AvalonMailRepository
      extends AbstractLoggable
-    implements MailRepository, Component, Configurable, Composable {
+    implements MailRepository, Component, Configurable, Composable, 
Initializable {

      private Lock lock;
      protected static boolean DEEP_DEBUG = false;
@@ -60,6 +61,7 @@

      public void configure(Configuration conf) throws 
ConfigurationException {
          destination = conf.getAttribute("destinationURL");
+        getLogger().debug("AvalonMailRepository.destinationURL: " + 
destination);
          String checkType = conf.getAttribute("type");
          if (! (checkType.equals("MAIL") || checkType.equals("SPOOL")) ) {
              getLogger().warn( "Attempt to configure 
AvalonMailRepository as " +
@@ -69,12 +71,16 @@
          // ignore model
      }

+
      public void compose( final ComponentManager componentManager )
-        throws ComponentException {
-        try {
-            store = (Store)componentManager.
-                lookup( 
"org.apache.avalon.cornerstone.services.store.Store" );
+            throws ComponentException {
+        store = (Store)componentManager.
+            lookup( "org.apache.avalon.cornerstone.services.store.Store" );
+    }

+    public void initialize()
+            throws Exception {
+        try {
              //prepare Configurations for object and stream repositories
              DefaultConfiguration objectConfiguration
                  = new DefaultConfiguration( "repository",
@@ -99,7 +105,7 @@
          } catch (Exception e) {
              final String message = "Failed to retrieve Store 
component:" + e.getMessage();
              getLogger().error( message, e );
-            throw new ComponentException( message, e );
+            throw e;
          }
      }

Index: src/java/org/apache/james/mailrepository/JDBCMailRepository.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-james/src/java/org/apache/james/mailrepository/JDBCMailRepository.java,v
retrieving revision 1.5
diff -u -r1.5 JDBCMailRepository.java
--- src/java/org/apache/james/mailrepository/JDBCMailRepository.java	2001/09/11 04:33:08	1.5
+++ src/java/org/apache/james/mailrepository/JDBCMailRepository.java	2001/09/11 19:52:53
@@ -14,6 +14,7 @@
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.io.ByteArrayOutputStream;
+import java.io.File;
  import java.io.FileInputStream;
  import java.io.InputStream;
  import java.io.IOException;
@@ -44,7 +45,11 @@
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.logger.AbstractLoggable;
+import org.apache.avalon.phoenix.BlockContext;
  import org.apache.james.core.MimeMessageWrapper;
  import org.apache.james.core.MailImpl;
  import org.apache.james.services.MailRepository;
@@ -74,8 +79,9 @@
   */
  public class JDBCMailRepository
      extends AbstractLoggable
-    implements MailRepository, Component, Configurable, Composable, 
Initializable
+    implements MailRepository, Component, Contextualizable, Composable, 
Configurable, Initializable
  {
+    protected Context context;

      private Lock lock;

@@ -96,6 +102,12 @@
      // Contains all of the sql strings for this component.
      protected SqlResources sqlQueries;

+
+    public void contextualize(final Context context)
+            throws ContextException {
+        this.context = context;
+    }
+
      public void configure(Configuration conf) throws 
ConfigurationException
      {
          getLogger().debug(this.getClass().getName() + ".configure()");
@@ -138,6 +150,10 @@

          filestore = conf.getChild("filestore").getValue(null);
          sqlFileName = conf.getChild("sqlFile").getValue();
+        if (!sqlFileName.startsWith("file://")) {
+            throw new ConfigurationException
+                ("Malformed sqlFile - Must be of the format 
\"file://<filename>\".");
+        }
      }

      public void compose( final ComponentManager componentManager )
@@ -197,7 +213,10 @@

          try{
              // Initialise the sql strings.
-            java.io.File sqlFile = new java.io.File(sqlFileName);
+            String fileName = sqlFileName.substring("file://".length());
+            fileName = ((BlockContext)context).getBaseDirectory() +
+                        File.separator + fileName;
+            File sqlFile = (new File(fileName)).getCanonicalFile();

              String resourceName = 
"org.apache.james.mailrepository.JDBCMailRepository";

Index: 
src/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-james/src/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java,v
retrieving revision 1.1
diff -u -r1.1 AbstractJdbcUsersRepository.java
--- src/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java	2001/09/11 04:34:49
1.1
+++ src/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java	2001/09/11 19:52:57
@@ -18,6 +18,7 @@
  import org.apache.avalon.framework.logger.*;
  import org.apache.avalon.excalibur.datasource.*;
  import 
org.apache.avalon.cornerstone.services.datasource.DataSourceSelector;
+import org.apache.avalon.phoenix.BlockContext;

  import java.sql.*;
  import java.util.*;
@@ -47,8 +48,9 @@
   * @author Darrell DeBoer <dd@bigdaz.com>
   */
  public abstract class AbstractJdbcUsersRepository extends 
AbstractUsersRepository
-    implements UsersRepository, Loggable, Component, Composable, 
Configurable, Initializable
+    implements UsersRepository, Loggable, Component, Contextualizable, 
Composable, Configurable, Initializable
  {
+    protected Context context;
      protected Map m_sqlParameters;
      private String m_sqlFileName;
      private String m_datasourceName;
@@ -71,6 +73,11 @@
      private String m_createUserTableSql;


+    public void contextualize(final Context context)
+            throws ContextException {
+        this.context = context;
+    }
+
      /**
       * Compose the repository with the DataSourceSelector component.
       */
@@ -140,6 +147,10 @@

          // Get the SQL file location
          m_sqlFileName = configuration.getChild("sqlFile", 
true).getValue();
+        if (!m_sqlFileName.startsWith("file://")) {
+            throw new ConfigurationException
+                ("Malformed sqlFile - Must be of the format 
\"file://<filename>\".");
+        }

          // Get other sql parameters from the configuration object,
          // if any.
@@ -174,7 +185,10 @@
              DatabaseMetaData dbMetaData = conn.getMetaData();

              // Initialise the sql strings.
-            java.io.File sqlFile = new java.io.File(m_sqlFileName);
+            String fileName = m_sqlFileName.substring("file://".length());
+            fileName = ((BlockContext)context).getBaseDirectory() +
+                        File.separator + fileName;
+            File sqlFile = (new File(fileName)).getCanonicalFile();

              getLogger().debug("Reading SQL resources from file: " +
                                sqlFile.getAbsolutePath() + ", section " +


---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org


Mime
View raw message