コード例 #1
0
  /**
   * Lookup resource.
   *
   * @param resource the resource
   * @param contextBound the context bound
   * @param global the global
   */
  public void lookupResource(ApplicationResource resource, boolean contextBound, boolean global) {
    DataSourceInfo dataSourceInfo = null;
    if (contextBound) {
      try {
        javax.naming.Context ctx = !global ? new InitialContext() : getGlobalNamingContext();
        String jndiName = resolveJndiName(resource.getName(), global);
        Object obj = ctx.lookup(jndiName);
        resource.setLookedUp(true);
        for (DatasourceAccessor accessor : datasourceMappers) {
          dataSourceInfo = accessor.getInfo(obj);
          if (dataSourceInfo != null) {
            break;
          }
        }

      } catch (Throwable e) {
        resource.setLookedUp(false);
        dataSourceInfo = null;
        logger.error("Failed to lookup: " + resource.getName(), e);
        //
        // make sure we always re-throw ThreadDeath
        //
        if (e instanceof ThreadDeath) {
          throw (ThreadDeath) e;
        }
      }
    } else {
      resource.setLookedUp(false);
    }

    /*
     * Tomcat 5.0.x DBCP datasources would have URL set to null if they incorrectly configured so we
     * need to deal with this little feature
     */
    if (dataSourceInfo != null && dataSourceInfo.getJdbcUrl() == null) {
      resource.setLookedUp(false);
    }

    if (resource.isLookedUp() && dataSourceInfo != null) {
      resource.setDataSourceInfo(dataSourceInfo);
    }
  }
コード例 #2
0
  /* (non-Javadoc)
   * @see com.googlecode.psiprobe.beans.DatasourceAccessor#getInfo(java.lang.Object)
   */
  public DataSourceInfo getInfo(Object resource) throws Exception {
    DataSourceInfo dataSourceInfo = null;

    if (canMap(resource)) {
      OracleDataSource source = (OracleDataSource) resource;
      OracleConnectionCacheManager occm =
          OracleConnectionCacheManager.getConnectionCacheManagerInstance();
      Properties cacheProperties = source.getConnectionCacheProperties();
      String cacheName = source.getConnectionCacheName();
      cacheName = cacheName != null && occm.existsCache(cacheName) ? cacheName : null;

      if (cacheProperties != null) {

        dataSourceInfo = new DataSourceInfo();
        if (cacheName != null) {
          dataSourceInfo.setBusyConnections(occm.getNumberOfActiveConnections(cacheName));
          dataSourceInfo.setEstablishedConnections(
              occm.getNumberOfAvailableConnections(cacheName)
                  + dataSourceInfo.getBusyConnections());
        } else {
          dataSourceInfo.setBusyConnections(0);
          dataSourceInfo.setEstablishedConnections(0);
        }

        dataSourceInfo.setMaxConnections(Utils.toInt(cacheProperties.getProperty("MaxLimit"), -1));
        dataSourceInfo.setJdbcUrl(source.getURL());
        dataSourceInfo.setUsername(source.getUser());
        dataSourceInfo.setResettable(true);
        dataSourceInfo.setType("oracle-jdbc");
      }
    }
    return dataSourceInfo;
  }