Exemplo n.º 1
0
  DirectoryAnswer getDA(DirectoryRequest dr) throws P2PDDSQLException {
    String sql =
        "select addresses, timestamp, strftime('%Y%m%d%H%M%fZ',timestamp,'unixepoch') from registered where global_peer_ID = ?;";
    ArrayList<ArrayList<Object>> adr = db_dir.select(sql, new String[] {dr.globalID}, DEBUG);
    if (DEBUG) System.out.println("Query: " + sql + " with ?= " + Util.trimmed(dr.globalID));
    if (DEBUG) System.out.println("Found addresses #: " + adr.size());
    DirectoryAnswer da = new DirectoryAnswer();
    da.version = dr.version;
    if (adr.size() != 0) {
      Integer time = Util.Ival(adr.get(0).get(1));
      if (time == null) {
        time = new Integer(0);
        out.println("EMPTY TIME. WHY?");
      }
      Date date = new Date();
      date.setTime(time.longValue());
      da.date.setTime(date);

      String addresses = (String) adr.get(0).get(0);
      if (DEBUG) System.out.println("This address: " + addresses);
      String a[] = Address.split(addresses);
      for (int k = 0; k < a.length; k++) {
        if ((a[k] == null) || ("".equals(a[k])) || ("null".equals(a[k]))) continue;
        if (DEBUG) System.out.println("This address [" + k + "]" + a[k]);
        da.addresses.add(new Address(a[k]));
      }
    } else {
      if (DEBUG) out.print("Empty ");
    }
    return da;
  }