DualConnection takes multiple aspects while deciding which connection to use:
- A connection's state.
- A replica's consistency.
- Context of
java.sql.Connection
/java.sql.Statement
API usage.
Some of the methods are intended to write into the database. For example every call to java.sq.PreparedStatement#executeUpdate
will switch the connection's state to the main database.
-
Availability of replica
-
The query will use the main database in case it's:
SELECT FOR UPDATE
statement.UPDATE
statement.DELETE
statement.- All calls with transaction isolation level higher than
TRANSACTION_READ_COMMITTED
.
-
The query will use the main database in case it's an unknown function call. Known read-only functions are standard SQL functions and user defined functions.