use of com.orm.androrm.statement.InStatement in project androrm by androrm.
the class FilterTest method testIn.
public void testIn() {
Filter set = new Filter();
List<Integer> values = new ArrayList<Integer>();
values.add(3);
values.add(5);
set.in("product__id", values);
List<Rule> filters = set.getRules();
Rule filter = filters.get(0);
Statement s = filter.getStatement();
Set<String> keys = s.getKeys();
assertEquals("product__id", filter.getKey());
assertTrue(keys.contains("id"));
assertTrue(s instanceof InStatement);
assertEquals("id IN ('3','5')", s.toString());
List<Product> products = new ArrayList<Product>();
Product p1 = new Product();
p1.setName("test 1");
p1.save(getContext());
Product p2 = new Product();
p2.setName("test 2");
p2.save(getContext());
products.add(p1);
products.add(p2);
set = new Filter();
set.in("supplier__product", products);
filters = set.getRules();
filter = filters.get(0);
s = filter.getStatement();
keys = s.getKeys();
assertEquals("supplier__product", filter.getKey());
assertTrue(keys.contains("product"));
assertTrue(s instanceof InStatement);
assertEquals("product IN ('" + p1.getId() + "','" + p2.getId() + "')", s.toString());
}
use of com.orm.androrm.statement.InStatement in project androrm by androrm.
the class QuerySet method containsAll.
/**
* See {@link QuerySet#contains}
* @param values
* @return
*/
public boolean containsAll(Collection<T> values) {
if (mQuery != null) {
List<Object> ids = new ArrayList<Object>();
for (T item : values) {
ids.add(item.getId());
}
Where where = new Where();
where.setStatement(new InStatement(Model.PK, ids));
SelectStatement query = new SelectStatement();
query.from(mQuery).where(where);
return getCount(query) == values.size();
}
return false;
}
use of com.orm.androrm.statement.InStatement in project androrm by androrm.
the class InStatementTest method testGetKeys.
public void testGetKeys() {
List<Object> values = new ArrayList<Object>();
values.add(1);
InStatement in = new InStatement("foo", values);
Set<String> keys = in.getKeys();
assertEquals(1, keys.size());
assertTrue(keys.contains("foo"));
}
use of com.orm.androrm.statement.InStatement in project androrm by androrm.
the class InStatementTest method testPlainStatement.
public void testPlainStatement() {
List<Object> values = new ArrayList<Object>();
values.add(1);
InStatement in = new InStatement("foo", values);
assertEquals("foo IN ('1')", in.toString());
values.add(2);
values.add(3);
in = new InStatement("foo", values);
assertEquals("foo IN ('1','2','3')", in.toString());
}
Aggregations