Skip to main content

Custom Adapter

Hint

This article is generated by AI translation.

With dbvisitor-driver, developers can more easily extend data source support, enabling applications to access various types of databases in a unified way. It is designed for the following scenarios:

  • Integrating non-relational databases into JDBC-based applications.
  • Projects that need to provide JDBC interfaces for custom data sources.

Architecture Design

The project adopts an interface-oriented design pattern, consisting of the following core components:

  1. Driver Entry
    • net.hasor.dbvisitor.driver.JdbcDriver implements the java.sql.Driver interface, responsible for URL parsing and creating supported connections.
    • The driver entry class mandates that all adapters follow the JDBC URL format: jdbc:dbvisitor:<adapterName>//<server?param=value>
  2. Adapter Manager
    • The net.hasor.dbvisitor.driver.AdapterManager class manages and loads adapter factories, using the Java SPI mechanism to discover and register adapters.
  3. JDBC Standard Implementation Layer
    • All classes prefixed with Jdbc under the net.hasor.dbvisitor.driver.* package implement JDBC standard interfaces.
  4. Adapter Layer
    • The net.hasor.dbvisitor.driver.AdapterFactory interface is the adapter connection factory, responsible for creating AdapterConnection instances.
    • The net.hasor.dbvisitor.driver.AdapterConnection abstract class is the adapter connection, handling adapter requests and responses.
  5. Type Support
    • TypeSupport, AdapterTypeSupport: Provide data type conversion support
    • ConvertUtils: Utility class for handling various data type conversions

Technical Features

  • SPI Mechanism: Dynamically loads adapters through the Java SPI mechanism, achieving a loosely coupled plugin architecture.
  • Type Conversion: Provides a flexible type conversion system supporting mappings between various data types.
  • Request/Response Model: Adopts a request/response model for database operations, facilitating adaptation to various data sources.
  • Compatibility: Strives for compatibility with standard JDBC interfaces, with some limitations.