{
logger.debug("Intiatilzing connection");
}
Properties connectionProperties = CassandraPropertyReader.csmd.getConnectionProperties();
Builder connectionBuilder = Cluster.builder();
// add host/port and AuthInfoProvider
for (Host host : configuration.getCassandraHosts())
{
connectionBuilder.addContactPoint(host.getHost()).withPort(host.getPort());
if (host.getUser() != null)
{
connectionBuilder.withCredentials(host.getUser(), host.getPassword());
}
}
// add policy configuration
String loadBalancingPolicy = connectionProperties.getProperty(Constants.LOADBALANCING_POLICY);
if (!StringUtils.isBlank(loadBalancingPolicy))
{
LoadBalancingPolicy policy = getPolicyInstance(BalancingPolicy.getPolicy(loadBalancingPolicy),
connectionProperties);
if (policy != null)
{
connectionBuilder.withLoadBalancingPolicy(policy);
}
}
// compression
String compression = connectionProperties.getProperty("compression");
if (!StringUtils.isBlank(compression))
{
connectionBuilder.withCompression(Compression.valueOf(compression));
}
// ReconnectionPolicy
String reconnectionPolicy = connectionProperties.getProperty("reconnection.policy");
if (!StringUtils.isBlank(reconnectionPolicy))
{
com.datastax.driver.core.policies.ReconnectionPolicy policy = getPolicy(
ReconnectionPolicy.getPolicy(reconnectionPolicy), connectionProperties);
if (policy != null)
{
connectionBuilder.withReconnectionPolicy(policy);
}
}
// , RetryPolicy
String retryPolicy = connectionProperties.getProperty("retry.policy");
if (!StringUtils.isBlank(retryPolicy))
{
com.datastax.driver.core.policies.RetryPolicy policy = getPolicy(RetryPolicy.getPolicy(retryPolicy),
connectionProperties);
if (policy != null)
{
connectionBuilder.withRetryPolicy(policy);
}
}
// TODO::: SSLOptions? Not sure how to add it.
// SocketOptions
connectionBuilder.withSocketOptions(getSocketOptions(connectionProperties));
// PoolingOptions,
connectionBuilder.withPoolingOptions(getPoolingOptions(connectionProperties));
// finally build cluster.
Cluster cluster = connectionBuilder.build();
PersistenceUnitMetadata persistenceUnitMetadata = kunderaMetadata.getApplicationMetadata()
.getPersistenceUnitMetadata(getPersistenceUnit());
Properties props = persistenceUnitMetadata.getProperties();