greenDao模仿加盟 [英] greenDao imitate join

查看:156
本文介绍了greenDao模仿加盟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个实体:订单和WorkPosition。的Workpositions通过订单的ID相关的,这意味着我有一个toMany-关系在这里。一个订单有NWorkpositions和一个Workpostion一向的order_id。因此,有一个功能:order.getWorkPositions()

I have two entities: "Orders" and "WorkPosition". The Workpositions are related through the id of the orders, that means i have an toMany-Relationship here. One order have "n" Workpositions and one Workpostion has always an order_id. So there is a function: order.getWorkPositions().

我在做什么现在:
RightNow的我正在查询所有订单,然后我公司通过订单迭代。如果订单有workposition.type workpositions =1。

What i am doing right now: Rightnow i am querying all Orders and then i am iterating through the Orders. If an order has workpositions that have workposition.type="1".

的问题是,这是很慢的,因为我有至少1000的订单和甚至更workpositions

The problem is that this is very slow, because i have at least 1000 orders and even more workpositions.

问:
我看到加入功能无法正常工作,但在greenDao首页我看到下面的查询:

Question: I saw that the "join" function is not working, but on the greenDao Homepage i saw the following Query:

Query query = userDao.queryBuilder().where(
new StringCondition("_ID IN " +
"(SELECT USER_ID FROM USER_MESSAGE WHERE READ_FLAG = 0)").build();

我该如何使用它来加速比我的查询?我可以有订单从查询的返回类型?或者,我可以只有一个ID列表?

How can i use it to speedup my query? Can i have orders as a returntype from the query? Or can i have only a list of ids?

作为查询我想是这样的:

As a query i want something like this:

Query<Orders> query = getDAOSession().getOrdersDao().queryBuilder()
.where(new StringCondition("?_ID IN? "+ 
"(SELECT * FROM Orders AS O JOIN WorkPosition AS W WHERE w.type=1)")).build();
List<Orders> orders = query.list();

我希望你能理解我的问题,如果不告诉我,我会尝试改善它!)

I hope you can understand my question, if not tell me and i will try to improve it!:)

推荐答案

加入 - 函数只是不被greendao-API的支持。这意味着你不能建立使用财产的平等命名的功能连接。

The "join"-function is only not supported by the greendao-api. This means you cannot build joins using the equal named function of Property.

但你可以建立每一个WhereCondition你因为它的SQLite支持要长。这意味着你的查询将正常工作,如果你正确地加入。 (我注意到,你没有指定ON语句来)。

But you can build every WhereCondition you want as long as it is supported by SQLite. This means your query will work, if you join correctly. (I noticed that you didn't specify "ON"-statement).

这篇关于greenDao模仿加盟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆