Skip to content

[Refactor] ConstraintViolationException 파싱 로직 유틸로 통합#176

Merged
pooreumjung merged 2 commits into
developfrom
refactor/#171-constraint-violation-utils
Jun 2, 2026
Merged

[Refactor] ConstraintViolationException 파싱 로직 유틸로 통합#176
pooreumjung merged 2 commits into
developfrom
refactor/#171-constraint-violation-utils

Conversation

@pooreumjung

Copy link
Copy Markdown
Member

🧾 요약

  • 3곳에 중복된 ConstraintViolationException 파싱 로직을 ConstraintViolationUtils로 통합 — 버그 수정 시 누락 방지

🔗 이슈

✨ 변경 내용

  • ConstraintViolationUtils.isViolation() 유틸 클래스 추가 (common/exception)
  • TrackingSessionService.isActiveSessionUniqueViolation() 제거 후 유틸로 교체
  • HikingRecordService.isDifficultyFeedbackHikingRecordUniqueViolation() 제거 후 유틸로 교체
  • UserBlockService.isUniqueViolation() 제거 후 유틸로 교체

✅ 확인

  • 빌드 OK
  • 테스트 OK

pooreumjung and others added 2 commits June 2, 2026 16:31
3곳에 중복된 예외 체인 탐색 로직을 ConstraintViolationUtils.isViolation()으로 추출.
버그 수정 시 한 곳만 고치면 되고, 제약 조건 이름 변경에도 누락 없이 대응 가능.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 395bfe34-35c9-4b13-88d0-91aa129455d1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/#171-constraint-violation-utils

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pooreumjung pooreumjung self-assigned this Jun 2, 2026
@pooreumjung
pooreumjung merged commit 8c8b5b2 into develop Jun 2, 2026
3 checks passed
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

본 PR은 데이터베이스 제약 조건 위반 예외를 처리하는 중복 로직을 통합하여 유지보수성을 높이고 버그 발생 가능성을 줄이는 것을 목적으로 합니다. 각 서비스에서 개별적으로 구현되어 있던 예외 파싱 로직을 공통 유틸리티 클래스로 추상화하였으며, 이를 통해 향후 유사한 예외 처리 시 일관된 방식을 적용할 수 있게 되었습니다.

Highlights

  • 유틸리티 클래스 도입: ConstraintViolationException 파싱 로직을 중앙화하기 위해 ConstraintViolationUtils 유틸리티 클래스를 신규 생성하였습니다.
  • 코드 중복 제거: 기존 서비스 계층(TrackingSessionService, HikingRecordService, UserBlockService)에 산재해 있던 중복 파싱 로직을 제거하고 유틸리티 클래스를 호출하도록 리팩토링하였습니다.
  • 정밀한 예외 처리: 정규표현식을 사용하여 제약 조건 이름의 부분 일치로 인한 오탐을 방지하고, 보다 정확한 예외 식별이 가능하도록 개선하였습니다.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request centralizes database unique constraint violation checks by introducing a shared ConstraintViolationUtils utility class and its corresponding tests, replacing duplicate local helper methods across several services. The review feedback suggests a performance improvement to cache the compiled regular expression patterns in a ConcurrentHashMap to avoid redundant compilation on every method call.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +7 to +14
public final class ConstraintViolationUtils {

private ConstraintViolationUtils() {}

public static boolean isViolation(Throwable exception, String constraintName) {
Pattern constraintNamePattern = Pattern.compile(
"(?<![A-Za-z0-9_])" + Pattern.quote(constraintName) + "(?![A-Za-z0-9_])"
);

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.

medium

[P3] 정규식 패턴 매번 컴파일하는 성능 비효율 개선

isViolation 메서드가 호출될 때마다 Pattern.compile을 사용하여 정규식 패턴을 매번 새로 생성하고 있습니다. 예외 처리 흐름이라 하더라도, 동시 요청이 많거나 예외가 빈번히 발생하는 상황에서는 CPU 자원을 불필요하게 소모할 수 있습니다.

제약 조건 이름(constraintName)별로 컴파일된 Pattern 객체를 캐싱하여 재사용하도록 개선하는 것을 권장합니다. ConcurrentHashMap을 사용해 간단히 캐싱할 수 있습니다.

public final class ConstraintViolationUtils {

    private static final java.util.Map<String, Pattern> PATTERN_CACHE = new java.util.concurrent.ConcurrentHashMap<>();

    private ConstraintViolationUtils() {}

    public static boolean isViolation(Throwable exception, String constraintName) {
        Pattern constraintNamePattern = PATTERN_CACHE.computeIfAbsent(constraintName, name ->
                Pattern.compile("(?<![A-Za-z0-9_])" + Pattern.quote(name) + "(?![A-Za-z0-9_])")
        );
References
  1. 우선순위 규칙에 따라 성능(Performance) 관련 개선 사항을 제안합니다. 정규식 패턴을 매번 컴파일하는 비효율을 캐싱을 통해 해결합니다. (link)

@howooyeon
howooyeon deleted the refactor/#171-constraint-violation-utils branch June 3, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[refactor] ConstraintViolationException 유틸 통합

1 participant