Skip to main content

11.2 Custom Adapter

Hint

This article is generated by AI translation.

With dbvisitor-driver you can more easily extend data-source support so applications access diverse databases in a unified way. It fits scenarios such as:

  • Integrating non-relational databases into JDBC-based apps.
  • Projects that need to expose JDBC interfaces for custom data sources.
  • Providing a unified database interface to dbVisitor so apps access different databases consistently.

Architecture

The project uses an interface-driven design with these core pieces:

  1. Driver entry
    • net.hasor.dbvisitor.driver.JdbcDriver implements java.sql.Driver, handling URL parsing and connection creation.
    • All adapters follow JDBC URL format jdbc:dbvisitor:<adapterName>//<server?param=value>.
  2. Adapter manager
    • net.hasor.dbvisitor.driver.AdapterManager manages and loads adapter factories via Java SPI discovery/registration.
  3. JDBC standard layer
    • Classes under net.hasor.dbvisitor.driver.* prefixed with Jdbc implement standard JDBC interfaces.
  4. Adapter layer
    • net.hasor.dbvisitor.driver.AdapterFactory is the adapter connection factory that creates AdapterConnection instances.
    • net.hasor.dbvisitor.driver.AdapterConnection is the abstract adapter connection handling requests/responses.
  5. Type support
    • TypeSupport, AdapterTypeSupport: data type conversion support.
    • ConvertUtils: utilities for type conversions.

Technical Highlights

  • SPI-based: dynamically load adapters via Java SPI for a pluggable, loosely coupled design.
  • Type conversion: flexible system for mapping data types.
  • Request/response model: handles DB operations in a request/response flow to fit varied data sources.
  • Compatibility: aims to comply with standard JDBC, with some limitations.