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


Java SqlFieldsQuery.setLocal方法代码示例

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


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

示例1: executeWithHints

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
private Iterable<List<?>> executeWithHints(IgniteCache<Object, BinaryObject> cache, SqlFieldsQuery sqlQuery, QueryHints hints) {
	Iterable<List<?>> result;

	if ( hints.isLocal() ) {
		if ( !provider.isClientMode() ) {
			sqlQuery.setLocal( true );
		}
	}
	if ( hints.isAffinityRun() ) {
		result = provider.affinityCall( cache.getName(), hints.getAffinityKey(), sqlQuery );
	}
	else {
		result = cache.query( sqlQuery );
	}

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

示例2: 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

示例3: 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

示例4: testMultiStatement

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
 * @throws Exception If failed.
 */
public void testMultiStatement() throws Exception {
    final IgniteInternalCache<Integer, FactPurchase> cache = ((IgniteKernal)ignite).getCache(PART_CACHE_NAME);

    final GridQueryProcessor qryProc = ((IgniteKernal) ignite).context().query();

    final SqlFieldsQuery qry = new SqlFieldsQuery(
        "insert into FactPurchase(_key, id, productId, storeId, price) values (555, 555, 555, 555, 555);" +
        "select count(*) from FactPurchase"
    );

    GridTestUtils.assertThrows(log,
        new Callable<Object>() {
            @Override public Object call() throws Exception {
                qryProc.querySqlFields(cache.context(), qry, false, true);

                return null;
            }
        }, IgniteSQLException.class, "Multiple statements queries are not supported");

    List<FieldsQueryCursor<List<?>>> cursors = qryProc.querySqlFields(cache.context(), qry, false, false);

    assertEquals(2, cursors.size());

    for(FieldsQueryCursor<List<?>> cur : cursors)
        U.closeQuiet(cur);

    qry.setLocal(true);

    GridTestUtils.assertThrows(log,
        new Callable<Object>() {
            @Override public Object call() throws Exception {
                qryProc.querySqlFields(cache.context(), qry, false, false);

                return null;
            }
        }, IgniteSQLException.class, "Multiple statements queries are not supported for local queries");
}
 
开发者ID:apache,项目名称:ignite,代码行数:41,代码来源:GridCacheCrossCacheQuerySelfTest.java

示例5: ComputeForLocalQueries

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
public ComputeForLocalQueries(String cacheName, SqlFieldsQuery query) {
	this.cacheName = cacheName;
	this.query = query.setLocal( true );
}
 
开发者ID:hibernate,项目名称:hibernate-ogm-ignite,代码行数:5,代码来源:IgniteDatastoreProvider.java

示例6: queryDistributedSql

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public <K, V> QueryCursor<Cache.Entry<K, V>> queryDistributedSql(String schemaName, String cacheName,
    SqlQuery qry, boolean keepBinary, int mainCacheId) {
    String type = qry.getType();

    H2TableDescriptor tblDesc = tableDescriptor(schemaName, cacheName, type);

    if (tblDesc == null)
        throw new IgniteSQLException("Failed to find SQL table for type: " + type,
            IgniteQueryErrorCode.TABLE_NOT_FOUND);

    String sql;

    try {
        sql = generateQuery(qry.getSql(), qry.getAlias(), tblDesc);
    }
    catch (IgniteCheckedException e) {
        throw new IgniteException(e);
    }

    SqlFieldsQuery fqry = new SqlFieldsQuery(sql);

    fqry.setArgs(qry.getArgs());
    fqry.setPageSize(qry.getPageSize());
    fqry.setDistributedJoins(qry.isDistributedJoins());
    fqry.setPartitions(qry.getPartitions());
    fqry.setLocal(qry.isLocal());

    if (qry.getTimeout() > 0)
        fqry.setTimeout(qry.getTimeout(), TimeUnit.MILLISECONDS);

    final QueryCursor<List<?>> res =
        queryDistributedSqlFields(schemaName, fqry, keepBinary, null, mainCacheId, true).get(0);

    final Iterable<Cache.Entry<K, V>> converted = new Iterable<Cache.Entry<K, V>>() {
        @Override public Iterator<Cache.Entry<K, V>> iterator() {
            final Iterator<List<?>> iter0 = res.iterator();

            return new Iterator<Cache.Entry<K, V>>() {
                @Override public boolean hasNext() {
                    return iter0.hasNext();
                }

                @Override public Cache.Entry<K, V> next() {
                    List<?> l = iter0.next();

                    return new CacheEntryImpl<>((K)l.get(0), (V)l.get(1));
                }

                @Override public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };

    // No metadata for SQL queries.
    return new QueryCursorImpl<Cache.Entry<K, V>>(converted) {
        @Override public void close() {
            res.close();
        }
    };
}
 
开发者ID:apache,项目名称:ignite,代码行数:65,代码来源:IgniteH2Indexing.java

示例7: run

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override protected VisorEither<VisorQueryResult> run(final VisorQueryTaskArg arg) {
    try {
        UUID nid = ignite.localNode().id();

        SqlFieldsQuery qry = new SqlFieldsQuery(arg.getQueryText());
        qry.setPageSize(arg.getPageSize());
        qry.setLocal(arg.isLocal());
        qry.setDistributedJoins(arg.isDistributedJoins());
        qry.setEnforceJoinOrder(arg.isEnforceJoinOrder());
        qry.setReplicatedOnly(arg.isReplicatedOnly());
        qry.setLazy(arg.getLazy());

        long start = U.currentTimeMillis();

        List<FieldsQueryCursor<List<?>>> qryCursors;

        String cacheName = arg.getCacheName();

        if (F.isEmpty(cacheName))
            qryCursors = ignite.context().query().querySqlFieldsNoCache(qry, true, false);
        else {
            IgniteCache<Object, Object> c = ignite.cache(cacheName);

            if (c == null)
                throw new SQLException("Fail to execute query. Cache not found: " + cacheName);

            qryCursors = ((IgniteCacheProxy)c.withKeepBinary()).queryMultipleStatements(qry);
        }

        // In case of multiple statements leave opened only last cursor.
        for (int i = 0; i < qryCursors.size() - 1; i++)
            U.closeQuiet(qryCursors.get(i));

        // In case of multiple statements return last cursor as result.
        VisorQueryCursor<List<?>> cur = new VisorQueryCursor<>(F.last(qryCursors));

        Collection<GridQueryFieldMetadata> meta = cur.fieldsMeta();

        if (meta == null)
            return new VisorEither<>(
                new VisorExceptionWrapper(new SQLException("Fail to execute query. No metadata available.")));
        else {
            List<VisorQueryField> names = new ArrayList<>(meta.size());

            for (GridQueryFieldMetadata col : meta)
                names.add(new VisorQueryField(col.schemaName(), col.typeName(),
                    col.fieldName(), col.fieldTypeName()));

            List<Object[]> rows = fetchSqlQueryRows(cur, arg.getPageSize());

            // Query duration + fetch duration.
            long duration = U.currentTimeMillis() - start;

            boolean hasNext = cur.hasNext();

            // Generate query ID to store query cursor in node local storage.
            String qryId = SQL_QRY_NAME + "-" + UUID.randomUUID();

            if (hasNext) {
                ignite.cluster().<String, VisorQueryCursor<List<?>>>nodeLocalMap().put(qryId, cur);

                scheduleResultSetHolderRemoval(qryId, ignite);
            }
            else
                cur.close();

            return new VisorEither<>(new VisorQueryResult(nid, qryId, names, rows, hasNext, duration));
        }
    }
    catch (Throwable e) {
        return new VisorEither<>(new VisorExceptionWrapper(e));
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:75,代码来源:VisorQueryTask.java

示例8: doSingleUpdate

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
 * Performs update.
 *
 * @param cache Cache.
 * @param sqlText SQL text.
 * @param args Parameters.
 * @return Update counter.
 * @throws SQLException If failed.
 */
private Integer doSingleUpdate(IgniteCache<?, ?> cache, String sqlText, List<Object> args) throws SQLException {
    SqlFieldsQuery qry = new SqlFieldsQueryEx(sqlText, false);

    qry.setPageSize(fetchSize);
    qry.setLocal(locQry);
    qry.setCollocated(collocatedQry);
    qry.setDistributedJoins(distributedJoins);
    qry.setSchema(schemaName);
    qry.setArgs(args == null ? null : args.toArray());

    QueryCursorImpl<List<?>> qryCursor = (QueryCursorImpl<List<?>>)cache.withKeepBinary().query(qry);

    if (qryCursor.isQuery()) {
        throw createJdbcSqlException(getError("Query produced result set", qry),
            IgniteQueryErrorCode.STMT_TYPE_MISMATCH);
    }

    List<List<?>> rows = qryCursor.getAll();

    if (F.isEmpty(rows))
        return SUCCESS_NO_INFO;

    if (rows.size() != 1)
        throw new SQLException(getError("Expected single row for update operation result", qry));

    List<?> row = rows.get(0);

    if (F.isEmpty(row) || row.size() != 1)
        throw new SQLException(getError("Expected row size of 1 for update operation", qry));

    Object objRes = row.get(0);

    if (!(objRes instanceof Long))
        throw new SQLException(getError("Unexpected update result type", qry));

    Long longRes = (Long)objRes;

    if (longRes > Integer.MAX_VALUE) {
        IgniteLogger log = ignite.log();

        if (log != null)
            log.warning(getError("Query updated row counter (" + longRes + ") exceeds integer range", qry));

        return Integer.MAX_VALUE;
    }

    return longRes.intValue();
}
 
开发者ID:apache,项目名称:ignite,代码行数:58,代码来源:JdbcBatchUpdateTask.java

示例9: testRunningSqlFieldsQuery

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
 * Test collecting info about running.
 *
 * @throws Exception If failed.
 */
public void testRunningSqlFieldsQuery() throws Exception {
    IgniteInternalFuture<?> fut = runQueryAsync(new SqlFieldsQuery("select _val, sleep(1000) from Value limit 3"));

    Thread.sleep(500);

    GridQueryProcessor qryProc = grid(0).context().query();

    Collection<GridRunningQueryInfo> queries = qryProc.runningQueries(0);

    assertEquals(1, queries.size());

    fut.get();

    queries = qryProc.runningQueries(0);

    assertEquals(0, queries.size());

    SqlFieldsQuery qry = new SqlFieldsQuery("select _val, sleep(1000) from Value limit 3");
    qry.setLocal(true);

    fut = runQueryAsync(qry);

    Thread.sleep(500);

    queries = qryProc.runningQueries(0);

    assertEquals(1, queries.size());

    fut.get();

    queries = qryProc.runningQueries(0);

    assertEquals(0, queries.size());
}
 
开发者ID:apache,项目名称:ignite,代码行数:40,代码来源:CacheSqlQueryValueCopySelfTest.java

示例10: testLocalQuery

import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/** Tests local query over partitions. */
public void testLocalQuery() {
    Affinity<Object> affinity = grid(0).affinity("cl");

    int[] parts = affinity.primaryPartitions(grid(0).localNode());

    Arrays.sort(parts);

    IgniteCache<ClientKey, Client> cl = grid(0).cache("cl");

    SqlQuery<ClientKey, Client> qry1 = new SqlQuery<>(Client.class, "1=1");
    qry1.setLocal(true);
    qry1.setPartitions(parts[0]);

    List<Cache.Entry<ClientKey, Client>> clients = cl.query(qry1).getAll();

    for (Cache.Entry<ClientKey, Client> client : clients)
        assertEquals("Incorrect partition", parts[0], affinity.partition(client.getKey()));

    SqlFieldsQuery qry2 = new SqlFieldsQuery("select cl._KEY, cl._VAL from \"cl\".Client cl");
    qry2.setLocal(true);
    qry2.setPartitions(parts[0]);

    List<List<?>> rows = cl.query(qry2).getAll();

    for (List<?> row : rows)
        assertEquals("Incorrect partition", parts[0], affinity.partition(row.get(0)));
}
 
开发者ID:apache,项目名称:ignite,代码行数:29,代码来源:IgniteCacheDistributedPartitionQuerySelfTest.java


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