Class FederatingDriver
- All Implemented Interfaces:
Driver
Unlike TeeDriver (write replication) or LoadBalancingDriver (read scaling), FederatingDriver merges query results from all data sources into a unified view.
Operating Modes
Broadcast Mode (default): Executes the same query on all configured databases and concatenates the results. Use for identical schemas across regions/tenants.
Table-Based Routing Mode: Routes queries to specific databases based on
the table name. Enable with the tableRouting parameter:
jdbc:federate[tableRouting=users:0;orders:1]:jdbc:h2:mem:db1;jdbc:h2:mem:db2
This routes users queries to db1 (index 0) and orders queries to db2 (index 1).
Tables not in the routing map fall back to broadcast behavior.
Limitations
This driver does NOT provide:
- Query rewriting for heterogeneous schemas
- Cross-database JOINs
- Shard key routing (use table-based routing for simple cases)
- Distributed query planning
For cross-database JOINs or complex federation: Use a federated query engine (Trino, Presto, Dremio) instead.
Transaction Limitations
This driver does NOT support coordinated transactions across databases. By default,
strictTransactions=true causes transactions to fail. If you set
strictTransactions=false, be aware that:
- Commit may succeed on some backends and fail on others (split-brain)
- Rollback cannot undo commits that already succeeded
- There is no two-phase commit (2PC) coordination
URL format: jdbc:federate[mergeStrategy=concat,parallelExecution=false]:url1;url2;...
Example URLs:
// Broadcast to all databases jdbc:federate:jdbc:h2:mem:db1;jdbc:h2:mem:db2 // Table-based routing: users→db1, orders→db2 jdbc:federate[tableRouting=users:0;orders:1]:jdbc:h2:mem:db1;jdbc:h2:mem:db2 // First non-empty result wins jdbc:federate[mergeStrategy=first_non_empty]:jdbc:postgresql://db1/sales;jdbc:mysql://db2/inventory
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConfiguration for the federating driver.static enumStrategy for merging ResultSets from multiple sources. -
Driver Parameters
URL format:
jdbc:federate[param=value,...]:<target-url>Parameter Type Default Constraints Description mergeStrategystring concatone of: "concat", "union_all", "first_non_empty" Result merge strategy parallelExecutionboolean false- Execute queries in parallel timeoutinteger 30000≥ 0 Timeout in milliseconds for parallel execution strictTransactionsboolean true- Throw exception when transactions are used (no cross-DB coordination). Set to false to allow uncoordinated transactions at your own risk. tableRoutingstring - - Optional table-to-database routing. Format: table1:idx1;table2:idx2 where idx is 0-based database index. Unrouted tables broadcast to all. Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanacceptsSubName(String subname) protected booleanacceptsSubProtocol(String subprotocol) connect(String url, Properties info) Methods inherited from class org.pjdbc.sql.AbstractDriver
acceptsProtocol, acceptsURL, getMajorVersion, getMinorVersion, getParentLogger, getPropertyInfo, getUrlParameter, getUrlParameter, getUrlParameters, jdbcCompliant, parseUrl, protocol, subname, subprotocol, validateParameters
-
Constructor Details
-
FederatingDriver
public FederatingDriver()
-
-
Method Details
-
acceptsSubProtocol
- Specified by:
acceptsSubProtocolin classAbstractDriver
-
acceptsSubName
- Specified by:
acceptsSubNamein classAbstractDriver
-
connect
- Throws:
SQLException
-