Frage

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().

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".

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

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();

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!:)

War es hilfreich?

Lösung 2

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

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).

Andere Tipps

In my experience I usually use the raw query for join statements. Only Ormlite supports partially join, but it is very simple and not usable for me in all cases. My proposition - use raw query and cursors

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top