/** * Construct an IntegerProperty represented by the expression "COUNT(field)" or "COUNT(DISTINCT field)" * * @param field the field to count * @param distinct whether to count distinct values only or not */ public static IntegerProperty countProperty(Field<?> field, boolean distinct) { Function<Integer> function = distinct ? Function.countDistinct(field) : Function.count(field); return fromFunction(function, "count"); }
/** * Construct an IntegerProperty represented by the expression "COUNT(1)" */ public static IntegerProperty countProperty() { return fromFunction(Function.count(), "count"); }
/** * Construct an IntegerProperty represented by the expression "COUNT(field)" or "COUNT(DISTINCT field)" * * @param field the field to count * @param distinct whether to count distinct values only or not */ public static IntegerProperty countProperty(Field<?> field, boolean distinct) { Function<Integer> function = distinct ? Function.countDistinct(field) : Function.count(field); return fromFunction(function, "count"); }
public void testBoundArgumentsWorkInHavingClause() { Query query = Query.select(Employee.PROPERTIES) .groupBy(Employee.MANAGER_ID) .having(Function.count(Employee.MANAGER_ID).gt(2)); SquidCursor<Employee> cursor = database.query(Employee.class, query); try { assertEquals(1, cursor.getCount()); cursor.moveToFirst(); assertEquals(bigBird.getRowId(), cursor.get(Employee.MANAGER_ID).longValue()); } finally { cursor.close(); } }
/** * Construct an IntegerProperty represented by the expression "COUNT(1)" */ public static IntegerProperty countProperty() { return fromFunction(Function.count(), "count"); }
subquery.having(Function.count().gt(1));
public void testEqualsAndHashCode() { LongProperty test1 = new LongProperty( new TableModelName(TestModel.class, TestModel.TABLE.getName()), "testCol"); LongProperty test2 = new LongProperty( new TableModelName(TestModel.class, TestModel.TABLE.getName()), "testCol"); assertEquals(test1, test2); assertEquals(test1.hashCode(), test2.hashCode()); StringProperty test3 = new StringProperty( new TableModelName(TestModel.class, TestModel.TABLE.getName()), "testCol"); StringProperty test4 = new StringProperty( new TableModelName(TestModel.class, TestModel.TABLE.getName()), "testCol", "DEFAULT 'A'"); assertEquals(test3, test4); assertEquals(test3.hashCode(), test4.hashCode()); Function<Integer> func1 = Function.count(); Function<Integer> func2 = Function.rawFunction("COUNT(*)"); assertEquals(func1, func2); assertEquals(func1.hashCode(), func2.hashCode()); IntegerProperty test5 = Property.IntegerProperty.fromFunction(func1, "count"); IntegerProperty test6 = Property.IntegerProperty.fromFunction(func2, "count"); assertEquals(test5, test6); assertEquals(test5.hashCode(), test6.hashCode()); }