Skip to content

Analysis: Request Lifecycle Interceptor Pattern for OJP#331

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/add-integration-pattern-interface
Draft

Analysis: Request Lifecycle Interceptor Pattern for OJP#331
Copilot wants to merge 4 commits intomainfrom
copilot/add-integration-pattern-interface

Conversation

Copy link
Contributor

Copilot AI commented Feb 1, 2026

Problem

Circuit Breaker, Slow Query Segregation, and SQL Enhancement are hard-coded into StatementServiceImpl. Each integrates differently, blocking third-party extensibility and ballooning the class to 2,528 lines.

Solution

Proposes a Request Lifecycle Interceptor Pattern using Chain of Responsibility with ServiceLoader discovery, inspired by Servlet Filters.

Design Overview

8 Lifecycle Phases:

PRE_REQUEST → PRE_EXECUTION → RESOURCE_ACQUISITION → EXECUTION 
→ POST_EXECUTION → RESOURCE_RELEASE → POST_REQUEST → EXCEPTION_HANDLING

Core Interface:

public interface RequestInterceptor {
    String id();
    int getPriority();
    void intercept(RequestContext context, InterceptorChain chain) throws Exception;
}

Current (Hard-coded):

public void executeUpdate(StatementRequest request, ...) {
    circuitBreaker.preCheck(hash);              // Hard-coded
    manager.executeWithSegregation(...);        // Hard-coded wrapper
    circuitBreaker.onSuccess(hash);             // Hard-coded
}

Proposed (Interceptors):

public void executeUpdate(StatementRequest request, ...) {
    RequestContext context = RequestContext.builder()
        .requestType(UPDATE).sql(request.getSql()).build();
    
    InterceptorChainExecutor.execute(context, ctx -> {
        result = executeUpdateInternal(request, ctx);
        ctx.setResult(result);
    });
}

Benefits

  • Extensibility: Third-parties drop JARs in ojp-libs/, no recompilation
  • Simplification: StatementServiceImpl reduces from 2,528 → <1,000 lines
  • Standardization: Single pattern for all lifecycle integration
  • Performance: <1% overhead (0.05-0.3ms per request)

Migration Strategy

5-phase approach with feature flags for gradual rollout. Existing features migrate to: CircuitBreakerInterceptor, SlowQueryInterceptor, SqlEnhancerInterceptor.

Deliverables

  • Full Design: 48KB technical specification with interface designs, examples, performance analysis
  • ADR-008: Architectural decision record evaluating 5 alternatives (Event-Driven, AOP, Decorator, OSGi, Status Quo)
  • Executive Summary: Quick reference for stakeholders
  • Visual Guide: ASCII diagrams showing lifecycle flow and chain execution
  • 12-week implementation timeline

No code changes - documentation only per issue requirements.

Original prompt

Make an analysis of a new integration pattern for OJP where libraries like Apache calcite or even our implementation of Slow Query ergregation or Circuit Breaker would not be hooked directly into the code, instead there would be interface (or interfaces) that would govern how a library or a module can access and interact with each lifecycle phase of the request (query/update or other) in OJP. That would be probably a Chain of responsibility implementation and it would look very much like the Filter implementation in the Servlet specification. The goal is to standardize how libraries and modules interact with the lifecycle hooks of the ojp flow, allowing for external providers to create their own implementations that can be loaded via service loader (the same we already use for JDBC drivers and implementations of our SPIs, from ojp-libs folder) and integrate with OJP, allowing for powerful extensibility. Do not change any code yet.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits February 1, 2026 18:44
…or OJP

Co-authored-by: rrobetti <7221783+rrobetti@users.noreply.github.com>
…umentation

Co-authored-by: rrobetti <7221783+rrobetti@users.noreply.github.com>
Co-authored-by: rrobetti <7221783+rrobetti@users.noreply.github.com>
Copilot AI changed the title [WIP] Propose integration pattern for OJP with lifecycle interfaces Analysis: Request Lifecycle Interceptor Pattern for OJP Feb 1, 2026
Copilot AI requested a review from rrobetti February 1, 2026 18:48
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