Martin Seal Martin Seal - 5 months ago 37
Java Question

green dao how to use one query for four properties

im trying to write a query in green dao and cant figure out exactly how to say what i want to say,
i have 3 properties im focusing my query on CardIconType, Type_of_word and Type_of_type (terrible naming convention but please lets not focus on this)
what i want to return are all the items of CardIconType that say "ORIGINAL" and all the items of CardIconType that say "USER" but only if Type_of_type is "PRONOUN" and Type_of_word is "QUICKS"

WHAT I'VE TRIED

So far ive tried this

qb.where(addNewCardDao.Properties.CardIconType.eq("ORIGINAL"),
qb.and(addNewCardDao.Properties.Type_of_type.eq("PRONOUNS"),
addNewCardDao.Properties.Type_of_word.eq("QUICKS")));
leaseList = qb.list();


which solves half of my issue it returns all the objects of "ORIGINAL" where Type_of_type is "PRONOUNS and Type_of_word is "QUICKS" and my first thought was to do this again for USER and join the lists, but i dont think thats the best way to do it so i then tried this

qb.where(addNewCardDao.Properties.CardIconType.eq("SIMPLE"),
qb.or(addNewCardDao.Properties.CardIconType.gt("USER"),

qb.and(addNewCardDao.Properties.Type_of_type.eq("PRONOUNS"),
addNewCardDao.Properties.Type_of_word.ge("QUICKS"))));
leaseList = qb.list();


but no joy can anyone help me out here please

Answer

Use QueryBuilder.in() method to look for multiple values in one property.

String[] strings = {"ORIGINAL", "USER"};
qb.where(addNewCardDao.Properties.CardIconType.in(strings),

Then add additional restrictions:

qb.and(addNewCardDao.Properties.Type_of_type.eq("PRONOUNS"),
addNewCardDao.Properties.Type_of_word.eq("QUICKS")));

And the just list it:

leaseList = qb.list();