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;
}
Aggregations