当前位置: 首页>>代码示例>>Java>>正文


Java SqlFieldsQuery.setArgs方法代码示例

本文整理汇总了Java中org.apache.ignite.cache.query.SqlFieldsQuery.setArgs方法的典型用法代码示例。如果您正苦于以下问题:Java SqlFieldsQuery.setArgs方法的具体用法?Java SqlFieldsQuery.setArgs怎么用?Java SqlFieldsQuery.setArgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.ignite.cache.query.SqlFieldsQuery的用法示例。


在下文中一共展示了SqlFieldsQuery.setArgs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkQuery

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
 * @param sql SQL.
 * @param cache Cache.
 * @param enforceJoinOrder Enforce join order flag.
 * @param expSize Expected results size.
 * @param args Arguments.
 */
private void checkQuery(String sql,
    IgniteCache<Object, Object> cache,
    boolean enforceJoinOrder,
    int expSize,
    Object... args) {
    SqlFieldsQuery qry = new SqlFieldsQuery(sql);

    qry.setDistributedJoins(true);
    qry.setEnforceJoinOrder(enforceJoinOrder);
    qry.setArgs(args);

    log.info("Plan: " + queryPlan(cache, qry));

    QueryCursor<List<?>> cur = cache.query(qry);

    List<List<?>> res = cur.getAll();

    if (expSize != res.size())
        log.info("Results: " + res);

    assertEquals(expSize, res.size());
}
 
开发者ID:apache,项目名称:ignite,代码行数:30,代码来源:IgniteCacheDistributedJoinQueryConditionsTest.java

示例2: testSqlQuery

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
 * @throws Exception If failed.
 */
public void testSqlQuery() throws Exception {
    Ignite node = ignite(0);

    IgniteCache c1 = node.createCache(personCacheConfiguration(GROUP1, "c1"));
    IgniteCache c2 = node.createCache(personCacheConfiguration(GROUP1, "c2"));

    SqlFieldsQuery qry = new SqlFieldsQuery("select name from Person where name=?");
    qry.setArgs("p1");

    assertEquals(0, c1.query(qry).getAll().size());
    assertEquals(0, c2.query(qry).getAll().size());

    c1.put(1, new Person("p1"));

    assertEquals(1, c1.query(qry).getAll().size());
    assertEquals(0, c2.query(qry).getAll().size());

    c2.put(2, new Person("p1"));

    assertEquals(1, c1.query(qry).getAll().size());
    assertEquals(1, c2.query(qry).getAll().size());
}
 
开发者ID:apache,项目名称:ignite,代码行数:26,代码来源:IgniteCacheGroupsSqlTest.java

示例3: checkQuery

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
 * @param sql SQL.
 * @param cache Cache.
 * @param enforceJoinOrder Enforce join order flag.
 * @param expSize Expected results size.
 * @param args Arguments.
 * @return Results.
 */
private List<List<?>> checkQuery(String sql,
    IgniteCache<Object, Object> cache,
    boolean enforceJoinOrder,
    int expSize,
    Object... args) {
    SqlFieldsQuery qry = new SqlFieldsQuery(sql);

    qry.setDistributedJoins(true);
    qry.setEnforceJoinOrder(enforceJoinOrder);
    qry.setArgs(args);

    log.info("Plan: " + queryPlan(cache, qry));

    QueryCursor<List<?>> cur = cache.query(qry);

    List<List<?>> res = cur.getAll();

    if (expSize != res.size())
        log.info("Results: " + res);

    assertEquals(expSize, res.size());

    return res;
}
 
开发者ID:apache,项目名称:ignite,代码行数:33,代码来源:IgniteCacheDistributedJoinPartitionedAndReplicatedTest.java

示例4: checkQuery

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
 * @param sql SQL.
 * @param cache Cache.
 * @param expSize Expected results size.
 * @param args Arguments.
 */
private void checkQuery(String sql,
    IgniteCache<Object, Object> cache,
    int expSize,
    Object... args) {
    String plan = (String)cache.query(new SqlFieldsQuery("explain " + sql))
        .getAll().get(0).get(0);

    log.info("Plan: " + plan);

    SqlFieldsQuery qry = new SqlFieldsQuery(sql);

    qry.setArgs(args);

    QueryCursor<List<?>> cur = cache.query(qry);

    List<List<?>> res = cur.getAll();

    if (expSize != res.size())
        log.info("Results: " + res);

    assertEquals(expSize, res.size());
}
 
开发者ID:apache,项目名称:ignite,代码行数:29,代码来源:IgniteCacheJoinPartitionedAndReplicatedTest.java

示例5: checkQuery

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
 * @param sql SQL.
 * @param cache Cache.
 * @param expSize Expected results size.
 * @param args Arguments.
 * @return Results.
 */
private List<List<?>> checkQuery(String sql,
    IgniteCache<Object, Object> cache,
    int expSize,
    Object... args) {
    SqlFieldsQuery qry = new SqlFieldsQuery(sql);

    qry.setDistributedJoins(true);
    qry.setArgs(args);

    log.info("Plan: " + queryPlan(cache, qry));

    QueryCursor<List<?>> cur = cache.query(qry);

    List<List<?>> res = cur.getAll();

    if (expSize != res.size())
        log.info("Results: " + res);

    assertEquals(expSize, res.size());

    return res;
}
 
开发者ID:apache,项目名称:ignite,代码行数:30,代码来源:IgniteCacheDistributedJoinNoIndexTest.java

示例6: createSqlFieldsQueryWithLog

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
public SqlFieldsQuery createSqlFieldsQueryWithLog(String sql, QueryHints hints, Object... args) {
	String comment = hints != null ? hints.toComment() : "";
	jdbcServices.getSqlStatementLogger().logStatement( comment + sql );

	SqlFieldsQuery query = new SqlFieldsQuery( sql );
	if ( args != null ) {
		query.setArgs( args );
	}

	return query;
}
 
开发者ID:hibernate,项目名称:hibernate-ogm-ignite,代码行数:12,代码来源:IgniteDatastoreProvider.java

示例7: prepareQuery

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
 * @param prmtrs Prmtrs.
 * @return prepared query for execution
 */
@NotNull private Query prepareQuery(Object[] prmtrs) {
    Object[] parameters = prmtrs;
    String sql = qry.sql();

    Query query;

    switch (qry.options()) {
        case SORTING:
            sql = IgniteQueryGenerator.addSorting(new StringBuilder(sql),
                (Sort)parameters[parameters.length - 1]).toString();
            parameters = Arrays.copyOfRange(parameters, 0, parameters.length - 1);
            break;
        case PAGINATION:
            sql = IgniteQueryGenerator.addPaging(new StringBuilder(sql),
                (Pageable)parameters[parameters.length - 1]).toString();
            parameters = Arrays.copyOfRange(parameters, 0, parameters.length - 1);
            break;
    }

    if (qry.isFieldQuery()) {
        SqlFieldsQuery sqlFieldsQry = new SqlFieldsQuery(sql);
        sqlFieldsQry.setArgs(parameters);

        query = sqlFieldsQry;
    }
    else {
        SqlQuery sqlQry = new SqlQuery(type, sql);
        sqlQry.setArgs(parameters);

        query = sqlQry;
    }

    return query;
}
 
开发者ID:apache,项目名称:ignite,代码行数:39,代码来源:IgniteRepositoryQuery.java

示例8: columnValue

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
 * method for create parametrized query and get first result
 * @param field name of field
 * @param val value
 * @return fist searched object
 * @see Bookmark
 */
private Object columnValue(String field, Object val) {
    IgniteCache<String, Bookmark> cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK);
    SqlFieldsQuery qry = new SqlFieldsQuery("SELECT " + field + " from  Bookmark where " + field + " = ?");
    qry.setArgs(val);

    QueryCursor<List<?>> cursor = cache.query(qry);
    List<List<?>> results = cursor.getAll();
    assertEquals("Search by field '" + field +"' returns incorrect row count!",1, results.size());
    List<?> row0 = results.get(0);
    return row0.get(0);
}
 
开发者ID:apache,项目名称:ignite,代码行数:19,代码来源:IgniteSqlParameterizedQueryTest.java

示例9: checkPersonOrganizationGroupBy

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
 * @param cache Cache.
 */
private void checkPersonOrganizationGroupBy(IgniteCache cache) {
    if (skipQuery(cache, PERSON_CACHE_NAME, ORG_CACHE_NAME))
        return;

    qry = "checkPersonOrganizationGroupBy";

    // Max salary per organization.
    SqlFieldsQuery q = new SqlFieldsQuery("select max(p.salary) " +
        "from \"" + PERSON_CACHE_NAME + "\".Person p join \"" + ORG_CACHE_NAME + "\".Organization o " +
        "on p.orgId = o.id " +
        "group by o.name " +
        "having o.id = ?");

    q.setDistributedJoins(distributedJoins());

    for (Map.Entry<Integer, Integer> e : data.maxSalaryPerOrg.entrySet()) {
        Integer orgId = e.getKey();
        Integer maxSalary = e.getValue();

        q.setArgs(orgId);

        List<List<?>> res = cache.query(q).getAll();

        String errMsg = "Expected data [orgId=" + orgId + ", maxSalary=" + maxSalary + ", data=" + data + "]";

        // MaxSalary == -1 means that there are no persons at organization.
        if (maxSalary > 0) {
            assertEquals(errMsg, 1, res.size());
            assertEquals(errMsg, 1, res.get(0).size());
            assertEquals(errMsg, maxSalary, res.get(0).get(0));
        }
        else
            assertEquals(errMsg, 0, res.size());
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:39,代码来源:IgniteCrossCachesJoinsQueryTest.java

示例10: checkPersonAccountGroupBy

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
 * @param cache Cache.
 */
private void checkPersonAccountGroupBy(IgniteCache cache) {
    if (skipQuery(cache, PERSON_CACHE_NAME, ACC_CACHE_NAME))
        return;

    qry = "checkPersonAccountGroupBy";

    // Count accounts per person.
    SqlFieldsQuery q = new SqlFieldsQuery("select count(a.id) " +
        "from \"" + PERSON_CACHE_NAME + "\".Person p join \"" + ACC_CACHE_NAME + "\".Account a " +
        "on p.strId = a.personStrId " +
        "group by p.name " +
        "having p.id = ?");

    q.setDistributedJoins(distributedJoins());

    List<Integer> keys = new ArrayList<>(data.accountsPerPerson.keySet());

    for (int i = 0; i < 10; i++) {
        Integer personId = keys.get(rnd.nextInt(keys.size()));
        Integer cnt = data.accountsPerPerson.get(personId);

        q.setArgs(personId);

        List<List<?>> res = cache.query(q).getAll();

        String errMsg = "Expected data [personId=" + personId + ", cnt=" + cnt + ", data=" + data + "]";

        // Cnt == 0 means that there are no accounts for the person.
        if (cnt > 0) {
            assertEquals(errMsg, 1, res.size());
            assertEquals(errMsg, 1, res.get(0).size());
            assertEquals(errMsg, (long)cnt, res.get(0).get(0));
        }
        else
            assertEquals(errMsg, 0, res.size());
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:41,代码来源:IgniteCrossCachesJoinsQueryTest.java

示例11: testKeyQuery

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
 * Test simple query by key.
 *
 * @param cacheName Cache name.
 * @param key1 Key 1.
 * @param key2 Key 2.
 * @param <T> Key type.
 */
private <T> void testKeyQuery(final String cacheName, final T key1, final T key2) {
    final IgniteCache<T, Person> cache = ignite(0).cache(cacheName);

    final Person p1 = new Person("p1");
    final Person p2 = new Person("p2");

    cache.put(key1, p1);
    cache.put(key2, p2);

    final SqlQuery<T, Person> qry = new SqlQuery<>(Person.class, "where _key=?");

    final SqlFieldsQuery fieldsQry = new SqlFieldsQuery("select _key, _val, * from Person where _key=?");

    qry.setLocal(isLocal());
    fieldsQry.setLocal(isLocal());

    qry.setArgs(key1);
    fieldsQry.setArgs(key1);

    final List<Cache.Entry<T, Person>> res = cache.query(qry).getAll();
    final List<List<?>> fieldsRes = cache.query(fieldsQry).getAll();

    assertEquals(1, res.size());
    assertEquals(1, fieldsRes.size());

    assertEquals(p1, res.get(0).getValue());
    assertEquals(key1, res.get(0).getKey());

    assertTrue(fieldsRes.get(0).size() >= 2);
    assertEquals(key1, fieldsRes.get(0).get(0));
    assertEquals(p1, fieldsRes.get(0).get(1));
}
 
开发者ID:apache,项目名称:ignite,代码行数:41,代码来源:IgniteBinaryObjectQueryArgumentsTest.java

示例12: testValQuery

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
 * Test simple query by value.
 *
 * @param cacheName Cache name.
 * @param val1 Value 1.
 * @param val2 Value 2.
 * @param <T> Value type.
 */
private <T> void testValQuery(final String cacheName, final T val1, final T val2) {
    final IgniteCache<Person, T> cache = ignite(0).cache(cacheName);

    final Class<?> valType = val1.getClass();

    final Person p1 = new Person("p1");
    final Person p2 = new Person("p2");

    cache.put(p1, val1);
    cache.put(p2, val2);

    final SqlQuery<Person, T> qry = new SqlQuery<>(valType, "where _val=?");

    final SqlFieldsQuery fieldsQry = new SqlFieldsQuery("select _key, _val, * from " + valType.getSimpleName() + " where _val=?");

    qry.setLocal(isLocal());
    fieldsQry.setLocal(isLocal());

    qry.setArgs(val1);
    fieldsQry.setArgs(val1);

    final List<Cache.Entry<Person, T>> res = cache.query(qry).getAll();
    final List<List<?>> fieldsRes = cache.query(fieldsQry).getAll();

    assertEquals(1, res.size());
    assertEquals(1, fieldsRes.size());

    assertEquals(p1, res.get(0).getKey());
    assertEquals(val1, res.get(0).getValue());

    assertTrue(fieldsRes.get(0).size() >= 2);
    assertEquals(p1, fieldsRes.get(0).get(0));
    assertEquals(val1, fieldsRes.get(0).get(1));
}
 
开发者ID:apache,项目名称:ignite,代码行数:43,代码来源:IgniteBinaryObjectQueryArgumentsTest.java

示例13: assertIndexUsed

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
 * Ensure index is used in plan.
 *
 * @param node Node.
 * @param idxName Index name.
 * @param sql SQL.
 * @param args Arguments.
 */
protected static void assertIndexUsed(IgniteEx node, String idxName, String sql, Object... args) {
    SqlFieldsQuery qry = new SqlFieldsQuery("EXPLAIN " + sql);

    if (args != null && args.length > 0)
        qry.setArgs(args);

    String plan = (String)node.cache(CACHE_NAME).query(qry).getAll().get(0).get(0);

    assertTrue("Index is not used: " + plan, plan.toLowerCase().contains(idxName.toLowerCase()));
}
 
开发者ID:apache,项目名称:ignite,代码行数:19,代码来源:DynamicIndexAbstractSelfTest.java

示例14: assertIndexNotUsed

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
 * Ensure index is not used in plan.
 *
 * @param node Node.
 * @param idxName Index name.
 * @param sql SQL.
 * @param args Arguments.
 */
protected static void assertIndexNotUsed(IgniteEx node, String idxName, String sql, Object... args) {
    SqlFieldsQuery qry = new SqlFieldsQuery("EXPLAIN " + sql);

    if (args != null && args.length > 0)
        qry.setArgs(args);

    String plan = (String)node.cache(CACHE_NAME).query(qry).getAll().get(0).get(0);

    assertFalse("Index is used: " + plan, plan.contains(idxName));
}
 
开发者ID:apache,项目名称:ignite,代码行数:19,代码来源:DynamicIndexAbstractSelfTest.java

示例15: executeQueryJoin

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
 * @param minSalary Min salary.
 * @param maxSalary Max salary.
 * @return Query results.
 * @throws Exception If failed.
 */
private Collection<List<?>> executeQueryJoin(double minSalary, double maxSalary) throws Exception {
    IgniteCache<Integer, Object> cache = cacheForOperation(true);

    SqlFieldsQuery qry = new SqlFieldsQuery(
        "select p.id, p.orgId, p.firstName, p.lastName, p.salary, o.name " +
        "from Person p " +
        "left join Organization o " +
        "on p.id = o.id " +
        "where salary >= ? and salary <= ?");

    qry.setArgs(minSalary, maxSalary);

    return cache.query(qry).getAll();
}
 
开发者ID:apache,项目名称:ignite,代码行数:21,代码来源:IgniteSqlQueryJoinBenchmark.java


注:本文中的org.apache.ignite.cache.query.SqlFieldsQuery.setArgs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。