org.greenrobot.greendao.query.QueryBuilder Java Examples
The following examples show how to use
org.greenrobot.greendao.query.QueryBuilder.
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 File: LocalKinoRepositoryTest.java From CineLog with GNU General Public License v3.0 | 6 votes |
@Test public void findAllByYearAsc() { TmdbKino oldTmdbKino = mock(TmdbKino.class); TmdbKino recentTmdbKino = mock(TmdbKino.class); //noinspection ResultOfMethodCallIgnored doReturn(1987).when(oldTmdbKino).getYear(); //noinspection ResultOfMethodCallIgnored doReturn(2012).when(recentTmdbKino).getYear(); LocalKino oldLocalKino = mock(LocalKino.class); doReturn(recentTmdbKino).when(localKino).getKino(); doReturn(oldTmdbKino).when(oldLocalKino).getKino(); QueryBuilder queryBuilder = mock(QueryBuilder.class); doReturn(queryBuilder).when(localKinoDao).queryBuilder(); Query query = mock(Query.class); doReturn(query).when(queryBuilder).build(); doReturn(Arrays.asList(localKino, oldLocalKino)).when(query).list(); assertEquals( Arrays.asList(oldLocalKino, localKino), new LocalKinoRepository(daoSession).findAllByYear(true) ); }
Example #2
Source File: TagListFragment.java From android-app with GNU General Public License v3.0 | 6 votes |
private QueryBuilder<Tag> getQueryBuilder() { QueryBuilder<Tag> qb = tagDao.queryBuilder(); if (!TextUtils.isEmpty(searchQuery)) { qb.where(TagDao.Properties.Label.like("%" + searchQuery + "%")); } switch (sortOrder) { case ASC: qb.orderAsc(TagDao.Properties.Label); break; case DESC: qb.orderDesc(TagDao.Properties.Label); break; default: throw new IllegalStateException("Sort order not implemented: " + sortOrder); } return qb; }
Example #3
Source File: GreenDaoKyHelper.java From BitkyShop with MIT License | 6 votes |
/** * 在[本地数据库]购物车中插入商品或增加其数量 * * @param c 商品bean */ public static void insertOrIncrease(Commodity c) { CommodityLocalDao commodityLocalDao = GreenDaoKyHelper.getDaoSession().getCommodityLocalDao(); QueryBuilder<CommodityLocal> queryBuilder = commodityLocalDao.queryBuilder(); queryBuilder.where(CommodityLocalDao.Properties.ObjectId.eq(c.getObjectId())); List<CommodityLocal> localList = queryBuilder.list(); KLog.d("查询到的结果数:" + localList.size()); CommodityLocal commodityLocal = new CommodityLocal(null, c.getObjectId(), c.getCategory(), c.getName(), c.getDetails(), 1, c.getPrice(), c.getCoverPhotoUrl(), false); if (localList.size() >= 1) { commodityLocal.setId(localList.get(0).getId()); commodityLocal.setCartCount(localList.get(0).getCartCount() + 1); commodityLocalDao.update(commodityLocal); } else { commodityLocalDao.insert(commodityLocal); } }
Example #4
Source File: LocalKinoRepositoryTest.java From CineLog with GNU General Public License v3.0 | 6 votes |
@Test public void findAllByReviewDateAsc() { QueryBuilder queryBuilder = mock(QueryBuilder.class); doReturn(queryBuilder).when(localKinoDao).queryBuilder(); doReturn(queryBuilder).when(queryBuilder).orderAsc(LocalKinoDao.Properties.Review_date); Query query = mock(Query.class); doReturn(query).when(queryBuilder).build(); doReturn(Collections.singletonList(localKino)).when(query).list(); assertEquals( Collections.singletonList(localKino), new LocalKinoRepository(daoSession).findAllByReviewDate(true) ); }
Example #5
Source File: SerieReviewRepositoryTest.java From CineLog with GNU General Public License v3.0 | 6 votes |
@Test public void findByMovieId() { QueryBuilder queryBuilder = mock(QueryBuilder.class); doReturn(queryBuilder).when(serieReviewDao).queryBuilder(); doReturn(queryBuilder).when(queryBuilder).where(any(WhereCondition.class)); doReturn(queryBuilder).when(queryBuilder).limit(1); Query query = mock(Query.class); doReturn(query).when(queryBuilder).build(); doReturn(Collections.singletonList(serieReview)).when(query).list(); assertEquals( serieReview, new SerieReviewRepository(daoSession).findByMovieId(45) ); }
Example #6
Source File: LocalKinoRepositoryTest.java From CineLog with GNU General Public License v3.0 | 6 votes |
@Test public void findAllByRatingDesc() { QueryBuilder queryBuilder = mock(QueryBuilder.class); doReturn(queryBuilder).when(localKinoDao).queryBuilder(); doReturn(queryBuilder).when(queryBuilder).orderDesc(LocalKinoDao.Properties.Rating); Query query = mock(Query.class); doReturn(query).when(queryBuilder).build(); doReturn(Arrays.asList(localKino)).when(query).list(); assertEquals( Arrays.asList(localKino), new LocalKinoRepository(daoSession).findAllByRating(false) ); }
Example #7
Source File: LocalKinoRepositoryTest.java From CineLog with GNU General Public License v3.0 | 6 votes |
@Test public void findAllByRatingAsc() { QueryBuilder queryBuilder = mock(QueryBuilder.class); doReturn(queryBuilder).when(localKinoDao).queryBuilder(); doReturn(queryBuilder).when(queryBuilder).orderAsc(LocalKinoDao.Properties.Rating); Query query = mock(Query.class); doReturn(query).when(queryBuilder).build(); doReturn(Arrays.asList(localKino)).when(query).list(); assertEquals( Arrays.asList(localKino), new LocalKinoRepository(daoSession).findAllByRating(true) ); }
Example #8
Source File: LocalKinoRepositoryTest.java From CineLog with GNU General Public License v3.0 | 6 votes |
@Test public void findByMovieId() { QueryBuilder queryBuilder = mock(QueryBuilder.class); doReturn(queryBuilder).when(localKinoDao).queryBuilder(); doReturn(queryBuilder).when(queryBuilder).where(any(WhereCondition.class));//LocalKinoDao.Properties.Tmdb_id.eq(45)); doReturn(queryBuilder).when(queryBuilder).limit(1); Query query = mock(Query.class); doReturn(query).when(queryBuilder).build(); doReturn(Arrays.asList(localKino)).when(query).list(); assertEquals( localKino, new LocalKinoRepository(daoSession).findByMovieId(45) ); }
Example #9
Source File: LocalKinoRepository.java From CineLog with GNU General Public License v3.0 | 6 votes |
public List<LocalKino> findAllByTitle(final boolean asc) { QueryBuilder<LocalKino> localKinoQueryBuilder = dao.queryBuilder(); List<LocalKino> list = localKinoQueryBuilder.build().list(); Collections.sort(list, new Comparator<LocalKino>() { @Override public int compare(LocalKino o1, LocalKino o2) { if (o1.getTitle() == null) { return -1; } else if (o2.getTitle() == null) { return 1; } else { // TODO take care of locale return Collator.getInstance().compare(o1.getTitle(), o2.getTitle()); } } }); if(!asc){ Collections.reverse(list); } return list; }
Example #10
Source File: WishlistMovieRepositoryTest.java From CineLog with GNU General Public License v3.0 | 6 votes |
@Test public void findByMovieId() { QueryBuilder queryBuilder = mock(QueryBuilder.class); doReturn(queryBuilder).when(wishlistMovieDao).queryBuilder(); doReturn(queryBuilder).when(queryBuilder).where(any(WhereCondition.class)); doReturn(queryBuilder).when(queryBuilder).limit(1); Query query = mock(Query.class); doReturn(query).when(queryBuilder).build(); doReturn(Collections.singletonList(wishlistMovie)).when(query).list(); assertEquals( wishlistMovie, new WishlistMovieRepository(daoSession).findByTmdbId(45) ); }
Example #11
Source File: ReadArticleActivity.java From android-app with GNU General Public License v3.0 | 6 votes |
private Long getAdjacentArticle(boolean previous) { QueryBuilder<Article> qb = articleDao.queryBuilder() .where(ArticleDao.Properties.ArticleId.isNotNull()); if (previous) qb.where(ArticleDao.Properties.ArticleId.gt(article.getArticleId())); else qb.where(ArticleDao.Properties.ArticleId.lt(article.getArticleId())); if (contextFavorites != null) qb.where(ArticleDao.Properties.Favorite.eq(contextFavorites)); if (contextArchived != null) qb.where(ArticleDao.Properties.Archive.eq(contextArchived)); if (previous) qb.orderAsc(ArticleDao.Properties.ArticleId); else qb.orderDesc(ArticleDao.Properties.ArticleId); List<Article> l = qb.limit(1).list(); if (!l.isEmpty()) { return l.get(0).getId(); } return null; }
Example #12
Source File: UserLocalDataSource.java From Android-Architecture with Apache License 2.0 | 6 votes |
@Override public void getByUsername(String username, final SourceCallback<UserModel> callback) { // TODO: 2017/7/28 根据用户名获取 QueryBuilder<UserModel> queryBuilder = GreenDaoManager.getInstance().queryBuilder(UserModel.class); queryBuilder.where(UserModelDao.Properties.UserName.eq(username)); GreenDaoManager.getInstance().query(queryBuilder, new DBManager.Callback<List<UserModel>>() { @Override public void onFinish(List<UserModel> dbModels) { if (callback == null) return; if (dbModels == null) { callback.onDataNotAvailable(); return; } if (dbModels.size() > 0) { callback.onLoaded(dbModels.get(0)); } } }); }
Example #13
Source File: ContactHelper.java From Android with MIT License | 5 votes |
/** * friend entity * * @param value * @return */ public ContactEntity loadFriendEntity(String value) { if (TextUtils.isEmpty(value)) { value = ""; } QueryBuilder<ContactEntity> queryBuilder = contactEntityDao.queryBuilder(); queryBuilder.whereOr(ContactEntityDao.Properties.Pub_key.eq(value), ContactEntityDao.Properties.Address.eq(value)).limit(1).build(); List<ContactEntity> friendEntities = queryBuilder.listLazy(); return (friendEntities == null || friendEntities.size() == 0) ? null : friendEntities.get(0); }
Example #14
Source File: BaseApplication.java From Android-IM with Apache License 2.0 | 5 votes |
private void setupDatabase() { //是否开启调试 MigrationHelper.DEBUG = true; QueryBuilder.LOG_SQL = true; QueryBuilder.LOG_VALUES = true; //数据库升级 helper = new MySQLiteOpenHelper(mContext, "text"); master = new DaoMaster(helper.getWritableDb()); }
Example #15
Source File: CookieDbUtil.java From Bailan with Apache License 2.0 | 5 votes |
public List<CookieResulte> queryCookieAll() { DaoMaster daoMaster = new DaoMaster(getReadableDatabase()); DaoSession daoSession = daoMaster.newSession(); CookieResulteDao downInfoDao = daoSession.getCookieResulteDao(); QueryBuilder<CookieResulte> qb = downInfoDao.queryBuilder(); return qb.list(); }
Example #16
Source File: ParamHelper.java From Android with MIT License | 5 votes |
public ParamEntity loadParamEntityDESC(String key) { QueryBuilder<ParamEntity> queryBuilder = paramEntityDao.queryBuilder(); queryBuilder.where(ParamEntityDao.Properties.Key.eq(key)).orderDesc(ParamEntityDao.Properties._id).limit(1).build(); List<ParamEntity> paramEntities = queryBuilder.list(); if (null == paramEntities || paramEntities.size() == 0) { return null; } return paramEntities.get(0); }
Example #17
Source File: LetterDao.java From ml-authentication with Apache License 2.0 | 5 votes |
/** Internal query to resolve the "letters" to-many relationship of Image. */ public List<Letter> _queryImage_Letters(long imageId) { synchronized (this) { if (image_LettersQuery == null) { QueryBuilder<Letter> queryBuilder = queryBuilder(); queryBuilder.join(JoinImagesWithLetters.class, JoinImagesWithLettersDao.Properties.LetterId) .where(JoinImagesWithLettersDao.Properties.ImageId.eq(imageId)); image_LettersQuery = queryBuilder.build(); } } Query<Letter> query = image_LettersQuery.forCurrentThread(); query.setParameter(0, imageId); return query.list(); }
Example #18
Source File: TransactionHelper.java From Android with MIT License | 5 votes |
/********************************************************************************************** * select *********************************************************************************************/ public TransactionEntity loadTransEntity(String hashid) { QueryBuilder<TransactionEntity> queryBuilder = transactionEntityDao.queryBuilder(); queryBuilder.where(TransactionEntityDao.Properties.Hashid.eq(hashid)).limit(1).build(); List<TransactionEntity> transEntities = queryBuilder.listLazy(); return transEntities.size() == 0 ? null : transEntities.get(0); }
Example #19
Source File: TransactionHelper.java From Android with MIT License | 5 votes |
/** * The query in recent 10 transfer record * @return */ public List<TransactionEntity> loadLatelyTrans() { QueryBuilder<TransactionEntity> queryBuilder = transactionEntityDao.queryBuilder(); queryBuilder.limit(10); List<TransactionEntity> transEntities = queryBuilder.list(); if(transEntities != null) Collections.reverse(transEntities); return transEntities; }
Example #20
Source File: ParamHelper.java From Android with MIT License | 5 votes |
public ParamEntity likeParamEntity(String key) { QueryBuilder<ParamEntity> queryBuilder = paramEntityDao.queryBuilder(); queryBuilder.where(ParamEntityDao.Properties.Key.like("%" + key + "%")). orderDesc(ParamEntityDao.Properties._id).limit(1).build(); List<ParamEntity> paramEntities = queryBuilder.list(); return paramEntities == null || paramEntities.size() == 0 ? null : paramEntities.get(0); }
Example #21
Source File: ContactHelper.java From Android with MIT License | 5 votes |
/** * query recommand friend * * @return */ public List<RecommandFriendEntity> loadRecommendEntity(int page, int pageSize) { QueryBuilder<RecommandFriendEntity> queryBuilder = recommandFriendEntityDao.queryBuilder(); queryBuilder.where(RecommandFriendEntityDao.Properties.Status.eq(0)).build(); queryBuilder.offset((page - 1) * pageSize); queryBuilder.limit(pageSize); List<RecommandFriendEntity> list = queryBuilder.list(); Collections.reverse(list); return list; }
Example #22
Source File: DeviceDao.java From ml-authentication with Apache License 2.0 | 5 votes |
/** Internal query to resolve the "devices" to-many relationship of Student. */ public List<Device> _queryStudent_Devices(long studentId) { synchronized (this) { if (student_DevicesQuery == null) { QueryBuilder<Device> queryBuilder = queryBuilder(); queryBuilder.join(JoinStudentsWithDevices.class, JoinStudentsWithDevicesDao.Properties.DeviceId) .where(JoinStudentsWithDevicesDao.Properties.StudentId.eq(studentId)); student_DevicesQuery = queryBuilder.build(); } } Query<Device> query = student_DevicesQuery.forCurrentThread(); query.setParameter(0, studentId); return query.list(); }
Example #23
Source File: PictureDao.java From Pretty-Zhihu with Apache License 2.0 | 5 votes |
/** Internal query to resolve the "pictures" to-many relationship of Question. */ public List<Picture> _queryQuestion_Pictures(int questionId) { synchronized (this) { if (question_PicturesQuery == null) { QueryBuilder<Picture> queryBuilder = queryBuilder(); queryBuilder.where(Properties.QuestionId.eq(null)); question_PicturesQuery = queryBuilder.build(); } } Query<Picture> query = question_PicturesQuery.forCurrentThread(); query.setParameter(0, questionId); return query.list(); }
Example #24
Source File: CookieDbUtil.java From Bailan with Apache License 2.0 | 5 votes |
public List<CookieResulte> queryCookieAll() { DaoMaster daoMaster = new DaoMaster(getReadableDatabase()); DaoSession daoSession = daoMaster.newSession(); CookieResulteDao downInfoDao = daoSession.getCookieResulteDao(); QueryBuilder<CookieResulte> qb = downInfoDao.queryBuilder(); return qb.list(); }
Example #25
Source File: DbDwonUtil.java From Rx-Retrofit with MIT License | 5 votes |
public DownInfo queryDownBy(long Id) { DaoMaster daoMaster = new DaoMaster(getReadableDatabase()); DaoSession daoSession = daoMaster.newSession(); DownInfoDao downInfoDao = daoSession.getDownInfoDao(); QueryBuilder<DownInfo> qb = downInfoDao.queryBuilder(); qb.where(DownInfoDao.Properties.Id.eq(Id)); List<DownInfo> list = qb.list(); if(list.isEmpty()){ return null; }else{ return list.get(0); } }
Example #26
Source File: UserDao.java From android-orm-benchmark-updated with Apache License 2.0 | 5 votes |
/** Internal query to resolve the "readers" to-many relationship of Message. */ public List<User> _queryMessage_Readers(Long id) { synchronized (this) { if (message_ReadersQuery == null) { QueryBuilder<User> queryBuilder = queryBuilder(); queryBuilder.where(Properties.Id.eq(null)); message_ReadersQuery = queryBuilder.build(); } } Query<User> query = message_ReadersQuery.forCurrentThread(); query.setParameter(0, id); return query.list(); }
Example #27
Source File: TingAlbumDao.java From AssistantBySDK with Apache License 2.0 | 5 votes |
/** * 获取指定名称(和集数)的历史记录 **/ public TrackAlbum checkHistory(NewAudioEntity audio) { QueryBuilder<TrackAlbum> builder = mAlbumDao.queryBuilder().where(TrackAlbumDao.Properties.TrackTitle.like(audio.getName() + "%")); if (audio.getEpisode() > 0) builder = builder.where(TrackAlbumDao.Properties.OrderNum.eq(audio.getEpisode() - 1)); return builder.where(TrackAlbumDao.Properties.BreakTime.isNotNull()) .limit(1).unique(); }
Example #28
Source File: RecordDao.java From AssistantBySDK with Apache License 2.0 | 5 votes |
/** * 获取指定数量的导航记录 * * @param list 待填充的数据集合 * @param number 指定数量 <=0则搜索全部 **/ public void getRecordList(List<NaviRecord> list, int number) { if (list == null) { return; } list.clear(); QueryBuilder<NaviRecord> queryBuilder = mNaviRecordDao.queryBuilder().where(NaviRecordDao.Properties.StartName.isNotNull(), NaviRecordDao.Properties.EndName.isNotNull()) .orderDesc(NaviRecordDao.Properties.Created); if (number > 0) { queryBuilder = queryBuilder.limit(number); } list.addAll(queryBuilder.list()); }
Example #29
Source File: BaiduNaviDao.java From AssistantBySDK with Apache License 2.0 | 5 votes |
/** * 根据指定搜索关键词和地址描述搜索地址 **/ public BaiduAddress findBySKAndName(String searchkeyWord, String name) { QueryBuilder<BaiduAddress> queryBuilder = mAddressDao.queryBuilder().where(BaiduAddressDao.Properties.Name.eq(name)); if (!TextUtils.isEmpty(searchkeyWord)) { queryBuilder = queryBuilder.where(BaiduAddressDao.Properties.SearchKeyWord.eq(searchkeyWord)); } return queryBuilder.limit(1).unique(); }
Example #30
Source File: CookieDbUtil.java From Rx-Retrofit with MIT License | 5 votes |
public List<CookieResulte> queryCookieAll() { DaoMaster daoMaster = new DaoMaster(getReadableDatabase()); DaoSession daoSession = daoMaster.newSession(); CookieResulteDao downInfoDao = daoSession.getCookieResulteDao(); QueryBuilder<CookieResulte> qb = downInfoDao.queryBuilder(); return qb.list(); }