예제 #1
0
  private void displayDS(String connectionName, String where) {
    try {
      DataSource ds = null;
      if (connectionName == null) {
        ds = (DataSource) DatabaseConfig.getInstance().getPooledDataSource();
      } else {
        ds = (DataSource) DatabaseConfig.getInstance().getPooledDataSource(connectionName);
      }

      // make sure it's a c3p0 PooledDataSource
      if (ds != null && (ds instanceof PooledDataSource)) {
        PooledDataSource pds = (PooledDataSource) ds;
        log.debug(
            "displayDS for "
                + where
                + " -      num_connections: "
                + pds.getNumConnectionsDefaultUser());
        log.debug(
            "displayDS for "
                + where
                + " - num_busy_connections: "
                + pds.getNumBusyConnectionsDefaultUser());
        log.debug(
            "displayDS for "
                + where
                + " - num_idle_connections: "
                + pds.getNumIdleConnectionsDefaultUser());
      }
    } catch (Exception ex) {
      log.debug("displayDS for " + where + " - ERROR: " + ex.getMessage());
    }
  }
  /**
   * Create a UserDatabaseConnection instance based on connection name. The properties related to
   * the name must be in the properties file.
   *
   * @param connectionName a connection name
   * @return UserDatabaseConnection
   */
  public UserDatabaseConnection createUserDatabaseConnection(String connectionName) {
    if (connectionName == null || connectionName.equals(""))
      throw new CreateConnectionFailureException(
          "Failed to create a database connection: connection name is null.");

    Properties prop =
        DatabaseConfig.getInstance().getPredefinedDatabaseConnectionProperties(connectionName);

    return buildUserDatabaseConnection(connectionName, prop);
  }
예제 #3
0
  public Transaction createTransaction(String type) {
    Transaction ts = null;
    boolean userTransactionAlreadyStarted = false;
    UserTransaction ut = null;

    if (type == null) {
      ut = lookupUserTransaction();

      if (TransactionUtil.isUserTransactionActive(ut)) {
        log.info("UserTransaction has started: Use JtaTransaction");
        type = Transaction.JTA_TRANSACTION_TYPE;
        userTransactionAlreadyStarted = true;
      } else // ignore the UserTransaction
      {
        // check if there is any default connection name specified in property file
        type = DatabaseConfig.getInstance().getDefaultTransactionType();
        if (type == null || type.equals("")) {
          log.warn(
              "No default transaction type specified in "
                  + "property file. Use JdbcTransaction as default.");
          type = Transaction.JDBC_TRANSACTION_TYPE;
        }
      }
    }

    if (type.equalsIgnoreCase(Transaction.JDBC_TRANSACTION_TYPE)) {
      ts = new JdbcTransaction();
    } else if (type.equalsIgnoreCase(Transaction.JTA_TRANSACTION_TYPE)) {
      if (userTransactionAlreadyStarted) {
        ts = new JtaTransaction(ut);
      } else {
        ts = new JtaTransaction();
      }
    } else if (type.equalsIgnoreCase(Transaction.CMT_TRANSACTION_TYPE)) {
      ts = new CmtTransaction();
    } else {
      throw new TransactionException(
          "TransactionFactory:createTransaction() failed. Type: " + type + ".");
    }

    return ts;
  }
 /**
  * Create a UserDatabaseConnection instance based on the default connection name in the properties
  * file.
  *
  * @return UserDatabaseConnection
  */
 public UserDatabaseConnection createUserDatabaseConnection() {
   // check if there is any default connection name specified in property file
   String connectionName = DatabaseConfig.getInstance().getDefaultDatabaseConnectionName();
   return createUserDatabaseConnection(connectionName);
 }