org.greenrobot.greendao.query.Query Java Examples

The following examples show how to use org.greenrobot.greendao.query.Query. 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 vote down vote up
@Test
public void findAllByTitleDesc() {
    LocalKino anotherKino = mock(LocalKino.class);
    doReturn("Banane").when(localKino).getTitle();
    doReturn("Poney").when(anotherKino).getTitle();

    QueryBuilder queryBuilder = mock(QueryBuilder.class);
    doReturn(queryBuilder).when(localKinoDao).queryBuilder();

    Query query = mock(Query.class);
    doReturn(query).when(queryBuilder).build();

    doReturn(Arrays.asList(localKino, anotherKino)).when(query).list();

    assertEquals(
            Arrays.asList(anotherKino, localKino),
            new LocalKinoRepository(daoSession).findAllByTitle(false)
    );
}
 
Example #2
Source File: SerieReviewRepositoryTest.java    From CineLog with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void findAllByTitleDesc() {
    Review aReview = mock(Review.class);
    Review anotherReview = mock(Review.class);
    //noinspection ResultOfMethodCallIgnored
    doReturn("Banane").when(aReview).getTitle();
    //noinspection ResultOfMethodCallIgnored
    doReturn("Pingouin").when(anotherReview).getTitle();

    SerieReview aSerieReview = mock(SerieReview.class);
    doReturn(anotherReview).when(serieReview).getReview();
    doReturn(aReview).when(aSerieReview).getReview();

    QueryBuilder queryBuilder = mock(QueryBuilder.class);
    doReturn(queryBuilder).when(serieReviewDao).queryBuilder();

    Query query = mock(Query.class);
    doReturn(query).when(queryBuilder).build();

    doReturn(Arrays.asList(serieReview, aSerieReview)).when(query).list();

    assertEquals(
            Arrays.asList(serieReview, aSerieReview),
            new SerieReviewRepository(daoSession).findAllByTitle(false)
    );
}
 
Example #3
Source File: SerieReviewRepositoryTest.java    From CineLog with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void findAllByTitleAsc() {
    Review aReview = mock(Review.class);
    Review anotherReview = mock(Review.class);
    //noinspection ResultOfMethodCallIgnored
    doReturn("Banane").when(aReview).getTitle();
    //noinspection ResultOfMethodCallIgnored
    doReturn("Pingouin").when(anotherReview).getTitle();

    SerieReview aSerieReview = mock(SerieReview.class);
    doReturn(anotherReview).when(serieReview).getReview();
    doReturn(aReview).when(aSerieReview).getReview();

    QueryBuilder queryBuilder = mock(QueryBuilder.class);
    doReturn(queryBuilder).when(serieReviewDao).queryBuilder();

    Query query = mock(Query.class);
    doReturn(query).when(queryBuilder).build();

    doReturn(Arrays.asList(serieReview, aSerieReview)).when(query).list();

    assertEquals(
            Arrays.asList(aSerieReview, serieReview),
            new SerieReviewRepository(daoSession).findAllByTitle(true)
    );
}
 
Example #4
Source File: SerieReviewRepositoryTest.java    From CineLog with GNU General Public License v3.0 6 votes vote down vote up
@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 #5
Source File: WishlistMovieRepositoryTest.java    From CineLog with GNU General Public License v3.0 6 votes vote down vote up
@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 #6
Source File: WishlistSerieRepositoryTest.java    From CineLog with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void findBySerieId() {
    QueryBuilder queryBuilder = mock(QueryBuilder.class);
    doReturn(queryBuilder).when(wishlistSerieDao).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(wishlistSerie)).when(query).list();

    assertEquals(
            wishlistSerie,
            new WishlistSerieRepository(daoSession).findByTmdbId(45)
    );

}
 
Example #7
Source File: LocalKinoRepositoryTest.java    From CineLog with GNU General Public License v3.0 6 votes vote down vote up
@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 #8
Source File: LocalKinoRepositoryTest.java    From CineLog with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void findAllByTitleDescNullO2() {
    LocalKino anotherKino = mock(LocalKino.class);
    doReturn(null).when(anotherKino).getTitle();

    QueryBuilder queryBuilder = mock(QueryBuilder.class);
    doReturn(queryBuilder).when(localKinoDao).queryBuilder();

    Query query = mock(Query.class);
    doReturn(query).when(queryBuilder).build();

    doReturn(Arrays.asList(localKino, anotherKino)).when(query).list();

    assertEquals(
            Arrays.asList(localKino, anotherKino),
            new LocalKinoRepository(daoSession).findAllByTitle(false)
    );
}
 
Example #9
Source File: LocalKinoRepositoryTest.java    From CineLog with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void findAllByTitleDescNullO1() {
    LocalKino anotherKino = mock(LocalKino.class);
    doReturn(null).when(localKino).getTitle();
    doReturn("Poney").when(anotherKino).getTitle();

    QueryBuilder queryBuilder = mock(QueryBuilder.class);
    doReturn(queryBuilder).when(localKinoDao).queryBuilder();

    Query query = mock(Query.class);
    doReturn(query).when(queryBuilder).build();

    doReturn(Arrays.asList(localKino, anotherKino)).when(query).list();

    assertEquals(
            Arrays.asList(anotherKino, localKino),
            new LocalKinoRepository(daoSession).findAllByTitle(false)
    );
}
 
Example #10
Source File: LocalKinoRepositoryTest.java    From CineLog with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void findAllByTitleAscNullO2() {
    LocalKino anotherKino = mock(LocalKino.class);
    doReturn(null).when(anotherKino).getTitle();

    QueryBuilder queryBuilder = mock(QueryBuilder.class);
    doReturn(queryBuilder).when(localKinoDao).queryBuilder();

    Query query = mock(Query.class);
    doReturn(query).when(queryBuilder).build();

    doReturn(Arrays.asList(localKino, anotherKino)).when(query).list();

    assertEquals(
            Arrays.asList(anotherKino, localKino),
            new LocalKinoRepository(daoSession).findAllByTitle(true)
    );
}
 
Example #11
Source File: LocalKinoRepositoryTest.java    From CineLog with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void findAllByTitleAscNullO1() {
    LocalKino anotherKino = mock(LocalKino.class);
    doReturn(null).when(localKino).getTitle();
    doReturn("Poney").when(anotherKino).getTitle();

    QueryBuilder queryBuilder = mock(QueryBuilder.class);
    doReturn(queryBuilder).when(localKinoDao).queryBuilder();

    Query query = mock(Query.class);
    doReturn(query).when(queryBuilder).build();

    doReturn(Arrays.asList(localKino, anotherKino)).when(query).list();

    assertEquals(
            Arrays.asList(localKino, anotherKino),
            new LocalKinoRepository(daoSession).findAllByTitle(true)
    );
}
 
Example #12
Source File: LocalKinoRepositoryTest.java    From CineLog with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void findAllByTitleAsc() {
    LocalKino anotherKino = mock(LocalKino.class);
    doReturn("Banane").when(localKino).getTitle();
    doReturn("Poney").when(anotherKino).getTitle();

    QueryBuilder queryBuilder = mock(QueryBuilder.class);
    doReturn(queryBuilder).when(localKinoDao).queryBuilder();

    Query query = mock(Query.class);
    doReturn(query).when(queryBuilder).build();

    doReturn(Arrays.asList(localKino, anotherKino)).when(query).list();

    assertEquals(
            Arrays.asList(localKino, anotherKino),
            new LocalKinoRepository(daoSession).findAllByTitle(true)
    );
}
 
Example #13
Source File: LocalKinoRepositoryTest.java    From CineLog with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void findAllByYearDesc() {
    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(localKino, oldLocalKino),
            new LocalKinoRepository(daoSession).findAllByYear(false)
    );
}
 
Example #14
Source File: LocalKinoRepositoryTest.java    From CineLog with GNU General Public License v3.0 6 votes vote down vote up
@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 #15
Source File: LocalKinoRepositoryTest.java    From CineLog with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void findAllByReviewDateDesc() {
    QueryBuilder queryBuilder = mock(QueryBuilder.class);
    doReturn(queryBuilder).when(localKinoDao).queryBuilder();
    doReturn(queryBuilder).when(queryBuilder).orderDesc(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(false)
    );
}
 
Example #16
Source File: LocalKinoRepositoryTest.java    From CineLog with GNU General Public License v3.0 6 votes vote down vote up
@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 #17
Source File: LocalKinoRepositoryTest.java    From CineLog with GNU General Public License v3.0 6 votes vote down vote up
@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 #18
Source File: LocalKinoRepositoryTest.java    From CineLog with GNU General Public License v3.0 6 votes vote down vote up
@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 #19
Source File: NewsChannelTableManager.java    From ZZShow with Apache License 2.0 5 votes vote down vote up
public static List<NewsChannelTable> loadNewsChannelsWithin(int from, int to) {
        Query<NewsChannelTable> newsChannelTableQuery = MyApplication.getDaoSession().getNewsChannelTableDao().queryBuilder()
                .where(NewsChannelTableDao.Properties.NewsChannelIndex.between(from,to))
                .build();
        return newsChannelTableQuery.list();
//        return DBManager.init(MyApplication.getInstance())
//                .loadNewsChannelsByWhere("news_channel_index BETWEEN ? AND ? ",new String[]{from+"",to+""});
    }
 
Example #20
Source File: NewsChannelTableManager.java    From ZZShow with Apache License 2.0 5 votes vote down vote up
/**
     *  加载 用户已选中的频道
     * @return 已被选择的频道
     */
    public static List<NewsChannelTable> loadNewsChannelsMine(){
        Query<NewsChannelTable> newsChannelTableQuery = MyApplication.getDaoSession().getNewsChannelTableDao()
                .queryBuilder()
                .where(NewsChannelTableDao.Properties.NewsChannelSelect.eq(true))
                .orderAsc(NewsChannelTableDao.Properties.NewsChannelIndex)
                .build();
        return newsChannelTableQuery.list();
//        return DBManager.init(MyApplication.getInstance()).loadNewsChannels("1");
    }
 
Example #21
Source File: NewsChannelTableManager.java    From ZZShow with Apache License 2.0 5 votes vote down vote up
/**
 *  查询 index > ?  频道
 * @param index
 */
public static List<NewsChannelTable> loadNewsChannelsIndexGt(int index){
    Query<NewsChannelTable> newsChannelTableQuery = MyApplication.getDaoSession().getNewsChannelTableDao().queryBuilder()
            .where(NewsChannelTableDao.Properties.NewsChannelIndex.gt(index)).build();
    return newsChannelTableQuery.list();
    //return DBManager.init(MyApplication.getInstance()).loadNewsChannelsByWhere(" news_channel_index > ? ",new String[]{index+""});
}
 
Example #22
Source File: SLSDatabaseManager.java    From aliyun-log-android-sdk with MIT License 5 votes vote down vote up
public void deleteTwoThousandRecords() {
    Query tableSelectQuery = daoSession.getLogEntityDao().queryBuilder().where(LogEntityDao.Properties.Timestamp.le(new Long(new Date().getTime()))).orderAsc(LogEntityDao.Properties.Timestamp).limit(2000).build();
    List<LogEntity> records = tableSelectQuery.list();
    List ids = new ArrayList();
    for(LogEntity log : records){
        ids.add(log.getId());
    }

    DeleteQuery tableDeleteQuery = daoSession.getLogEntityDao().queryBuilder().where(LogEntityDao.Properties.Id.in(ids)).buildDelete();
    tableDeleteQuery.executeDeleteWithoutDetachingEntities();
    daoSession.clear();
    DbUtils.vacuum(daoSession.getDatabase());
}
 
Example #23
Source File: NewsChannelTableManager.java    From ZZShow with Apache License 2.0 5 votes vote down vote up
/**
 *  index < channelIndex ,且 未被选中的
 * @param channelIndex
 * @return
 */
public static List<NewsChannelTable> loadNewsChannelsIndexLtAndIsUnselect(int channelIndex) {
    Query<NewsChannelTable> newsChannelTableQuery = MyApplication.getDaoSession().getNewsChannelTableDao().queryBuilder()
            .where(NewsChannelTableDao.Properties.NewsChannelIndex.lt(channelIndex)
                    ,NewsChannelTableDao.Properties.NewsChannelSelect.eq(false))
            .build();
    return newsChannelTableQuery.list();
    //return DBManager.init(MyApplication.getInstance()).loadNewsChannelsByWhere("news_channel_index < ? and news_channel_select = ? ",new String[]{channelIndex+"","0"});
}
 
Example #24
Source File: WordDao.java    From ml-authentication with Apache License 2.0 5 votes vote down vote up
/** Internal query to resolve the "words" to-many relationship of Image. */
public List<Word> _queryImage_Words(long imageId) {
    synchronized (this) {
        if (image_WordsQuery == null) {
            QueryBuilder<Word> queryBuilder = queryBuilder();
            queryBuilder.join(JoinImagesWithWords.class, JoinImagesWithWordsDao.Properties.WordId)
                .where(JoinImagesWithWordsDao.Properties.ImageId.eq(imageId));
            image_WordsQuery = queryBuilder.build();
        }
    }
    Query<Word> query = image_WordsQuery.forCurrentThread();
    query.setParameter(0, imageId);
    return query.list();
}
 
Example #25
Source File: NewsChannelTableManager.java    From ZZShow with Apache License 2.0 5 votes vote down vote up
/**
     *  加载 推荐频道
     * @return 推荐频道列表
     */
    public static List<NewsChannelTable> loadNewsChannelsRecommend(){
        Query<NewsChannelTable> newsChannelTableQuery = MyApplication.getDaoSession().getNewsChannelTableDao()
                .queryBuilder()
                .where(NewsChannelTableDao.Properties.NewsChannelSelect.eq(false))
                .orderAsc(NewsChannelTableDao.Properties.NewsChannelIndex)
                .build();
        return newsChannelTableQuery.list();
//        return DBManager.init(MyApplication.getInstance()).loadNewsChannels("0");
    }
 
Example #26
Source File: PlanTemplateRepository.java    From friendly-plans with GNU General Public License v3.0 5 votes vote down vote up
public List<TaskTemplate> getTaskWithThisPlanByTypeId(Long planId, Integer typeId) {
    QueryBuilder<TaskTemplate> queryBuilder = daoSession.getTaskTemplateDao().queryBuilder();
    queryBuilder.where(TaskTemplateDao.Properties.TypeId.eq(typeId))
            .join(PlanTaskTemplate.class, PlanTaskTemplateDao.Properties.TaskTemplateId)
            .where(PlanTaskTemplateDao.Properties.PlanTemplateId.eq(planId));
    Query<TaskTemplate> getTaskWithThisPlanByTypeIdQuery = queryBuilder.build();
    return getTaskWithThisPlanByTypeIdQuery.list();
}
 
Example #27
Source File: PlanTemplateRepository.java    From friendly-plans with GNU General Public License v3.0 5 votes vote down vote up
public List<PlanTemplate> getPlansWithThisTask(Long taskId) {
    QueryBuilder<PlanTemplate> queryBuilder = daoSession.getPlanTemplateDao().queryBuilder();
    queryBuilder.join(PlanTaskTemplate.class, PlanTaskTemplateDao.Properties.PlanTemplateId)
            .where(PlanTaskTemplateDao.Properties.TaskTemplateId.eq(taskId));
    Query<PlanTemplate> getPlansWithThisTaskQuery = queryBuilder.build();
    return getPlansWithThisTaskQuery.list();
}
 
Example #28
Source File: UserDao.java    From android-orm-benchmark-updated with Apache License 2.0 5 votes vote down vote up
/** 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 #29
Source File: WordDao.java    From ml-authentication with Apache License 2.0 5 votes vote down vote up
/** Internal query to resolve the "words" to-many relationship of Audio. */
public List<Word> _queryAudio_Words(long audioId) {
    synchronized (this) {
        if (audio_WordsQuery == null) {
            QueryBuilder<Word> queryBuilder = queryBuilder();
            queryBuilder.join(JoinAudiosWithWords.class, JoinAudiosWithWordsDao.Properties.WordId)
                .where(JoinAudiosWithWordsDao.Properties.AudioId.eq(audioId));
            audio_WordsQuery = queryBuilder.build();
        }
    }
    Query<Word> query = audio_WordsQuery.forCurrentThread();
    query.setParameter(0, audioId);
    return query.list();
}
 
Example #30
Source File: AllophoneDao.java    From ml-authentication with Apache License 2.0 5 votes vote down vote up
/** Internal query to resolve the "allophones" to-many relationship of Letter. */
public List<Allophone> _queryLetter_Allophones(long letterId) {
    synchronized (this) {
        if (letter_AllophonesQuery == null) {
            QueryBuilder<Allophone> queryBuilder = queryBuilder();
            queryBuilder.join(JoinLettersWithAllophones.class, JoinLettersWithAllophonesDao.Properties.AllophoneId)
                .where(JoinLettersWithAllophonesDao.Properties.LetterId.eq(letterId));
            letter_AllophonesQuery = queryBuilder.build();
        }
    }
    Query<Allophone> query = letter_AllophonesQuery.forCurrentThread();
    query.setParameter(0, letterId);
    return query.list();
}