本文整理匯總了Java中com.datastax.driver.core.QueryOptions.setConsistencyLevel方法的典型用法代碼示例。如果您正苦於以下問題:Java QueryOptions.setConsistencyLevel方法的具體用法?Java QueryOptions.setConsistencyLevel怎麽用?Java QueryOptions.setConsistencyLevel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.datastax.driver.core.QueryOptions
的用法示例。
在下文中一共展示了QueryOptions.setConsistencyLevel方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: configureQueryOptions
import com.datastax.driver.core.QueryOptions; //導入方法依賴的package包/類
private void configureQueryOptions() {
final String consistencyConfiguration = (String) configuration.get(TRIDENT_CASSANDRA_CONSISTENCY);
final String serialConsistencyConfiguration = (String) configuration.get(TRIDENT_CASSANDRA_SERIAL_CONSISTENCY);
final QueryOptions queryOptions = builder.getConfiguration().getQueryOptions();
if (StringUtils.isNotEmpty(consistencyConfiguration)) {
queryOptions.setConsistencyLevel(ConsistencyLevel.valueOf(consistencyConfiguration));
}
if (StringUtils.isNotEmpty(serialConsistencyConfiguration)) {
queryOptions.setSerialConsistencyLevel(ConsistencyLevel.valueOf(serialConsistencyConfiguration));
}
builder = builder.withQueryOptions(queryOptions);
}
示例2: configureQueryOptions
import com.datastax.driver.core.QueryOptions; //導入方法依賴的package包/類
/**
* Creates the query options for this factory.
*
* @param configuration the configuration.
* @return the query options for this factory.
*/
private QueryOptions configureQueryOptions(final Configuration<Map<String, Object>> configuration) {
final QueryOptions queryOptions = new QueryOptions();
queryOptions.setConsistencyLevel(
ConsistencyLevel.valueOf(
configuration.getParameter(
"consistency_level",
"ONE")));
queryOptions.setSerialConsistencyLevel(
ConsistencyLevel.valueOf(
configuration.getParameter(
"serial_consistency_level",
"ONE")));
queryOptions.setFetchSize(configuration.getParameter(
"fetch_size",
1000));
return queryOptions;
}
示例3: populateQueryOptions
import com.datastax.driver.core.QueryOptions; //導入方法依賴的package包/類
private Cluster.Builder populateQueryOptions(Properties properties, Cluster.Builder builder) {
String consistencyLevelProp = properties.getProperty(CassandraStoreParameters.CONSISTENCY_LEVEL);
String serialConsistencyLevelProp = properties.getProperty(CassandraStoreParameters.SERIAL_CONSISTENCY_LEVEL);
String fetchSize = properties.getProperty(CassandraStoreParameters.FETCH_SIZE);
QueryOptions options = new QueryOptions();
if (consistencyLevelProp != null) {
options.setConsistencyLevel(ConsistencyLevel.valueOf(consistencyLevelProp));
}
if (serialConsistencyLevelProp != null) {
options.setSerialConsistencyLevel(ConsistencyLevel.valueOf(serialConsistencyLevelProp));
}
if (fetchSize != null) {
options.setFetchSize(Integer.parseInt(fetchSize));
}
return builder.withQueryOptions(options);
}
示例4: populateQueryOptions
import com.datastax.driver.core.QueryOptions; //導入方法依賴的package包/類
private Builder populateQueryOptions(Map<String, String> properties, Builder builder) {
String consistencyLevelProp = properties.get(DBConstants.Cassandra.CONSISTENCY_LEVEL);
String serialConsistencyLevelProp = properties.get(DBConstants.Cassandra.SERIAL_CONSISTENCY_LEVEL);
String fetchSize = properties.get(DBConstants.Cassandra.FETCH_SIZE);
QueryOptions options = new QueryOptions();
if (consistencyLevelProp != null) {
options.setConsistencyLevel(ConsistencyLevel.valueOf(consistencyLevelProp));
}
if (serialConsistencyLevelProp != null) {
options.setSerialConsistencyLevel(ConsistencyLevel.valueOf(serialConsistencyLevelProp));
}
if (fetchSize != null) {
options.setFetchSize(Integer.parseInt(fetchSize));
}
return builder.withQueryOptions(options);
}
示例5: getQueryOptions
import com.datastax.driver.core.QueryOptions; //導入方法依賴的package包/類
private QueryOptions getQueryOptions(CassandraProperties properties) {
QueryOptions options = new QueryOptions();
if (properties.getConsistencyLevel() != null) {
options.setConsistencyLevel(properties.getConsistencyLevel());
}
if (properties.getSerialConsistencyLevel() != null) {
options.setSerialConsistencyLevel(properties.getSerialConsistencyLevel());
}
options.setFetchSize(properties.getFetchSize());
return options;
}
示例6: connect
import com.datastax.driver.core.QueryOptions; //導入方法依賴的package包/類
/**
* Currently we connect just once and then reuse the connection.
* We do not bother with closing the connection.
*
* It is normal to use one Session per DB. The Session is thread safe.
*/
private void connect() {
if (cluster == null) {
log.info("Connecting to Cassandra server on " + this.dbHost + " at port " + this.dbPort);
// allow fetching as much data as present in the DB
QueryOptions queryOptions = new QueryOptions();
queryOptions.setFetchSize(Integer.MAX_VALUE);
queryOptions.setConsistencyLevel(ConsistencyLevel.ONE);
cluster = Cluster.builder()
.addContactPoint(this.dbHost)
.withPort(this.dbPort)
.withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()))
.withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 30000))
.withQueryOptions(queryOptions)
.withCredentials(this.dbUser, this.dbPassword)
.build();
}
if (session == null) {
log.info("Connecting to Cassandra DB with name " + this.dbName);
session = cluster.connect(dbName);
}
}
示例7: getQueryOptions
import com.datastax.driver.core.QueryOptions; //導入方法依賴的package包/類
private static QueryOptions getQueryOptions(CassandraProperties properties) {
QueryOptions options = new QueryOptions();
if (properties.getConsistencyLevel() != null) {
options.setConsistencyLevel(properties.getConsistencyLevel());
}
if (properties.getSerialConsistencyLevel() != null) {
options.setSerialConsistencyLevel(properties.getSerialConsistencyLevel());
}
options.setFetchSize(properties.getFetchSize());
return options;
}
示例8: getQueryOptions
import com.datastax.driver.core.QueryOptions; //導入方法依賴的package包/類
private QueryOptions getQueryOptions() {
QueryOptions options = new QueryOptions();
if (eventStoreConfig.getConsistencyLevel() != null) {
options.setConsistencyLevel(eventStoreConfig.getConsistencyLevel());
}
if (eventStoreConfig.getSerialConsistencyLevel() != null) {
options.setSerialConsistencyLevel(eventStoreConfig.getSerialConsistencyLevel());
}
options.setFetchSize(eventStoreConfig.getFetchSize());
return options;
}
示例9: getQueryOptions
import com.datastax.driver.core.QueryOptions; //導入方法依賴的package包/類
private QueryOptions getQueryOptions() {
QueryOptions options = new QueryOptions();
CassandraProperties properties = this.properties;
if (properties.getConsistencyLevel() != null) {
options.setConsistencyLevel(properties.getConsistencyLevel());
}
if (properties.getSerialConsistencyLevel() != null) {
options.setSerialConsistencyLevel(properties.getSerialConsistencyLevel());
}
options.setFetchSize(properties.getFetchSize());
return options;
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:13,代碼來源:CassandraAutoConfiguration.java
示例10: getReadQueryOptions
import com.datastax.driver.core.QueryOptions; //導入方法依賴的package包/類
private static QueryOptions getReadQueryOptions(Configuration conf)
{
String CL = ConfigHelper.getReadConsistencyLevel(conf);
Optional<Integer> fetchSize = getInputPageRowSize(conf);
QueryOptions queryOptions = new QueryOptions();
if (CL != null && !CL.isEmpty())
queryOptions.setConsistencyLevel(com.datastax.driver.core.ConsistencyLevel.valueOf(CL));
if (fetchSize.isPresent())
queryOptions.setFetchSize(fetchSize.get());
return queryOptions;
}
示例11: getClusterBuilder
import com.datastax.driver.core.QueryOptions; //導入方法依賴的package包/類
public Cluster.Builder getClusterBuilder() {
final List<InetSocketAddress> sockets = new ArrayList<InetSocketAddress>();
for (String host : hosts) {
if(StringUtils.contains(host, ":")) {
String hostParts [] = StringUtils.split(host, ":");
sockets.add(new InetSocketAddress(hostParts[0], Integer.valueOf(hostParts[1])));
LOG.debug("Connecting to [" + host + "] with port [" + hostParts[1] + "]");
} else {
sockets.add(new InetSocketAddress(host, ProtocolOptions.DEFAULT_PORT));
LOG.debug("Connecting to [" + host + "] with port [" + ProtocolOptions.DEFAULT_PORT + "]");
}
}
Cluster.Builder builder = Cluster.builder().addContactPointsWithPorts(sockets).withCompression(compression);
QueryOptions queryOptions = new QueryOptions();
queryOptions.setConsistencyLevel(clusterConsistencyLevel);
queryOptions.setSerialConsistencyLevel(serialConsistencyLevel);
builder = builder.withQueryOptions(queryOptions);
if (StringUtils.isNotEmpty(clusterName)) {
builder = builder.withClusterName(clusterName);
}
return builder;
}
示例12: createCassandraSession
import com.datastax.driver.core.QueryOptions; //導入方法依賴的package包/類
@Singleton
@Provides
public static CassandraSession createCassandraSession(
CassandraConnectorId connectorId,
CassandraClientConfig config,
JsonCodec<List<ExtraColumnMetadata>> extraColumnMetadataCodec)
{
requireNonNull(config, "config is null");
requireNonNull(extraColumnMetadataCodec, "extraColumnMetadataCodec is null");
Cluster.Builder clusterBuilder = Cluster.builder();
List<String> contactPoints = requireNonNull(config.getContactPoints(), "contactPoints is null");
checkArgument(!contactPoints.isEmpty(), "empty contactPoints");
clusterBuilder.addContactPoints(contactPoints.toArray(new String[contactPoints.size()]));
clusterBuilder.withPort(config.getNativeProtocolPort());
clusterBuilder.withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 10000));
clusterBuilder.withRetryPolicy(config.getRetryPolicy().getPolicy());
SocketOptions socketOptions = new SocketOptions();
socketOptions.setReadTimeoutMillis(Ints.checkedCast(config.getClientReadTimeout().toMillis()));
socketOptions.setConnectTimeoutMillis(Ints.checkedCast(config.getClientConnectTimeout().toMillis()));
if (config.getClientSoLinger() != null) {
socketOptions.setSoLinger(config.getClientSoLinger());
}
clusterBuilder.withSocketOptions(socketOptions);
if (config.getUsername() != null && config.getPassword() != null) {
clusterBuilder.withCredentials(config.getUsername(), config.getPassword());
}
QueryOptions options = new QueryOptions();
options.setFetchSize(config.getFetchSize());
options.setConsistencyLevel(config.getConsistencyLevel());
clusterBuilder.withQueryOptions(options);
return new CassandraSession(
connectorId.toString(),
clusterBuilder,
config.getFetchSizeForPartitionKeySelect(),
config.getLimitForPartitionKeySelect(),
extraColumnMetadataCodec);
}
示例13: CassandraCluster
import com.datastax.driver.core.QueryOptions; //導入方法依賴的package包/類
@Inject
public CassandraCluster(final PersisterConfig config) {
this.dbConfig = config.getCassandraDbConfiguration();
QueryOptions qo = new QueryOptions();
qo.setConsistencyLevel(ConsistencyLevel.valueOf(dbConfig.getConsistencyLevel()));
qo.setDefaultIdempotence(true);
String[] contactPoints = dbConfig.getContactPoints();
int retries = dbConfig.getMaxWriteRetries();
Builder builder = Cluster.builder().addContactPoints(contactPoints).withPort(dbConfig.getPort());
builder
.withSocketOptions(new SocketOptions().setConnectTimeoutMillis(dbConfig.getConnectionTimeout())
.setReadTimeoutMillis(dbConfig.getReadTimeout()));
builder.withQueryOptions(qo).withRetryPolicy(new MonascaRetryPolicy(retries, retries, retries));
lbPolicy = new TokenAwarePolicy(
DCAwareRoundRobinPolicy.builder().withLocalDc(dbConfig.getLocalDataCenter()).build());
builder.withLoadBalancingPolicy(lbPolicy);
String user = dbConfig.getUser();
if (user != null && !user.isEmpty()) {
builder.withAuthProvider(new PlainTextAuthProvider(dbConfig.getUser(), dbConfig.getPassword()));
}
cluster = builder.build();
PoolingOptions poolingOptions = cluster.getConfiguration().getPoolingOptions();
poolingOptions.setConnectionsPerHost(HostDistance.LOCAL, dbConfig.getMaxConnections(),
dbConfig.getMaxConnections()).setConnectionsPerHost(HostDistance.REMOTE,
dbConfig.getMaxConnections(), dbConfig.getMaxConnections());
poolingOptions.setMaxRequestsPerConnection(HostDistance.LOCAL, dbConfig.getMaxRequests())
.setMaxRequestsPerConnection(HostDistance.REMOTE, dbConfig.getMaxRequests());
metricsSession = cluster.connect(dbConfig.getKeySpace());
measurementInsertStmt = metricsSession.prepare(MEASUREMENT_INSERT_CQL).setIdempotent(true);
measurementUpdateStmt = metricsSession.prepare(MEASUREMENT_UPDATE_CQL).setIdempotent(true);
metricInsertStmt = metricsSession.prepare(METRICS_INSERT_CQL).setIdempotent(true);
metricUpdateStmt = metricsSession.prepare(METRICS_UPDATE_CQL).setIdempotent(true);
dimensionStmt = metricsSession.prepare(DIMENSION_INSERT_CQL).setIdempotent(true);
dimensionMetricStmt = metricsSession.prepare(DIMENSION_METRIC_INSERT_CQL).setIdempotent(true);
metricDimensionStmt = metricsSession.prepare(METRIC_DIMENSION_INSERT_CQL).setIdempotent(true);
retrieveMetricIdStmt = metricsSession.prepare(RETRIEVE_METRIC_ID_CQL).setIdempotent(true);
retrieveMetricDimensionStmt = metricsSession.prepare(RETRIEVE_METRIC_DIMENSION_CQL)
.setIdempotent(true);
alarmsSession = cluster.connect(dbConfig.getKeySpace());
alarmHistoryInsertStmt = alarmsSession.prepare(INSERT_ALARM_STATE_HISTORY_SQL).setIdempotent(true);
metricIdCache = CacheBuilder.newBuilder()
.maximumSize(config.getCassandraDbConfiguration().getDefinitionMaxCacheSize()).build();
dimensionCache = CacheBuilder.newBuilder()
.maximumSize(config.getCassandraDbConfiguration().getDefinitionMaxCacheSize()).build();
metricDimensionCache = CacheBuilder.newBuilder()
.maximumSize(config.getCassandraDbConfiguration().getDefinitionMaxCacheSize()).build();
logger.info("loading cached definitions from db");
ExecutorService executor = Executors.newFixedThreadPool(250);
//a majority of the ids are for metrics not actively receiving msgs anymore
//loadMetricIdCache(executor);
loadDimensionCache();
loadMetricDimensionCache(executor);
executor.shutdown();
}