Repository: cayenne
Updated Branches:
  refs/heads/master 4116471c1 -> 92ecdfe6d


CAY-2009 Non-blocking connection pool

* no need for special formatting of logs in JNDIDataSourceFactory,
  (moreover what it does is not connection, but JNDI lookup),
   so using JCL logger instead of JdbcEventLogger


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/92ecdfe6
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/92ecdfe6
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/92ecdfe6

Branch: refs/heads/master
Commit: 92ecdfe6d3076fc89aba7aacc2f1f6c02ea14ef3
Parents: 4116471
Author: aadamchik <[email protected]>
Authored: Tue May 19 10:57:01 2015 +0300
Committer: aadamchik <[email protected]>
Committed: Tue May 19 11:11:29 2015 +0300

----------------------------------------------------------------------
 .../server/JNDIDataSourceFactory.java           | 76 +++++++++-----------
 1 file changed, 35 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/92ecdfe6/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/JNDIDataSourceFactory.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/JNDIDataSourceFactory.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/JNDIDataSourceFactory.java
index fb90ea1..786cc99 100644
--- 
a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/JNDIDataSourceFactory.java
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/JNDIDataSourceFactory.java
@@ -25,8 +25,6 @@ import javax.sql.DataSource;
 
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.configuration.DataNodeDescriptor;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.log.JdbcEventLogger;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -37,51 +35,47 @@ import org.apache.commons.logging.LogFactory;
  */
 public class JNDIDataSourceFactory implements DataSourceFactory {
 
-    private static final Log logger = 
LogFactory.getLog(JNDIDataSourceFactory.class);
-    
-    @Inject
-    protected JdbcEventLogger jdbcEventLogger;
+       private static final Log LOGGER = 
LogFactory.getLog(JNDIDataSourceFactory.class);
 
-    @Override
-    public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) throws 
Exception {
+       @Override
+       public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) 
throws Exception {
 
-        String location = getLocation(nodeDescriptor);
+               String location = getLocation(nodeDescriptor);
 
-        try {
-            return lookupViaJNDI(location);
-        }
-        catch (Exception ex) {
-            logger.info("failed JNDI lookup of DataSource location '" + 
location + "'");
-            jdbcEventLogger.logConnectFailure(ex);
-            throw ex;
-        }
-    }
-    
-    protected String getLocation(DataNodeDescriptor nodeDescriptor) {
-        String location = nodeDescriptor.getParameters();
-        if (location == null) {
-            throw new CayenneRuntimeException("Null 'location' for 
nodeDescriptor '%s'", nodeDescriptor.getName());
-        }
+               try {
+                       return lookupViaJNDI(location);
+               } catch (Exception e) {
+                       LOGGER.info("*** failed JNDI lookup of DataSource at 
location: " + location, e);
+                       throw e;
+               }
+       }
 
-        return location;
-    }
+       protected String getLocation(DataNodeDescriptor nodeDescriptor) {
+               String location = nodeDescriptor.getParameters();
+               if (location == null) {
+                       throw new CayenneRuntimeException("Null 'location' for 
nodeDescriptor '%s'", nodeDescriptor.getName());
+               }
 
-    DataSource lookupViaJNDI(String location) throws NamingException {
-        jdbcEventLogger.logConnect(location);
+               return location;
+       }
 
-        Context context = new InitialContext();
-        DataSource dataSource;
-        try {
-            Context envContext = (Context) context.lookup("java:comp/env");
-            dataSource = (DataSource) envContext.lookup(location);
-        }
-        catch (NamingException namingEx) {
-            // try looking up the location directly...
-            dataSource = (DataSource) context.lookup(location);
-        }
+       DataSource lookupViaJNDI(String location) throws NamingException {
 
-        jdbcEventLogger.logConnectSuccess();
-        return dataSource;
-    }
+               LOGGER.info("Connecting. JNDI path: " + location);
+
+               Context context = new InitialContext();
+               DataSource dataSource;
+               try {
+                       Context envContext = (Context) 
context.lookup("java:comp/env");
+                       dataSource = (DataSource) envContext.lookup(location);
+               } catch (NamingException namingEx) {
+                       // try looking up the location directly...
+                       dataSource = (DataSource) context.lookup(location);
+               }
+
+               LOGGER.info("Found JNDI DataSource at location: " + location);
+
+               return dataSource;
+       }
 
 }

Reply via email to