Package jodd.db

Examples of jodd.db.DbSqlException


    try {
      InitialContext initialContext = new InitialContext();

      this.dataSource = (DataSource) initialContext.lookup(jndiName);
    } catch (NamingException nex) {
      throw new DbSqlException("Invalid JNDI datasource name: " + jndiName, nex);
    }
    this.username = user;
    this.password = pass;
  }
View Full Code Here


        return dataSource.getConnection(username, password);
      } else {
        return dataSource.getConnection();
      }
    } catch (SQLException sex) {
      throw new DbSqlException("Invalid datasource connection", sex);
    }
  }
View Full Code Here

    log.debug("Requesting db TX manager session");

    DbJtxTransaction jtx = (DbJtxTransaction) jtxTxManager.getTransaction();

    if (jtx == null) {
      throw new DbSqlException(
          "No transaction is in progress and DbSession can't be provided. " +
          "It seems that transaction manager is not used to begin a transaction.");
    }

    return jtx.requestResource();
View Full Code Here

      log.info("Core connection pool initialization");
    }
    try {
      Class.forName(driver);
    } catch (ClassNotFoundException cnfex) {
      throw new DbSqlException("Database driver not found: " + driver, cnfex);
    }
    if (minConnections > maxConnections) {
      minConnections = maxConnections;
    }
    availableConnections = new ArrayList<ConnectionData>(maxConnections);
    busyConnections = new ArrayList<ConnectionData>(maxConnections);
    for (int i = 0; i < minConnections; i++) {
      try {
        Connection conn = DriverManager.getConnection(url, user, password);
        availableConnections.add(new ConnectionData(conn));
      } catch (SQLException sex) {
        throw new DbSqlException("No database connection", sex);
      }
    }
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  public synchronized Connection getConnection() {
    if (availableConnections == null) {
      throw new DbSqlException("Connection pool is not initialized");
    }
    if (availableConnections.isEmpty() == false) {
      int lastIndex = availableConnections.size() - 1;
      ConnectionData existingConnection = availableConnections.get(lastIndex);
      availableConnections.remove(lastIndex);
     
      // If conn on available list is closed (e.g., it timed out), then remove it from available list
      // and repeat the process of obtaining a conn. Also wake up threads that were waiting for a
      // conn because maxConnection limit was reached.
      long now = System.currentTimeMillis();
      boolean isValid = isConnectionValid(existingConnection, now);
      if (isValid == false) {
        if (log.isDebugEnabled()) {
          log.debug("Pooled connection not valid, resetting");
        }

        notifyAll();         // freed up a spot for anybody waiting
        return getConnection();
      } else {
        if (log.isDebugEnabled()) {
          log.debug("Returning valid pooled connection");
        }

        busyConnections.add(existingConnection);
        existingConnection.lastUsed = now;
        return existingConnection.connection;
      }
    }
    if (log.isDebugEnabled()) {
      log.debug("No more available connections");
    }

    // no available connections
    if (((availableConnections.size() + busyConnections.size()) < maxConnections) && !connectionPending) {
      makeBackgroundConnection();
    } else if (!waitIfBusy) {
      throw new DbSqlException("Connection limit reached: " + maxConnections);
    }
    // wait for either a new conn to be established (if you called makeBackgroundConnection) or for
    // an existing conn to be freed up.
    try {
      wait();
View Full Code Here

TOP

Related Classes of jodd.db.DbSqlException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.