本文整理汇总了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);
}
}
示例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;
}
示例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());
}
示例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);
}
示例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));
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}