예제 #1
0
  // Get a list of images that have been added, but not yet added into
  // the database.
  protected void doFlush() {
    SpyDB pdb = getDB();
    Vector v = null;
    try {
      Connection db = pdb.getConn();
      Statement st = db.createStatement();
      String query = "select * from upload_log where stored is null";
      ResultSet rs = st.executeQuery(query);
      v = new Vector();
      while (rs.next()) {
        v.addElement(rs.getString("photo_id"));
      }
    } catch (Exception e) {
      // Do nothing, we'll try again later.
    } finally {
      pdb.freeDBConn();
    }

    // Got the vector, now store the actual images.  This is done so
    // that we don't hold the database connection open whlie we're
    // making the list *and* getting another database connection to act
    // on it.
    if (v != null) {
      try {
        for (int i = 0; i < v.size(); i++) {
          String stmp = (String) v.elementAt(i);
          storeImage(Integer.valueOf(stmp).intValue());
        }
      } catch (Exception e) {
        // Don't care, we'll try again soon.
      }
    }
  }
예제 #2
0
  public String getViewersOf(Integer photo_id) throws Exception {
    Connection db;
    Statement st;
    String query, out = "";

    try {
      db = getDBConn();
    } catch (Exception e) {
      throw new Exception("Can't get database connection: " + e.getMessage());
    }

    query =
        "select wwwusers.username, log.remote_addr,\n"
            + "   user_agent.user_agent, log.cached, log.ts\n"
            + "  from wwwusers, photo_log log, user_agent\n"
            + "  where log.wwwuser_id = wwwusers.id and\n"
            + "    log.photo_id = "
            + photo_id
            + " and\n"
            + "    user_agent.user_agent_id = log.user_agent\n"
            + "  order by log.ts\n";
    try {
      st = db.createStatement();
      ResultSet rs = st.executeQuery(query);

      Hashtable htmp = new Hashtable();
      htmp.put("PHOTO_ID", photo_id.toString());
      out = PhotoUtil.tokenize(photosession, "log/viewers_top.inc", htmp);

      while (rs.next()) {
        try {
          Hashtable h = new Hashtable();
          h.put("USERNAME", rs.getString(1));
          h.put("REMOTE_ADDR", rs.getString(2));
          h.put("USER_AGENT", rs.getString(3));
          h.put("CACHED", rs.getString(4));
          h.put("TS", rs.getString(5));
          out += PhotoUtil.tokenize(photosession, "log/viewers_match.inc", h);
        } catch (Exception e) {
          log("Error reporting log entry for " + photo_id.toString() + " from " + rs.getString(5));
        }
      }

      out += PhotoUtil.tokenize(photosession, "log/viewers_bottom.inc", new Hashtable());

    } catch (Exception e) {
      throw new Exception(e.getMessage());
    } finally {
      freeDBConn(db);
    }

    return (out);
  }