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


Java Statement.setConsistencyLevel方法代碼示例

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


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

示例1: queryForLastWriteTimes

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
@Override
public DBResult queryForLastWriteTimes()
{
	if (cluster == null)
		return null;

	try (Session session = cluster.newSession())
	{
		Statement statement = new SimpleStatement(String.format("SELECT WRITETIME (%s) FROM %s.%s;", columnName, keyspace, tableName));
		statement.setConsistencyLevel(ConsistencyLevel.ALL);
		ResultSet results = session.execute(statement);
		List<Row> allRows = results.all();

		// sort all of the rows accordingly
		allRows.sort(new RowComparator());

		// gather the information we need
		long startTime = allRows.get(0).getLong(0) / 1000;
		long endTime = allRows.get(allRows.size() - 1).getLong(0) / 1000;
		int totalCount = allRows.size();
		return new DBResult(startTime, endTime, totalCount);
	}
}
 
開發者ID:Esri,項目名稱:performance-test-harness-for-geoevent,代碼行數:24,代碼來源:CassandraClient.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: findListByStatementAsync

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
protected ListenableFuture<List<D>> findListByStatementAsync(Statement statement) {
    if (statement != null) {
        statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
        ResultSetFuture resultSetFuture = getSession().executeAsync(statement);
        return Futures.transform(resultSetFuture, new Function<ResultSet, List<D>>() {
            @Nullable
            @Override
            public List<D> apply(@Nullable ResultSet resultSet) {
                Result<E> result = getMapper().map(resultSet);
                if (result != null) {
                    List<E> entities = result.all();
                    return DaoUtil.convertDataList(entities);
                } else {
                    return Collections.emptyList();
                }
            }
        });
    }
    return Futures.immediateFuture(Collections.emptyList());
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:21,代碼來源:CassandraAbstractModelDao.java

示例4: findOneByStatementAsync

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
protected ListenableFuture<D> findOneByStatementAsync(Statement statement) {
    if (statement != null) {
        statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
        ResultSetFuture resultSetFuture = getSession().executeAsync(statement);
        return Futures.transform(resultSetFuture, new Function<ResultSet, D>() {
            @Nullable
            @Override
            public D apply(@Nullable ResultSet resultSet) {
                Result<E> result = getMapper().map(resultSet);
                if (result != null) {
                    E entity = result.one();
                    return DaoUtil.getData(entity);
                } else {
                    return null;
                }
            }
        });
    }
    return Futures.immediateFuture(null);
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:21,代碼來源:CassandraAbstractModelDao.java

示例5: executePut

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
public void executePut(String query, String consistency){
	logger.debug("in data store handle, executing put:"+query);
	long start = System.currentTimeMillis();
	Statement statement = new SimpleStatement(query);
	if(consistency.equalsIgnoreCase("critical")){
		logger.info("Executing critical put query:"+query);
		statement.setConsistencyLevel(ConsistencyLevel.QUORUM);
	}
	else if (consistency.equalsIgnoreCase("eventual")){
		logger.info("Executing normal put query:"+query);
		statement.setConsistencyLevel(ConsistencyLevel.ONE);
	}
	session.execute(statement); 
	long end = System.currentTimeMillis();
	logger.debug("Time taken for actual put in cassandra:"+(end-start));
}
 
開發者ID:att,項目名稱:music,代碼行數:17,代碼來源:MusicDataStore.java

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

示例7: execute

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
private ResultSet execute(Statement statement, ConsistencyLevel level) {
    log.debug("Execute cassandra statement {}", statement);
    if (statement.getConsistencyLevel() == null) {
        statement.setConsistencyLevel(level);
    }
    return getSession().execute(statement);
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:8,代碼來源:CassandraAbstractDao.java

示例8: executeAsync

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
private ResultSetFuture executeAsync(Statement statement, ConsistencyLevel level) {
    log.debug("Execute cassandra async statement {}", statement);
    if (statement.getConsistencyLevel() == null) {
        statement.setConsistencyLevel(level);
    }
    return getSession().executeAsync(statement);
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:8,代碼來源:CassandraAbstractDao.java

示例9: findListByStatement

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
protected List<E> findListByStatement(Statement statement) {
    List<E> list = Collections.emptyList();
    if (statement != null) {
        statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
        ResultSet resultSet = getSession().execute(statement);
        Result<E> result = getMapper().map(resultSet);
        if (result != null) {
            list = result.all();
        }
    }
    return list;
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:13,代碼來源:CassandraAbstractModelDao.java

示例10: findOneByStatement

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
protected E findOneByStatement(Statement statement) {
    E object = null;
    if (statement != null) {
        statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
        ResultSet resultSet = getSession().execute(statement);
        Result<E> result = getMapper().map(resultSet);
        if (result != null) {
            object = result.one();
        }
    }
    return object;
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:13,代碼來源:CassandraAbstractModelDao.java

示例11: saveWithResult

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
protected EntityResultSet<E> saveWithResult(E entity) {
    log.debug("Save entity {}", entity);
    if (entity.getId() == null) {
        entity.setId(UUIDs.timeBased());
    } else if (isDeleteOnSave()) {
        removeById(entity.getId());
    }
    Statement saveStatement = getSaveQuery(entity);
    saveStatement.setConsistencyLevel(cluster.getDefaultWriteConsistencyLevel());
    ResultSet resultSet = executeWrite(saveStatement);
    return new EntityResultSet<>(resultSet, entity);
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:13,代碼來源:CassandraAbstractModelDao.java

示例12: executeEventualGet

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
public ResultSet executeEventualGet(String query){
	logger.info("Executing normal get query:"+query);
	long start = System.currentTimeMillis();
	Statement statement = new SimpleStatement(query);
	statement.setConsistencyLevel(ConsistencyLevel.ONE);
	ResultSet results = session.execute(statement);
	long end = System.currentTimeMillis();
	logger.debug("Time taken for actual get in cassandra:"+(end-start));
	return results;	
}
 
開發者ID:att,項目名稱:music,代碼行數:11,代碼來源:MusicDataStore.java

示例13: executeCriticalGet

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
public ResultSet executeCriticalGet(String query){
	Statement statement = new SimpleStatement(query);
	logger.info("Executing critical get query:"+query);
	statement.setConsistencyLevel(ConsistencyLevel.QUORUM);
	ResultSet results = session.execute(statement);
	return results;	
}
 
開發者ID:att,項目名稱:music,代碼行數:8,代碼來源:MusicDataStore.java

示例14: executeCreateQuery

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
private void executeCreateQuery(String query, String consistency) throws Exception {
	Statement statement = new SimpleStatement(query);
	if (consistency.equalsIgnoreCase("atomic"))
		statement.setConsistencyLevel(ConsistencyLevel.ALL);
	else if (consistency.equalsIgnoreCase("eventual"))
		statement.setConsistencyLevel(ConsistencyLevel.ONE);
	else
		throw new Exception("Consistency level "+consistency+ " unknown!!");
	session.execute(statement);
}
 
開發者ID:att,項目名稱:music,代碼行數:11,代碼來源:MusicClient.java

示例15: healthCheck

import com.datastax.driver.core.Statement; //導入方法依賴的package包/類
public int healthCheck() {
    final Statement health = QueryBuilder.select().all().from(HEALTHCHECK_KEYSPACE_NAME, "healthcheck")
            .where(eq("healthkey", "healthy"));
    health.setConsistencyLevel(ConsistencyLevel.ALL);
    health.enableTracing();
    QueryTrace queryTrace;
    cluster.register(new LoggingLatencyTracker());
    try {
        final ResultSet results = session.execute(health);
        final ExecutionInfo executionInfo = results.getExecutionInfo();
        queryTrace = executionInfo.getQueryTrace();
    } catch (NoHostAvailableException e) {
        LOG.error("No hosts available", e);
        return 2;
    }
    if (retryPolicy.getLastDecision() != null) {
        LOG.warn("Could not query all hosts");
        if (queryTrace != null) {
            final Set<InetAddress> missingHosts = new HashSet<>(hosts.size());
            for (Host host : hosts) {
                missingHosts.add(host.getSocketAddress().getAddress());
            }
            for (QueryTrace.Event event : queryTrace.getEvents()) {
                missingHosts.remove(event.getSource());
                LOG.debug("description={} elapsed={} source={} micros={}",
                        event.getDescription(),
                        millis2Date(event.getTimestamp()),
                        event.getSource(),
                        event.getSourceElapsedMicros());
            }
            if (!missingHosts.isEmpty()) {
                LOG.error("Missing log entries from these hosts: {}", missingHosts);
            }
        }
        return 1;
    }
    return 0;
}
 
開發者ID:lookout,項目名稱:cassandra-health-check,代碼行數:39,代碼來源:CassandraHealthCheck.java


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