Skip to content

Commit

Permalink
refactor: connection null 중복 확인 로직 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
kiarakim committed Oct 14, 2023
1 parent 2ae1bc3 commit 52f90a4
Showing 1 changed file with 1 addition and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package org.springframework.transaction.support;

import org.springframework.jdbc.CannotGetJdbcConnectionException;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -17,27 +14,13 @@ private TransactionSynchronizationManager() {

public static Connection getResource(DataSource key) {
Map<DataSource, Connection> map = getMap();
Connection connection = map.get(key);
try {
if (connection == null || connection.isClosed()) {
connection = key.getConnection();
map.put(key, connection);
}
return connection;
} catch (SQLException e) {
throw new CannotGetJdbcConnectionException("Failed to obtain JDBC Connection");
}
return map.get(key);
}

private static Map<DataSource, Connection> getMap() {
return resources.get();
}

public static boolean hasConnection(DataSource key) {
Map<DataSource, Connection> map = resources.get();
return map.containsKey(key);
}

public static void bindResource(DataSource key, Connection value) {
Map<DataSource, Connection> map = resources.get();
map.put(key, value);
Expand Down

0 comments on commit 52f90a4

Please sign in to comment.