[APIM] Change Parameters data type from String to Blob#13856
Conversation
There was a problem hiding this comment.
AI Agent Log Improvement Checklist
- The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
- Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.
✅ Before merging this pull request:
- Review all AI-generated comments for accuracy and relevance.
- Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
| Comment | Accepted (Y/N) | Reason |
|---|---|---|
| #### Log Improvement Suggestion No: 1 |
📝 WalkthroughWalkthroughThis PR refactors the DAO to centralize OperationPolicy population and switches AM_GATEWAY_POLICY_MAPPING.PARAMETERS from fixed-width VARCHAR types to binary column types across all supported databases. ChangesPolicy Parameters Binary Storage Migration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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.
Pull request overview
This PR updates the AM_GATEWAY_POLICY_MAPPING.PARAMETERS column to use a binary type across supported DB schema scripts, and refactors DAO result-set handling to reuse a shared OperationPolicy population utility.
Changes:
- Updated
AM_GATEWAY_POLICY_MAPPING.PARAMETERSfromVARCHAR(2048)to DB-specific binary types (e.g.,BYTEA,BLOB,LONGBLOB,VARBINARY(MAX)). - Refactored
ApiMgtDAO#getGatewayPoliciesOfPolicyMapping(...)to reusepopulateOperationPolicyWithRS(ResultSet)forOperationPolicycreation.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/postgresql.sql | Change PARAMETERS to BYTEA for PostgreSQL base schema. |
| features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle.sql | Change PARAMETERS to BLOB for Oracle base schema. |
| features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_rac.sql | Change PARAMETERS to BLOB for Oracle RAC base schema. |
| features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_23c.sql | Change PARAMETERS to BLOB for Oracle 23c base schema. |
| features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql.sql | Change PARAMETERS to LONGBLOB for MySQL base schema. |
| features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql_cluster.sql | Change PARAMETERS to LONGBLOB for MySQL Cluster base schema. |
| features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mssql.sql | Change PARAMETERS to VARBINARY(MAX) for SQL Server base schema. |
| features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/h2.sql | Change PARAMETERS to BLOB for H2 base schema. |
| features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/db2.sql | Change PARAMETERS to BLOB for DB2 base schema. |
| components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java | Reuse shared RS-to-OperationPolicy population logic when reading gateway policies for a mapping UUID. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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
`@components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java`:
- Around line 27148-27149: populateOperationPolicyWithRS reads PARAMETERS as
binary (rs.getBinaryStream("PARAMETERS")), but addGatewayPolicyMapping writes
PARAMETERS with preparedStatement.setString(5, paramJSON) causing a binary/SQL
dialect mismatch; update addGatewayPolicyMapping to bind PARAMETERS as binary
(use preparedStatement.setBytes or setBinaryStream for the param JSON bytes and
use preparedStatement.setNull(index, Types.BINARY) when null/empty) so the write
path matches populateOperationPolicyWithRS; keep the column index/parameter
order used in addGatewayPolicyMapping and ensure UTF-8 encoding when converting
the JSON string to bytes.
🪄 Autofix (Beta)
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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 54b5d2c1-8a52-4fce-8343-cf77b7ae4455
📒 Files selected for processing (10)
components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.javafeatures/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/db2.sqlfeatures/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/h2.sqlfeatures/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mssql.sqlfeatures/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql.sqlfeatures/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql_cluster.sqlfeatures/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle.sqlfeatures/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_23c.sqlfeatures/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_rac.sqlfeatures/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/postgresql.sql
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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
`@components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java`:
- Around line 27511-27518: The code in ApiMgtDAO creates paramInputStream from
paramJSON.getBytes(StandardCharsets.UTF_8) but passes paramJSON.length()
(character count) to preparedStatement.setBinaryStream, causing truncation for
multi-byte UTF‑8 characters; fix by storing the UTF‑8 bytes in a byte[] (e.g.,
byte[] paramBytes = paramJSON.getBytes(StandardCharsets.UTF_8)), create the
ByteArrayInputStream from that array, and pass paramBytes.length to
setBinaryStream(5, paramInputStream, paramBytes.length) so the full byte length
is written.
🪄 Autofix (Beta)
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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c13df2b4-34b1-4d83-8981-ec295851d368
📒 Files selected for processing (1)
components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java
Related to wso2/api-manager#4959
This pull request updates how the
PARAMETERSfield is stored for gateway policy mappings, migrating from a string-based approach to a binary/blob-based approach across all supported databases. It also updates the Java DAO layer to handle this change, ensuring that policy parameters are correctly written and read as binary data, and improves error handling during this process.Database schema changes (PARAMETERS field migration):
PARAMETERScolumn type from a string (e.g.,VARCHAR,VARCHAR(2048)) to a binary/blob type (e.g.,BLOB,BYTEA,VARBINARY(MAX),LONGBLOB) in all relevantAM_GATEWAY_POLICY_MAPPINGtable definitions for Oracle, PostgreSQL, SQL Server, MySQL, H2, and DB2 databases. (F867878L2430R2430, [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]Java DAO layer updates:
addGatewayPolicyMappinginApiMgtDAO.javato write thePARAMETERSfield as a binary stream instead of a string, including new error handling for stream creation and IO exceptions.addGatewayPolicyMappingto throwAPIManagementExceptionin addition to existing exceptions, reflecting the new error handling.getGatewayPoliciesOfPolicyMappingto use a helper method (populateOperationPolicyWithRS) for populatingOperationPolicyobjects, likely to centralize the logic for handling binary parameter deserialization.