Search in sources :

Example 1 with JokeBeans

use of org.aisen.weibo.sina.support.bean.JokeBeans in project AisenWeiBo by wangdan.

the class JokesCacheUtility method addCacheData.

@Override
public void addCacheData(Setting action, Params params, IResult result) {
    long id = Long.parseLong(params.getParameter("id"));
    int type = Integer.parseInt(params.getParameter("mode"));
    String direction = params.getParameter("direction");
    JokeBeans beans = (JokeBeans) result;
    if (id == 0 || ("down".equalsIgnoreCase(direction) && beans.getData().getContents().size() >= 20)) {
        SinaDB.getDB().deleteAll(new Extra(null, String.valueOf(type)), JokeBean.class);
    }
    CacheTimeUtils.saveTime("Jokes" + type, null);
    SinaDB.getDB().insert(new Extra(null, String.valueOf(type)), beans.getData().getContents());
}
Also used : JokeBeans(org.aisen.weibo.sina.support.bean.JokeBeans) Extra(org.aisen.android.component.orm.extra.Extra)

Example 2 with JokeBeans

use of org.aisen.weibo.sina.support.bean.JokeBeans in project AisenWeiBo by wangdan.

the class JokesCacheUtility method findCacheData.

@Override
public IResult findCacheData(Setting action, Params params) {
    long id = Integer.parseInt(params.getParameter("id"));
    int type = Integer.parseInt(params.getParameter("mode"));
    // 只有第一次加载数据的时候才加载缓存
    if (id == 0) {
        // 根据id倒序
        String selection = String.format(" %s = ? ", FieldUtils.KEY);
        String[] selectionArgs = new String[] { String.valueOf(type) };
        List<JokeBean> beanList = SinaDB.getDB().select(JokeBean.class, selection, selectionArgs, null, null, " id desc ", null);
        if (beanList.size() > 0) {
            JokeBeans beans = new JokeBeans();
            JokeBeans.Data data = new JokeBeans.Data();
            data.setContents(beanList);
            beans.setData(data);
            beans.setFromCache(true);
            beans.setEndPaging(beanList.size() == 0);
            beans.setOutofdate(CacheTimeUtils.isOutofdate("Jokes" + type, null));
            return beans;
        }
    }
    return null;
}
Also used : JokeBeans(org.aisen.weibo.sina.support.bean.JokeBeans) JokeBean(org.aisen.weibo.sina.support.bean.JokeBean)

Aggregations

JokeBeans (org.aisen.weibo.sina.support.bean.JokeBeans)2 Extra (org.aisen.android.component.orm.extra.Extra)1 JokeBean (org.aisen.weibo.sina.support.bean.JokeBean)1