Java Code Examples for de.greenrobot.dao.query.QueryBuilder

The following examples show how to use de.greenrobot.dao.query.QueryBuilder. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: JianDan_OkHttpWithVolley   Source File: FreshNewsCache.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ArrayList<FreshNews> getCacheByPage(int page) {

    QueryBuilder<com.socks.greendao.FreshNewsCache> query = mFreshNewsCacheDao.queryBuilder().where(FreshNewsCacheDao
            .Properties.Page.eq("" + page));

    if (query.list().size() > 0) {
        try {
            return FreshNews.parseCache(new JSONArray(query.list().get(0)
                    .getResult()));
        } catch (JSONException e) {
            e.printStackTrace();
            return new ArrayList<>();
        }
    } else {
        return new ArrayList<>();
    }

}
 
Example 2
Source Project: JianDan_OkHttpWithVolley   Source File: PictureCache.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 根据页码获取缓存数据
 *
 * @param page
 * @return
 */
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.PictureCache> query = mPictureCacheDao.queryBuilder().where(PictureCacheDao
			.Properties.Page.eq("" + page));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<Picture>();
	}

}
 
Example 3
Source Project: JianDan   Source File: FreshNewsCache.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ArrayList<FreshNews> getCacheByPage(int page) {

    QueryBuilder<com.socks.greendao.FreshNewsCache> query = mFreshNewsCacheDao.queryBuilder().where(FreshNewsCacheDao
            .Properties.Page.eq("" + page));

    if (query.list().size() > 0) {
        try {
            return FreshNews.parseCache(new JSONArray(query.list().get(0)
                    .getResult()));
        } catch (JSONException e) {
            e.printStackTrace();
            return new ArrayList<>();
        }
    } else {
        return new ArrayList<>();
    }

}
 
Example 4
Source Project: JianDan   Source File: PictureCache.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 根据页码获取缓存数据
 *
 * @param page
 * @return
 */
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.PictureCache> query = mPictureCacheDao.queryBuilder().where(PictureCacheDao
			.Properties.Page.eq("" + page));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<Picture>();
	}

}
 
Example 5
Source Project: JianDanRxJava   Source File: FreshNewsCache.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ArrayList<FreshNews> getCacheByPage(int page) {

    QueryBuilder<com.socks.greendao.FreshNewsCache> query = mFreshNewsCacheDao.queryBuilder().where(FreshNewsCacheDao
            .Properties.Page.eq("" + page));

    if (query.list().size() > 0) {
        try {
            return FreshNews.parseCache(new JSONArray(query.list().get(0)
                    .getResult()));
        } catch (JSONException e) {
            e.printStackTrace();
            return new ArrayList<>();
        }
    } else {
        return new ArrayList<>();
    }

}
 
Example 6
Source Project: JianDanRxJava   Source File: PictureCache.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 根据页码获取缓存数据
 *
 * @param page
 * @return
 */
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.PictureCache> query = mPictureCacheDao.queryBuilder().where(PictureCacheDao
			.Properties.Page.eq("" + page));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<>();
	}

}
 
Example 7
Source Project: MiBandDecompiled   Source File: LuaAction.java    License: Apache License 2.0 6 votes vote down vote up
public void delMsg4(WhereCondition wherecondition, WhereCondition wherecondition1, WhereCondition wherecondition2, WhereCondition wherecondition3)
{
    QueryBuilder querybuilder = DaoManager.getInstance().getLuaListDao().queryBuilder();
    querybuilder.where(wherecondition, new WhereCondition[0]);
    if (wherecondition1 != null)
    {
        querybuilder.where(wherecondition1, new WhereCondition[0]);
    }
    if (wherecondition2 != null)
    {
        querybuilder.where(wherecondition2, new WhereCondition[0]);
    }
    if (wherecondition3 != null)
    {
        querybuilder.where(wherecondition3, new WhereCondition[0]);
    }
    querybuilder.buildDelete().executeDeleteWithoutDetachingEntities();
}
 
Example 8
Source Project: MiBandDecompiled   Source File: LuaAction.java    License: Apache License 2.0 6 votes vote down vote up
public int getCount4(WhereCondition wherecondition, WhereCondition wherecondition1, WhereCondition wherecondition2, WhereCondition wherecondition3)
{
    QueryBuilder querybuilder = DaoManager.getInstance().getLuaListDao().queryBuilder();
    querybuilder.where(wherecondition, new WhereCondition[0]);
    if (wherecondition1 != null)
    {
        querybuilder.where(wherecondition1, new WhereCondition[0]);
    }
    if (wherecondition2 != null)
    {
        querybuilder.where(wherecondition2, new WhereCondition[0]);
    }
    if (wherecondition2 != null)
    {
        querybuilder.where(wherecondition2, new WhereCondition[0]);
    }
    return (int)querybuilder.count();
}
 
Example 9
Source Project: MiBandDecompiled   Source File: LuaManager.java    License: Apache License 2.0 6 votes vote down vote up
private String getDBLuaFileByVersion(String s)
{
    LuaZipFileDao luazipfiledao = DaoManager.getInstance().getLuaZipFileDao();
    int j = (int)luazipfiledao.count();
    Debug.i("chenee", (new StringBuilder()).append("lzipDao.count:").append(j).toString());
    if (j > 0)
    {
        QueryBuilder querybuilder = luazipfiledao.queryBuilder();
        Property aproperty[] = new Property[1];
        aproperty[0] = de.greenrobot.daobracelet.LuaZipFileDao.Properties.Version;
        querybuilder.orderDesc(aproperty);
        querybuilder.where(de.greenrobot.daobracelet.LuaZipFileDao.Properties.Version.eq(s), new WhereCondition[0]);
        LuaZipFile luazipfile = (LuaZipFile)querybuilder.listLazy().get(0);
        String s1 = luazipfile.getVersion();
        Debug.i("chenee", (new StringBuilder()).append("luaZipFile.version:").append(s1).toString());
        return unzip(luazipfile.getZipFile());
    } else
    {
        Debug.e("chenee", (new StringBuilder()).append("read DB zip failed,version:").append(s).toString());
        return null;
    }
}
 
Example 10
Source Project: WaveHeartRate   Source File: DbUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static List<HistoryEntity> getTopTen(Context m_Context){
        SQLiteDatabase m_Database = null;
        List<HistoryEntity> result = null;
        try{
            HistoryEntityDao entryDao = getReadDao(m_Context);
            m_Database = entryDao.getDatabase();
            QueryBuilder qb = entryDao.queryBuilder();
//            maybe the order is not need,cause the calcuate time of later is always bigger than before.
            result = qb.orderDesc(HistoryEntityDao.Properties.CalculateTime).limit(LIMITED_RECORD_SIZE).list();
            if(result != null){
                for(HistoryEntity entity : result){
                    entity.setStrCalculateTime(CommonUtil.getReadableDateTime(entity.getCalculateTime()));
                }
            }
        }catch(Exception e){
            // ignore the exception handler
        }finally{
            if(m_Database != null){
                m_Database.close();
                m_Database = null;
            }
        }
        return result;
    }
 
Example 11
Source Project: JianDan_OkHttp   Source File: FreshNewsCache.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ArrayList<FreshNews> getCacheByPage(int page) {

    QueryBuilder<com.socks.greendao.FreshNewsCache> query = mFreshNewsCacheDao.queryBuilder().where(FreshNewsCacheDao
            .Properties.Page.eq("" + page));

    if (query.list().size() > 0) {
        try {
            return FreshNews.parseCache(new JSONArray(query.list().get(0)
                    .getResult()));
        } catch (JSONException e) {
            e.printStackTrace();
            return new ArrayList<>();
        }
    } else {
        return new ArrayList<>();
    }

}
 
Example 12
Source Project: JianDan_OkHttp   Source File: PictureCache.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 根据页码获取缓存数据
 *
 * @param page
 * @return
 */
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.PictureCache> query = mPictureCacheDao.queryBuilder().where(PictureCacheDao
			.Properties.Page.eq("" + page));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<Picture>();
	}

}
 
Example 13
Source Project: anetty_client   Source File: PushDbService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 从数据库中获取设备信息
 * 
 * @return
 */
public Map<String, Device> queryDevicesForMap() {
	QueryBuilder<Device> qb = this.deviceDao.queryBuilder();
	List<Device> list = qb.list();
	if (list != null && list.size() > 0) {
		Map<String, Device> map = new HashMap<String, Device>();
		for (Device device : list) {
			if (device != null) {
				// 设备从数据库中取出来默认为已经离线
				device.setIsOnline(ApplicationContextClient.DEVICE_OFFLINE);
				map.put(device.getAppPackage(), device);
			}
		}
		return map;
	}
	return null;
}
 
Example 14
Source Project: sctalk   Source File: DBInterface.java    License: Apache License 2.0 5 votes vote down vote up
public void deleteMessageByMsgId(int msgId){
    if(msgId <= 0){
        return;
    }
    MessageDao messageDao =  openWritableDb().getMessageDao();
    QueryBuilder<MessageEntity> qb = openWritableDb().getMessageDao().queryBuilder();
    DeleteQuery<MessageEntity> bd = qb.where(MessageDao.Properties.MsgId.eq(msgId)).buildDelete();
    bd.executeDeleteWithoutDetachingEntities();
}
 
Example 15
/**
 * Get all completion objects depending on the user and the stage
 * @param user the user
 * @param stage the stage
 * @return List of completion objects
 */
public List<Completion> findByUserAndStage(User user, int stage) {
    QueryBuilder<Completion> completed = mDaoSession.getCompletionDao().queryBuilder()
        .where(CompletionDao.Properties.UserId.eq(user.getId()),
            CompletionDao.Properties.Stage.eq(stage));
    return completed.list();
}
 
Example 16
Source Project: BrainPhaser   Source File: ChallengeDao.java    License: GNU General Public License v3.0 5 votes vote down vote up
/** Internal query to resolve the "challenges" to-many relationship of Category. */
public List<Challenge> _queryCategory_Challenges(long categoryId) {
    synchronized (this) {
        if (category_ChallengesQuery == null) {
            QueryBuilder<Challenge> queryBuilder = queryBuilder();
            queryBuilder.where(Properties.CategoryId.eq(null));
            category_ChallengesQuery = queryBuilder.build();
        }
    }
    Query<Challenge> query = category_ChallengesQuery.forCurrentThread();
    query.setParameter(0, categoryId);
    return query.list();
}
 
Example 17
Source Project: BrainPhaser   Source File: CompletionDao.java    License: GNU General Public License v3.0 5 votes vote down vote up
/** Internal query to resolve the "completions" to-many relationship of User. */
public List<Completion> _queryUser_Completions(long userId) {
    synchronized (this) {
        if (user_CompletionsQuery == null) {
            QueryBuilder<Completion> queryBuilder = queryBuilder();
            queryBuilder.where(Properties.UserId.eq(null));
            user_CompletionsQuery = queryBuilder.build();
        }
    }
    Query<Completion> query = user_CompletionsQuery.forCurrentThread();
    query.setParameter(0, userId);
    return query.list();
}
 
Example 18
Source Project: BrainPhaser   Source File: StatisticsDao.java    License: GNU General Public License v3.0 5 votes vote down vote up
/** Internal query to resolve the "statistics" to-many relationship of User. */
public List<Statistics> _queryUser_Statistics(long userId) {
    synchronized (this) {
        if (user_StatisticsQuery == null) {
            QueryBuilder<Statistics> queryBuilder = queryBuilder();
            queryBuilder.where(Properties.UserId.eq(null));
            user_StatisticsQuery = queryBuilder.build();
        }
    }
    Query<Statistics> query = user_StatisticsQuery.forCurrentThread();
    query.setParameter(0, userId);
    return query.list();
}
 
Example 19
Source Project: BrainPhaser   Source File: AnswerDao.java    License: GNU General Public License v3.0 5 votes vote down vote up
/** Internal query to resolve the "answers" to-many relationship of Challenge. */
public List<Answer> _queryChallenge_Answers(long challengeId) {
    synchronized (this) {
        if (challenge_AnswersQuery == null) {
            QueryBuilder<Answer> queryBuilder = queryBuilder();
            queryBuilder.where(Properties.ChallengeId.eq(null));
            challenge_AnswersQuery = queryBuilder.build();
        }
    }
    Query<Answer> query = challenge_AnswersQuery.forCurrentThread();
    query.setParameter(0, challengeId);
    return query.list();
}
 
Example 20
Source Project: RxJavaApp   Source File: alloperatorsDao.java    License: Apache License 2.0 5 votes vote down vote up
/** Internal query to resolve the "alloperatorsList" to-many relationship of operators. */
public List<alloperators> _queryOperators_AlloperatorsList(Long outer_id) {
    synchronized (this) {
        if (operators_AlloperatorsListQuery == null) {
            QueryBuilder<alloperators> queryBuilder = queryBuilder();
            queryBuilder.where(Properties.Outer_id.eq(null));
            operators_AlloperatorsListQuery = queryBuilder.build();
        }
    }
    Query<alloperators> query = operators_AlloperatorsListQuery.forCurrentThread();
    query.setParameter(0, outer_id);
    return query.list();
}
 
Example 21
Source Project: Nimingban   Source File: DB.java    License: Apache License 2.0 5 votes vote down vote up
public static List<DisplayForum> getACForums(boolean onlyVisible, boolean autoSorting) {
    ACForumDao dao = sDaoSession.getACForumDao();
    QueryBuilder<ACForumRaw> query = dao.queryBuilder();
    if (autoSorting) {
        query = query.orderDesc(ACForumDao.Properties.Frequency);
    }
    query = query.orderAsc(ACForumDao.Properties.Priority);
    List<ACForumRaw> list = query.list();
    List<DisplayForum> result = new ArrayList<>();
    for (ACForumRaw raw : list) {
        if (onlyVisible && !raw.getVisibility()) {
            continue;
        }

        DisplayForum dForum = new DisplayForum();
        dForum.site = ACSite.getInstance();
        dForum.id = raw.getForumid();
        dForum.displayname = raw.getDisplayname();
        dForum.priority = raw.getPriority();
        dForum.visibility = raw.getVisibility();
        dForum.msg = raw.getMsg();
        dForum.official = raw.getOfficial();
        result.add(dForum);
    }

    return result;
}
 
Example 22
Source Project: Nimingban   Source File: DB.java    License: Apache License 2.0 5 votes vote down vote up
public static LazyList<ACForumRaw> getACForumLazyList(boolean autoSorting) {
    QueryBuilder<ACForumRaw> query = sDaoSession.getACForumDao().queryBuilder();
    if (autoSorting) {
        query = query.orderDesc(ACForumDao.Properties.Frequency);
    }
    query = query.orderAsc(ACForumDao.Properties.Priority);
    return query.listLazy();
}
 
Example 23
Source Project: AndroidDatabaseLibraryComparison   Source File: ContactDao.java    License: MIT License 5 votes vote down vote up
/** Internal query to resolve the "contactList" to-many relationship of AddressBook. */
public List<Contact> _queryAddressBook_ContactList(Long id) {
    synchronized (this) {
        if (addressBook_ContactListQuery == null) {
            QueryBuilder<Contact> queryBuilder = queryBuilder();
            queryBuilder.where(Properties.Id.eq(null));
            addressBook_ContactListQuery = queryBuilder.build();
        }
    }
    Query<Contact> query = addressBook_ContactListQuery.forCurrentThread();
    query.setParameter(0, id);
    return query.list();
}
 
Example 24
Source Project: AndroidDatabaseLibraryComparison   Source File: AddressItemDao.java    License: MIT License 5 votes vote down vote up
/** Internal query to resolve the "addressItemList" to-many relationship of AddressBook. */
public List<AddressItem> _queryAddressBook_AddressItemList(Long id) {
    synchronized (this) {
        if (addressBook_AddressItemListQuery == null) {
            QueryBuilder<AddressItem> queryBuilder = queryBuilder();
            queryBuilder.where(Properties.Id.eq(null));
            addressBook_AddressItemListQuery = queryBuilder.build();
        }
    }
    Query<AddressItem> query = addressBook_AddressItemListQuery.forCurrentThread();
    query.setParameter(0, id);
    return query.list();
}
 
Example 25
Source Project: JianDan_OkHttpWithVolley   Source File: SisterCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.SisterCache> query = mPictureCacheDao.queryBuilder().where(SisterCacheDao
			.Properties.Page.eq(Integer.toString(page)));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<>();
	}

}
 
Example 26
Source Project: JianDan_OkHttpWithVolley   Source File: VideoCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Video> getCacheByPage(int page) {

    QueryBuilder<com.socks.greendao.VideoCache> query = mVideoCacheDao.queryBuilder().where(VideoCacheDao.Properties.Page.eq("" + page));
    if (query.list().size() > 0) {
        return (ArrayList<Video>) JSONParser.toObject(query.list().get(0).getResult(),
                new TypeToken<ArrayList<Video>>() {
                }.getType());
    } else {
        return new ArrayList<>();
    }

}
 
Example 27
Source Project: JianDan_OkHttpWithVolley   Source File: JokeCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Joke> getCacheByPage(int page) {
    QueryBuilder<com.socks.greendao.JokeCache> query = mJokeCacheDao.queryBuilder().where(JokeCacheDao.Properties.Page.eq("" + page));

    if (query.list().size() > 0) {
        return (ArrayList<Joke>) JSONParser.toObject(query.list().get(0).getResult(),
                new TypeToken<ArrayList<Joke>>() {
                }.getType());
    } else {
        return new ArrayList<>();
    }

}
 
Example 28
Source Project: NBAPlus   Source File: DBHelper.java    License: Apache License 2.0 5 votes vote down vote up
private DBHelper(Context context) {
    DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, DB_NAME, null);
    db = helper.getWritableDatabase();
    // 注意:该数据库连接属于 DaoMaster,所以多个 Session 指的是相同的数据库连接。
    DaoMaster daoMaster = new DaoMaster(db);
    daoSession = daoMaster.newSession();
    if(Config.DEBUG) {
        QueryBuilder.LOG_SQL = true;
        QueryBuilder.LOG_VALUES = true;
    }
}
 
Example 29
Source Project: JianDan   Source File: SisterCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.SisterCache> query = mPictureCacheDao.queryBuilder().where(SisterCacheDao
			.Properties.Page.eq(Integer.toString(page)));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<>();
	}

}
 
Example 30
Source Project: JianDan   Source File: VideoCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Video> getCacheByPage(int page) {

    QueryBuilder<com.socks.greendao.VideoCache> query = mVideoCacheDao.queryBuilder().where(VideoCacheDao.Properties.Page.eq("" + page));
    if (query.list().size() > 0) {
        return (ArrayList<Video>) JSONParser.toObject(query.list().get(0).getResult(),
                new TypeToken<ArrayList<Video>>() {
                }.getType());
    } else {
        return new ArrayList<>();
    }

}