Skip to content

Refactor StatementServiceImpl and CallResourceAction; introduce ResultSetHelper and FetchNextRowsAction#362

Open
felipestanzani wants to merge 1 commit intoOpen-J-Proxy:mainfrom
felipestanzani:issue222
Open

Refactor StatementServiceImpl and CallResourceAction; introduce ResultSetHelper and FetchNextRowsAction#362
felipestanzani wants to merge 1 commit intoOpen-J-Proxy:mainfrom
felipestanzani:issue222

Conversation

@felipestanzani
Copy link
Collaborator

closes #222

Summary

Refactors the gRPC statement and resource handling to reduce duplication, centralize shared logic, and improve maintainability. Net change: -420 lines, +269 lines across 4 files.

Changes

New components

  • ResultSetHelper (org.openjproxy.grpc.server.action.session)

    • Extracted result set handling from StatementServiceImpl into a reusable helper.
    • Handles row iteration, type conversion (LOB, CLOB, BLOB, dates, timestamps), metadata collection for DB2, and streaming via ResultSetWrapper.
    • Exposes handleResultSet() and updateSessionActivity() for use by other actions.
  • FetchNextRowsAction (org.openjproxy.grpc.server.action.transaction)

    • New action for fetching subsequent rows from result sets.
    • Encapsulates session activity updates, cluster health processing, and result set handling.
    • Replaces the inline logic previously in StatementServiceImpl.fetchNextRows().

Refactored components

  • StatementServiceImpl

    • Removed ~250 lines of duplicated logic.
    • Uses SessionConnectionHelper.sessionConnection() instead of its own sessionConnection().
    • Uses ResultSetHelper.handleResultSet() instead of its own handleResultSet().
    • Delegates fetchNextRows to FetchNextRowsAction.
    • Moved XADataSource, XATransactionRegistry, unpooled connection details, and cluster health tracker into ActionContext.
    • Cleaned up imports and simplified null checks.
  • CallResourceAction

    • Removed ~95 lines of duplicated sessionConnection() logic.
    • Uses SessionConnectionHelper.sessionConnection() for connection/session handling.
    • Uses pattern matching for instanceof (e.g. CallableStatement cs, ResultSet rs).
    • Simplified null checks and removed redundant conditionals.

Benefits

  • DRY: Shared session connection and result set logic moved into helpers.
  • Single responsibility: FetchNextRowsAction owns fetch-next-rows behavior.
  • Testability: ResultSetHelper and FetchNextRowsAction can be tested in isolation.
  • Consistency: Session connection and error handling aligned across statement and resource flows.

Testing

  • Existing tests pass
  • Manual verification of query execution and result set streaming
  • Manual verification of fetch-next-rows behavior
  • Manual verification of resource operations (statements, prepared statements, callable statements)

…tSetHelper and FetchNextRowsAction

- Removed unused imports and commented-out code in StatementServiceImpl.
- Consolidated XADataSource and transaction registry management within ActionContext.
- Added ResultSetHelper for handling result sets and improved session management.
- Introduced FetchNextRowsAction to facilitate fetching subsequent rows from result sets.
- Enhanced session connection handling and error management in CallResourceAction.
@sonarqubecloud
Copy link

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.

Refactor fetchNextRows() to use Action pattern

1 participant