当前位置: 首页>>代码示例>>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;未经允许,请勿转载。