com.datastax.driver.core.querybuilder.Select.setConsistencyLevel()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(15.2k)|赞(0)|评价(0)|浏览(213)

本文整理了Java中com.datastax.driver.core.querybuilder.Select.setConsistencyLevel()方法的一些代码示例,展示了Select.setConsistencyLevel()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Select.setConsistencyLevel()方法的具体详情如下:
包路径:com.datastax.driver.core.querybuilder.Select
类名称:Select
方法名:setConsistencyLevel

Select.setConsistencyLevel介绍

暂无

代码示例

代码示例来源:origin: kaaproject/kaa

/**
 * Get all entities from cassandra database.
 * @return <code>List</code> of entities
 */
public List<T> find() {
 LOG.debug("Get all entities from column family {}", getColumnFamilyName());
 return findListByStatement(
   QueryBuilder.select()
     .all().from(getColumnFamilyName())
     .setConsistencyLevel(getReadConsistencyLevel()));
}

代码示例来源:origin: otaviojava/Easy-Cassandra

@Override
public SelectBuilder<T> withConsistencyLevel(ConsistencyLevel consistency) {
  select.setConsistencyLevel(consistency);
  return this;
}

代码示例来源:origin: stackoverflow.com

Select s = QueryBuilder.select().from("employee");
   s.where(QueryBuilder.eq("id", "234"));
   s.setConsistencyLevel(ConsistencyLevel.QUORUM) ;

代码示例来源:origin: Stratio/stratio-cassandra-benchmark

public void run() {
  try {
    RateLimiter rateLimiter = RateLimiter.create(rate);
    for (String data : dataset) {
      rateLimiter.acquire();
      String clause = String.format("{%s : {type : \"lucene\", default_field : \"%s\", query : \"%s\"}}",
                     relevance ? "query" : "filter",
                     column,
                     data);
      Select select = QueryBuilder.select()
                    .from(keyspace, table)
                    .where(QueryBuilder.eq(column, clause))
                    .limit(limit);
      long startTime = System.currentTimeMillis();
      ResultSet rs = session.execute(select.setConsistencyLevel(ConsistencyLevel.ONE));
      List<Row> rows = rs.all();
      long queryTime = System.currentTimeMillis() - startTime;
      stats.inc(queryTime);
      logger.debug("QUERY : " + select.toString() + " " + queryTime + " ms");
      for (Row row : rows) {
        logger.debug("\tROW : " + row);
      }
    }
  } catch (Exception e) {
    e.printStackTrace();
    logger.error(e);
  }
}

代码示例来源:origin: valchkou/cassandra-driver-mapping

private static void appendOptions(Select select, ReadOptions options) {
  if (options != null) {
    if (options.getConsistencyLevel() != null) {
      select.setConsistencyLevel(options.getConsistencyLevel());
    }
    if (options.getRetryPolicy() != null) {
      select.setRetryPolicy(options.getRetryPolicy());
    }
  }
}

代码示例来源:origin: Contrast-Security-OSS/cassandra-migration

/**
 * Calculates the installed rank for the new migration to be inserted.
 *
 * @return The installed rank.
 */
private int calculateInstalledRank() {
  Statement statement = new SimpleStatement(
      "UPDATE " + keyspace.getName() + "." + tableName + COUNTS_TABLE_NAME_SUFFIX +
          " SET count = count + 1" +
          "WHERE name = 'installed_rank';");
  session.execute(statement);
  Select select = QueryBuilder
      .select("count")
      .from(tableName + COUNTS_TABLE_NAME_SUFFIX);
  select.where(eq("name", "installed_rank"));
  select.setConsistencyLevel(this.consistencyLevel);
  ResultSet result = session.execute(select);
  return (int) result.one().getLong("count");
}

代码示例来源:origin: otaviojava/Easy-Cassandra

protected Select prepareCount(Class<?> bean, ConsistencyLevel consistency) {
    ClassInformation classInformation = ClassInformations.INSTACE.getClass(bean);
    KeySpaceInformation key = classInformation.getKeySpace(keySpace);
    Select select = QueryBuilder.select().countAll()
        .from(key.getKeySpace(), key.getColumnFamily());
    select.setConsistencyLevel(consistency);
    return select;
  }
}

代码示例来源:origin: smartcat-labs/cassandra-migration-tool-java

/**
 * Get current database version for given migration type with ALL consistency. Select one row since
 * migration history is saved ordered descending by timestamp. If there are no rows in the schema_version table,
 * return 0 as default database version. Data version is changed by executing migrations.
 *
 * @param type Migration type
 * @return Database version for given type
 */
public int getCurrentVersion(final MigrationType type) {
  final Statement select = QueryBuilder.select().all().from(SCHEMA_VERSION_CF)
      .where(QueryBuilder.eq(TYPE, type.name())).limit(1).setConsistencyLevel(ConsistencyLevel.ALL);
  final ResultSet result = session.execute(select);
  final Row row = result.one();
  return row == null ? 0 : row.getInt(VERSION);
}

代码示例来源:origin: Netflix/CassJMeter

@Override
public ResponseData get(Object rkey, Object colName) throws OperationException {
  Session session = DataStaxClientConnection.instance.session();
  TableMetadata tm = DataStaxClientConnection.instance.getKeyspaceMetadata().getTable(cfName);
  String partitionKey = tm.getPartitionKey().get(0).getName();
  
  Query query = QueryBuilder.select(colName.toString()).from(cfName).where(QueryBuilder.eq(partitionKey, rkey)).limit(1000000)
      .setConsistencyLevel(ConsistencyLevel.valueOf(com.netflix.jmeter.properties.Properties.instance.cassandra.getReadConsistency()));
  
  ResultSetFuture rs = session.executeAsync(query);
  int size = 0;
  try {
    Row row = rs.getUninterruptibly(1000000, TimeUnit.MILLISECONDS).one();
    size = row != null ? row.getBytesUnsafe(colName.toString()).capacity() : 0;
  }
  catch (TimeoutException e) {
    e.printStackTrace();
    throw new OperationException(e);
  }
  return new DataStaxClientResponseData("", size, "", 0, rkey, colName, null);
}

代码示例来源:origin: com.bazaarvoice.emodb/emodb-sor

@Override
  protected ResultSet queryRowGroupRowsAfter(Row row) {
    Statement statement = selectDeltaFrom(_placement.getBlockedDeltaTableDDL())
        .where(eq(_placement.getBlockedDeltaTableDDL().getRowKeyColumnName(), getKey(row)))
        .and(gt(ImmutableList.of(_placement.getBlockedDeltaTableDDL().getChangeIdColumnName(), _placement.getBlockedDeltaTableDDL().getBlockColumnName()),
            ImmutableList.of(getChangeId(row), getBlock(row))))
        .orderBy(asc(_placement.getBlockedDeltaTableDDL().getChangeIdColumnName()))
        .setConsistencyLevel(_consistency);
    return AdaptiveResultSet.executeAdaptiveQuery(_placement.getKeyspace().getCqlSession(), statement, _driverConfig.getSingleRowFetchSize());
  }
}

代码示例来源:origin: bazaarvoice/emodb

@Override
  protected ResultSet queryRowGroupRowsAfter(Row row) {
    Statement statement = selectDeltaFrom(_placement.getBlockedDeltaTableDDL())
        .where(eq(_placement.getBlockedDeltaTableDDL().getRowKeyColumnName(), getKey(row)))
        .and(gt(ImmutableList.of(_placement.getBlockedDeltaTableDDL().getChangeIdColumnName(), _placement.getBlockedDeltaTableDDL().getBlockColumnName()),
            ImmutableList.of(getChangeId(row), getBlock(row))))
        .orderBy(asc(_placement.getBlockedDeltaTableDDL().getChangeIdColumnName()))
        .setConsistencyLevel(_consistency);
    return AdaptiveResultSet.executeAdaptiveQuery(_placement.getKeyspace().getCqlSession(), statement, _driverConfig.getSingleRowFetchSize());
  }
}

代码示例来源:origin: otaviojava/Easy-Cassandra

/**
 * create the {@link QueryBean}.
 * @param bean the bean
 * @param consistency the consistency
 * @param <T> kind of class
 * @return {@link QueryBean}
 */
protected <T> QueryBean createQueryBean(Class<T> bean,
    ConsistencyLevel consistency) {
  ClassInformation classInformation = ClassInformations.INSTACE.getClass(bean);
  QueryBean byKeyBean = prepare(new QueryBean(), classInformation);
  KeySpaceInformation keySpaceInformation = classInformation.getKeySpace(keySpace);
  byKeyBean.select = QueryBuilder.select(byKeyBean.getArray()).from(
      keySpaceInformation.getKeySpace(), keySpaceInformation.getColumnFamily());
  byKeyBean.select.setConsistencyLevel(consistency);
  return byKeyBean;
}

代码示例来源:origin: Stratio/stratio-cassandra-test

public List<Row> selectAllFromIndexQueryWithFiltering(int limit, String name, Object value) {
  String search = search().query(all()).refresh(true).toJson();
  return execute(QueryBuilder.select()
                .from(keyspace, table)
                .where(QueryBuilder.eq(indexColumn, search))
                .and(QueryBuilder.eq(name, value))
                .limit(limit)
                .allowFiltering()
                .setConsistencyLevel(consistencyLevel));
}

代码示例来源:origin: Contrast-Security-OSS/cassandra-migration

.from(keyspace.getName(), tableName);
select.setConsistencyLevel(this.consistencyLevel);
ResultSet results = session.execute(select);
List<AppliedMigration> resultsList = new ArrayList<>();

代码示例来源:origin: com.bazaarvoice.emodb/emodb-table

private Iterator<ProtoStashTokenRange> getTokenRangesBetweenIntraShard(String stashId, String placement,
                                    ByteBuffer fromInclusive, ByteBuffer toExclusive) {
  // Since the range falls entirely within a single shard run a targeted query that only looks for the beginning
  // of that shard.
  ByteBuffer startToken = RowKeyUtils.getRowKeyRaw(RowKeyUtils.getShardId(fromInclusive), RowKeyUtils.getTableUuid(fromInclusive), new byte[0]);
  ResultSet resultSet = _placementCache.get(_systemTablePlacement)
      .getKeyspace()
      .getCqlSession()
      .execute(
          QueryBuilder.select(TABLE_JSON_COLUMN)
              .from(STASH_TOKEN_RANGE_TABLE)
              .where(QueryBuilder.eq(STASH_ID_COLUMN, stashId))
              .and(QueryBuilder.eq(DATA_CENTER_COLUMN, _dataCenters.getSelf().getName()))
              .and(QueryBuilder.eq(PLACEMENT_COLUMN, placement))
              .and(QueryBuilder.eq(RANGE_TOKEN_COLUMN, startToken))
              .and(QueryBuilder.eq(IS_START_TOKEN_COLUMN, true))
              .limit(1)
              .setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM));
  Row row = resultSet.one();
  if (row == null) {
    return Iterators.emptyIterator();
  }
  TableJson tableJson = toTableJson(row.getString(0));
  return Iterators.singletonIterator(new ProtoStashTokenRange(fromInclusive, toExclusive, tableJson));
}

代码示例来源:origin: bazaarvoice/emodb

private Iterator<ProtoStashTokenRange> getTokenRangesBetweenIntraShard(String stashId, String placement,
                                    ByteBuffer fromInclusive, ByteBuffer toExclusive) {
  // Since the range falls entirely within a single shard run a targeted query that only looks for the beginning
  // of that shard.
  ByteBuffer startToken = RowKeyUtils.getRowKeyRaw(RowKeyUtils.getShardId(fromInclusive), RowKeyUtils.getTableUuid(fromInclusive), new byte[0]);
  ResultSet resultSet = _placementCache.get(_systemTablePlacement)
      .getKeyspace()
      .getCqlSession()
      .execute(
          QueryBuilder.select(TABLE_JSON_COLUMN)
              .from(STASH_TOKEN_RANGE_TABLE)
              .where(QueryBuilder.eq(STASH_ID_COLUMN, stashId))
              .and(QueryBuilder.eq(DATA_CENTER_COLUMN, _dataCenters.getSelf().getName()))
              .and(QueryBuilder.eq(PLACEMENT_COLUMN, placement))
              .and(QueryBuilder.eq(RANGE_TOKEN_COLUMN, startToken))
              .and(QueryBuilder.eq(IS_START_TOKEN_COLUMN, true))
              .limit(1)
              .setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM));
  Row row = resultSet.one();
  if (row == null) {
    return Iterators.emptyIterator();
  }
  TableJson tableJson = toTableJson(row.getString(0));
  return Iterators.singletonIterator(new ProtoStashTokenRange(fromInclusive, toExclusive, tableJson));
}

代码示例来源:origin: com.bazaarvoice.emodb/emodb-sor

/**
 * Reads columns from the delta or delta history table.  The range of columns, order, and limit can be
 * parameterized.
 */
private ResultSet columnScan(DeltaPlacement placement, TableDDL tableDDL, ByteBuffer rowKey, Range<RangeTimeUUID> columnRange,
               boolean ascending, int limit, ConsistencyLevel consistency) {
  Select.Where where = selectFrom(tableDDL)
      .where(eq(tableDDL.getRowKeyColumnName(), rowKey));
  if (columnRange.hasLowerBound()) {
    if (columnRange.lowerBoundType() == BoundType.CLOSED) {
      where = where.and(gte(tableDDL.getChangeIdColumnName(), columnRange.lowerEndpoint().getUuid()));
    } else {
      where = where.and(gt(tableDDL.getChangeIdColumnName(), columnRange.lowerEndpoint().getUuid()));
    }
  }
  if (columnRange.hasUpperBound()) {
    if (columnRange.upperBoundType() == BoundType.CLOSED) {
      where = where.and(lte(tableDDL.getChangeIdColumnName(), columnRange.upperEndpoint().getUuid()));
    } else {
      where = where.and(lt(tableDDL.getChangeIdColumnName(), columnRange.upperEndpoint().getUuid()));
    }
  }
  Statement statement = where
      .orderBy(ascending ? asc(tableDDL.getChangeIdColumnName()) : desc(tableDDL.getChangeIdColumnName()))
      .limit(limit)
      .setConsistencyLevel(consistency);
  return AdaptiveResultSet.executeAdaptiveQuery(placement.getKeyspace().getCqlSession(), statement, _driverConfig.getSingleRowFetchSize());
}

代码示例来源:origin: bazaarvoice/emodb

/**
 * Reads columns from the delta or delta history table.  The range of columns, order, and limit can be
 * parameterized.
 */
private ResultSet columnScan(DeltaPlacement placement, TableDDL tableDDL, ByteBuffer rowKey, Range<RangeTimeUUID> columnRange,
               boolean ascending, int limit, ConsistencyLevel consistency) {
  Select.Where where = selectFrom(tableDDL)
      .where(eq(tableDDL.getRowKeyColumnName(), rowKey));
  if (columnRange.hasLowerBound()) {
    if (columnRange.lowerBoundType() == BoundType.CLOSED) {
      where = where.and(gte(tableDDL.getChangeIdColumnName(), columnRange.lowerEndpoint().getUuid()));
    } else {
      where = where.and(gt(tableDDL.getChangeIdColumnName(), columnRange.lowerEndpoint().getUuid()));
    }
  }
  if (columnRange.hasUpperBound()) {
    if (columnRange.upperBoundType() == BoundType.CLOSED) {
      where = where.and(lte(tableDDL.getChangeIdColumnName(), columnRange.upperEndpoint().getUuid()));
    } else {
      where = where.and(lt(tableDDL.getChangeIdColumnName(), columnRange.upperEndpoint().getUuid()));
    }
  }
  Statement statement = where
      .orderBy(ascending ? asc(tableDDL.getChangeIdColumnName()) : desc(tableDDL.getChangeIdColumnName()))
      .limit(limit)
      .setConsistencyLevel(consistency);
  return AdaptiveResultSet.executeAdaptiveQuery(placement.getKeyspace().getCqlSession(), statement, _driverConfig.getSingleRowFetchSize());
}

代码示例来源:origin: com.bazaarvoice.emodb/emodb-sor

/**
 * Reads columns from the delta or delta history table.  The range of columns, order, and limit can be
 * parameterized.
 */
private ResultSet columnScan(DeltaPlacement placement, TableDDL tableDDL, ByteBuffer rowKey, Range<RangeTimeUUID> columnRange,
               boolean ascending, ConsistencyLevel consistency) {
  Select.Where where = (tableDDL == placement.getBlockedDeltaTableDDL() ? selectDeltaFrom(placement.getBlockedDeltaTableDDL()) : selectFrom(tableDDL))
      .where(eq(tableDDL.getRowKeyColumnName(), rowKey));
  if (columnRange.hasLowerBound()) {
    if (columnRange.lowerBoundType() == BoundType.CLOSED) {
      where = where.and(gte(tableDDL.getChangeIdColumnName(), columnRange.lowerEndpoint().getUuid()));
    } else {
      where = where.and(gt(tableDDL.getChangeIdColumnName(), columnRange.lowerEndpoint().getUuid()));
    }
  }
  if (columnRange.hasUpperBound()) {
    if (columnRange.upperBoundType() == BoundType.CLOSED) {
      where = where.and(lte(tableDDL.getChangeIdColumnName(), columnRange.upperEndpoint().getUuid()));
    } else {
      where = where.and(lt(tableDDL.getChangeIdColumnName(), columnRange.upperEndpoint().getUuid()));
    }
  }
  Statement statement = where
      .orderBy(ascending ? asc(tableDDL.getChangeIdColumnName()) : desc(tableDDL.getChangeIdColumnName()))
      .setConsistencyLevel(consistency);
  return AdaptiveResultSet.executeAdaptiveQuery(placement.getKeyspace().getCqlSession(), statement, _driverConfig.getSingleRowFetchSize());
}

代码示例来源:origin: bazaarvoice/emodb

/**
 * Reads columns from the delta or delta history table.  The range of columns, order, and limit can be
 * parameterized.
 */
private ResultSet columnScan(DeltaPlacement placement, TableDDL tableDDL, ByteBuffer rowKey, Range<RangeTimeUUID> columnRange,
               boolean ascending, ConsistencyLevel consistency) {
  Select.Where where = (tableDDL == placement.getBlockedDeltaTableDDL() ? selectDeltaFrom(placement.getBlockedDeltaTableDDL()) : selectFrom(tableDDL))
      .where(eq(tableDDL.getRowKeyColumnName(), rowKey));
  if (columnRange.hasLowerBound()) {
    if (columnRange.lowerBoundType() == BoundType.CLOSED) {
      where = where.and(gte(tableDDL.getChangeIdColumnName(), columnRange.lowerEndpoint().getUuid()));
    } else {
      where = where.and(gt(tableDDL.getChangeIdColumnName(), columnRange.lowerEndpoint().getUuid()));
    }
  }
  if (columnRange.hasUpperBound()) {
    if (columnRange.upperBoundType() == BoundType.CLOSED) {
      where = where.and(lte(tableDDL.getChangeIdColumnName(), columnRange.upperEndpoint().getUuid()));
    } else {
      where = where.and(lt(tableDDL.getChangeIdColumnName(), columnRange.upperEndpoint().getUuid()));
    }
  }
  Statement statement = where
      .orderBy(ascending ? asc(tableDDL.getChangeIdColumnName()) : desc(tableDDL.getChangeIdColumnName()))
      .setConsistencyLevel(consistency);
  return AdaptiveResultSet.executeAdaptiveQuery(placement.getKeyspace().getCqlSession(), statement, _driverConfig.getSingleRowFetchSize());
}

相关文章