diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterNameCommander.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterNameCommander.java index db9bdbd1..5d68d994 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterNameCommander.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterNameCommander.java @@ -1,7 +1,6 @@ package kr.hakdang.cassdio.core.domain.cluster; import com.datastax.oss.driver.api.core.CqlSession; -import kr.hakdang.cassdio.common.utils.IdGenerator; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterUtils.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterUtils.java index 2b1d2c11..420a4722 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterUtils.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterUtils.java @@ -1,17 +1,15 @@ package kr.hakdang.cassdio.core.domain.cluster; import com.datastax.oss.driver.api.core.CqlSession; -import com.datastax.oss.driver.api.core.Version; import com.datastax.oss.driver.api.core.config.DefaultDriverOption; import com.datastax.oss.driver.api.core.context.DriverContext; -import com.datastax.oss.driver.api.core.metadata.Node; import com.datastax.oss.driver.api.querybuilder.QueryBuilder; import com.datastax.oss.driver.api.querybuilder.select.SelectFrom; -import com.datastax.oss.driver.internal.core.channel.DriverChannel; -import com.datastax.oss.driver.internal.core.context.InternalDriverContext; import com.datastax.oss.driver.internal.core.metadata.schema.queries.KeyspaceFilter; import kr.hakdang.cassdio.core.domain.cluster.keyspace.CassandraSystemKeyspace; import kr.hakdang.cassdio.core.domain.cluster.keyspace.table.CassandraSystemTable; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import java.util.Collections; @@ -21,7 +19,8 @@ * @author akageun * @since 2024-07-05 */ -public abstract class ClusterUtils { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ClusterUtils { public static KeyspaceFilter makeKeyspaceFilter(DriverContext context) { return KeyspaceFilter.newInstance(context.getSessionName(), context.getConfig() diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterVersionGetCommander.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterVersionGetCommander.java index d690eedf..4474af99 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterVersionGetCommander.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterVersionGetCommander.java @@ -17,8 +17,6 @@ @Service public class ClusterVersionGetCommander extends BaseClusterCommander { - private final CqlSessionFactory cqlSessionFactory; - public ClusterVersionGetCommander( CqlSessionFactory cqlSessionFactory ) { diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/CqlSessionFactory.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/CqlSessionFactory.java index 4191320a..f1726362 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/CqlSessionFactory.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/CqlSessionFactory.java @@ -3,10 +3,10 @@ import com.datastax.oss.driver.api.core.CqlSession; import kr.hakdang.cassdio.core.domain.cluster.info.ClusterInfo; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; /** * CqlSessionFactory @@ -21,7 +21,7 @@ public class CqlSessionFactory { private final ClusterProvider clusterProvider; private final ClusterConnector clusterConnector; - public static ConcurrentHashMap SESSION = new ConcurrentHashMap<>(); + private static final ConcurrentMap SESSION = new ConcurrentHashMap<>(); public CqlSessionFactory(ClusterProvider clusterProvider, ClusterConnector clusterConnector) { this.clusterProvider = clusterProvider; @@ -30,13 +30,7 @@ public CqlSessionFactory(ClusterProvider clusterProvider, ClusterConnector clust public CqlSession get(String clusterId) { String key = String.format("%s", clusterId); - CqlSession session = SESSION.get(key); - if (session == null) { - session = makeSession(clusterId); - SESSION.put(key, session); - } - - return session; + return SESSION.computeIfAbsent(key, this::makeSession); } public CqlSession makeSession(String clusterId) { diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/client/ClusterClientListCommander.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/client/ClusterClientListCommander.java index 727bc2d7..d7cf6fb6 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/client/ClusterClientListCommander.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/client/ClusterClientListCommander.java @@ -14,7 +14,6 @@ import org.springframework.stereotype.Service; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.StreamSupport; /** @@ -26,8 +25,6 @@ @Service public class ClusterClientListCommander extends BaseClusterCommander { - private final CqlSessionFactory cqlSessionFactory; - private final ClusterVersionEvaluator clusterVersionEvaluator; public ClusterClientListCommander( @@ -53,7 +50,7 @@ public ClusterClientListResult getClients(String clusterId) { List clients = StreamSupport.stream(rs.spliterator(), false) .map(ClusterClient::from) - .collect(Collectors.toList()); + .toList(); return ClusterClientListResult.builder() .clients(clients) diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/compaction/CompactionHistoryListCommander.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/compaction/CompactionHistoryListCommander.java index 15fe20db..59aab66d 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/compaction/CompactionHistoryListCommander.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/compaction/CompactionHistoryListCommander.java @@ -12,7 +12,6 @@ import java.util.Comparator; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.StreamSupport; /** @@ -39,7 +38,7 @@ public CompactionHistoryListResult getCompactionHistories(String clusterId, Stri .map(CompactionHistory::from) .filter(history -> StringUtils.isBlank(keyspace) || history.getKeyspaceName().equals(keyspace)) .sorted(Comparator.comparing(CompactionHistory::getCompactedAt).reversed()) - .collect(Collectors.toList()); + .toList(); return CompactionHistoryListResult.builder() .histories(historyList) diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/KeyspaceDTO.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/KeyspaceDTO.java index ab35ffe9..32bdaff7 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/KeyspaceDTO.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/KeyspaceDTO.java @@ -7,7 +7,6 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.extern.slf4j.Slf4j; import java.util.List; import java.util.Map; @@ -18,6 +17,7 @@ * @author akageun * @since 2024-07-09 */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class KeyspaceDTO { @Getter diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/udt/ClusterUDTTypeListCommander.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/udt/ClusterUDTTypeListCommander.java index 8c25ef0b..0506057e 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/udt/ClusterUDTTypeListCommander.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/udt/ClusterUDTTypeListCommander.java @@ -11,7 +11,6 @@ import org.springframework.stereotype.Service; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.StreamSupport; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.bindMarker; @@ -44,7 +43,7 @@ public ClusterUDTTypeListResult listTypes(String clusterId, ClusterUDTTypeListAr List types = StreamSupport.stream(rs.spliterator(), false) .limit(rs.getAvailableWithoutFetching()) .map(ClusterUDTType::from) - .collect(Collectors.toList()); + .toList(); return ClusterUDTTypeListResult.of(types, rs.getExecutionInfo().getPagingState()); } diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/node/ClusterNodeGetCommander.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/node/ClusterNodeGetCommander.java index 9dda514b..434d9cca 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/node/ClusterNodeGetCommander.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/node/ClusterNodeGetCommander.java @@ -19,8 +19,6 @@ @Service public class ClusterNodeGetCommander extends BaseClusterCommander { - private final CqlSessionFactory cqlSessionFactory; - public ClusterNodeGetCommander( CqlSessionFactory cqlSessionFactory ) { diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/node/ClusterNodeListCommander.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/node/ClusterNodeListCommander.java index 4d088c97..98d7aecd 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/node/ClusterNodeListCommander.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/node/ClusterNodeListCommander.java @@ -7,7 +7,6 @@ import java.util.Comparator; import java.util.List; -import java.util.stream.Collectors; /** * ClusterNodeListCommander @@ -18,8 +17,6 @@ @Service public class ClusterNodeListCommander extends BaseClusterCommander { - private final CqlSessionFactory cqlSessionFactory; - public ClusterNodeListCommander( CqlSessionFactory cqlSessionFactory ) { @@ -33,7 +30,7 @@ public List listNodes(String clusterId) { .map(ClusterNode::from) .sorted(Comparator.comparing(ClusterNode::getDatacenter) .thenComparing(ClusterNode::getRack)) - .collect(Collectors.toList()); + .toList(); } } diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/query/ClusterQueryCommander.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/query/ClusterQueryCommander.java index 04c41217..9e6a9395 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/query/ClusterQueryCommander.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/query/ClusterQueryCommander.java @@ -53,10 +53,8 @@ public QueryDTO.ClusterQueryCommanderResult execute( QueryDTO.ClusterQueryCommanderArgs args ) { CqlSession session = cqlSessionFactory.get(clusterId); - if (useKeyspaceQueryCommandNotSupportWithSession(session)) { - if (StringUtils.isNotBlank(args.getKeyspace())) { - throw new NotSupportedCassandraVersionException("It is available in Cassandra version 4.0 and later"); - } + if (useKeyspaceQueryCommandNotSupportWithSession(session) && StringUtils.isNotBlank(args.getKeyspace())) { + throw new NotSupportedCassandraVersionException("It is available in Cassandra version 4.0 and later"); } SimpleStatementBuilder simpleBuilder = SimpleStatement.builder(args.getQuery()) diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/support/cache/LocalCacheConfig.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/support/cache/LocalCacheConfig.java index 5415b79b..30499e36 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/support/cache/LocalCacheConfig.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/support/cache/LocalCacheConfig.java @@ -10,7 +10,6 @@ import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; /** * LocalCacheConfig @@ -30,7 +29,7 @@ public CacheManager cacheManager() { .expireAfterWrite(cache.getDuration()) .build() )) - .collect(Collectors.toList()); + .toList(); cacheManager.setCaches(caches); return cacheManager; } diff --git a/cassdio-core/src/test/java/kr/hakdang/cassdio/BaseTest.java b/cassdio-core/src/test/java/kr/hakdang/cassdio/BaseTest.java index fe33636b..675abf10 100644 --- a/cassdio-core/src/test/java/kr/hakdang/cassdio/BaseTest.java +++ b/cassdio-core/src/test/java/kr/hakdang/cassdio/BaseTest.java @@ -16,5 +16,5 @@ @ExtendWith(SpringExtension.class) public abstract class BaseTest { - protected final static String CLUSTER_ID = "12345"; + protected static final String CLUSTER_ID = "12345"; } diff --git a/cassdio-core/src/test/java/kr/hakdang/cassdio/IntegrationTest.java b/cassdio-core/src/test/java/kr/hakdang/cassdio/IntegrationTest.java index a1b27a3a..8e9c4dfd 100644 --- a/cassdio-core/src/test/java/kr/hakdang/cassdio/IntegrationTest.java +++ b/cassdio-core/src/test/java/kr/hakdang/cassdio/IntegrationTest.java @@ -11,7 +11,6 @@ import java.net.InetSocketAddress; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; /** @@ -32,7 +31,7 @@ public abstract class IntegrationTest extends BaseTest { @BeforeEach void setup() { - given(clusterManager.findById(eq(CLUSTER_ID))).willReturn(ClusterInfo.builder() + given(clusterManager.findById(CLUSTER_ID)).willReturn(ClusterInfo.builder() .contactPoints("127.0.0.1") .port(29042) .localDatacenter("dc1") diff --git a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/ClusterConnectionTest.java b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/ClusterConnectionTest.java index acf2e6f9..32869211 100644 --- a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/ClusterConnectionTest.java +++ b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/ClusterConnectionTest.java @@ -29,8 +29,8 @@ void anonymous_cluster_connection() { assertThat(connection.isAuthCredentials()).isFalse(); assertThat(connection.getContactPoints()).isEqualTo("127.0.0.1"); assertThat(connection.getPort()).isEqualTo(29042); - assertThat(connection.getUsername()).isEqualTo(null); - assertThat(connection.getPassword()).isEqualTo(null); + assertThat(connection.getUsername()).isNull(); + assertThat(connection.getPassword()).isNull(); assertThat(connection.getLocalDatacenter()).isEqualTo("dc1"); } diff --git a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableListCommanderTest.java b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableListCommanderTest.java index de785b72..73a4761f 100644 --- a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableListCommanderTest.java +++ b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableListCommanderTest.java @@ -4,7 +4,6 @@ import kr.hakdang.cassdio.core.domain.cluster.CqlSessionSelectResults; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; -import org.springframework.test.context.TestConstructor; import static org.assertj.core.api.Assertions.assertThat; @@ -15,8 +14,7 @@ * @since 2024-07-01 */ @Slf4j -@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) -public class ClusterTableListCommanderTest extends IntegrationTest { +class ClusterTableListCommanderTest extends IntegrationTest { private final ClusterTableListCommander clusterTableListCommander; @@ -81,7 +79,7 @@ void when_empty_table_in_keyspace_result_empty() { // then assertThat(sut).isNotNull(); - assertThat(sut.getRows()).hasSize(0); + assertThat(sut.getRows()).isEmpty(); // assertThat(sut.getNextPageState()).isNull(); } diff --git a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/query/ClusterQueryCommanderTest.java b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/query/ClusterQueryCommanderTest.java index 05a5f39d..ad44fda1 100644 --- a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/query/ClusterQueryCommanderTest.java +++ b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/query/ClusterQueryCommanderTest.java @@ -23,7 +23,7 @@ class ClusterQueryCommanderTest extends IntegrationTest { @Value("${cassdio.test-cassandra.keyspace}") private String keyspaceName; - private final static String TABLE_NAME = "test_table_1"; + private static final String TABLE_NAME = "test_table_1"; @Test void queryTest() { diff --git a/cassdio-web/src/main/java/kr/hakdang/cassdio/web/config/context/CassdioContextHolder.java b/cassdio-web/src/main/java/kr/hakdang/cassdio/web/config/context/CassdioContextHolder.java index 173acfda..f7307796 100644 --- a/cassdio-web/src/main/java/kr/hakdang/cassdio/web/config/context/CassdioContextHolder.java +++ b/cassdio-web/src/main/java/kr/hakdang/cassdio/web/config/context/CassdioContextHolder.java @@ -1,11 +1,15 @@ package kr.hakdang.cassdio.web.config.context; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + /** * CassdioContextHolder * * @author akageun * @since 2024-07-29 */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class CassdioContextHolder { private static final ThreadLocal DATA = new ThreadLocal<>(); diff --git a/cassdio-web/src/main/java/kr/hakdang/cassdio/web/route/BootstrapResponse.java b/cassdio-web/src/main/java/kr/hakdang/cassdio/web/route/BootstrapResponse.java deleted file mode 100644 index adc86a2b..00000000 --- a/cassdio-web/src/main/java/kr/hakdang/cassdio/web/route/BootstrapResponse.java +++ /dev/null @@ -1,10 +0,0 @@ -package kr.hakdang.cassdio.web.route; - -/** - * BootstrapResponse - * - * @author akageun - * @since 2024-07-28 - */ -public class BootstrapResponse { -} diff --git a/cassdio-web/src/main/java/kr/hakdang/cassdio/web/route/cluster/ClusterRegisterRequest.java b/cassdio-web/src/main/java/kr/hakdang/cassdio/web/route/cluster/ClusterRegisterRequest.java index 605b8b8d..a4ae83da 100644 --- a/cassdio-web/src/main/java/kr/hakdang/cassdio/web/route/cluster/ClusterRegisterRequest.java +++ b/cassdio-web/src/main/java/kr/hakdang/cassdio/web/route/cluster/ClusterRegisterRequest.java @@ -1,6 +1,5 @@ package kr.hakdang.cassdio.web.route.cluster; -import kr.hakdang.cassdio.core.domain.cluster.ClusterConnection; import kr.hakdang.cassdio.core.domain.cluster.info.ClusterInfoArgs; import lombok.AccessLevel; import lombok.Builder;