本文整理汇总了Java中com.datastax.driver.core.QueryOptions类的典型用法代码示例。如果您正苦于以下问题:Java QueryOptions类的具体用法?Java QueryOptions怎么用?Java QueryOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueryOptions类属于com.datastax.driver.core包,在下文中一共展示了QueryOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCluster
import com.datastax.driver.core.QueryOptions; //导入依赖的package包/类
/**
* Get a Cassandra cluster using hosts and port.
*/
private Cluster getCluster(List<String> hosts, int port, String username, String password,
String localDc, String consistencyLevel) {
Cluster.Builder builder = Cluster.builder()
.addContactPoints(hosts.toArray(new String[0]))
.withPort(port);
if (username != null) {
builder.withAuthProvider(new PlainTextAuthProvider(username, password));
}
if (localDc != null) {
builder.withLoadBalancingPolicy(
new TokenAwarePolicy(new DCAwareRoundRobinPolicy.Builder().withLocalDc(localDc).build()));
} else {
builder.withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()));
}
if (consistencyLevel != null) {
builder.withQueryOptions(
new QueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf(consistencyLevel)));
}
return builder.build();
}
示例2: getClientSession
import com.datastax.driver.core.QueryOptions; //导入依赖的package包/类
public static Session getClientSession(String hostAddr) {
if(REGISTRY.containsKey(hostAddr)) {
return REGISTRY.get(hostAddr);
} else {
Cluster.Builder clientClusterBuilder = new Cluster.Builder()
.addContactPoint(hostAddr)
.withQueryOptions(new QueryOptions()
.setConsistencyLevel(ConsistencyLevel.ONE)
.setSerialConsistencyLevel(ConsistencyLevel.LOCAL_SERIAL))
.withoutJMXReporting()
.withoutMetrics()
.withReconnectionPolicy(new ConstantReconnectionPolicy(RECONNECT_DELAY_IN_MS));
long startTimeInMillis = System.currentTimeMillis();
Cluster clientCluster = clientClusterBuilder.build();
Session clientSession = clientCluster.connect();
LOG.info("Client session established after {} ms.", System.currentTimeMillis() - startTimeInMillis);
REGISTRY.putIfAbsent(hostAddr, clientSession);
return clientSession;
}
}
示例3: CassandraConfigDb
import com.datastax.driver.core.QueryOptions; //导入依赖的package包/类
public CassandraConfigDb(List<String> contactPoints, int port) {
this.contactPoints = new ArrayList<InetAddress> (contactPoints.size());
for (String contactPoint : contactPoints) {
try {
this.contactPoints.add(InetAddress.getByName(contactPoint));
} catch (UnknownHostException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
this.port = port;
cluster = (new Cluster.Builder()).withPort (this.port)
.addContactPoints(this.contactPoints)
.withSocketOptions(new SocketOptions().setReadTimeoutMillis(60000).setKeepAlive(true).setReuseAddress(true))
.withLoadBalancingPolicy(new RoundRobinPolicy())
.withReconnectionPolicy(new ConstantReconnectionPolicy(500L))
.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.ONE))
.build ();
session = cluster.newSession();
preparedStatements = new ConcurrentHashMap<StatementName, PreparedStatement> ();
prepareStatementCreateLock = new Object();
}
示例4: 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);
}
示例5: createCache
import com.datastax.driver.core.QueryOptions; //导入依赖的package包/类
protected void createCache(Map<String, String> mapParams) throws Exception {
final Cluster.Builder bluePrint = Cluster.builder().withClusterName("BluePrint")
.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM))
.withRetryPolicy(DefaultRetryPolicy.INSTANCE)
.withLoadBalancingPolicy(new TokenAwarePolicy(new DCAwareRoundRobinPolicy()))
.addContactPoint(mapParams.get("cassandra.server.ip.address")).withPort(9042);
cache1 = mache(String.class, CassandraTestEntity.class)
.cachedBy(guava())
.storedIn(cassandra()
.withCluster(bluePrint)
.withKeyspace(mapParams.get("keyspace.name"))
.withSchemaOptions(SchemaOptions.CREATE_SCHEMA_IF_NEEDED)
.build())
.withMessaging(kafka()
.withKafkaMqConfig(KafkaMqConfigBuilder.builder()
.withZkHost(mapParams.get("kafka.connection"))
.build())
.withTopic(mapParams.get("kafka.topic"))
.build())
.macheUp();
}
示例6: 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;
}
示例7: createCluster
import com.datastax.driver.core.QueryOptions; //导入依赖的package包/类
private static Cluster createCluster(CentralConfiguration centralConfig,
TimestampGenerator defaultTimestampGenerator) {
Cluster.Builder builder = Cluster.builder()
.addContactPoints(
centralConfig.cassandraContactPoint().toArray(new String[0]))
// aggressive reconnect policy seems ok since not many clients
.withReconnectionPolicy(new ConstantReconnectionPolicy(1000))
// let driver know that only idempotent queries are used so it will retry on timeout
.withQueryOptions(new QueryOptions()
.setDefaultIdempotence(true)
.setConsistencyLevel(centralConfig.cassandraConsistencyLevel()))
// central runs lots of parallel async queries and is very spiky since all
// aggregates come in right after each minute marker
.withPoolingOptions(
new PoolingOptions().setMaxQueueSize(Session.MAX_CONCURRENT_QUERIES))
.withTimestampGenerator(defaultTimestampGenerator);
String cassandraUsername = centralConfig.cassandraUsername();
if (!cassandraUsername.isEmpty()) {
// empty password is strange but valid
builder.withCredentials(cassandraUsername, centralConfig.cassandraPassword());
}
return builder.build();
}
示例8: initSuite
import com.datastax.driver.core.QueryOptions; //导入依赖的package包/类
@BeforeSuite
public static void initSuite() {
Cluster cluster = Cluster.builder()
.addContactPoints("127.0.0.01")
.withQueryOptions(new QueryOptions().setRefreshSchemaIntervalMillis(0))
.build();
String keyspace = System.getProperty("keyspace", "hawkulartest");
session = cluster.connect("system");
rxSession = new RxSessionImpl(session);
boolean resetdb = Boolean.valueOf(System.getProperty("resetdb", "true"));
SchemaService schemaService = new SchemaService();
schemaService.run(session, keyspace, resetdb);
session.execute("USE " + keyspace);
jobsService = new JobsService(rxSession);
findFinishedJobs = session.prepare("SELECT job_id FROM finished_jobs_idx WHERE time_slice = ?");
getActiveTimeSlices = session.prepare("SELECT distinct time_slice FROM active_time_slices");
addActiveTimeSlice = session.prepare("INSERT INTO active_time_slices (time_slice) VALUES (?)");
}
示例9: initSuite
import com.datastax.driver.core.QueryOptions; //导入依赖的package包/类
@BeforeSuite
public static void initSuite() {
String nodeAddresses = System.getProperty("nodes", "127.0.0.1");
Cluster cluster = new Cluster.Builder()
.addContactPoints(nodeAddresses.split(","))
.withQueryOptions(new QueryOptions().setRefreshSchemaIntervalMillis(0))
.build();
session = cluster.connect();
rxSession = new RxSessionImpl(session);
SchemaService schemaService = new SchemaService();
schemaService.run(session, getKeyspace(), Boolean.valueOf(System.getProperty("resetdb", "true")));
session.execute("USE " + getKeyspace());
metricRegistry = new HawkularMetricRegistry();
metricRegistry.setMetricNameService(new MetricNameService());
}
示例10: 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);
}
示例11: 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);
}
示例12: 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;
}
示例13: 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);
}
}
示例14: 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;
}
示例15: 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;
}