7
7
import java .sql .Connection ;
8
8
import java .sql .SQLException ;
9
9
10
+ import org .hibernate .Incubating ;
10
11
import org .hibernate .dialect .Dialect ;
11
12
import org .hibernate .engine .jdbc .connections .internal .DatabaseConnectionInfoImpl ;
12
13
import org .hibernate .engine .jdbc .env .spi .ExtractedDatabaseMetaData ;
@@ -40,20 +41,62 @@ public interface ConnectionProvider extends Service, Wrapped {
40
41
* @return The obtained JDBC connection
41
42
*
42
43
* @throws SQLException Indicates a problem opening a connection
43
- * @throws org.hibernate.HibernateException Indicates a problem otherwise obtaining a connection.
44
+ * @throws org.hibernate.HibernateException Indicates a problem obtaining a connection.
44
45
*/
45
46
Connection getConnection () throws SQLException ;
46
47
48
+ /**
49
+ * Obtains a connection to a read-only replica for use according to the underlying
50
+ * strategy of this provider.
51
+ *
52
+ * @return The obtained JDBC connection
53
+ *
54
+ * @throws SQLException Indicates a problem opening a connection
55
+ * @throws org.hibernate.HibernateException Indicates a problem obtaining a connection.
56
+ *
57
+ * @implNote This default implementation simply calls {@link #getConnection()},
58
+ * which returns a connection to a writable replica. If this operation is overridden
59
+ * to return a connection to a distinct read-only replica, the matching operation
60
+ * {@link #closeReadOnlyConnection(Connection)} must also be overridden.
61
+ *
62
+ * @since 7.2
63
+ */
64
+ @ Incubating
65
+ default Connection getReadOnlyConnection () throws SQLException {
66
+ return getConnection ();
67
+ }
68
+
47
69
/**
48
70
* Release a connection from Hibernate use.
49
71
*
50
72
* @param connection The JDBC connection to release
51
73
*
52
74
* @throws SQLException Indicates a problem closing the connection
53
- * @throws org.hibernate.HibernateException Indicates a problem otherwise releasing a connection.
75
+ * @throws org.hibernate.HibernateException Indicates a problem releasing a connection.
54
76
*/
55
77
void closeConnection (Connection connection ) throws SQLException ;
56
78
79
+ /**
80
+ * Release a connection to a read-only replica from Hibernate use.
81
+ *
82
+ * @param connection The JDBC connection to release
83
+ *
84
+ * @throws SQLException Indicates a problem closing the connection
85
+ * @throws org.hibernate.HibernateException Indicates a problem otherwise releasing a connection.
86
+ *
87
+ * @implNote This default implementation simply calls
88
+ * {@link #closeConnection(Connection)}. If
89
+ * {@link #getReadOnlyConnection()} is overridden to return a
90
+ * connection to a distinct read-only replica, this operation must also
91
+ * be overridden.
92
+ *
93
+ * @since 7.2
94
+ */
95
+ @ Incubating
96
+ default void closeReadOnlyConnection (Connection connection ) throws SQLException {
97
+ closeConnection ( connection );
98
+ }
99
+
57
100
/**
58
101
* Does this connection provider support aggressive release of JDBC connections and later
59
102
* re-acquisition of those connections if needed?
@@ -72,6 +115,34 @@ public interface ConnectionProvider extends Service, Wrapped {
72
115
*/
73
116
boolean supportsAggressiveRelease ();
74
117
118
+ /**
119
+ * Does this connection provider correctly set the
120
+ * {@linkplain java.sql.Connection#setSchema schema}
121
+ * of the returned JDBC connections?
122
+ * @return {@code true} if the connection provider handles this;
123
+ * {@code false} if the client should set the schema
124
+ *
125
+ * @implNote If necessary, a {@code ConnectionProvider} may
126
+ * call {@link org.hibernate.context.spi.MultiTenancy#getTenantSchemaMapper}
127
+ * to obtain the {@link org.hibernate.context.spi.TenantSchemaMapper}.
128
+ */
129
+ @ Incubating
130
+ default boolean handlesConnectionSchema () {
131
+ return false ;
132
+ }
133
+
134
+ /**
135
+ * Does this connection provider correctly set the
136
+ * {@linkplain java.sql.Connection#setReadOnly read-only mode}
137
+ * of the returned JDBC connections?
138
+ * @return {@code true} if the connection provider handles this;
139
+ * {@code false} if the client should set the read-only mode
140
+ */
141
+ @ Incubating
142
+ default boolean handlesConnectionReadOnly () {
143
+ return false ;
144
+ }
145
+
75
146
/**
76
147
* @return an informative instance of {@link DatabaseConnectionInfo} for logging.
77
148
*
0 commit comments