com.yahoo.squidb.data.SquidCursor Java Examples

The following examples show how to use com.yahoo.squidb.data.SquidCursor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testCriterionWithNestedSelect() {
    TestModel modelOne = new TestModel().setFirstName("Sam").setLastName("Bosley");
    TestModel modelTwo = new TestModel().setFirstName("Kevin").setLastName("Lim");
    TestModel modelThree = new TestModel().setFirstName("Jonathan").setLastName("Koren");

    database.persist(modelOne);
    database.persist(modelTwo);
    database.persist(modelThree);
    assertEquals(3, database.countAll(TestModel.class));

    database.deleteWhere(TestModel.class,
            TestModel.ID.lt(Query.select(Function.max(TestModel.ID)).from(TestModel.TABLE)));
    SquidCursor<TestModel> cursor = null;
    try {
        cursor = database.query(TestModel.class, Query.select());
        assertEquals(1, cursor.getCount());
        cursor.moveToFirst();
        assertEquals(3, cursor.get(TestModel.ID).longValue());
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
 
Example #2
Source File: SquidCursorLoader.java    From squidb with Apache License 2.0 6 votes vote down vote up
@Override
public void deliverResult(SquidCursor<T> data) {
    if (isReset()) {
        if (data != null) {
            data.close();
        }
        return;
    }

    SquidCursor<T> oldCursor = this.cursor;
    this.cursor = data;

    if (isStarted()) {
        super.deliverResult(data);
    }

    if (oldCursor != null && oldCursor != data && !oldCursor.isClosed()) {
        oldCursor.close();
    }
}
 
Example #3
Source File: FtsQueryTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
private void testQueryResults(Criterion criterion, TestVirtualModel... expectedResults) {
    Query query = Query.select(TestVirtualModel.PROPERTIES).where(criterion);
    SquidCursor<TestVirtualModel> cursor = database.query(TestVirtualModel.class, query);
    try {
        int expectedCount = expectedResults == null ? 0 : expectedResults.length;
        assertEquals(expectedCount, cursor.getCount());
        if (expectedCount == 0) {
            return;
        }

        for (int i = 0; i < expectedCount; i++) {
            cursor.moveToPosition(i);
            assertEquals(expectedResults[i], new TestVirtualModel(cursor));
        }
    } finally {
        cursor.close();
    }
}
 
Example #4
Source File: SquidRecyclerAdapterTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
private void testRecyclerAdapterInternal(LongProperty idProperty, RecyclerAdapterTest test) {
    Query query = Query.select(TestModel.PROPERTIES)
            .orderBy(TestModel.BIRTHDAY.asc())
            .limit(2);
    if (idProperty != null) {
        query.selectMore(idProperty);
    }
    SquidCursor<TestModel> cursor = database.query(TestModel.class, query);

    TestRecyclerAdapter adapter = new TestRecyclerAdapter(idProperty);
    adapter.changeCursor(cursor);
    try {
        test.testRecyclerAdapter(adapter);
    } finally {
        cursor.close();
    }
}
 
Example #5
Source File: SquidSupportCursorLoader.java    From squidb with Apache License 2.0 6 votes vote down vote up
@Override
public void deliverResult(SquidCursor<T> data) {
    if (isReset()) {
        if (data != null) {
            data.close();
        }
        return;
    }

    SquidCursor<T> oldCursor = this.cursor;
    this.cursor = data;

    if (isStarted()) {
        super.deliverResult(data);
    }

    if (oldCursor != null && oldCursor != data && !oldCursor.isClosed()) {
        oldCursor.close();
    }
}
 
Example #6
Source File: SqlFunctionsTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testSubstr() {
    testSubstrInternal(2, 0);
    testSubstrInternal(2, 2);
    testSubstrInternal(3, 4);

    String literal = "ABC/DEF";
    StringProperty prefix = StringProperty.literal(literal.substring(0, literal.indexOf('/') + 1), "prefix");
    StringProperty full = StringProperty.literal(literal, "full");

    Field<String> fullField = Field.field(full.getName());
    Field<String> prefixField = Field.field(prefix.getName());
    SquidCursor<?> cursor = database.query(null,
            Query.select(Function.substr(fullField, Function.add(Function.length(prefixField), 1)))
                    .from(Query.select(full, prefix).as("subquery")));
    try {
        assertTrue(cursor.moveToFirst());
        assertEquals("DEF", cursor.getString(0));
    } finally {
        cursor.close();
    }
}
 
Example #7
Source File: SquidCursorAdapterTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testSwapCursorDoesNotCloseOldCursor() {
    TestAdapter adapter = new TestAdapter(new TestModel());

    SquidCursor<TestModel> cursor1 = database.query(TestModel.class, Query.select());
    try {
        adapter.swapCursor(cursor1);
        SquidCursor<TestModel> cursor2 = database.query(TestModel.class, Query.select().where(TestModel.ID.eq(1)));
        try {
            SquidCursor<?> swappedCursor = adapter.swapCursor(cursor2);
            assertFalse(swappedCursor.isClosed());
        } finally {
            adapter.swapCursor(null);
            cursor2.close();
        }
    } finally {
        cursor1.close();
    }
}
 
Example #8
Source File: ContentProviderQueryBuilderTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testDefaultOrderBy() {
    ContentProviderQueryBuilder builder = getBuilder();
    builder.setDefaultOrder(TestModel.LUCKY_NUMBER.desc());
    Query query = builder.setDataSource(TestModel.TABLE).build(null, null, null, null);
    CompiledStatement compiled = query.compile(database.getCompileContext());
    verifyCompiledSqlArgs(compiled, 0);

    SquidCursor<TestModel> cursor = null;
    try {
        cursor = database.query(TestModel.class, query);
        assertEquals(3, cursor.getCount());
        cursor.moveToFirst();
        assertEquals(model2, buildModelFromCursor(cursor));
        cursor.moveToNext();
        assertEquals(model1, buildModelFromCursor(cursor));
        cursor.moveToNext();
        assertEquals(model3, buildModelFromCursor(cursor));
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
 
Example #9
Source File: ContentProviderQueryBuilderTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testRawOrderBy() {
    String sortOrder = COL_GIVEN_NAME + " ASC";
    ContentProviderQueryBuilder builder = getBuilder();
    Query query = builder.setDataSource(TestModel.TABLE).build(null, null, null, sortOrder);
    CompiledStatement compiled = query.compile(database.getCompileContext());
    verifyCompiledSqlArgs(compiled, 0);

    SquidCursor<TestModel> cursor = null;
    try {
        cursor = database.query(TestModel.class, query);
        assertEquals(3, cursor.getCount());
        cursor.moveToFirst();
        assertEquals(model3, buildModelFromCursor(cursor));
        cursor.moveToNext();
        assertEquals(model2, buildModelFromCursor(cursor));
        cursor.moveToNext();
        assertEquals(model1, buildModelFromCursor(cursor));
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
 
Example #10
Source File: SquidCursorAdapterTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
private void testCursorAdapterInternal(AbstractModel model, LongProperty idColumn, Query query,
        CursorAdapterTest test) {
    TestAdapter adapter;
    if (idColumn == null) {
        adapter = new TestAdapter(model);
    } else {
        adapter = new TestAdapter(model, idColumn);
    }

    SquidCursor<? extends AbstractModel> cursor = database.query(model.getClass(), query);
    try {
        adapter.swapCursor(cursor);
        test.testCursorAdapter(adapter);
    } finally {
        cursor.close();
    }
}
 
Example #11
Source File: SqlFunctionsTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testAvgAndAvgDistinct() {
    setUpAggregateTest();

    DoubleProperty avg = DoubleProperty.fromFunction(Function.avg(TestModel.LUCKY_NUMBER), "avg");
    DoubleProperty avgDistinct = DoubleProperty.fromFunction(
            Function.avgDistinct(TestModel.LUCKY_NUMBER), "avgDistinct");

    SquidCursor<TestModel> cursor = database.query(TestModel.class, Query.select(avg, avgDistinct));
    try {
        cursor.moveToFirst();
        assertEquals(2.0, cursor.get(avg));
        assertEquals(4.0, cursor.get(avgDistinct));
    } finally {
        cursor.close();
    }
}
 
Example #12
Source File: SqlFunctionsTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testGroupConcat() {
    setUpAggregateTest();

    StringProperty firstNameConcat = StringProperty.fromFunction(
            Function.groupConcat(TestModel.FIRST_NAME), "fname_concat");
    StringProperty firstNameConcatSeparator = StringProperty.fromFunction(
            Function.groupConcat(TestModel.FIRST_NAME, "|"), "fname_concat_separator");
    StringProperty firstNameDistinct = StringProperty.fromFunction(
            Function.groupConcatDistinct(TestModel.FIRST_NAME), "fname_distinct");
    SquidCursor<TestModel> cursor = database.query(TestModel.class,
            Query.select(firstNameConcat, firstNameConcatSeparator, firstNameDistinct)
                    .groupBy(TestModel.FIRST_NAME));
    try {
        assertEquals(2, cursor.getCount());
        cursor.moveToFirst();
        assertEquals("A,A,A", cursor.get(firstNameConcat));
        assertEquals("A|A|A", cursor.get(firstNameConcatSeparator));
        assertEquals("A", cursor.get(firstNameDistinct));
        cursor.moveToNext();
        assertEquals("B,B,B", cursor.get(firstNameConcat));
        assertEquals("B|B|B", cursor.get(firstNameConcatSeparator));
        assertEquals("B", cursor.get(firstNameDistinct));
    } finally {
        cursor.close();
    }
}
 
Example #13
Source File: SqlFunctionsTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #14
Source File: QueryTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testQueryAsFunction() {
    Table qualifiedTable = Employee.TABLE.as("e1");
    Query subquery = Query.select(Function.add(qualifiedTable.qualifyField(Employee.ID), 1))
            .from(qualifiedTable).where(Employee.ID.eq(qualifiedTable.qualifyField(Employee.ID)));
    Function<Long> fromQuery = subquery.asFunction();
    LongProperty idPlus1 = LongProperty.fromFunction(fromQuery, "idPlus1");
    Query baseQuery = Query.select(Employee.ID, idPlus1);

    SquidCursor<Employee> cursor = database.query(Employee.class, baseQuery);
    try {
        assertEquals(database.countAll(Employee.class), cursor.getCount());
        while (cursor.moveToNext()) {
            assertEquals(cursor.get(Employee.ID) + 1, cursor.get(idPlus1).longValue());
        }
    } finally {
        cursor.close();
    }
}
 
Example #15
Source File: QueryTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testSelectDistinct() {
    Query query = Query.selectDistinct(Employee.MANAGER_ID).orderBy(Employee.MANAGER_ID.asc());
    SquidCursor<Employee> cursor = database.query(Employee.class, query);
    try {
        assertEquals(4, cursor.getCount());
        cursor.moveToFirst();
        assertEquals(Long.valueOf(0), cursor.get(Employee.MANAGER_ID));
        cursor.moveToNext();
        assertEquals(Long.valueOf(1), cursor.get(Employee.MANAGER_ID));
        cursor.moveToNext();
        assertEquals(Long.valueOf(2), cursor.get(Employee.MANAGER_ID));
        cursor.moveToNext();
        assertEquals(Long.valueOf(5), cursor.get(Employee.MANAGER_ID));
    } finally {
        cursor.close();
    }
}
 
Example #16
Source File: QueryTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testReverseOrder() {
    long max = database.countAll(Employee.class);
    SquidCursor<Employee> cursor = database.query(Employee.class,
            Query.select(Employee.ID).orderBy(Employee.ID.asc().reverse()));
    try {
        assertEquals(max, cursor.getCount());
        assertTrue(max > 0);
        while (cursor.moveToNext()) {
            long nextId = cursor.get(Employee.ID);
            if (nextId > max) {
                fail("IDs not in reverse order");
            }
            max = nextId;
        }
    } finally {
        cursor.close();
    }
}
 
Example #17
Source File: QueryTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testLikeSubquery() {
    insertBasicTestModel("Sam 1", "A", System.currentTimeMillis() - 5);
    insertBasicTestModel("Sam 2", "B", System.currentTimeMillis() - 4);
    insertBasicTestModel("Sam 3", "C", System.currentTimeMillis() - 3);
    insertBasicTestModel("Bla 1", "D", System.currentTimeMillis() - 2);
    insertBasicTestModel("Bla 2", "E", System.currentTimeMillis() - 1);

    Function<String> substr = Function.substr(TestModel.FIRST_NAME, 1, 3);
    Function<String> strConcat = Function.strConcat(substr, "%");
    Query likeFirstName = Query.select().where(TestModel.FIRST_NAME.like(
            Query.select(strConcat).from(TestModel.TABLE).where(TestModel.ID.eq(1)))).orderBy(TestModel.ID.asc());

    SquidCursor<TestModel> cursor = database.query(TestModel.class, likeFirstName);
    try {
        assertEquals(3, cursor.getCount());
        int index = 1;
        while (cursor.moveToNext()) {
            assertEquals("Sam " + index, cursor.get(TestModel.FIRST_NAME));
            index++;
        }
    } finally {
        cursor.close();
    }
}
 
Example #18
Source File: QueryTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
private void testGlob(List<Employee> expected, boolean useNotGlob) {
    SquidCursor<Employee> cursor = database.query(Employee.class,
            Query.select(Employee.ID, Employee.NAME).where(useNotGlob ? Employee.NAME.notGlob("b*") :
                    Employee.NAME.glob("b*"))
                    .orderBy(Employee.ID.asc()));
    try {
        assertEquals(expected.size(), cursor.getCount());
        for (Employee e : expected) {
            cursor.moveToNext();
            assertEquals(e.getRowId(), cursor.get(Employee.ID).longValue());
            assertEquals(e.getName(), cursor.get(Employee.NAME));
        }
    } finally {
        cursor.close();
    }
}
 
Example #19
Source File: QueryTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testAggregateCount() {
    TestModel model1 = insertBasicTestModel();
    TestModel model2 = new TestModel().setFirstName(model1.getFirstName()).setLastName("Smith");
    database.persist(model2);

    IntegerProperty groupCount = IntegerProperty.countProperty(TestModel.FIRST_NAME, false);
    Query query = Query.select(TestModel.PROPERTIES).selectMore(groupCount).groupBy(TestModel.FIRST_NAME);
    SquidCursor<TestModel> groupedCursor = database.query(TestModel.class, query);
    try {
        groupedCursor.moveToFirst();
        assertEquals(1, groupedCursor.getCount());
        assertEquals(2, groupedCursor.get(groupCount).intValue());
    } finally {
        groupedCursor.close();
    }
}
 
Example #20
Source File: QueryTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testUnionAll() {
    Query query = Query.select().from(Employee.TABLE).where(Employee.MANAGER_ID.eq(1))
            .unionAll(Query.select().from(Employee.TABLE).where(Employee.ID.eq(2)))
            .orderBy(Employee.ID.asc());
    SquidCursor<Employee> cursor = database.query(Employee.class, query);
    try {
        assertEquals(4, cursor.getCount());
        cursor.moveToFirst();
        assertEquals(cookieMonster, new Employee(cursor));
        cursor.moveToNext();
        assertEquals(cookieMonster, new Employee(cursor));
        cursor.moveToNext();
        assertEquals(elmo, new Employee(cursor));
        cursor.moveToNext();
        assertEquals(oscar, new Employee(cursor));
    } finally {
        cursor.close();
    }
}
 
Example #21
Source File: QueryTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testLimitAndOffsetWithExpressions() {
    // limit = 1 + (count(*) / 4), offset = count(*) / 2
    Field<Integer> limit = Function.add(1, Function.divide(
            Query.select(IntegerProperty.countProperty()).from(Employee.TABLE).asFunction(), 4));
    Field<Integer> offset = Function.divide(
            Query.select(IntegerProperty.countProperty()).from(Employee.TABLE).asFunction(), 2);

    Query query = Query.select().orderBy(Employee.NAME.asc()).limit(limit, offset);
    SquidCursor<Employee> cursor = database.query(Employee.class, query);
    try {
        assertEquals(2, cursor.getCount());
        cursor.moveToFirst();
        assertEquals(elmo, new Employee(cursor));
        cursor.moveToNext();
        assertEquals(ernie, new Employee(cursor));
    } finally {
        cursor.close();
    }
}
 
Example #22
Source File: QueryTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testUnion() {
    Query query = Query.select().from(Employee.TABLE).where(Employee.MANAGER_ID.eq(1))
            .union(Query.select().from(Employee.TABLE).where(Employee.ID.eq(2)))
            .orderBy(Employee.ID.asc());
    SquidCursor<Employee> cursor = database.query(Employee.class, query);
    try {
        assertEquals(3, cursor.getCount());
        cursor.moveToFirst();
        assertEquals(cookieMonster, new Employee(cursor));
        cursor.moveToNext();
        assertEquals(elmo, new Employee(cursor));
        cursor.moveToNext();
        assertEquals(oscar, new Employee(cursor));
    } finally {
        cursor.close();
    }
}
 
Example #23
Source File: QueryTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testAtomicIntegers() {
    AtomicInteger id = new AtomicInteger(1);
    Query query = Query.select(Employee.ID).where(Employee.ID.eq(id));

    SquidCursor<Employee> cursor = database.query(Employee.class, query);
    try {
        assertEquals(1, cursor.getCount());
        cursor.moveToFirst();
        assertEquals(1, cursor.get(Employee.ID).longValue());
    } finally {
        cursor.close();
    }
    id.set(2);
    cursor = database.query(Employee.class, query);
    try {
        assertEquals(1, cursor.getCount());
        cursor.moveToFirst();
        assertEquals(2, cursor.get(Employee.ID).longValue());
    } finally {
        cursor.close();
    }
}
 
Example #24
Source File: QueryTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testAtomicBoolean() {
    AtomicBoolean isHappy = new AtomicBoolean(false);

    Query query = Query.select().where(Employee.IS_HAPPY.eq(isHappy));
    SquidCursor<Employee> unhappyEmployee = database.query(Employee.class, query);
    try {
        assertEquals(1, unhappyEmployee.getCount());
        unhappyEmployee.moveToFirst();
        assertEquals(oscar.getRowId(), unhappyEmployee.get(Employee.ID).longValue());
    } finally {
        unhappyEmployee.close();
    }

    isHappy.set(true);
    SquidCursor<Employee> happyEmployees = database.query(Employee.class, query);
    try {
        assertEquals(5, happyEmployees.getCount());
    } finally {
        happyEmployees.close();
    }
}
 
Example #25
Source File: QueryTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testSubqueryJoin() {
    StringProperty managerName = Employee.NAME.as("managerName");
    Query query = Query
            .fromSubquery(Query.select(Employee.MANAGER_ID).from(Employee.TABLE).groupBy(Employee.MANAGER_ID),
                    "subquery");
    query.selectMore(managerName);
    query.join(Join.inner(Employee.TABLE, query.getTable().qualifyField(Employee.MANAGER_ID).eq(Employee.ID)))
            .orderBy(Employee.MANAGER_ID.asc());

    SquidCursor<Employee> cursor = database.query(Employee.class, query);
    try {
        assertEquals(3, cursor.getCount());
        cursor.moveToFirst();
        assertEquals("bigBird", cursor.get(managerName));
        cursor.moveToNext();
        assertEquals("cookieMonster", cursor.get(managerName));
        cursor.moveToNext();
        assertEquals("bert", cursor.get(managerName));
    } finally {
        cursor.close();
    }
}
 
Example #26
Source File: QueryTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testSelectFromView() {
    View view = View.fromQuery(Query.select(Employee.PROPERTIES)
            .from(Employee.TABLE).where(Employee.MANAGER_ID.eq(bigBird.getRowId())), "bigBirdsEmployees");

    database.tryCreateView(view);

    Query fromView = Query.fromView(view).orderBy(view.qualifyField(Employee.ID).asc());

    SquidCursor<Employee> cursor = database.query(Employee.class, fromView);
    try {
        assertEquals(3, cursor.getCount());
        cursor.moveToFirst();
        assertEquals("cookieMonster", cursor.get(Employee.NAME));
        cursor.moveToNext();
        assertEquals("elmo", cursor.get(Employee.NAME));
        cursor.moveToNext();
        assertEquals("oscar", cursor.get(Employee.NAME));
    } finally {
        cursor.close();
    }
}
 
Example #27
Source File: ContentProviderQueryBuilderTest.java    From squidb with Apache License 2.0 6 votes vote down vote up
public void testRawSelection() {
    String selection = COL_LUCKY_NUMBER + " > ? AND " + COL_IS_HAPPY + " != ?";
    String[] selectionArgs = new String[]{"50", "0"};
    ContentProviderQueryBuilder builder = getBuilder();
    Query query = builder.setDataSource(TestModel.TABLE).build(null, selection, selectionArgs, null);
    CompiledStatement compiled = query.compile(database.getCompileContext());
    verifyCompiledSqlArgs(compiled, 2, "50", "0");

    SquidCursor<TestModel> cursor = null;
    try {
        cursor = database.query(TestModel.class, query);
        assertEquals(1, cursor.getCount());
        cursor.moveToFirst();
        assertEquals(model2, buildModelFromCursor(cursor));
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
 
Example #28
Source File: QueryTest.java    From squidb with Apache License 2.0 5 votes vote down vote up
public void testSelectLiteral() {
    StringProperty literal = StringProperty.literal("literal", "name");
    LongProperty literalLong = LongProperty.literal(12, "twelve");
    SquidCursor<?> c = database.query(null, Query.select(literal, literalLong));
    try {
        assertEquals(1, c.getCount());
        c.moveToFirst();
        assertEquals("literal", c.get(literal));
        assertEquals(12, c.get(literalLong).longValue());
    } finally {
        if (c != null) {
            c.close();
        }
    }
}
 
Example #29
Source File: QueryTest.java    From squidb with Apache License 2.0 5 votes vote down vote up
public void testFrozenQueryWorksWithDatabase() {
    Query query = Query.select().limit(2).freeze();
    SquidCursor<Employee> cursor = database.query(Employee.class, query);
    try {
        assertEquals(2, cursor.getCount());
        assertNull(query.getTable());
    } finally {
        cursor.close();
    }

    Employee employee = database.fetchByQuery(Employee.class, query);
    assertNotNull(employee);
    assertNull(query.getTable());
    assertEquals(Field.field("2"), query.getLimit());
}
 
Example #30
Source File: QueryTest.java    From squidb with Apache License 2.0 5 votes vote down vote up
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();
    }
}