Search in sources :

Example 6 with QueryOptions

use of com.datastax.driver.core.QueryOptions in project ats-framework by Axway.

the class CassandraDbProvider method connect.

/**
     * 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);
    }
}
Also used : ExponentialReconnectionPolicy(com.datastax.driver.core.policies.ExponentialReconnectionPolicy) QueryOptions(com.datastax.driver.core.QueryOptions) TokenAwarePolicy(com.datastax.driver.core.policies.TokenAwarePolicy) RoundRobinPolicy(com.datastax.driver.core.policies.RoundRobinPolicy)

Aggregations

QueryOptions (com.datastax.driver.core.QueryOptions)6 Cluster (com.datastax.driver.core.Cluster)3 ExponentialReconnectionPolicy (com.datastax.driver.core.policies.ExponentialReconnectionPolicy)3 RoundRobinPolicy (com.datastax.driver.core.policies.RoundRobinPolicy)3 TokenAwarePolicy (com.datastax.driver.core.policies.TokenAwarePolicy)3 PlainTextAuthProvider (com.datastax.driver.core.PlainTextAuthProvider)2 SocketOptions (com.datastax.driver.core.SocketOptions)2 LoadBalancingPolicy (com.datastax.driver.core.policies.LoadBalancingPolicy)2 AuthProvider (com.datastax.driver.core.AuthProvider)1 JdkSSLOptions (com.datastax.driver.core.JdkSSLOptions)1 PoolingOptions (com.datastax.driver.core.PoolingOptions)1 SSLOptions (com.datastax.driver.core.SSLOptions)1 ConstantSpeculativeExecutionPolicy (com.datastax.driver.core.policies.ConstantSpeculativeExecutionPolicy)1 DCAwareRoundRobinPolicy (com.datastax.driver.core.policies.DCAwareRoundRobinPolicy)1 WhiteListPolicy (com.datastax.driver.core.policies.WhiteListPolicy)1 Provides (com.google.inject.Provides)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Singleton (javax.inject.Singleton)1