Skip to content

fix: 롤 배정 목록 처리를 단일 트랜잭션으로 묶음 - #92

Merged
jei007 merged 1 commit into
eGovFramework:mainfrom
wantaekchoi:fix/roleinfo-batch-tx
Sep 18, 2026
Merged

jei007 merged 1 commit into
eGovFramework:mainfrom
wantaekchoi:fix/roleinfo-batch-tx

Conversation

@wantaekchoi

Copy link
Copy Markdown
Contributor

수정 사유 Reason for modification

  • 버그수정 Bug fixes
  • 기능개선 Enhancements
  • 기능추가 Adding features
  • 기타 Others

수정된 소스 내용 Modified source

EgovRoleInfoAPIController.roleInfoInsert는 화면에서 세미콜론으로 이어 보낸 롤 배정 목록을 항목마다 순회하며, 각 항목에서 서비스의 delete·insert를 직접 호출합니다.

for (int i = 0; i < strAuthorCodes.length; i++) {
    authorRoleRelatedVO.setAuthorCode(strAuthorCodes[i]);
    authorRoleRelatedVO.setRoleCode(strRoleCodes[i]);

    if ("Y".equals(strRegYns[i])) {
        result = service.delete(authorRoleRelatedVO);
        service.insert(authorRoleRelatedVO);
    } else {
        result = service.delete(authorRoleRelatedVO);
    }
}

insert·delete는 각각 @Transactional입니다.

@Transactional
@Override
public AuthorRoleRelatedVO insert(AuthorRoleRelatedVO authorRoleRelatedVO) {
@Transactional
@Override
public boolean delete(AuthorRoleRelatedVO authorRoleRelatedVO) {

컨트롤러가 서비스 빈(프록시)의 메서드를 항목마다 호출하므로, @Transactional은 호출마다 새 트랜잭션을 엽니다. regYn="Y"인 항목은 delete와 insert가 서로 다른 트랜잭션이라, delete 다음 insert에서 예외가 나면 그 롤 배정이 insert 없이 영구히 사라집니다. 항목이 여러 개면 이미 처리된 앞쪽 항목은 롤백되지 않고, 예외가 난 항목 뒤는 아예 처리되지 않습니다. 이 프로젝트는 AspectJ 로드타임 위빙을 쓰지 않아(-javaagent 설정·@EnableTransactionManagement(mode=ASPECTJ) 없음) @Transactional은 기본값인 프록시 기반으로 동작합니다.

서비스에 배치 메서드를 추가해, 컨트롤러의 루프를 서비스 메서드 하나 안으로 옮겼습니다. 프록시 기반 AOP는 같은 인스턴스 안의 자기호출(this.delete(...))을 가로채지 않으므로, 안쪽 delete·insert는 새 트랜잭션을 열지 않고 updateRoleInfoList가 연 트랜잭션 하나를 그대로 씁니다.

@Transactional
@Override
public boolean updateRoleInfoList(String[] authorCodes, String[] roleCodes, String[] regYns, AuthorRoleRelatedVO authorRoleRelatedVO) {
    boolean result = false;
    for (int i = 0; i < authorCodes.length; i++) {
        authorRoleRelatedVO.setAuthorCode(authorCodes[i]);
        authorRoleRelatedVO.setRoleCode(roleCodes[i]);

        if ("Y".equals(regYns[i])) {
            result = this.delete(authorRoleRelatedVO);
            this.insert(authorRoleRelatedVO);
        } else {
            result = this.delete(authorRoleRelatedVO);
        }
    }
    return result;
}

컨트롤러는 이 메서드 하나만 호출합니다.

boolean result = service.updateRoleInfoList(strAuthorCodes, strRoleCodes, strRegYns, authorRoleRelatedVO);

JUnit 테스트 JUnit tests

  • JUnit 테스트 JUnit tests
  • 수동 테스트 Manual testing

EgovAuthorRoleRepository를 Mockito로 스텁해 EgovAuthorRoleServiceImplUpdateListTest를 추가했습니다. regYn="Y"인 항목마다 delete·insert가 순서대로 불리는지, regYn이 그 외 값이면 delete만 불리고 save는 안 불리는지 확인합니다.

수정 전(RED, 배치 메서드가 delete만 하도록 되돌려 재현):

$ mvn -o -Dtest=EgovAuthorRoleServiceImplUpdateListTest -DfailIfNoTests=false test
[ERROR] Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.469 s <<< FAILURE! -- in egovframework.com.sec.ram.service.impl.EgovAuthorRoleServiceImplUpdateListTest
[ERROR]   EgovAuthorRoleServiceImplUpdateListTest.updateRoleInfoListReplacesEachRoleAssignment:45 
[ERROR] Tests run: 2, Failures: 1, Errors: 0, Skipped: 0

수정 후(GREEN):

$ mvn -o -Dtest=EgovAuthorRoleServiceImplUpdateListTest -DfailIfNoTests=false test
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.411 s -- in egovframework.com.sec.ram.service.impl.EgovAuthorRoleServiceImplUpdateListTest
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS

같은 모듈의 기존 테스트 2건(EgovAuthorGroupServiceImplTest·EgovAuthorGroupInfoServiceImplTest)은 @SpringBootTest로 로컬 MySQL 접속이 필요한데, 이 환경에는 그 DB가 떠 있지 않아 origin/main 기준으로도 이미 실패합니다. 이 변경과 무관합니다.

테스트 브라우저 Test Browser

  • Chrome
  • Firefox
  • Edge
  • Safari
  • Opera
  • Internet Explorer
  • 기타 Others

JUnit 테스트로 대체합니다.

테스트 스크린샷 또는 캡처 영상 Test screenshots or captured video

위 JUnit 테스트 실행 결과로 대체합니다.

@jei007 jei007 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

표준프레임워크에 대한 지속적인 참여에
대단히 감사드립니다.

@jei007
jei007 merged commit 4ddd40f into eGovFramework:main Sep 18, 2026
11 checks passed
@wantaekchoi
wantaekchoi deleted the fix/roleinfo-batch-tx branch September 18, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants