2020import java .sql .SQLException ;
2121import java .util .List ;
2222import java .util .Properties ;
23- import java .util .concurrent .atomic .AtomicReference ;
2423import org .checkerframework .checker .nullness .qual .NonNull ;
2524import org .checkerframework .checker .nullness .qual .Nullable ;
2625import software .amazon .jdbc .cleanup .CanReleaseResources ;
2726
2827public class ConnectionProviderManager {
2928
30- private static AtomicReference <ConnectionProvider > customConnectionProvider = new AtomicReference <>(null );
31-
3229 private final ConnectionProvider defaultProvider ;
3330 private final @ Nullable ConnectionProvider effectiveConnProvider ;
3431
35- private static ConnectionInitFunc connectionInitFunc = null ;
36-
3732 /**
3833 * {@link ConnectionProviderManager} constructor.
3934 *
@@ -57,9 +52,11 @@ public ConnectionProviderManager(
5752 * {@link ConnectionProvider#acceptsUrl} for more info.
5853 *
5954 * @param connProvider the {@link ConnectionProvider} to use to establish new connections
55+ * @deprecated Use software.amazon.jdbc.Driver instead
6056 */
57+ @ Deprecated
6158 public static void setConnectionProvider (ConnectionProvider connProvider ) {
62- customConnectionProvider . set (connProvider );
59+ Driver . setCustomConnectionProvider (connProvider );
6360 }
6461
6562 /**
@@ -78,9 +75,9 @@ public static void setConnectionProvider(ConnectionProvider connProvider) {
7875 public ConnectionProvider getConnectionProvider (
7976 String driverProtocol , HostSpec host , Properties props ) {
8077
81- final ConnectionProvider tmpCustomConnectionProvider = customConnectionProvider . get ();
82- if (tmpCustomConnectionProvider != null && tmpCustomConnectionProvider .acceptsUrl (driverProtocol , host , props )) {
83- return tmpCustomConnectionProvider ;
78+ final ConnectionProvider customConnectionProvider = Driver . getCustomConnectionProvider ();
79+ if (customConnectionProvider != null && customConnectionProvider .acceptsUrl (driverProtocol , host , props )) {
80+ return customConnectionProvider ;
8481 }
8582
8683 if (this .effectiveConnProvider != null && this .effectiveConnProvider .acceptsUrl (driverProtocol , host , props )) {
@@ -110,8 +107,8 @@ public ConnectionProvider getDefaultProvider() {
110107 * return false
111108 */
112109 public boolean acceptsStrategy (HostRole role , String strategy ) {
113- final ConnectionProvider tmpCustomConnectionProvider = customConnectionProvider . get ();
114- if (tmpCustomConnectionProvider != null && tmpCustomConnectionProvider .acceptsStrategy (role , strategy )) {
110+ final ConnectionProvider customConnectionProvider = Driver . getCustomConnectionProvider ();
111+ if (customConnectionProvider != null && customConnectionProvider .acceptsStrategy (role , strategy )) {
115112 return true ;
116113 }
117114
@@ -143,10 +140,10 @@ public boolean acceptsStrategy(HostRole role, String strategy) {
143140 public HostSpec getHostSpecByStrategy (List <HostSpec > hosts , HostRole role , String strategy , Properties props )
144141 throws SQLException , UnsupportedOperationException {
145142 HostSpec host = null ;
146- final ConnectionProvider tmpCustomConnectionProvider = customConnectionProvider . get ();
143+ final ConnectionProvider customConnectionProvider = Driver . getCustomConnectionProvider ();
147144 try {
148- if (tmpCustomConnectionProvider != null && tmpCustomConnectionProvider .acceptsStrategy (role , strategy )) {
149- host = tmpCustomConnectionProvider .getHostSpecByStrategy (hosts , role , strategy , props );
145+ if (customConnectionProvider != null && customConnectionProvider .acceptsStrategy (role , strategy )) {
146+ host = customConnectionProvider .getHostSpecByStrategy (hosts , role , strategy , props );
150147 }
151148 } catch (UnsupportedOperationException e ) {
152149 // The custom provider does not support the provided strategy, ignore it and try with the other providers.
@@ -170,27 +167,43 @@ public HostSpec getHostSpecByStrategy(List<HostSpec> hosts, HostRole role, Strin
170167 * Clears the non-default {@link ConnectionProvider} if it has been set. The default
171168 * ConnectionProvider will be used if the non-default ConnectionProvider has not been set or has
172169 * been cleared.
170+ *
171+ * @deprecated Use software.amazon.jdbc.Driver instead
173172 */
173+ @ Deprecated
174174 public static void resetProvider () {
175- customConnectionProvider . set ( null );
175+ Driver . resetCustomConnectionProvider ( );
176176 }
177177
178178 /**
179179 * Releases any resources held by the available {@link ConnectionProvider} instances.
180180 */
181181 public static void releaseResources () {
182- final ConnectionProvider tmpCustomConnectionProvider = customConnectionProvider . get ();
183- if (tmpCustomConnectionProvider instanceof CanReleaseResources ) {
184- ((CanReleaseResources ) tmpCustomConnectionProvider ).releaseResources ();
182+ final ConnectionProvider customConnectionProvider = Driver . getCustomConnectionProvider ();
183+ if (customConnectionProvider instanceof CanReleaseResources ) {
184+ ((CanReleaseResources ) customConnectionProvider ).releaseResources ();
185185 }
186186 }
187187
188+ /**
189+ * Sets a custom connection initialization function. It'll be used
190+ * for every brand-new database connection.
191+ *
192+ * @deprecated Use software.amazon.jdbc.Driver instead
193+ */
194+ @ Deprecated
188195 public static void setConnectionInitFunc (final @ NonNull ConnectionInitFunc func ) {
189- connectionInitFunc = func ;
196+ Driver . setConnectionInitFunc ( func ) ;
190197 }
191198
199+ /**
200+ * Resets a custom connection initialization function.
201+ *
202+ * @deprecated Use software.amazon.jdbc.Driver instead
203+ */
204+ @ Deprecated
192205 public static void resetConnectionInitFunc () {
193- connectionInitFunc = null ;
206+ Driver . resetConnectionInitFunc () ;
194207 }
195208
196209 public void initConnection (
@@ -199,12 +212,12 @@ public void initConnection(
199212 final @ NonNull HostSpec hostSpec ,
200213 final @ NonNull Properties props ) throws SQLException {
201214
202- final ConnectionInitFunc copy = connectionInitFunc ;
203- if (copy == null ) {
215+ final ConnectionInitFunc connectionInitFunc = Driver . getConnectionInitFunc () ;
216+ if (connectionInitFunc == null ) {
204217 return ;
205218 }
206219
207- copy .initConnection (connection , protocol , hostSpec , props );
220+ connectionInitFunc .initConnection (connection , protocol , hostSpec , props );
208221 }
209222
210223 public interface ConnectionInitFunc {
0 commit comments