Update of /var/cvs/src/org/mmbase/module/core
In directory james.mmbase.org:/tmp/cvs-serv25964/src/org/mmbase/module/core

Modified Files:
        MMBase.java 
Log Message:
since Datasource is governed by mmbaseroot.xml properties, it is more logical 
that it is acquired there too


See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/module/core


Index: MMBase.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/module/core/MMBase.java,v
retrieving revision 1.249
retrieving revision 1.250
diff -u -b -r1.249 -r1.250
--- MMBase.java 1 Aug 2008 19:20:35 -0000       1.249
+++ MMBase.java 1 Aug 2008 22:15:08 -0000       1.250
@@ -12,6 +12,8 @@
 import java.io.File;
 import java.util.*;
 import java.text.DateFormat;
+import javax.naming.*;
+import javax.sql.DataSource;
 
 import org.mmbase.core.event.*;
 import org.mmbase.datatypes.DataTypes;
@@ -43,7 +45,7 @@
  * @author Pierre van Rooden
  * @author Johannes Verelst
  * @author Ernst Bunders
- * @version $Id: MMBase.java,v 1.249 2008/08/01 19:20:35 michiel Exp $
+ * @version $Id: MMBase.java,v 1.250 2008/08/01 22:15:08 michiel Exp $
  */
 public class MMBase extends ProcessorModule {
 
@@ -1350,6 +1352,31 @@
         return dataDir;
 
     }
+    /**
+     * Returns the datasource as was configured with mmbaseroot.xml properties.
+     * since MMBase-1.9
+     */
+    public DataSource getDataSource() {
+        // get the Datasource for the database to use
+        // the datasource uri (i.e. 'jdbc/xa/MMBase' )
+        // is stored in the mmbaseroot module configuration file
+        String dataSourceURI = getInitParameter("datasource");
+        if (dataSourceURI != null) {
+            try {
+                String contextName = getInitParameter("datasource-context");
+                if (contextName == null) {
+                    contextName = "java:comp/env";
+                }
+                log.service("Using configured datasource " + dataSourceURI);
+                Context initialContext = new InitialContext();
+                Context environmentContext = (Context) 
initialContext.lookup(contextName);
+                return (DataSource)environmentContext.lookup(dataSourceURI);
+            } catch(NamingException ne) {
+                log.warn("Datasource '" + dataSourceURI + "' not available. (" 
+ ne.getMessage() + "). Will attempt to use JDBC Module to access database.");
+            }
+        }
+        return null;
+    }
 
 
 }
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to