Пример #1
0
  public List<Topic> getRecentReplyTopics(int userId, Pager pager) {

    Map<Integer, UserProfile> authors = new HashMap<Integer, UserProfile>();
    Cnd cnd = Cnd.where("userId", "=", userId);
    cnd.desc("createTime");

    Sql sql =
        Sqls.queryString("select DISTINCT topicId from t_topic_reply $cnd")
            .setEntity(dao.getEntity(TopicReply.class))
            .setVar("cnd", cnd);
    pager.setRecordCount(
        dao.execute(
                Sqls.fetchInt("select count(DISTINCT topicId) from t_topic_reply $cnd")
                    .setEntity(dao.getEntity(TopicReply.class))
                    .setVar("cnd", cnd))
            .getInt());
    sql.setPager(pager);
    String[] replies_topic_ids = dao.execute(sql).getObject(String[].class);
    List<Topic> recent_replies = new ArrayList<Topic>();
    for (String topic_id : replies_topic_ids) {
      Topic _topic = dao.fetch(Topic.class, topic_id);
      if (_topic == null) continue;
      recent_replies.add(_topic);
    }
    if (!recent_replies.isEmpty()) {
      for (Topic topic : recent_replies) {
        fillTopic(topic, authors);
      }
    }
    return recent_replies;
  }
Пример #2
0
 public static List getRecords(Dao dao, String sql, Class t, int page, int size) {
   Sql s = Sqls.create(sql);
   s.setCallback(Sqls.callback.entities());
   s.setPager(dao.createPager(page, size));
   s.setEntity(dao.getEntity(t));
   dao.execute(s);
   return s.getList(Record.class);
 }
Пример #3
0
 /** 查询sql并把结果放入传入的class组成的List中 */
 public static <T> List<T> query(
     Dao dao, Class<T> classOfT, String sql, Condition cnd, Pager pager) {
   Sql sql2 = Sqls.queryEntity(sql);
   sql2.setEntity(dao.getEntity(classOfT));
   sql2.setCondition(cnd);
   sql2.setPager(pager);
   dao.execute(sql2);
   return sql2.getList(classOfT);
 }
Пример #4
0
 /**
  * 用没有处理过的Nutz.sql带分页
  *
  * @param dao
  * @param s
  * @param page
  * @param size
  * @return
  */
 public static Record getRecordsByNutSql(Dao dao, Sql s, int page, int size) {
   int total = getRecordSize(dao, s.toString());
   s.setCallback(Sqls.callback.entities());
   s.setPager(dao.createPager(page, size));
   s.setEntity(dao.getEntity(Record.class));
   dao.execute(s);
   Record rd = new Record();
   List<Record> records = s.getList(Record.class);
   rd.put("total", total);
   rd.put("rows", records);
   return rd;
 }