Example #1
0
 static void display(ComboPooledDataSource cpds) throws Exception {
   System.err.println("numConnections: " + cpds.getNumConnections());
   System.err.println("numBusyConnections: " + cpds.getNumBusyConnections());
   System.err.println("numIdleConnections: " + cpds.getNumIdleConnections());
   System.err.println(
       "numUnclosedOrphanedConnections: " + cpds.getNumUnclosedOrphanedConnections());
   System.err.println();
 }
  /**
   * Get Status
   *
   * @return status info
   */
  @Override
  public String getStatus() {
    if (m_ds == null) {
      return null;
    }

    StringBuffer sb = new StringBuffer();
    try {
      sb.append("# Connections: ").append(m_ds.getNumConnections());
      sb.append(" , # Busy Connections: ").append(m_ds.getNumBusyConnections());
      sb.append(" , # Idle Connections: ").append(m_ds.getNumIdleConnections());
      sb.append(" , # Orphaned Connections: ").append(m_ds.getNumUnclosedOrphanedConnections());
    } catch (Exception e) {
    }
    return sb.toString();
  } //  getStatus
 /**
  * String Representation
  *
  * @return info
  */
 @Override
 public String toString() {
   StringBuffer sb = new StringBuffer("DB_Oracle[");
   sb.append(m_connectionURL);
   try {
     StringBuffer logBuffer = new StringBuffer(50);
     logBuffer.append("# Connections: ").append(m_ds.getNumConnections());
     logBuffer.append(" , # Busy Connections: ").append(m_ds.getNumBusyConnections());
     logBuffer.append(" , # Idle Connections: ").append(m_ds.getNumIdleConnections());
     logBuffer
         .append(" , # Orphaned Connections: ")
         .append(m_ds.getNumUnclosedOrphanedConnections());
   } catch (Exception e) {
     sb.append("=").append(e.getLocalizedMessage());
   }
   sb.append("]");
   return sb.toString();
 } //  toString
 public Connection getConnection(AccessConfiguration configuration) throws DAOException {
   init(configuration);
   Connection connection = null;
   try {
     if (logger.isTraceEnabled()) logger.trace("Getting connection from pool ");
     if (logger.isTraceEnabled()) logger.trace("    getMaxPoolSize: " + cpds.getMaxPoolSize());
     if (logger.isTraceEnabled())
       logger.trace("    getNumConnections: " + cpds.getNumConnections());
     if (logger.isTraceEnabled())
       logger.trace("    getNumBusyConnections: " + cpds.getNumBusyConnections());
     connection = cpds.getConnection();
     if (logger.isTraceEnabled()) logger.trace("Opened connections: " + cpds.getNumConnections());
   } catch (SQLException sqle) {
     close(connection);
     throw new DAOException(
         " getConnection: "
             + sqle
             + "\n\ndriver: "
             + configuration.getDriver()
             + " - uri: "
             + configuration.getUri()
             + " - login: "******" - password: "******"\n");
   }
   if (connection == null) {
     throw new DAOException(
         "Connection is NULL !"
             + "\n\ndriver: "
             + configuration.getDriver()
             + " - uri: "
             + configuration.getUri()
             + " - login: "******" - password: "******"\n");
   }
   return connection;
 }
Example #5
0
 public int getNumBusyConnections(String username, String password) throws SQLException {
   return combods.getNumBusyConnections(username, password);
 }
  /**
   * Get Cached Connection
   *
   * @param connection info
   * @param autoCommit true if autocommit connection
   * @param transactionIsolation Connection transaction level
   * @return connection or null
   * @throws Exception
   */
  @Override
  public Connection getCachedConnection(
      CConnection connection, boolean autoCommit, int transactionIsolation) throws Exception {
    Connection conn = null;
    Exception exception = null;
    try {
      if (m_ds == null) getDataSource(connection);

      //
      try {
        conn = m_ds.getConnection();
        if (conn != null) {
          if (conn.getTransactionIsolation() != transactionIsolation)
            conn.setTransactionIsolation(transactionIsolation);
          if (conn.getAutoCommit() != autoCommit) conn.setAutoCommit(autoCommit);
          //                      conn.setDefaultRowPrefetch(20);     //  10 default - reduces round
          // trips
        }
      } catch (Exception e) {
        exception = e;
        conn = null;
        if (DBException.isInvalidUserPassError(e)) {
          // log might cause infinite loop since it will try to acquire database connection again
          /*
          log.severe("Cannot connect to database: "
              + getConnectionURL(connection)
              + " - UserID=" + connection.getDbUid());
          */
          System.err.println(
              "Cannot connect to database: "
                  + getConnectionURL(connection)
                  + " - UserID="
                  + connection.getDbUid());
        }
      }

      if (conn == null && exception != null) {
        // log might cause infinite loop since it will try to acquire database connection again
        /*
        log.log(Level.SEVERE, exception.toString());
        log.fine(toString()); */
        System.err.println(exception.toString());
      }
    } catch (Exception e) {
      exception = e;
    }

    try {
      if (conn != null) {
        int numConnections = m_ds.getNumBusyConnections();
        if (numConnections >= m_maxbusyconnections && m_maxbusyconnections > 0) {
          log.warning(getStatus());
          // hengsin: make a best effort to reclaim leak connection
          Runtime.getRuntime().runFinalization();
        }
      }
    } catch (Exception ex) {

    }
    if (exception != null) throw exception;
    return conn;
  } //  getCachedConnection