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


Java QueryOptions類代碼示例

本文整理匯總了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();
}
 
開發者ID:apache,項目名稱:beam,代碼行數:28,代碼來源:CassandraServiceImpl.java

示例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;
    }
}
 
開發者ID:mcfongtw,項目名稱:flink-cassandra-connector-examples,代碼行數:22,代碼來源:ClientSessionProvider.java

示例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();
}
 
開發者ID:att,項目名稱:dmaap-framework,代碼行數:27,代碼來源:CassandraConfigDb.java

示例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);

    }
 
開發者ID:hpcc-systems,項目名稱:storm-cassandra-cql,代碼行數:18,代碼來源:MapConfiguredCqlClientFactory.java

示例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();
}
 
開發者ID:Excelian,項目名稱:Mache,代碼行數:23,代碼來源:MacheAbstractCassandraKafkaSamplerClient.java

示例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;
}
 
開發者ID:spaziocodice,項目名稱:jena-nosql,代碼行數:28,代碼來源:CassandraStorageLayerFactory.java

示例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();
}
 
開發者ID:glowroot,項目名稱:glowroot,代碼行數:24,代碼來源:CentralModule.java

示例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 (?)");
}
 
開發者ID:hawkular,項目名稱:hawkular-metrics,代碼行數:24,代碼來源:JobSchedulerTest.java

示例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());
}
 
開發者ID:hawkular,項目名稱:hawkular-metrics,代碼行數:19,代碼來源:BaseITest.java

示例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);
}
 
開發者ID:apache,項目名稱:gora,代碼行數:17,代碼來源:CassandraClient.java

示例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);
}
 
開發者ID:wso2,項目名稱:carbon-data,代碼行數:17,代碼來源:CassandraConfig.java

示例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;
}
 
開發者ID:ElectronicArmory,項目名稱:Armory,代碼行數:12,代碼來源:CassandraConfiguration.java

示例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);
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:35,代碼來源:CassandraDbProvider.java

示例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;
}
 
開發者ID:xm-online,項目名稱:xm-gate,代碼行數:12,代碼來源:CassandraConfiguration.java

示例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;
}
 
開發者ID:kloiasoft,項目名稱:eventapis,代碼行數:12,代碼來源:CassandraSession.java


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