Principle:Apache Dolphinscheduler DataSource Processor Implementation
| Knowledge Sources | |
|---|---|
| Domains | Plugin_Architecture, Data_Integration |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
A strategy pattern that encapsulates database-specific connection logic, parameter handling, and SQL parsing behind a unified processor interface discovered via Java SPI.
Description
The DataSource Processor principle defines a contract where each database type provides a processor implementation that knows how to: deserialize connection parameters from JSON, create JDBC connection parameters, build JDBC URLs, obtain raw connections, validate connectivity, and parse SQL statements. The processor extends AbstractDataSourceProcessor which provides common validation logic including host validation, database name validation, and security checks against malicious JDBC parameters.
This principle addresses the challenge of supporting 28+ heterogeneous database types with vastly different connection string formats, authentication mechanisms, and SQL dialects while presenting a uniform interface to the rest of the system.
Usage
Use this principle when adding support for a new database type in DolphinScheduler. Each database requires a dedicated processor class annotated with @AutoService(DataSourceProcessor.class) that extends AbstractDataSourceProcessor and implements all abstract methods for that database's connection specifics.
Theoretical Basis
The DataSource Processor follows the Strategy Pattern combined with Template Method Pattern:
- Strategy Pattern: Each database processor is an interchangeable strategy for handling database connections
- Template Method Pattern: AbstractDataSourceProcessor provides the template with common validation, while subclasses override database-specific methods
- SPI Discovery: @AutoService generates META-INF/services entries, enabling ServiceLoader to discover processors at runtime
Abstract algorithm:
// Template method in AbstractDataSourceProcessor
checkDatasourceParam(dto):
checkHost(dto.host) // validate IPv4/IPv6
checkDatabasePatter(dto.db) // validate against allowed pattern
checkOther(dto.other) // block malicious JDBC params
// Strategy methods (overridden per database)
createConnectionParams(dto) -> ConnectionParam
getJdbcUrl(param) -> String
getDatasourceDriver() -> String
getConnection(param) -> Connection