Skip to content

Commit

Permalink
Support Cassandra 3.x (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
seungh0 authored Jul 5, 2024
1 parent 14a7194 commit d8d7e55
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
cassandra-version: [ '4.0', '4.1', '5.0' ] # TODO: Add 3.11
cassandra-version: [ '3.11', '4.0', '4.1', '5.0' ]
steps:
- name: checkout@v4
uses: actions/checkout@v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.CqlSessionBuilder;
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
import kr.hakdang.cadio.core.domain.cluster.info.ClusterInfo;
import kr.hakdang.cadio.core.domain.cluster.info.ClusterInfoProvider;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -51,6 +54,13 @@ public CqlSession makeSession(ClusterConnection clusterConnection) {
builder.withAuthCredentials(clusterConnection.getUsername(), clusterConnection.getPassword());
}

builder.withConfigLoader(
DriverConfigLoader.programmaticBuilder()
.withDuration(DefaultDriverOption.CONNECTION_INIT_QUERY_TIMEOUT, Duration.ofSeconds(5))
.withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(5))
.build()
);

return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;

/**
* ClusterTable
Expand All @@ -38,8 +37,13 @@ private ClusterTable(UUID id, String tableName, String comment, Map<String, Obje
}

public static ClusterTable from(Row row) {
Map<String, Object> options = Arrays.stream(ClusterTableOption.values())
.collect(Collectors.toMap(option -> option.name().toLowerCase(Locale.ROOT), option -> option.extract(row)));
Map<String, Object> options = new HashMap<>();
for (ClusterTableOption option : ClusterTableOption.values()) {
Object optionValue = option.extract(row);
if (optionValue != null) {
options.put(option.name().toLowerCase(Locale.ROOT), optionValue);
}
}

return ClusterTable.builder()
.id(row.getUuid("id"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ public enum ClusterTableOption {
}

public Object extract(Row row) {
return this.extracting.apply(row);
try {
return this.extracting.apply(row);
} catch (Exception exception) {
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void initialize() {

session.execute(createKeyspace.build());

SimpleStatement createTable1 = SchemaBuilder.createTable("test_table_1")
SimpleStatement createTable1 = SchemaBuilder.createTable(keyspaceName, "test_table_1")
.withPartitionKey("partition_key_1", DataTypes.TEXT)
.withPartitionKey("partition_key_2", DataTypes.BIGINT)
.withClusteringColumn("clustering_key_1", DataTypes.BIGINT)
Expand All @@ -49,20 +49,18 @@ public void initialize() {
.withClusteringOrder("clustering_key_2", ClusteringOrder.ASC)
.withComment("test_table_one")
.withBloomFilterFpChance(0.01)
.build()
.setKeyspace(keyspaceName);
.build();
session.execute(createTable1);

SimpleStatement createTable2 = SchemaBuilder.createTable("test_table_2")
SimpleStatement createTable2 = SchemaBuilder.createTable(keyspaceName, "test_table_2")
.withPartitionKey("partition_key_11", DataTypes.TEXT)
.withPartitionKey("partition_key_12", DataTypes.BIGINT)
.withClusteringColumn("clustering_key_11", DataTypes.BIGINT)
.withClusteringColumn("clustering_key_12", DataTypes.TEXT)
.withColumn("column_11", DataTypes.TEXT)
.withComment("test_table_two")
.withBloomFilterFpChance(0.001)
.build()
.setKeyspace(keyspaceName);
.build();
session.execute(createTable2);
}

Expand Down

0 comments on commit d8d7e55

Please sign in to comment.