5151import software .amazon .jdbc .util .FullServicesContainer ;
5252import software .amazon .jdbc .util .Messages ;
5353import software .amazon .jdbc .util .Utils ;
54- import software .amazon .jdbc .util .WrapperUtils ;
5554import software .amazon .jdbc .util .telemetry .TelemetryContext ;
5655import software .amazon .jdbc .util .telemetry .TelemetryFactory ;
5756import software .amazon .jdbc .util .telemetry .TelemetryTraceLevel ;
58- import software .amazon .jdbc .wrapper .ConnectionWrapper ;
5957
6058/**
6159 * This class creates and handles a chain of {@link ConnectionPlugin} for each connection.
@@ -92,29 +90,25 @@ public class ConnectionPluginManager implements CanReleaseResources, Wrapper {
9290 }
9391 };
9492
95- private final ReentrantLock lock = new ReentrantLock ();
96-
97- protected Properties props = new Properties ();
98- protected List <ConnectionPlugin > plugins ;
99- protected final @ NonNull ConnectionProvider defaultConnProvider ;
100- protected final @ Nullable ConnectionProvider effectiveConnProvider ;
101- protected final ConnectionWrapper connectionWrapper ;
102- protected FullServicesContainer servicesContainer ;
103- protected PluginService pluginService ;
104- protected TelemetryFactory telemetryFactory ;
105- protected boolean isTelemetryInUse ;
10693 @ SuppressWarnings ("rawtypes" )
10794 protected final PluginChainJdbcCallableInfo [] pluginChainFuncMap =
10895 new PluginChainJdbcCallableInfo [JdbcMethod .ALL .id + 1 ]; // it should be the last element in JdbcMethod enum
96+ protected final ReentrantLock lock = new ReentrantLock ();
97+ protected final Properties props ;
98+ protected final TelemetryFactory telemetryFactory ;
99+ protected final boolean isTelemetryInUse ;
100+ protected final ConnectionProvider defaultConnProvider ;
101+ protected final @ Nullable ConnectionProvider effectiveConnProvider ;
102+ protected List <ConnectionPlugin > plugins ;
109103
110104 public ConnectionPluginManager (
105+ final @ NonNull Properties props ,
106+ final @ NonNull TelemetryFactory telemetryFactory ,
111107 final @ NonNull ConnectionProvider defaultConnProvider ,
112- final @ Nullable ConnectionProvider effectiveConnProvider ,
113- final @ Nullable ConnectionWrapper connectionWrapper ,
114- final @ NonNull TelemetryFactory telemetryFactory ) {
108+ final @ Nullable ConnectionProvider effectiveConnProvider ) {
109+ this .props = props ;
115110 this .defaultConnProvider = defaultConnProvider ;
116111 this .effectiveConnProvider = effectiveConnProvider ;
117- this .connectionWrapper = connectionWrapper ;
118112 this .telemetryFactory = telemetryFactory ;
119113 this .isTelemetryInUse = telemetryFactory .inUse ();
120114 }
@@ -127,28 +121,11 @@ public ConnectionPluginManager(
127121 final @ Nullable ConnectionProvider effectiveConnProvider ,
128122 final Properties props ,
129123 final List <ConnectionPlugin > plugins ,
130- final ConnectionWrapper connectionWrapper ,
131- final PluginService pluginService ,
132- final TelemetryFactory telemetryFactory ) {
133- this (defaultConnProvider , effectiveConnProvider , props , plugins , connectionWrapper , telemetryFactory );
134- this .pluginService = pluginService ;
135- }
136-
137- /**
138- * This constructor is for testing purposes only.
139- */
140- ConnectionPluginManager (
141- final @ NonNull ConnectionProvider defaultConnProvider ,
142- final @ Nullable ConnectionProvider effectiveConnProvider ,
143- final Properties props ,
144- final List <ConnectionPlugin > plugins ,
145- final ConnectionWrapper connectionWrapper ,
146124 final TelemetryFactory telemetryFactory ) {
147125 this .defaultConnProvider = defaultConnProvider ;
148126 this .effectiveConnProvider = effectiveConnProvider ;
149127 this .props = props ;
150128 this .plugins = plugins ;
151- this .connectionWrapper = connectionWrapper ;
152129 this .telemetryFactory = telemetryFactory ;
153130 this .isTelemetryInUse = telemetryFactory .inUse ();
154131 }
@@ -170,30 +147,18 @@ public void unlock() {
170147 * connection plugin in the chain.
171148 *
172149 * @param servicesContainer the service container for the services required by this class.
173- * @param props the configuration of the connection
174- * @param pluginManagerService a reference to a plugin manager service
175150 * @param configurationProfile a profile configuration defined by the user
176151 * @throws SQLException if errors occurred during the execution
177152 */
178- public void init (
153+ public void initPlugins (
179154 final FullServicesContainer servicesContainer ,
180- final Properties props ,
181- final PluginManagerService pluginManagerService ,
182155 @ Nullable ConfigurationProfile configurationProfile ) throws SQLException {
183-
184- this .props = props ;
185- this .servicesContainer = servicesContainer ;
186- this .pluginService = servicesContainer .getPluginService ();
187- this .telemetryFactory = servicesContainer .getTelemetryFactory ();
188- this .isTelemetryInUse = telemetryFactory .inUse ();
189-
190156 ConnectionPluginChainBuilder pluginChainBuilder = new ConnectionPluginChainBuilder ();
191157 this .plugins = pluginChainBuilder .getPlugins (
192- this . servicesContainer ,
158+ servicesContainer ,
193159 this .defaultConnProvider ,
194160 this .effectiveConnProvider ,
195- pluginManagerService ,
196- props ,
161+ this .props ,
197162 configurationProfile );
198163 }
199164
@@ -223,14 +188,8 @@ protected <T, E extends Exception> T executeWithSubscribedPlugins(
223188 this .pluginChainFuncMap [jdbcMethod .id ] = pluginChainJdbcCallableInfo ;
224189 }
225190
226-
227- if (pluginChainJdbcCallableInfo == null ) {
228- throw new RuntimeException ("Error processing this JDBC call." );
229- }
230-
231191 if (jdbcMethod .alwaysUsePipeline || pluginChainJdbcCallableInfo .isSubscribed ) {
232192 // noinspection unchecked
233- @ SuppressWarnings ("unchecked" )
234193 PluginChainJdbcCallable <T , E > pluginChainFunc = pluginChainJdbcCallableInfo .func ;
235194 return pluginChainFunc .call (pluginPipeline , jdbcMethodFunc , pluginToSkip );
236195 } else {
@@ -320,10 +279,6 @@ protected <E extends Exception> void notifySubscribedPlugins(
320279 }
321280 }
322281
323- public ConnectionWrapper getConnectionWrapper () {
324- return this .connectionWrapper ;
325- }
326-
327282 public TelemetryFactory getTelemetryFactory () {
328283 return this .telemetryFactory ;
329284 }
@@ -345,18 +300,6 @@ public <T, E extends Exception> T execute(
345300 final JdbcCallable <T , E > jdbcMethodFunc ,
346301 final Object [] jdbcMethodArgs )
347302 throws E {
348-
349- // The target driver may block on Statement.getConnection().
350- if (jdbcMethod .shouldLockConnection && jdbcMethod .checkBoundedConnection ) {
351- final Connection conn = WrapperUtils .getConnectionFromSqlObject (methodInvokeOn );
352- if (conn != null && conn != this .pluginService .getCurrentConnection ()) {
353- throw WrapperUtils .wrapExceptionIfNeeded (
354- exceptionClass ,
355- new SQLException (
356- Messages .get ("ConnectionPluginManager.invokedAgainstOldConnection" , new Object []{methodInvokeOn })));
357- }
358- }
359-
360303 return executeWithSubscribedPlugins (
361304 jdbcMethod ,
362305 (plugin , func ) ->
@@ -635,9 +578,7 @@ public <T> T unwrap(Class<T> iface) throws SQLException {
635578 if (iface == ConnectionPluginManager .class ) {
636579 return iface .cast (this );
637580 }
638- if (iface == PluginService .class ) {
639- return iface .cast (this .pluginService );
640- }
581+
641582 if (this .plugins == null ) {
642583 return null ;
643584 }
@@ -647,6 +588,7 @@ public <T> T unwrap(Class<T> iface) throws SQLException {
647588 return iface .cast (p );
648589 }
649590 }
591+
650592 return null ;
651593 }
652594
0 commit comments