org.greenrobot.greendao.query.WhereCondition Java Examples

The following examples show how to use org.greenrobot.greendao.query.WhereCondition. 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: 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 #2
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 #3
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 #4
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 #5
Source File: MediaDownloadInfoHelper.java    From FimiX8-RE with MIT License 5 votes vote down vote up
private void update(String url, MediaDownloadInfo info) {
    MediaDownloadInfo findUser = (MediaDownloadInfo) this.dao.queryBuilder().where(Properties.Url.eq(url), new WhereCondition[0]).build().unique();
    if (findUser != null) {
        findUser.setUrl(info.getUrl());
        findUser.setCompeleteZize(info.getCompeleteZize());
        findUser.setEndPos(info.getEndPos());
        findUser.setStartPos(info.getStartPos());
        this.dao.update(findUser);
    }
}
 
Example #6
Source File: BaiduNaviDao.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
/**
 * 根据指定地址名称或经纬度查询地址
 **/
public BaiduAddress get(BaiduAddress baiduAddress) {
    DecimalFormat df = new DecimalFormat("0.0000");
    WhereCondition andCondition = mAddressDao.queryBuilder().and(BaiduAddressDao.Properties.Latitude.like(df.format(baiduAddress.getLatitude()) + "%"),
            BaiduAddressDao.Properties.Longitude.like(df.format(baiduAddress.getLongitude()) + "%"));
    return mAddressDao.queryBuilder().whereOr(BaiduAddressDao.Properties.Address.eq(baiduAddress.getAddress())
            , andCondition).orderDesc(BaiduAddressDao.Properties.FavoritedTime).limit(1).unique();
}
 
Example #7
Source File: DataStasicInfoHelper.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void addRecord(DataStaticInfo dataStaticInfo) {
    DataStaticInfo unique = (DataStaticInfo) this.dao.queryBuilder().where(Properties.CurrentTime.eq(dataStaticInfo.getCurrentTime()), new WhereCondition[0]).where(Properties.Type.eq(Byte.valueOf(dataStaticInfo.getType())), new WhereCondition[0]).where(Properties.DeviceType.eq(Byte.valueOf(dataStaticInfo.getDeviceType())), new WhereCondition[0]).build().unique();
    if (unique != null) {
        LogUtil.i(X11CmdConstants.OPTION_APPSTATUS_RECORD, "addRecord: 1");
        unique.setUseTime(dataStaticInfo.getUseTime());
        unique.setFlyTime(dataStaticInfo.getFlyTime());
        this.dao.update(unique);
        return;
    }
    LogUtil.i(X11CmdConstants.OPTION_APPSTATUS_RECORD, "addRecord: 2");
    this.dao.insert(dataStaticInfo);
}
 
Example #8
Source File: GH2DataStasicInfoHelper.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void addRecord(GH2DataStaticInfo gh2DataStaticInfo) {
    GH2DataStaticInfo unique = (GH2DataStaticInfo) this.gh2DataStaticInfoDao.queryBuilder().where(Properties.CreateTime.eq(gh2DataStaticInfo.getCreateTime()), new WhereCondition[0]).build().unique();
    if (unique != null) {
        LogUtil.i(X11CmdConstants.OPTION_APPSTATUS_RECORD, "addRecord: 1");
        unique.setUseTime(gh2DataStaticInfo.getUseTime());
        unique.setCreateTime(gh2DataStaticInfo.getCreateTime());
        this.gh2DataStaticInfoDao.update(unique);
        return;
    }
    LogUtil.i(X11CmdConstants.OPTION_APPSTATUS_RECORD, "addRecord: 2");
    this.gh2DataStaticInfoDao.insert(gh2DataStaticInfo);
}
 
Example #9
Source File: X8AiLinePointInfoHelper.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public List<X8AiLinePointInfo> getLastItem(int count, int mapType, boolean isFavorites) {
    QueryBuilder<X8AiLinePointInfo> qb = this.lineDao.queryBuilder();
    if (isFavorites) {
        WhereCondition where = Properties.MapType.eq(Integer.valueOf(mapType));
        WhereCondition where1 = Properties.SaveFlag.eq(Integer.valueOf(1));
        qb.where(where, where1).build();
    } else {
        qb.where(Properties.MapType.eq(Integer.valueOf(mapType)), new WhereCondition[0]);
    }
    qb.orderDesc(Properties.Id);
    qb.limit(count);
    return qb.list();
}
 
Example #10
Source File: MediaDownloadInfoHelper.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void updateMediaDownloadInfo(String url, MediaDownloadInfo info) {
    MediaDownloadInfo findUser = (MediaDownloadInfo) this.dao.queryBuilder().where(Properties.Url.eq(url), new WhereCondition[0]).build().unique();
    if (findUser != null) {
        findUser.setUrl(info.getUrl());
        findUser.setCompeleteZize(info.getCompeleteZize());
        findUser.setEndPos(info.getEndPos());
        findUser.setStartPos(info.getStartPos());
        this.dao.update(findUser);
    }
}
 
Example #11
Source File: X8AiLinePointInfoHelper.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void updatelineSaveFlag(int saveFlag, long lineId) {
    X8AiLinePointInfo find = (X8AiLinePointInfo) this.lineDao.queryBuilder().where(Properties.Id.eq(Long.valueOf(lineId)), new WhereCondition[0]).build().unique();
    if (find != null) {
        find.setSaveFlag(saveFlag);
        this.lineDao.update(find);
    }
}
 
Example #12
Source File: X8AiLinePointInfoHelper.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void updateLineName(String name, long lineId) {
    X8AiLinePointInfo find = (X8AiLinePointInfo) this.lineDao.queryBuilder().where(Properties.Id.eq(Long.valueOf(lineId)), new WhereCondition[0]).build().unique();
    if (find != null) {
        find.setName(name);
        this.lineDao.update(find);
    }
}
 
Example #13
Source File: OperationFragment.java    From GreenDaoSample with Apache License 2.0 5 votes vote down vote up
private void select() {
    List<WhereCondition> whereConditionList = new ArrayList<>();

    //模糊匹配姓名
    whereConditionList.add(Properties.Name.like("%" + getContent(mOperationUser.getName()) + "%"));
    //模糊匹配电话号码
    whereConditionList.add(Properties.Phone.like("%" + getContent(mOperationUser.getPhone()) + "%"));
    //精确匹配男/女
    if (!TextUtils.isEmpty(mOperationUser.getSex())) {
        whereConditionList.add(UserDao.Properties.Sex.eq(getContent(mOperationUser.getSex())));
    }
    postEvent(new SelectEvent(mUserDao.queryBuilder().where(Properties.Time.isNotNull(),
            whereConditionList.toArray(new WhereCondition[]{})).list()));
    pop();
}
 
Example #14
Source File: LocalAudioDataSource.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
public PlayMusic getByCloudMusic(PlayMusic music) {
    WhereCondition condition = dao.queryBuilder().and(Properties.Title.eq(music.getTitle()), Properties.Singer.eq(music.getSinger()));
    return dao.queryBuilder().whereOr(Properties.Musicid.eq(music.getId()), condition).limit(1).unique();
}
 
Example #15
Source File: X8AiLinePointInfoHelper.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public List<X8AiLinePointLatlngInfo> getLatlngByLineId(int mapType, long lineId) {
    QueryBuilder<X8AiLinePointLatlngInfo> qb = this.pointDao.queryBuilder();
    qb.where(X8AiLinePointLatlngInfoDao.Properties.LineId.eq(Long.valueOf(lineId)), new WhereCondition[0]);
    return qb.list();
}
 
Example #16
Source File: ChineseCityEntityController.java    From GeometricWeather with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Nullable
public ChineseCityEntity selectChineseCityEntity(@NonNull String province,
                                                 @NonNull String city,
                                                 @NonNull String district) {
    ChineseCityEntityDao dao = getSession().getChineseCityEntityDao();

    List<WhereCondition> conditionList = new ArrayList<>();
    conditionList.add(
            dao.queryBuilder().and(
                    ChineseCityEntityDao.Properties.District.eq(district),
                    ChineseCityEntityDao.Properties.City.eq(city)
            )
    );
    conditionList.add(
            dao.queryBuilder().and(
                    ChineseCityEntityDao.Properties.District.eq(district),
                    ChineseCityEntityDao.Properties.Province.eq(province)
            )
    );
    conditionList.add(
            dao.queryBuilder().and(
                    ChineseCityEntityDao.Properties.City.eq(city),
                    ChineseCityEntityDao.Properties.Province.eq(province)
            )
    );
    conditionList.add(ChineseCityEntityDao.Properties.City.eq(city));
    conditionList.add(
            dao.queryBuilder().and(
                    ChineseCityEntityDao.Properties.District.eq(city),
                    ChineseCityEntityDao.Properties.Province.eq(province)
            )
    );
    conditionList.add(
            dao.queryBuilder().and(
                    ChineseCityEntityDao.Properties.District.eq(city),
                    ChineseCityEntityDao.Properties.City.eq(province)
            )
    );
    conditionList.add(ChineseCityEntityDao.Properties.District.eq(city));
    conditionList.add(ChineseCityEntityDao.Properties.City.eq(district));

    List<ChineseCityEntity> entityList;
    for (WhereCondition c : conditionList) {
        try {
            entityList = dao.queryBuilder().where(c).list();
        } catch (Exception e) {
            entityList = null;
        }
        if (entityList != null && entityList.size() > 0) {
            return entityList.get(0);
        }
    }

    return null;
}
 
Example #17
Source File: ArticleListFragment.java    From android-app with GNU General Public License v3.0 4 votes vote down vote up
private QueryBuilder<Article> getQueryBuilder() {
    QueryBuilder<Article> qb = articleDao.queryBuilder()
            .where(ArticleDao.Properties.ArticleId.isNotNull());

    if (untagged) {
        qb.where(new WhereCondition.StringCondition(UNTAGGED_WHERE));
    } else if (tagIDs != null && !tagIDs.isEmpty()) {
        // TODO: try subquery
        qb.join(ArticleTagsJoin.class, ArticleTagsJoinDao.Properties.ArticleId)
                .where(ArticleTagsJoinDao.Properties.TagId.in(tagIDs));
    }

    switch (listType) {
        case LIST_TYPE_ARCHIVED:
            qb.where(ArticleDao.Properties.Archive.eq(true));
            break;

        case LIST_TYPE_FAVORITES:
            qb.where(ArticleDao.Properties.Favorite.eq(true));
            break;

        default:
            qb.where(ArticleDao.Properties.Archive.eq(false));
            break;
    }

    if (!TextUtils.isEmpty(searchQuery)) {
        qb.where(new WhereCondition.StringCondition(ArticleDao.Properties.Id.columnName + " IN (" +
                FtsDao.getQueryString() + DatabaseUtils.sqlEscapeString(searchQuery) + ")"));
    }

    switch (sortOrder) {
        case ASC:
            qb.orderAsc(ArticleDao.Properties.ArticleId);
            break;

        case DESC:
            qb.orderDesc(ArticleDao.Properties.ArticleId);
            break;

        default:
            throw new IllegalStateException("Sort order not implemented: " + sortOrder);
    }

    return qb;
}
 
Example #18
Source File: X8AiLinePointInfoHelper.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public X8AiLinePointInfo getLineInfoById(long lineId) {
    QueryBuilder<X8AiLinePointInfo> qb = this.lineDao.queryBuilder();
    qb.where(Properties.Id.eq(Long.valueOf(lineId)), new WhereCondition[0]);
    qb.orderDesc(Properties.Id);
    return (X8AiLinePointInfo) qb.list().get(0);
}
 
Example #19
Source File: DataStasicInfoHelper.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public List<DataStaticInfo> queryX9UseTime() {
    QueryBuilder<DataStaticInfo> qb = this.dao.queryBuilder();
    qb.where(Properties.Type.eq(Integer.valueOf(0)), new WhereCondition[0]).where(Properties.DeviceType.eq(Integer.valueOf(0)), new WhereCondition[0]);
    return qb.list();
}
 
Example #20
Source File: DataStasicInfoHelper.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public List<DataStaticInfo> queryX9FlyTime() {
    QueryBuilder<DataStaticInfo> qb = this.dao.queryBuilder();
    qb.where(Properties.Type.eq(Integer.valueOf(1)), new WhereCondition[0]).where(Properties.DeviceType.eq(Integer.valueOf(0)), new WhereCondition[0]);
    return qb.list();
}
 
Example #21
Source File: MediaDownloadInfoHelper.java    From FimiX8-RE with MIT License 4 votes vote down vote up
private List<MediaDownloadInfo> queryList(String url) {
    QueryBuilder<MediaDownloadInfo> qb = this.dao.queryBuilder();
    qb.where(Properties.Url.eq(url), new WhereCondition[0]);
    return qb.list();
}
 
Example #22
Source File: MediaDownloadInfoHelper.java    From FimiX8-RE with MIT License 4 votes vote down vote up
private void delete(String url) {
    MediaDownloadInfo findUser = (MediaDownloadInfo) this.dao.queryBuilder().where(Properties.Url.eq(url), new WhereCondition[0]).build().unique();
    if (findUser != null) {
        this.dao.deleteByKey(findUser.getId());
    }
}
 
Example #23
Source File: MediaDownloadInfoHelper.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public MediaDownloadInfo queryMediaDownloadInfo(String url) {
    return (MediaDownloadInfo) this.dao.queryBuilder().where(Properties.Url.eq(url), new WhereCondition[0]).build().unique();
}
 
Example #24
Source File: MediaDownloadInfoHelper.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public void deleteMediaDownloadInfo(String url) {
    MediaDownloadInfo findUser = (MediaDownloadInfo) this.dao.queryBuilder().where(Properties.Url.eq(url), new WhereCondition[0]).build().unique();
    if (findUser != null) {
        this.dao.deleteByKey(findUser.getId());
    }
}