Commits

hani  committed 946dfc1

Removed dependency on EJBUtils

git-svn-id: http://svn.opensymphony.com/svn/propertyset/trunk@133bf3cbcdd-1c1a-0410-9a68-d6f521e3fa7b

  • Participants
  • Parent commits 3f9ecb6

Comments (0)

Files changed (1)

File src/java/com/opensymphony/module/propertyset/database/JDBCPropertySet.java

 import com.opensymphony.module.propertyset.*;
 
 import com.opensymphony.util.Data;
-import com.opensymphony.util.EJBUtils;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import java.util.*;
 import java.util.Date;
 
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
 import javax.sql.DataSource;
 
 
         globalKey = (String) args.get("globalKey");
 
         // config
-        try {
-            ds = (DataSource) EJBUtils.lookup((String) config.get("datasource"));
-        } catch (Exception e) {
-            log.fatal("Could not get DataSource", e);
+        String jndi = (String) config.get("datasource");
+
+        if (jndi != null) {
+            try {
+                ds = (DataSource) lookup(jndi);
+
+                if (ds == null) {
+                    ds = (DataSource) new javax.naming.InitialContext().lookup(jndi);
+                }
+            } catch (Exception e) {
+                log.fatal("Error looking up DataSource at " + jndi, e);
+
+                return;
+            }
         }
 
         tableName = (String) config.get("table.name");
             log.error("Could not close connection");
         }
     }
+
+    private Object lookup(String location) throws NamingException {
+        try {
+            InitialContext context = new InitialContext();
+
+            try {
+                return context.lookup(location);
+            } catch (NamingException e) {
+                //ok, couldn't find it, look in env
+                return context.lookup("java:comp/env/" + location);
+            }
+        } catch (NamingException e) {
+            throw e;
+        }
+    }
 }