public void testLengthOfNumeric() { IntegerProperty length = IntegerProperty.fromFunction(Function.length(TestModel.BIRTHDAY), "length"); TestModel fetch = database.fetch(TestModel.class, model1.getRowId(), length); assertEquals(Long.toString(model1.getBirthday()).length(), fetch.get(length).intValue()); }
public void testLengthOfString() { IntegerProperty length = IntegerProperty.fromFunction(Function.length(TestModel.FIRST_NAME), "length"); TestModel fetch = database.fetch(TestModel.class, model2.getRowId(), length); assertEquals(5, fetch.get(length).intValue()); }
public void testSumAndSumDistinct() { setUpAggregateTest(); IntegerProperty sum = IntegerProperty.fromFunction( Function.sum(TestModel.LUCKY_NUMBER), "sum"); IntegerProperty sumDistinct = IntegerProperty.fromFunction( Function.sumDistinct(TestModel.LUCKY_NUMBER), "sumDistinct"); SquidCursor<TestModel> cursor = database.query(TestModel.class, Query.select(sum, sumDistinct)); try { assertEquals(1, cursor.getCount()); cursor.moveToFirst(); assertEquals(12, cursor.get(sum).intValue()); assertEquals(8, cursor.get(sumDistinct).intValue()); } finally { cursor.close(); } }
/** * 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"); }
IntegerProperty hasLongName = IntegerProperty.fromFunction(longNameFunc, "hasLongName"); assertExpectedValues(Query.select(hasLongName).from(TestModel.TABLE).orderBy(TestModel.ID.asc()), hasLongName, 0, 0, 1);
public void testMath() { Function<Integer> addition = Function.add(1, 2, 3, 4, 5); IntegerProperty sum = IntegerProperty.fromFunction(addition, "sum"); testMath(sum, 15); Function<Integer> subtraction = Function.subtract(100, 30, 20); IntegerProperty difference = IntegerProperty.fromFunction(subtraction, "difference"); testMath(difference, 50); Function<Integer> multiplcation = Function.multiply(1, 2, 3, 4, 5); IntegerProperty product = IntegerProperty.fromFunction(multiplcation, "product"); testMath(product, 120); Function<Integer> division = Function.divide(1000, 10, 5); IntegerProperty quotient = IntegerProperty.fromFunction(division, "quotient"); testMath(quotient, 20); Function<Integer> modulus = Function.modulo(512, 9); IntegerProperty remainder = IntegerProperty.fromFunction(modulus, "remainder"); testMath(remainder, 8); Function<Integer> bitAnd = Function.bitwiseAnd(0xcafe0000, 0xba00, 0xbe); IntegerProperty and = IntegerProperty.fromFunction(bitAnd, "bitAnd"); testMath(and, 0); Function<Integer> bitOr = Function.bitwiseOr(0xcafe0000, 0xba00, 0xbe); IntegerProperty or = IntegerProperty.fromFunction(bitOr, "bitOr"); testMath(or, 0xcafebabe); }
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()); }
/** * 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"); }