Search in sources :

Example 1 with ZonedDateTimeCodec

use of com.datastax.driver.extras.codecs.jdk8.ZonedDateTimeCodec in project jhipster-sample-app-cassandra by jhipster.

the class CassandraConfiguration method cluster.

@Bean
public Cluster cluster(CassandraProperties properties) {
    Cluster.Builder builder = Cluster.builder().withClusterName(properties.getClusterName()).withProtocolVersion(protocolVersion).withPort(getPort(properties));
    if (properties.getUsername() != null) {
        builder.withCredentials(properties.getUsername(), properties.getPassword());
    }
    if (properties.getCompression() != null) {
        builder.withCompression(properties.getCompression());
    }
    if (properties.getLoadBalancingPolicy() != null) {
        LoadBalancingPolicy policy = instantiate(properties.getLoadBalancingPolicy());
        builder.withLoadBalancingPolicy(policy);
    }
    builder.withQueryOptions(getQueryOptions(properties));
    if (properties.getReconnectionPolicy() != null) {
        ReconnectionPolicy policy = instantiate(properties.getReconnectionPolicy());
        builder.withReconnectionPolicy(policy);
    }
    if (properties.getRetryPolicy() != null) {
        RetryPolicy policy = instantiate(properties.getRetryPolicy());
        builder.withRetryPolicy(policy);
    }
    builder.withSocketOptions(getSocketOptions(properties));
    if (properties.isSsl()) {
        builder.withSSL();
    }
    builder.addContactPoints(StringUtils.toStringArray(properties.getContactPoints()));
    Cluster cluster = builder.build();
    TupleType tupleType = cluster.getMetadata().newTupleType(DataType.timestamp(), DataType.varchar());
    cluster.getConfiguration().getCodecRegistry().register(LocalDateCodec.instance).register(InstantCodec.instance).register(new ZonedDateTimeCodec(tupleType));
    if (metricRegistry != null) {
        cluster.init();
        metricRegistry.registerAll(cluster.getMetrics().getRegistry());
    }
    return cluster;
}
Also used : LoadBalancingPolicy(com.datastax.driver.core.policies.LoadBalancingPolicy) ReconnectionPolicy(com.datastax.driver.core.policies.ReconnectionPolicy) TupleType(com.datastax.driver.core.TupleType) Cluster(com.datastax.driver.core.Cluster) RetryPolicy(com.datastax.driver.core.policies.RetryPolicy) ZonedDateTimeCodec(com.datastax.driver.extras.codecs.jdk8.ZonedDateTimeCodec) Bean(org.springframework.context.annotation.Bean)

Aggregations

Cluster (com.datastax.driver.core.Cluster)1 TupleType (com.datastax.driver.core.TupleType)1 LoadBalancingPolicy (com.datastax.driver.core.policies.LoadBalancingPolicy)1 ReconnectionPolicy (com.datastax.driver.core.policies.ReconnectionPolicy)1 RetryPolicy (com.datastax.driver.core.policies.RetryPolicy)1 ZonedDateTimeCodec (com.datastax.driver.extras.codecs.jdk8.ZonedDateTimeCodec)1 Bean (org.springframework.context.annotation.Bean)1