feat(postgresql): Add java.sql.Types.ARRAY support to PostgresqlDataT… - #932
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Reviewer's GuideAdds PostgreSQL array (java.sql.Types.ARRAY) support via a new ArrayType and wires it into PostgresqlDataTypeFactory, with comprehensive unit and integration tests plus documentation and changelog updates. Sequence diagram for writing PostgreSQL array literals via ArrayTypesequenceDiagram
actor Client
participant ArrayType
participant PreparedStatement
participant Connection
Client->>ArrayType: setSqlValue(value, column, statement)
ArrayType->>PreparedStatement: setNull(column, Types.ARRAY) [value is null]
ArrayType-->>Client: [return]
alt value is Array
ArrayType->>PreparedStatement: setArray(column, value)
else value is literal_text
ArrayType->>ArrayType: parseElements(value.toString)
ArrayType->>PreparedStatement: getConnection()
PreparedStatement-->>ArrayType: connection
ArrayType->>Connection: createArrayOf(elementSqlTypeName, elements)
Connection-->>ArrayType: array
ArrayType->>PreparedStatement: setArray(column, array)
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning Review limit reached
Next review available in: 31 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis change adds PostgreSQL array support through a new ChangesPostgreSQL array support
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant PostgresqlDataTypeFactory
participant ArrayType
participant Connection
participant PreparedStatement
PostgresqlDataTypeFactory->>ArrayType: create ArrayType from SQL type name
ArrayType->>ArrayType: parse array literal
ArrayType->>Connection: createArrayOf element type and values
ArrayType->>PreparedStatement: bind JDBC array
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/test/java/org/dbunit/ext/postgresql/PostgresqlArrayIT.java (2)
69-69: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse a direct null check.
!Objects.isNull(_connection)is a negated call._connection != nullstates the same condition directly.♻️ Proposed simplification
- if (!Objects.isNull(_connection)) + if (_connection != null)Remove the
java.util.Objectsimport if it becomes unused.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/test/java/org/dbunit/ext/postgresql/PostgresqlArrayIT.java` at line 69, Update the null check in PostgresqlArrayIT to use the direct condition _connection != null instead of negating Objects.isNull(_connection), and remove the java.util.Objects import if it is no longer used.
127-148: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winRow order is not guaranteed by the query.
createDataSet()reads the table without anORDER BY. The assertions index rows 0, 1, and 2 and assume insert order. PostgreSQL can return rows in another order. Sort byIDto make the test deterministic, for example throughcreateQueryTable(testTable, "SELECT * FROM " + testTable + " ORDER BY ID").🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/test/java/org/dbunit/ext/postgresql/PostgresqlArrayIT.java` around lines 127 - 148, Update the dataset retrieval in the PostgreSQL array integration test to use an explicitly ordered query via createQueryTable, sorting by ID before indexing rows. Keep the existing assertions and testTable usage unchanged so row 0, 1, and 2 consistently correspond to their intended records.src/main/java/org/dbunit/ext/postgresql/ArrayType.java (1)
179-210: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueBackslash escapes are ignored outside double quotes.
PostgreSQL accepts backslash escapes in unquoted array elements, for example
{a\,b}is one elementa,b. The parser handles\only inside quotes, so it splits such a literal intoa\andb. Reads are unaffected, because PostgreSQL quotes elements that need escaping. Writes of hand-written literals can bind wrong elements.♻️ Proposed handling for unquoted escapes
} else if (c == '"') { inQuotes = true; quoted = true; + } else if (c == '\\' && i + 1 < body.length()) + { + token.append(body.charAt(++i)); + quoted = true; } else if (c == '{')Setting
quotedalso prevents the escaped text from being trimmed or read as theNULLkeyword.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/java/org/dbunit/ext/postgresql/ArrayType.java` around lines 179 - 210, Update the unquoted-element parsing branch in ArrayType’s array-literal loop to recognize backslash escapes and append the following character as literal content, including escaped commas. Mark the element as quoted/escaped when such an escape is encountered so toElement does not trim it or interpret the result as the NULL keyword, while preserving the existing quoted parsing behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/test/java/org/dbunit/ext/postgresql/PostgresqlArrayIT.java`:
- Line 1: Add the repository’s standard DbUnit LGPL license header at the
beginning of PostgresqlArrayIT.java, before the package declaration, matching
the header used by the other new files in the PR.
---
Nitpick comments:
In `@src/main/java/org/dbunit/ext/postgresql/ArrayType.java`:
- Around line 179-210: Update the unquoted-element parsing branch in ArrayType’s
array-literal loop to recognize backslash escapes and append the following
character as literal content, including escaped commas. Mark the element as
quoted/escaped when such an escape is encountered so toElement does not trim it
or interpret the result as the NULL keyword, while preserving the existing
quoted parsing behavior.
In `@src/test/java/org/dbunit/ext/postgresql/PostgresqlArrayIT.java`:
- Line 69: Update the null check in PostgresqlArrayIT to use the direct
condition _connection != null instead of negating Objects.isNull(_connection),
and remove the java.util.Objects import if it is no longer used.
- Around line 127-148: Update the dataset retrieval in the PostgreSQL array
integration test to use an explicitly ordered query via createQueryTable,
sorting by ID before indexing rows. Keep the existing assertions and testTable
usage unchanged so row 0, 1, and 2 consistently correspond to their intended
records.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: a6beeb2d-7b07-4467-b1b5-3632a9bf2aed
📒 Files selected for processing (8)
src/changes/changes.xmlsrc/main/java/org/dbunit/ext/postgresql/ArrayType.javasrc/main/java/org/dbunit/ext/postgresql/PostgresqlDataTypeFactory.javasrc/site/asciidoc/databases.adocsrc/site/asciidoc/databases/postgresql.adocsrc/test/java/org/dbunit/ext/postgresql/ArrayTypeTest.javasrc/test/java/org/dbunit/ext/postgresql/PostgresqlArrayIT.javasrc/test/java/org/dbunit/ext/postgresql/PostgresqlDataTypeFactoryTest.java
|
Addressed CodeRabbit's nitpick findings in fixup commit 59afa882 (not yet squashed):
Full unit suite (2091 tests) and the full |
…ypeFactory * Add ArrayType, recognized for every array column (e.g. integer[], text[]), read/written as PostgreSQL's own array literal text representation. * On write, split the literal into top-level elements - honoring double-quoted, backslash-escaped elements and the unquoted NULL keyword - and bind via the standard Connection#createArrayOf(String, Object[]), so PostgreSQL itself parses and validates each element against the column's actual base type. Only single-dimension arrays are supported for writing. * Document ArrayType in databases/postgresql.adoc and databases.adoc. Refs: 646 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XBjSJ2bgVtwqyxGv2nvwP9
7a57e5b to
f807ca8
Compare
…ypeFactory
Refs: 646
Claude-Session: https://claude.ai/code/session_01XBjSJ2bgVtwqyxGv2nvwP9
Summary by Sourcery
Add PostgreSQL array column support by introducing a dedicated ArrayType and wiring it into the PostgresqlDataTypeFactory for java.sql.Types.ARRAY.
New Features:
Enhancements:
Tests:
Summary by CodeRabbit
New Features
Documentation