예제 #1
0
 public void performJNDILookup(Context context, PoolConfiguration poolProperties) {
   Object jndiDS = null;
   try {
     if (context != null) {
       jndiDS = context.lookup(poolProperties.getDataSourceJNDI());
     } else {
       log.warn("dataSourceJNDI property is configued, but local JNDI context is null.");
     }
   } catch (NamingException e) {
     log.debug(
         "The name \""
             + poolProperties.getDataSourceJNDI()
             + "\" can not be found in the local context.");
   }
   if (jndiDS == null) {
     try {
       context = new InitialContext();
       jndiDS = context.lookup(poolProperties.getDataSourceJNDI());
     } catch (NamingException e) {
       log.warn(
           "The name \""
               + poolProperties.getDataSourceJNDI()
               + "\" can not be found in the InitialContext.");
     }
   }
   if (jndiDS != null) {
     poolProperties.setDataSource(jndiDS);
   }
 }
예제 #2
0
 public DataSource createDataSource(Properties properties, Context context, boolean XA)
     throws Exception {
   PoolConfiguration poolProperties = DataSourceFactory.parsePoolProperties(properties);
   if (poolProperties.getDataSourceJNDI() != null && poolProperties.getDataSource() == null) {
     performJNDILookup(context, poolProperties);
   }
   org.apache.tomcat.jdbc.pool.DataSource dataSource =
       XA
           ? new org.apache.tomcat.jdbc.pool.XADataSource(poolProperties)
           : new org.apache.tomcat.jdbc.pool.DataSource(poolProperties);
   // initialise the pool itself
   dataSource.createPool();
   // Return the configured DataSource instance
   return dataSource;
 }