Skip to content

[APIM] Change Parameters data type from String to Blob#13856

Open
DDH13 wants to merge 5 commits into
wso2:masterfrom
DDH13:master.global-policy-fix
Open

[APIM] Change Parameters data type from String to Blob#13856
DDH13 wants to merge 5 commits into
wso2:masterfrom
DDH13:master.global-policy-fix

Conversation

@DDH13

@DDH13 DDH13 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Related to wso2/api-manager#4959

This pull request updates how the PARAMETERS field 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):

  • Changed the PARAMETERS column type from a string (e.g., VARCHAR, VARCHAR(2048)) to a binary/blob type (e.g., BLOB, BYTEA, VARBINARY(MAX), LONGBLOB) in all relevant AM_GATEWAY_POLICY_MAPPING table 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:

  • Updated addGatewayPolicyMapping in ApiMgtDAO.java to write the PARAMETERS field as a binary stream instead of a string, including new error handling for stream creation and IO exceptions.
  • Modified the method signature of addGatewayPolicyMapping to throw APIManagementException in addition to existing exceptions, reflecting the new error handling.
  • Refactored getGatewayPoliciesOfPolicyMapping to use a helper method (populateOperationPolicyWithRS) for populating OperationPolicy objects, likely to centralize the logic for handling binary parameter deserialization.

@wso2-engineering wso2-engineering 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.

AI Agent Log Improvement Checklist

⚠️ Warning: AI-Generated Review Comments

  • 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

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This 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.

Changes

Policy Parameters Binary Storage Migration

Layer / File(s) Summary
DAO: OperationPolicy population and binary parameter binding
components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java
Replaced inline construction of OperationPolicy with populateOperationPolicyWithRS(rs); updated addGatewayPolicyMapping to throw APIManagementException; bind global policy PARAMETERS using a UTF-8 ByteArrayInputStream and setBinaryStream, with IOException logged and rethrown.
Multi-database AM_GATEWAY_POLICY_MAPPING PARAMETERS column migration
features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/db2.sql, .../sql/h2.sql, .../sql/mssql.sql, .../sql/mysql.sql, .../sql/mysql_cluster.sql, .../sql/oracle.sql, .../sql/oracle_23c.sql, .../sql/oracle_rac.sql, .../sql/postgresql.sql, .../multi-dc/OGG/oracle/apimgt/tables.sql, .../multi-dc/OGG/oracle/apimgt/tables_23c.sql, .../multi-dc/Postgresql/apimgt/tables.sql, .../multi-dc/SQLServer/mssql/apimgt/tables.sql
Changed AM_GATEWAY_POLICY_MAPPING.PARAMETERS from VARCHAR(2048)/VARCHAR2(2048) to binary types per dialect: BLOB (DB2, H2, Oracle variants), VARBINARY(MAX) (MSSQL), LONGBLOB (MySQL variants), and BYTEA (PostgreSQL). Columns remain NOT NULL.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: converting the PARAMETERS column data type from String/VARCHAR to binary types (Blob) across the database schema and codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description clearly relates to the changeset, detailing database schema migration from VARCHAR to binary/blob types and corresponding Java DAO layer updates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copilot AI 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.

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.PARAMETERS from VARCHAR(2048) to DB-specific binary types (e.g., BYTEA, BLOB, LONGBLOB, VARBINARY(MAX)).
  • Refactored ApiMgtDAO#getGatewayPoliciesOfPolicyMapping(...) to reuse populateOperationPolicyWithRS(ResultSet) for OperationPolicy creation.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8968fc6 and b1fd892.

📒 Files selected for processing (10)
  • components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java
  • features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/db2.sql
  • features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/h2.sql
  • features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mssql.sql
  • features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql.sql
  • features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql_cluster.sql
  • features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle.sql
  • features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_23c.sql
  • features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_rac.sql
  • features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/postgresql.sql

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between b1fd892 and a042794.

📒 Files selected for processing (1)
  • components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 3, 2026
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