/** Creates a Pooled connection and adds it to the connection pool. */
  private void installConnection() throws EmanagerDatabaseException {
    logger.debug("enter");

    PooledConnection connection;

    try {
      connection = poolDataSource.getPooledConnection();
      connection.addConnectionEventListener(this);
      connection.getConnection().setAutoCommit(false);
      synchronized (connectionPool) {
        connectionPool.add(connection);
        logger.debug("Database connection added.");
      }
    } catch (SQLException ex) {
      logger.fatal("exception caught while obtaining database " + "connection: ex = " + ex);
      SQLException ex1 = ex.getNextException();
      while (ex1 != null) {
        logger.fatal("chained sql exception ex1 = " + ex1);
        SQLException nextEx = ex1.getNextException();
        ex1 = nextEx;
      }
      String logString;
      EmanagerDatabaseException ede;

      logString =
          EmanagerDatabaseStatusCode.DatabaseConnectionFailure.getStatusCodeDescription()
              + ex.getMessage();

      logger.fatal(logString);
      ede =
          new EmanagerDatabaseException(
              EmanagerDatabaseStatusCode.DatabaseConnectionFailure, logString);
      throw ede;
    }
  }
Ejemplo n.º 2
0
 public List<PromoterRowGateway> findAll() {
   List result = new ArrayList();
   List promoters = jdbcTemplate.queryForList(findAllStatement);
   for (int i = 0; i < promoters.size(); i++)
     result.add(PromoterRowGateway.load(dataSource, (Map) promoters.get(i)));
   return result;
 }
Ejemplo n.º 3
0
  /**
   * Elimina registro de base de datos
   *
   * @param
   * @return
   * @throws
   */
  public void delete() {
    if (jdbcTemplate == null) createJdbcTemplate();

    List categories = jdbcTemplate.queryForList(findCategoryProductStatement, idCategory);

    if (categories.size() < 1) jdbcTemplate.update(deleteStatement, idCategory);
  }
Ejemplo n.º 4
0
 public List retrieveAttachmentsByCustomerId(long customerId) throws RemoteException {
   List attachments = new ArrayList();
   AttachmentDAO attachmentDAO = new AttachmentDAO(conn);
   attachments = attachmentDAO.retrieveAttachmentsByCustomerId(customerId);
   USFEnv.getLog().writeDebug("attachments size is......" + attachments.size(), this, null);
   return attachments;
 }
  /**
   * @param arg0
   * @roseuid 3F4E5F400123
   */
  public void connectionClosed(ConnectionEvent event) {
    logger.debug("Enter: " + event.getSource());

    synchronized (connectionPool) {
      if (!SHUTTING_DOWN) {
        if (connectionPool.size() < connectionPoolSize) {
          logger.debug("Reading Connection: " + event.getSource());

          connectionPool.add(event.getSource());
        }
      }
    }
  }
  /**
   * @param arg0
   * @roseuid 3F4E5F40012D
   */
  public void connectionErrorOccurred(ConnectionEvent event) {
    logger.debug("Connection Error " + event.getSQLException().getMessage());

    synchronized (connectionPool) {
      if (connectionPool.size() <= connectionPoolSize) {
        connectionPool.remove(event.getSource());
        if (!SHUTTING_DOWN) {
          try {
            installConnection();
          } catch (EmanagerDatabaseException e) {
            // noop.  can't throw an exception here, so we'll ignore.
            // It will surface later.
          }
        }
      }
    }
  }
  /** @roseuid 3F3A89D40175 */
  public void shutdown() {
    logger.debug("Enter");

    Iterator iter;
    PooledConnection pooledConnection;

    SHUTTING_DOWN = true;
    iter = connectionPool.iterator();
    while (iter.hasNext()) {
      pooledConnection = (PooledConnection) iter.next();

      try {
        if (!pooledConnection.getConnection().isClosed()) {
          pooledConnection.getConnection().close();
        }
      } catch (Exception ex) {
        // We don't care what happens here, we're on the way out!
      }
    }

    connectionPool.clear();
  }
Ejemplo n.º 8
0
  public static List<Movie> getAllMovies() {
    String query = "SELECT * FROM movie";
    List<Movie> movies = new LinkedList<>();
    try (Connection connection = Config.getConnection(); // step 1
        Statement statement = connection.createStatement(); // step 2
        ResultSet result = statement.executeQuery(query); ) { // step 3 and 4
      while (result.next()) { // step 5
        Movie movie = new Movie();
        // you should be validating the following,
        // this is just an example to get you started
        movie.setName(result.getString(1));
        movie.setYear(result.getDate(2).getYear());
        movie.setUrl(result.getString(3));
        movies.add(movie);
      }
    } catch (SQLException e) {
      System.err.println(e.getMessage());
      System.err.println(e.getStackTrace());
    }

    return movies;
  }
 public CFBamDataScopeBuff[] readAllDerived(CFSecurityAuthorization Authorization) {
   final String S_ProcName = "readAllDerived";
   String rqst =
       CFBamXMsgSchemaMessageFormatter.formatRqstXmlPreamble()
           + "\n"
           + "\t"
           + CFBamXMsgDataScopeMessageFormatter.formatDataScopeRqstReadAll("\n\t\t\t")
           + "\n"
           + CFBamXMsgSchemaMessageFormatter.formatRqstXmlPostamble();
   try {
     schema.getCFTipClientHandler().issueAppRequest(rqst);
   } catch (BadPaddingException e) {
     throw CFLib.getDefaultExceptionFactory()
         .newRuntimeException(
             getClass(), S_ProcName, "Caught BadPaddingException - " + e.getMessage(), e);
   } catch (IllegalBlockSizeException e) {
     throw CFLib.getDefaultExceptionFactory()
         .newRuntimeException(
             getClass(), S_ProcName, "Caught IllegalBlockSizeException - " + e.getMessage(), e);
   } catch (InvalidKeyException e) {
     throw CFLib.getDefaultExceptionFactory()
         .newRuntimeException(
             getClass(), S_ProcName, "Caught InvalidKeyException - " + e.getMessage(), e);
   } catch (NoSuchAlgorithmException e) {
     throw CFLib.getDefaultExceptionFactory()
         .newRuntimeException(
             getClass(), S_ProcName, "Caught NoSuchAlgorithmException - " + e.getMessage(), e);
   } catch (InvalidAlgorithmParameterException e) {
     throw CFLib.getDefaultExceptionFactory()
         .newRuntimeException(
             getClass(),
             S_ProcName,
             "Caught InvalidAlgorithmParameterException - " + e.getMessage(),
             e);
   } catch (NoSuchPaddingException e) {
     throw CFLib.getDefaultExceptionFactory()
         .newRuntimeException(
             getClass(), S_ProcName, "Caught NoSuchPaddingException - " + e.getMessage(), e);
   }
   ICFTipResponseHandler responseHandler = schema.getCFTipClientHandler().getResponseHandler();
   CFLibRuntimeException exceptionRaised = responseHandler.getExceptionRaised();
   if (exceptionRaised != null) {
     throw exceptionRaised;
   }
   Object sortedListObj = responseHandler.getListOfObjects();
   if (sortedListObj == null) {
     throw CFLib.getDefaultExceptionFactory()
         .newNullArgumentException(getClass(), S_ProcName, 0, "responseHandler.getListOfObjects");
   }
   @SuppressWarnings("unchecked")
   List<ICFBamDataScopeObj> sortedList = (List<ICFBamDataScopeObj>) sortedListObj;
   int sz = sortedList.size();
   CFBamDataScopeBuff arr[] = new CFBamDataScopeBuff[sz];
   Iterator<ICFBamDataScopeObj> iter = sortedList.iterator();
   ICFBamDataScopeObj cur;
   for (int idx = 0; idx < sz; idx++) {
     cur = (ICFBamDataScopeObj) iter.next();
     arr[idx] = cur.getDataScopeBuff();
   }
   return (arr);
 }
Ejemplo n.º 10
0
 public List<Customer> findCustomers(String id, String match, int limit) {
   Connection connection = null;
   CallableStatement callableStatement = null;
   ResultSet resultSet = null;
   boolean hasResults;
   List<Customer> customers = new ArrayList<Customer>();
   try {
     connection = dataSource.getConnection(); // get connection from dataSource
     connection.setTransactionIsolation(
         Connection.TRANSACTION_READ_COMMITTED); // prevent dirty reads
     callableStatement = connection.prepareCall(listCustomersSql); // prepare callable statement
     if (id == null) {
       callableStatement.setNull(1, Types.INTEGER);
     } else {
       callableStatement.setInt(1, Integer.parseInt(id));
     }
     if (match == null) {
       callableStatement.setNull(2, Types.VARCHAR);
     } else {
       callableStatement.setString(2, match);
     }
     callableStatement.setInt(3, limit);
     callableStatement.setNull(4, Types.INTEGER);
     hasResults = callableStatement.execute();
     if (hasResults) {
       resultSet = callableStatement.getResultSet();
       if (resultSet.isBeforeFirst()) { // customers have been returned
         while (resultSet.next()) {
           customers.add(
               new Customer(
                   resultSet.getString("id"),
                   resultSet.getString("first_name"),
                   resultSet.getString("last_name"),
                   resultSet.getString("street_address"),
                   resultSet.getString("apt_address"),
                   resultSet.getString("city"),
                   resultSet.getString("state"),
                   resultSet.getString("zip"),
                   resultSet.getString("phone"),
                   resultSet.getString("email"),
                   resultSet.getString("notes")));
         }
       } else {
         log.debug("No customers returned.");
       }
     } else {
       log.debug("No customers returned.");
     }
   } catch (SQLException se) {
     log.error("SQL error: ", se);
     return null;
   } finally {
     try {
       resultSet.close();
     } catch (Exception se) {
       log.error("Unable to close resultSet: ", se);
     }
     try {
       callableStatement.close();
     } catch (Exception se) {
       log.error("Unable to close callableStatement: ", se);
     }
     try {
       connection.close();
     } catch (Exception se) {
       log.error("Unable to close connection: ", se);
     }
   }
   return customers;
 }
Ejemplo n.º 11
0
 public PromoterRowGateway find(int code) {
   List promoters = jdbcTemplate.queryForList(findStatement, code);
   PromoterRowGateway promoter = PromoterRowGateway.load(dataSource, (Map) promoters.get(0));
   return promoter;
 }
  /**
   * @return Connection
   * @roseuid 3F3A5FFD0338
   */
  public Connection getConnection() throws EmanagerDatabaseException {
    long connectionId;
    Connection connection;
    PooledConnection pooledConnection;

    connection = null;
    pooledConnection = null;
    connectionId = InvalidConnectionId;

    try {
      synchronized (connectionPool) {
        if (!connectionPool.isEmpty()) {
          try {
            boolean connectionClosed;

            connectionClosed = false;

            pooledConnection = (PooledConnection) connectionPool.remove(0);
            connection = pooledConnection.getConnection();
            connection.clearWarnings();
            connectionId = getConnectionID(connection);
            connectionClosed = connection.isClosed();
            if (connectionId == InvalidConnectionId || connectionClosed == true) {
              logger.debug("Pooled connection closed.");
              connection = null;
            }
          } catch (SQLException sqe) {
            logger.debug("Pooled connection closed.");
            connection = null;
          }
        }
      }

      if (connection == null) {
        logger.debug("Getting a new connection.");
        pooledConnection = poolDataSource.getPooledConnection();
        pooledConnection.addConnectionEventListener(this);
        connection = pooledConnection.getConnection();
        connection.clearWarnings();
        connectionId = getConnectionID(connection);
      }
    } catch (SQLException sqe) {
      String logString;
      EmanagerDatabaseException ede;

      logString =
          EmanagerDatabaseStatusCode.UnableToGetPooledConnection.getStatusCodeDescription()
              + sqe.getMessage();

      logger.error(logString);
      ede =
          new EmanagerDatabaseException(
              EmanagerDatabaseStatusCode.UnableToGetPooledConnection, logString);
      throw ede;
    }

    if (connectionId == InvalidConnectionId) {
      EmanagerDatabaseException ede;
      ede =
          new EmanagerDatabaseException(
              EmanagerDatabaseStatusCode.UnableToGetPooledConnection,
              EmanagerDatabaseStatusCode.UnableToGetPooledConnection.getStatusCodeDescription());
      throw ede;
    }

    logger.debug(
        "\n*****************************"
            + "\nPooled Connection Init"
            + "\nCon ID:"
            + connectionId
            + "\nCon Object:"
            + pooledConnection
            + "\nPool Object:"
            + connection
            + "\n*****************************");

    return connection;
  }
 public CFFreeSwitchFSSFProfileDomainBuff[] readDerivedByUNameIdx(
     CFSecurityAuthorization Authorization,
     long argTenantId,
     long argFSSFProfileId,
     String argName) {
   final String S_ProcName = "readDerivedByUNameIdx";
   String rqst =
       CFFreeSwitchXMsgSchemaMessageFormatter.formatRqstXmlPreamble()
           + "\n"
           + "\t"
           + CFFreeSwitchXMsgFSSFProfileDomainMessageFormatter
               .formatFSSFProfileDomainRqstReadByUNameIdx(
                   "\n\t\t\t", argTenantId, argFSSFProfileId, argName)
           + "\n"
           + CFFreeSwitchXMsgSchemaMessageFormatter.formatRqstXmlPostamble();
   try {
     schema.getCFTipClientHandler().issueAppRequest(rqst);
   } catch (BadPaddingException e) {
     throw CFLib.getDefaultExceptionFactory()
         .newRuntimeException(
             getClass(), S_ProcName, "Caught BadPaddingException - " + e.getMessage(), e);
   } catch (IllegalBlockSizeException e) {
     throw CFLib.getDefaultExceptionFactory()
         .newRuntimeException(
             getClass(), S_ProcName, "Caught IllegalBlockSizeException - " + e.getMessage(), e);
   } catch (InvalidKeyException e) {
     throw CFLib.getDefaultExceptionFactory()
         .newRuntimeException(
             getClass(), S_ProcName, "Caught InvalidKeyException - " + e.getMessage(), e);
   } catch (NoSuchAlgorithmException e) {
     throw CFLib.getDefaultExceptionFactory()
         .newRuntimeException(
             getClass(), S_ProcName, "Caught NoSuchAlgorithmException - " + e.getMessage(), e);
   } catch (InvalidAlgorithmParameterException e) {
     throw CFLib.getDefaultExceptionFactory()
         .newRuntimeException(
             getClass(),
             S_ProcName,
             "Caught InvalidAlgorithmParameterException - " + e.getMessage(),
             e);
   } catch (NoSuchPaddingException e) {
     throw CFLib.getDefaultExceptionFactory()
         .newRuntimeException(
             getClass(), S_ProcName, "Caught NoSuchPaddingException - " + e.getMessage(), e);
   }
   ICFTipResponseHandler responseHandler = schema.getCFTipClientHandler().getResponseHandler();
   CFLibRuntimeException exceptionRaised = responseHandler.getExceptionRaised();
   if (exceptionRaised != null) {
     throw exceptionRaised;
   }
   Object sortedListObj = responseHandler.getListOfObjects();
   @SuppressWarnings("unchecked")
   List<ICFFreeSwitchFSSFProfileDomainObj> sortedList =
       (List<ICFFreeSwitchFSSFProfileDomainObj>) sortedListObj;
   CFFreeSwitchFSSFProfileDomainBuff arr[];
   if (sortedList != null) {
     int sz = sortedList.size();
     arr = new CFFreeSwitchFSSFProfileDomainBuff[sz];
     Iterator<ICFFreeSwitchFSSFProfileDomainObj> iter = sortedList.iterator();
     ICFFreeSwitchFSSFProfileDomainObj cur;
     for (int idx = 0; idx < sz; idx++) {
       cur = (ICFFreeSwitchFSSFProfileDomainObj) iter.next();
       arr[idx] = cur.getFSSFProfileDomainBuff();
     }
   } else {
     arr = new CFFreeSwitchFSSFProfileDomainBuff[0];
   }
   return (arr);
 }