public ArrayList<String> getCollections() {
    ArrayList<String> collections = new ArrayList<String>();
    ConnectionManager connManager = ConnectionManager.getInstance();
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {
      conn = connManager.getConnection();
      stmt = SqlManager.getInstance().getSqlStatement(conn, "SELECT.COLLECTIONS");
      rs = stmt.executeQuery();

      while (rs.next()) {
        String name = rs.getString("name");
        collections.add(name);
      }
    } catch (SQLException e) {
      throw new RuntimeException("Error reading collection", e);
    } finally {
      SqlUtil.close(rs);
      SqlUtil.close(stmt);
      SqlUtil.close(conn);
    }

    return collections;
  }
  public boolean isUnique(String collection) {
    ConnectionManager connManager = ConnectionManager.getInstance();
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {
      conn = connManager.getConnection();
      stmt = SqlManager.getInstance().getSqlStatement(conn, "SELECT.COLLECTION.BY.NAME");
      stmt.setString(1, collection);
      rs = stmt.executeQuery();

      if (rs.next()) {
        return false;
      } else {
        return true;
      }
    } catch (SQLException e) {
      throw new RuntimeException("Error loading data from database", e);
    } finally {
      SqlUtil.close(rs);
      SqlUtil.close(stmt);
      SqlUtil.close(conn);
    }
  }
Esempio n. 3
0
 public boolean open(Process p, Any toOpen, IntI mode) throws AnyException {
   // try
   // {
   // Acquire an SQL connection
   AnySql sql = (AnySql) SqlManager.instance().acquire(sqlLogin_);
   if (sql == null) throw new AnyException("Cannot acquire an SQL connection resource"); // ,
   // sqlLogin_);
   // }
   return true;
 }
Esempio n. 4
0
  /**
   * Close the IO connection. This implementation releases any sql resources that may still be held.
   */
  public void close() {
    if (anySql_ != null) {
      try {
        // Gah!
        e_.setThrowable(null);
        SqlManager.instance().release(sqlLogin_, anySql_, null, e_);
      } catch (Exception e) {
        throw new RuntimeContainedException(e);
      }

      if (e_.getThrowable() != null) throw new RuntimeContainedException(e_.getThrowable());
    }
  }
  public int getNextCollectionId() {
    ConnectionManager connManager = ConnectionManager.getInstance();
    int aux = -1;
    try (Connection conn = connManager.getConnection();
        PreparedStatement stmt =
            SqlManager.getInstance().getSqlStatement(conn, "SELECT.MAX.IDCOLLECTION");
        ResultSet rs = stmt.executeQuery(); ) {
      rs.next();
      aux = rs.getInt(1) + 1;
    } catch (SQLException ex) {
      throw new RuntimeException(ex);
    }

    return aux;
  }
  public int getCollectionId(String name) {
    ConnectionManager connManager = ConnectionManager.getInstance();
    int aux = -1;
    try (Connection conn = connManager.getConnection();
        PreparedStatement stmt =
            SqlManager.getInstance().getSqlStatement(conn, "SELECT.COLLECTION.BY.NAME")) {
      stmt.setString(1, name);
      try (ResultSet rs = stmt.executeQuery()) {
        if (rs.next()) {
          aux = rs.getInt(1);
        }
      }
    } catch (SQLException ex) {
      throw new IllegalArgumentException("Could not find a collection named " + name, ex);
    }

    return aux;
  }
  public boolean removeCollection(String name) {
    ConnectionManager connManager = ConnectionManager.getInstance();
    Connection conn = null;
    PreparedStatement stmt = null;
    int rows = 0;

    try {
      conn = connManager.getConnection();
      stmt = SqlManager.getInstance().getSqlStatement(conn, "REMOVE.COLLECTION_BY_NAME");
      stmt.setString(1, name);
      rows = stmt.executeUpdate();
    } catch (SQLException e) {
      throw new RuntimeException("Error removing collection", e);
    } finally {
      SqlUtil.close(stmt);
      SqlUtil.close(conn);
    }

    return (rows > 0);
  }