Exemplo n.º 1
0
  public Collection<Exchange> findByFilter(Filter iFilter)
      throws StockPlayException, FilterException {
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
      try {
        conn = OracleConnection.getConnection();

        StringBuilder tQuery = new StringBuilder(SELECT_EXCHANGES);
        if (!iFilter.empty()) tQuery.append(" WHERE " + (String) iFilter.compile("sql"));
        stmt = conn.prepareStatement(tQuery.toString());

        rs = stmt.executeQuery();
        ArrayList<Exchange> list = new ArrayList<Exchange>();
        while (rs.next()) {
          Exchange tExchange = new Exchange(rs.getString(1));
          tExchange.setName(rs.getString(2));
          tExchange.setLocation(rs.getString(3));
          list.add(tExchange);
        }
        return list;
      } finally {
        if (rs != null) rs.close();
        if (stmt != null) stmt.close();
        if (conn != null) conn.close();
      }
    } catch (SQLException ex) {
      throw new SubsystemException(SubsystemException.Type.DATABASE_FAILURE, ex.getCause());
    }
  }
Exemplo n.º 2
0
  public Exchange findById(String symbol) throws StockPlayException {
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
      try {
        conn = OracleConnection.getConnection();
        stmt = conn.prepareStatement(SELECT_EXCHANGE);

        stmt.setString(1, symbol);

        rs = stmt.executeQuery();
        if (rs.next()) {
          Exchange tExchange = new Exchange(symbol);
          tExchange.setName(rs.getString(1));
          tExchange.setLocation(rs.getString(2));
          return tExchange;
        } else {
          throw new InvocationException(
              InvocationException.Type.NON_EXISTING_ENTITY,
              "There is no security with symbol '" + symbol + "'");
        }
      } finally {
        if (rs != null) {
          rs.close();
        }
        if (stmt != null) {
          stmt.close();
        }
        if (conn != null) {
          conn.close();
        }
      }
    } catch (SQLException ex) {
      throw new SubsystemException(SubsystemException.Type.DATABASE_FAILURE, ex.getCause());
    }
  }