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


Java Statement.setFetchSize方法代碼示例

本文整理匯總了Java中com.datastax.driver.core.Statement.setFetchSize方法的典型用法代碼示例。如果您正苦於以下問題:Java Statement.setFetchSize方法的具體用法?Java Statement.setFetchSize怎麽用?Java Statement.setFetchSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.datastax.driver.core.Statement的用法示例。


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

示例1: executeAdaptiveQueryAsync

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
private static ListenableFuture<ResultSet> executeAdaptiveQueryAsync(Session session, Statement statement, int fetchSize,
                                                                     int remainingAdaptations) {

    statement.setFetchSize(fetchSize);

    ResultSetFuture rawFuture = session.executeAsync(statement);

    // Lazily wrap the result set from the async result with an AdaptiveResultSet
    ListenableFuture<ResultSet> adaptiveFuture = Futures.transform(rawFuture, new Function<ResultSet, ResultSet>() {
        @Override
        public ResultSet apply(ResultSet resultSet) {
            return new AdaptiveResultSet(session, resultSet, remainingAdaptations);
        }
    });

    return Futures.withFallback(adaptiveFuture, t -> {
        if (isAdaptiveException(t) && remainingAdaptations > 0 && fetchSize > MIN_FETCH_SIZE) {
            // Try again with half the fetch size
            int reducedFetchSize = Math.max(fetchSize / 2, MIN_FETCH_SIZE);
            _log.debug("Repeating previous query with fetch size {} due to {}", reducedFetchSize, t.getMessage());
            return executeAdaptiveQueryAsync(session, statement, reducedFetchSize, remainingAdaptations - 1);
        }
        throw Throwables.propagate(t);
    });
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:26,代碼來源:AdaptiveResultSet.java

示例2: tuneStatementExecutionOptions

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
/**
 * Tunes CQL statement execution options (consistency level, fetch option and etc.).
 *
 * @param statement Statement.
 * @return Modified statement.
 */
private Statement tuneStatementExecutionOptions(Statement statement) {
    String qry = "";
    if (statement instanceof BoundStatement) {
        qry = ((BoundStatement)statement).preparedStatement().getQueryString().trim().toLowerCase();
    }
    else if (statement instanceof PreparedStatement) {
        qry = ((PreparedStatement)statement).getQueryString().trim().toLowerCase();
    }
    boolean readStatement = qry.startsWith("select");
    boolean writeStatement = statement instanceof Batch || statement instanceof BatchStatement ||
        qry.startsWith("insert") || qry.startsWith("delete") || qry.startsWith("update");
    if (readStatement && readConsistency != null) {
        statement.setConsistencyLevel(readConsistency);
    }
    if (writeStatement && writeConsistency != null) {
        statement.setConsistencyLevel(writeConsistency);
    }
    if (fetchSize != null) {
        statement.setFetchSize(fetchSize);
    }
    return statement;
}
 
開發者ID:epam,項目名稱:Lagerta,代碼行數:29,代碼來源:CassandraSessionImpl.java

示例3: executeAdaptiveQuery

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
/**
 * Executes a query sychronously, dynamically adjusting the fetch size down if necessary.
 */
public static ResultSet executeAdaptiveQuery(Session session, Statement statement, int fetchSize) {
    int remainingAdaptations = MAX_ADAPTATIONS;
    while (true) {
        try {
            statement.setFetchSize(fetchSize);
            ResultSet resultSet = session.execute(statement);
            return new AdaptiveResultSet(session, resultSet, remainingAdaptations);
        } catch (Throwable t) {
            if (isAdaptiveException(t) && --remainingAdaptations != 0 && fetchSize > MIN_FETCH_SIZE) {
                // Try again with half the fetch size
                fetchSize = Math.max(fetchSize / 2, MIN_FETCH_SIZE);
                _log.debug("Repeating previous query with fetch size {} due to {}", fetchSize, t.getMessage());
            } else {
                throw Throwables.propagate(t);
            }
        }
    }
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:22,代碼來源:AdaptiveResultSet.java

示例4: values

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
/**
 * @return a Collection view of all refs in the store
 * @throws IOException if an exception occurs when communicating to the
 *                     database
 */
public Collection<Ref> values() throws IOException {
    try {
        List<Ref> refs = new ArrayList<Ref>();
        Statement stmt = QueryBuilder
                .select()
                .all()
                .from(keyspace, TABLE_NAME);
        stmt.setFetchSize(FETCH_SIZE);
        ResultSet results = session.execute(stmt);
        for (Row row : results) {
            refs.add(rowToRef(row));
        }
        return refs;
    } catch (RuntimeException e) {
        e.printStackTrace();
        throw new IOException(e);
    }
}
 
開發者ID:benhumphreys,項目名稱:jgit-cassandra,代碼行數:24,代碼來源:RefStore.java

示例5: tuneStatementExecutionOptions

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
/**
 * Tunes CQL statement execution options (consistency level, fetch option and etc.).
 *
 * @param statement Statement.
 * @return Modified statement.
 */
private Statement tuneStatementExecutionOptions(Statement statement) {
    String qry = "";

    if (statement instanceof BoundStatement)
        qry = ((BoundStatement)statement).preparedStatement().getQueryString().trim().toLowerCase();
    else if (statement instanceof PreparedStatement)
        qry = ((PreparedStatement)statement).getQueryString().trim().toLowerCase();

    boolean readStatement = qry.startsWith("select");
    boolean writeStatement = statement instanceof Batch || statement instanceof BatchStatement ||
        qry.startsWith("insert") || qry.startsWith("delete") || qry.startsWith("update");

    if (readStatement && readConsistency != null)
        statement.setConsistencyLevel(readConsistency);

    if (writeStatement && writeConsistency != null)
        statement.setConsistencyLevel(writeConsistency);

    if (fetchSize != null)
        statement.setFetchSize(fetchSize);

    return statement;
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:30,代碼來源:CassandraSessionImpl.java

示例6: reduceFetchSize

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
/**
 * Reduces the fetch size and retries the query.  Returns true if the query succeeded, false if the root cause
 * of the exception does not indicate a frame size issue, if the frame size cannot be adjusted down any further,
 * or if the retried query fails for an unrelated reason.
 */
private boolean reduceFetchSize(Throwable reason) {
    if (!isAdaptiveException(reason) || --_remainingAdaptations == 0) {
        return false;
    }

    ExecutionInfo executionInfo = _delegate.getExecutionInfo();
    Statement statement = executionInfo.getStatement();
    PagingState pagingState = executionInfo.getPagingState();
    int fetchSize = statement.getFetchSize();

    while (fetchSize > MIN_FETCH_SIZE) {
        fetchSize = Math.max(fetchSize / 2, MIN_FETCH_SIZE);
        _log.debug("Retrying query at next page with fetch size {} due to {}", fetchSize, reason.getMessage());
        statement.setFetchSize(fetchSize);
        statement.setPagingState(pagingState);
        try {
            _delegate = _session.execute(statement);
            return true;
        } catch (Throwable t) {
            // Exit the adaptation loop if the exception isn't one where adapting further may help
            if (!isAdaptiveException(t) || --_remainingAdaptations == 0) {
                return false;
            }
        }
    }

    return false;
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:34,代碼來源:AdaptiveResultSet.java

示例7: listPacks

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
/**
 * @return a list of all pack descriptions in the store.
 * @throws IOException  if an exception occurs when communicating to the
 *                      database
 */
public List<DfsPackDescription> listPacks() throws IOException {
    Statement stmt = QueryBuilder
            .select()
            .all()
            .from(keyspace, DESC_TABLE_NAME);
    stmt.setFetchSize(FETCH_SIZE);
    ResultSet results = session.execute(stmt);
    List<DfsPackDescription> packs = new ArrayList<DfsPackDescription>();
    for (Row row : results) {
        packs.add(rowToPackDescription(row));
    }
    return packs;
}
 
開發者ID:benhumphreys,項目名稱:jgit-cassandra,代碼行數:19,代碼來源:ObjStore.java

示例8: pageQueriedResults

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
@Test
public void pageQueriedResults() {
    Statement query = new SimpleStatement("select * from cql3_pagination.simple_uuid_pk");
    query.setFetchSize(5);
    ResultSet resultSet = embeddedCassandra.session().execute(query);

    List<Row> page1 = new ArrayList<>();
    Iterator<Row> iterator1 = resultSet.iterator();
    while (resultSet.getAvailableWithoutFetching() > 0) {
        page1.add(iterator1.next());
    }
    print("Page 1: ", page1);

    Assert.assertEquals(5, page1.size());

    List<Row> page2 = new ArrayList<>();
    Iterator<Row> iterator2 = resultSet.iterator();
    resultSet.fetchMoreResults();
    iterator2.hasNext();
    while (resultSet.getAvailableWithoutFetching() > 0) {
        page2.add(iterator2.next());
    }
    print("Page 2: ", page2);

    Assert.assertEquals(5, page2.size());

    Assert.assertNotEquals(page1.get(0).getUUID("id"), page2.get(0).getUUID("id"));
}
 
開發者ID:codesandnotes,項目名稱:cassandra-cql3-pagination,代碼行數:29,代碼來源:AutomaticPagingTest.java

示例9: executePagingQuery

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
private void executePagingQuery(String cql, int rowCount)
{
    // Execute an index query which should return all rows,
    // setting the fetch size < than the row count. Assert
    // that all rows are returned, so we know that paging
    // of the results was involved.
    Session session = sessionNet();
    Statement stmt = new SimpleStatement(String.format(cql, KEYSPACE + '.' + currentTable()));
    stmt.setFetchSize(rowCount - 1);
    assertEquals(rowCount, session.execute(stmt).all().size());
}
 
開發者ID:scylladb,項目名稱:scylla-tools-java,代碼行數:12,代碼來源:IndexQueryPagingTest.java

示例10: run

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
public boolean run() throws Exception
{
    State state = currentState.get();
    if (state == null)
    { // start processing a new token range
        TokenRange range = tokenRangeIterator.next();
        if (range == null)
            return true; // no more token ranges to process

        state = new State(range, buildQuery(range));
        currentState.set(state);
    }

    ResultSet results;
    Statement statement = new SimpleStatement(state.query);
    statement.setFetchSize(pageSize);

    if (state.pagingState != null)
        statement.setPagingState(state.pagingState);

    results = client.getSession().execute(statement);
    state.pagingState = results.getExecutionInfo().getPagingState();

    int remaining = results.getAvailableWithoutFetching();
    rowCount += remaining;

    for (Row row : results)
    {
        // this call will only succeed if we've added token(partition keys) to the query
        Token partition = row.getPartitionKeyToken();
        if (!state.partitions.contains(partition))
        {
            partitionCount += 1;
            state.partitions.add(partition);
        }

        if (--remaining == 0)
            break;
    }

    if (results.isExhausted() || isWarmup)
    { // no more pages to fetch or just warming up, ready to move on to another token range
        currentState.set(null);
    }

    return true;
}
 
開發者ID:scylladb,項目名稱:scylla-tools-java,代碼行數:48,代碼來源:TokenRangeQuery.java


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