Пример #1
0
  public static ArrayList<Person> loadPersons(HttpServletRequest req, String query)
      throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {

    ArrayList<Person> persons = new ArrayList<Person>();
    Chain chain = new SQLChain().open(DATABASE_URL);
    SelectChain sel =
        User.loadAllSelect(req, chain, PROJECTION).innerJoin(FROM).on(FK_USERID, User.PK_USERID);
    whereLike(sel, query);
    ResultSet rs = sel.exec();

    rs.beforeFirst();
    while (rs.next()) {
      persons.add(new Person(rs));
    }
    rs.close();
    chain.close();
    return persons;
  }
Пример #2
0
  public static Person loadPerson(String userName, HttpServletRequest req)
      throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {

    User u = getSessionUser(req);
    if (userName == null) {
      if (u == null) return null;
    }
    u = User.loadUser(userName, req);
    if (u == null) return null;

    Person person = null;
    Chain chain = new SQLChain().open(DATABASE_URL);
    ResultSet rs =
        chain.select(PROJECTION).from(FROM).whereIs(FK_USERID, "" + u.getUserId()).exec();

    if (rs.next()) {
      person = new Person(rs, u);
    }
    rs.close();
    chain.close();

    return person;
  }