Refactor: decompose conditional, extract SqlTransformerBuilder, and replace conditional with polymorphism in SqlTransformer#1778
Conversation
…and replace conditional with polymorphism in SQLKeyWords
PR Summary
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1778 +/- ##
============================================
+ Coverage 92.37% 92.49% +0.12%
- Complexity 3448 3466 +18
============================================
Files 339 340 +1
Lines 6794 6798 +4
Branches 670 666 -4
============================================
+ Hits 6276 6288 +12
+ Misses 353 348 -5
+ Partials 165 162 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR refactors the SQL transformation utilities by extracting SqlTransformer’s builder into a standalone class and doing small internal cleanups to SQL keyword casing and identifier-quoting logic.
Changes:
- Extract
SqlTransformerBuilderintosrc/main/java/net/datafaker/transformations/sql/SqlTransformerBuilder.javaand routeSqlTransformer.builder()through it. - Introduce a package-private
SqlTransformer.create(...)factory used by the new builder. - Refactor identifier-quoting checks and simplify SQL keyword case selection via
Case.apply(...).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/main/java/net/datafaker/transformations/sql/SqlTransformerBuilder.java |
New standalone builder that constructs SqlTransformer instances via a factory method. |
src/main/java/net/datafaker/transformations/sql/SqlTransformer.java |
Updates builder entry point, adds factory method, refactors quoting checks, and adjusts keyword case handling. |
| public static <IN> SqlTransformerBuilder<IN> builder() { | ||
| return new SqlTransformerBuilder<>(); | ||
| } |
There was a problem hiding this comment.
Yeah the tests already show this is an issue
| return new SqlTransformer<>(schemaName, tableName, quote, dialect, sqlIdentifier, | ||
| casing, withBatchMode, batchSize, keywordCase, forceSqlQuoteIdentifierUsage); |
There was a problem hiding this comment.
You should use the spotless apply task to fix formatting
| || name.charAt(i) == DEFAULT_CATALOG_SEPARATOR) { | ||
| char currentChar = name.charAt(i); | ||
| if (requiresQuotingForCasing(currentChar) | ||
| ||containsSpecialCharacter(currentChar)) { |
| return casing == Casing.TO_UPPER && Character.isLowerCase(c) | ||
| || casing == Casing.TO_LOWER && Character.isUpperCase(c); |
| return casing == Casing.TO_UPPER && Character.isLowerCase(c) | ||
| || casing == Casing.TO_LOWER && Character.isUpperCase(c); | ||
| } | ||
|
|
||
| private boolean containsSpecialCharacter(char c) { | ||
| return c == openSqlIdentifier | ||
| || c == closeSqlIdentifier | ||
| || c == DEFAULT_CATALOG_SEPARATOR; |
There was a problem hiding this comment.
Thank you for the review @kingthorin I've addressed all the feedback:
- Reintroduced SqlTransformer.SqlTransformerBuilder as a deprecated wrapper extending the new top-level class to avoid breaking API changes
- Fixed formatting and indentation in create(), requiresQuotingForCasing(), containsSpecialCharacter() and the || spacing issue
- Added unit tests to improve coverage
…er alias, fix formatting, and added Test cases for SqlTransformer for better coverage
|
AI PR |
Summary
This PR introduces three structural refactoring improvements in the sql transformation package to improve readability, separation of responsibilities, and object-oriented design.
Changes Made
SqlTransformer.java - Decompose Conditional
Refactored the method isSqlQuoteIdentifierRequiredFor() by decomposing a complex conditional expression into smaller helper methods. This separates the logical concerns and makes the intent of each condition clearer.
SqlTransformerBuilder - Extract Class
Extracted the SqlTransformerBuilder nested class into its own dedicated file.
SQLKeyWords.java - Replace Conditional with Polymorphism
Refactored SQLKeyWords.getValue() to eliminate a switch conditional by moving behavior into the Case enum.
Testing
Notes
This PR introduces only structural refactoring improvements to improve maintainability and clarity without altering application behavior.