當前位置: 首頁>>代碼示例>>Java>>正文


Java Query類代碼示例

本文整理匯總了Java中com.yahoo.squidb.sql.Query的典型用法代碼示例。如果您正苦於以下問題:Java Query類的具體用法?Java Query怎麽用?Java Query使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Query類屬於com.yahoo.squidb.sql包,在下文中一共展示了Query類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testRawSelection

import com.yahoo.squidb.sql.Query; //導入依賴的package包/類
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();
        }
    }
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:21,代碼來源:ContentProviderQueryBuilderTest.java

示例2: testRawOrderBy

import com.yahoo.squidb.sql.Query; //導入依賴的package包/類
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();
        }
    }
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:24,代碼來源:ContentProviderQueryBuilderTest.java

示例3: testDefaultOrderBy

import com.yahoo.squidb.sql.Query; //導入依賴的package包/類
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();
        }
    }
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:24,代碼來源:ContentProviderQueryBuilderTest.java

示例4: testJsonInsertReplaceSetInternal

import com.yahoo.squidb.sql.Query; //導入依賴的package包/類
private void testJsonInsertReplaceSetInternal(int type, String path, Object value, String expectedResult) {
    String jsonString = "{\"a\":2,\"c\":4}";
    Function<String> func = null;
    switch (type) {
        case 0:
            func = JSONFunctions.jsonInsert(jsonString, path, value);
            break;
        case 1:
            func = JSONFunctions.jsonReplace(jsonString, path, value);
            break;
        case 2:
            func = JSONFunctions.jsonSet(jsonString, path, value);
            break;
        default:
            fail("Unsupported insert/replace/set type " + type);
    }
    String result = database.simpleQueryForString(Query.select(func));
    assertEquals(expectedResult, result);
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:20,代碼來源:JSONFunctionTest.java

示例5: testJsonGroupArray

import com.yahoo.squidb.sql.Query; //導入依賴的package包/類
public void testJsonGroupArray() {
    testJsonFunction(new Runnable() {
        @Override
        public void run() {
            Thing thing = new Thing();
            for (int i = 0; i < 5; i++) {
                thing.setFoo(Integer.toString(i));
                database.createNew(thing);
            }
            Function<String> groupArray = JSONFunctions.jsonGroupArray(Thing.FOO);
            String result = database.simpleQueryForString(Query.select(groupArray).from(Thing.TABLE));
            try {
                JSONArray resultArray = new JSONArray(result);
                Set<String> resultValues = new HashSet<>();
                for (int i = 0; i < resultArray.length(); i++) {
                    resultValues.add(resultArray.getString(i));
                }
                assertEquals(5, resultValues.size());
                assertTrue(resultValues.containsAll(Arrays.asList("0", "1", "2", "3", "4")));
            } catch (JSONException e) {
                fail("JSONException: " + e.getMessage());
            }
        }
    }, JSONFunctions.JSON1_GROUP_FUNCTIONS_VERSION);
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:26,代碼來源:JSONFunctionTest.java

示例6: testJsonGroupObject

import com.yahoo.squidb.sql.Query; //導入依賴的package包/類
public void testJsonGroupObject() {
    testJsonFunction(new Runnable() {
        @Override
        public void run() {
            Thing thing = new Thing();
            for (int i = 0; i < 5; i++) {
                thing.setFoo(Integer.toString(i))
                        .setBar(i * 2);
                database.createNew(thing);
            }
            Function<String> groupObject = JSONFunctions.jsonGroupObject(Thing.FOO, Thing.BAR);
            String result = database.simpleQueryForString(Query.select(groupObject).from(Thing.TABLE));
            try {
                JSONObject resultObject = new JSONObject(result);
                assertEquals(5, resultObject.length());
                for (int i = 0; i < 5; i++) {
                    assertEquals(i * 2, resultObject.getInt(Integer.toString(i)));
                }
            } catch (JSONException e) {
                fail("JSONException: " + e.getMessage());
            }
        }
    }, JSONFunctions.JSON1_GROUP_FUNCTIONS_VERSION);
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:25,代碼來源:JSONFunctionTest.java

示例7: testEnumProperties

import com.yahoo.squidb.sql.Query; //導入依賴的package包/類
public void testEnumProperties() {
    final TestEnum enumValue = TestEnum.APPLE;
    final String enumAsString = enumValue.name();
    TestModel model = new TestModel()
            .setFirstName("A")
            .setLastName("Z")
            .setBirthday(System.currentTimeMillis())
            .setSomeEnum(enumValue);

    ValuesStorage setValues = model.getSetValues();
    assertEquals(enumAsString, setValues.get(TestModel.SOME_ENUM.getName()));

    database.persist(model);

    SquidCursor<TestModel> cursor = database.query(TestModel.class, Query.select()
            .where(TestModel.SOME_ENUM.eq(TestEnum.APPLE)));
    assertEquals(1, cursor.getCount());
    assertTrue(cursor.moveToFirst());
    assertEquals(enumAsString, cursor.get(TestModel.SOME_ENUM));

    TestModel fromDatabase = new TestModel(cursor);
    assertEquals(enumValue, fromDatabase.getSomeEnum());
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:24,代碼來源:ModelTest.java

示例8: testRecyclerAdapterInternal

import com.yahoo.squidb.sql.Query; //導入依賴的package包/類
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();
    }
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:18,代碼來源:SquidRecyclerAdapterTest.java

示例9: testCursorAdapterInternal

import com.yahoo.squidb.sql.Query; //導入依賴的package包/類
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();
    }
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:18,代碼來源:SquidCursorAdapterTest.java

示例10: testSwapCursorDoesNotCloseOldCursor

import com.yahoo.squidb.sql.Query; //導入依賴的package包/類
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();
    }
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:19,代碼來源:SquidCursorAdapterTest.java

示例11: build

import com.yahoo.squidb.sql.Query; //導入依賴的package包/類
/**
 * Build a {@link Query} combining this object's internal state with the arguments passed. If a
 * {@link ProjectionMap} is set, the projection elements will be evaluated and transformed accordingly. If the
 * sortOrder is null or empty, the default order will be used (if one was set).
 *
 * @param projection the raw column names to be selected
 * @param selection a raw selection string
 * @param selectionArgs array of strings which substitute replaceable arguments in the selection string
 * @param sortOrder a raw ordering clause
 * @return a {@link Query} using the projection, selection, selection args, and sort order
 */
public Query build(String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Query query = Query.select(computeProjection(projection)).from(dataSource);
    boolean hasUserSelection = !SqlUtils.isEmpty(selection);
    if (hasUserSelection) {
        query.where(Criterion.fromRawSelection(selection, selectionArgs));
    }
    if (!SqlUtils.isEmpty(sortOrder)) {
        query.orderBy(Order.fromExpression(sortOrder));
    } else if (defaultOrder != null && defaultOrder.length > 0) {
        query.orderBy(defaultOrder);
    }
    if (strictMode && hasUserSelection) {
        query.requestValidation();
    }
    return query;
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:28,代碼來源:ContentProviderQueryBuilder.java

示例12: count

import com.yahoo.squidb.sql.Query; //導入依賴的package包/類
/**
 * Count the number of rows matching a given {@link Criterion}. Use null to count all rows.
 *
 * @param modelClass the model class corresponding to the table
 * @param criterion the criterion to match
 * @return the number of rows matching the given criterion
 */
public int count(Class<? extends AbstractModel> modelClass, Criterion criterion) {
    Property.IntegerProperty countProperty = Property.IntegerProperty.countProperty();
    Query query = Query.select(countProperty);
    if (criterion != null) {
        query.where(criterion);
    }
    query = inferTableForQuery(modelClass, query);
    CompiledStatement compiled = query.compile(getCompileContext());
    acquireNonExclusiveLock();
    try {
        return (int) getDatabase().simpleQueryForLong(compiled.sql, compiled.sqlArgs);
    } finally {
        releaseNonExclusiveLock();
    }
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:23,代碼來源:SquidDatabase.java

示例13: readWholeData

import com.yahoo.squidb.sql.Query; //導入依賴的package包/類
@Override
public long readWholeData() throws SQLException
{
    long start = System.nanoTime();
    SquidCursor<Message> query = myDatabase.query(Message.class, Query.select());
    Message message = new Message();
    while(query.moveToNext())
    {
        message.readPropertiesFromCursor(query);
    }
    return System.nanoTime() - start;
}
 
開發者ID:touchlab,項目名稱:android-orm-benchmark-updated,代碼行數:13,代碼來源:SquidbExecutor.java

示例14: testEmptyProjectionWithMapUsesDefault

import com.yahoo.squidb.sql.Query; //導入依賴的package包/類
public void testEmptyProjectionWithMapUsesDefault() {
    final Field<?>[] expectedProjection = new Field<?>[]{
            TestModel.ID,
            TestModel.FIRST_NAME.as(COL_GIVEN_NAME),
            TestModel.LAST_NAME.as(COL_SURNAME),
            TestModel.LUCKY_NUMBER,
            TestModel.IS_HAPPY
    };

    ContentProviderQueryBuilder builder = getBuilder();
    Query query = builder.setDataSource(TestModel.TABLE).build(null, null, null, null);
    assertEquals(Arrays.asList(expectedProjection), query.getFields());
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:14,代碼來源:ContentProviderQueryBuilderTest.java

示例15: testInvalidProjectionIgnored

import com.yahoo.squidb.sql.Query; //導入依賴的package包/類
public void testInvalidProjectionIgnored() {
    ContentProviderQueryBuilder builder = getBuilder();
    final String IGNORE = "foo";
    String[] projection = {IGNORE, COL_GIVEN_NAME, COL_SURNAME, COL_LUCKY_NUMBER};
    Query query = builder.setDataSource(TestModel.TABLE).build(projection, null, null, null);
    List<Field<?>> fields = query.getFields();
    assertEquals(3, fields.size());
    for (int i = 0; i < fields.size(); i++) {
        if (IGNORE.equals(fields.get(i).getName())) {
            fail("Invalid projection not ignored!");
        }
    }
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:14,代碼來源:ContentProviderQueryBuilderTest.java


注:本文中的com.yahoo.squidb.sql.Query類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。