Skip to content

Commit

Permalink
fix: UserService 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
echo724 committed Oct 10, 2023
1 parent 5300ee4 commit 48437c8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void changePassword(final long id, final String newPassword, final String
userHistoryDao.log(new UserHistory(user, createBy));
}

@Override
public User findById(final long id) {
return userDao.findById(id);
}
Expand Down
27 changes: 2 additions & 25 deletions app/src/main/java/com/techcourse/service/TxUserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.techcourse.domain.User;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.transaction.support.TransactionSynchronizationManager;

import java.sql.Connection;
import java.sql.SQLException;
Expand All @@ -18,28 +17,12 @@ public TxUserService(final UserService userService) {

@Override
public User findById(final long id) {
final Connection connection = DataSourceUtils.getConnection(DataSourceConfig.getInstance());
try {
return userService.findById(id);
} catch (final Exception e) {
throw new RuntimeException(e);
} finally {
DataSourceUtils.releaseConnection(connection, DataSourceConfig.getInstance());
TransactionSynchronizationManager.unbindResource(DataSourceConfig.getInstance());
}
return userService.findById(id);
}

@Override
public void insert(final User user) {
final Connection connection = DataSourceUtils.getConnection(DataSourceConfig.getInstance());
try {
userService.insert(user);
} catch (final Exception e) {
throw new RuntimeException(e);
} finally {
DataSourceUtils.releaseConnection(connection, DataSourceConfig.getInstance());
TransactionSynchronizationManager.unbindResource(DataSourceConfig.getInstance());
}
userService.insert(user);
}

@Override
Expand All @@ -57,13 +40,7 @@ public void changePassword(final long id, final String newPassword, final String
}
throw new DataAccessException(e);
} finally {
try {
connection.setAutoCommit(true);
} catch (SQLException e) {
throw new DataAccessException(e);
}
DataSourceUtils.releaseConnection(connection, DataSourceConfig.getInstance());
TransactionSynchronizationManager.unbindResource(DataSourceConfig.getInstance());
}
}
}

0 comments on commit 48437c8

Please sign in to comment.