Пример #1
0
  public ConnectionHandler(ConnectionConfig conConfig) {
    this.conConfig = conConfig;

    if (conConfig.isPooled()) {
      initializeConnectionPool();
    } else {
      try {
        Class.forName(conConfig.getDriver());
      } catch (ClassNotFoundException e) {
        throw new IllegalStateException(
            "The configured driver '" + conConfig.getDriver() + "' can not be found.");
      }
    }
  }
Пример #2
0
 /**
  * Borrow a new connection.
  *
  * @return
  * @throws SQLException
  */
 public Connection getConnection() throws SQLException {
   connCount++;
   if (connCount == Long.MAX_VALUE) {
     connCount = Long.MIN_VALUE;
   }
   Connection conn = null;
   if (conConfig.isPooled()) {
     conn = ds.getConnection();
   } else {
     // Open connection directly
     conn =
         DriverManager.getConnection(
             conConfig.getUrl(), conConfig.getUsername(), conConfig.getPassword());
   }
   if (conConfig.isTraced()) {
     TracedConnection tc = new TracedConnection(connCount, this, conn);
     conn = tc;
     connectionList.add(tc);
   }
   return conn;
 }