|
30 | 30 | import software.amazon.jdbc.JdbcMethod; |
31 | 31 | import software.amazon.jdbc.PluginService; |
32 | 32 | import software.amazon.jdbc.plugin.AbstractConnectionPlugin; |
| 33 | +import software.amazon.jdbc.states.SessionStateService; |
33 | 34 | import software.amazon.jdbc.util.Messages; |
34 | 35 | import software.amazon.jdbc.util.StringUtils; |
35 | 36 | import software.amazon.jdbc.util.WrapperUtils; |
@@ -89,13 +90,21 @@ private String getCacheQueryKey(String query) { |
89 | 90 | try { |
90 | 91 | Connection currentConn = pluginService.getCurrentConnection(); |
91 | 92 | DatabaseMetaData metadata = currentConn.getMetaData(); |
| 93 | + // Fetch and record the schema name if the session state doesn't currently have it |
| 94 | + SessionStateService sessionStateService = pluginService.getSessionStateService(); |
| 95 | + String schema = sessionStateService.getSchema().orElse(null); |
| 96 | + if (schema == null) { |
| 97 | + // Fetch the current schema name and store it in sessionStateService |
| 98 | + schema = currentConn.getSchema(); |
| 99 | + sessionStateService.setSchema(schema); |
| 100 | + } |
| 101 | + |
92 | 102 | LOGGER.finest("DB driver protocol " + pluginService.getDriverProtocol() |
93 | | - + ", schema: " + currentConn.getSchema() |
94 | 103 | + ", database product: " + metadata.getDatabaseProductName() + " " + metadata.getDatabaseProductVersion() |
95 | | - + ", user: " + metadata.getUserName() |
| 104 | + + ", schema: " + schema + ", user: " + metadata.getUserName() |
96 | 105 | + ", driver: " + metadata.getDriverName() + " " + metadata.getDriverVersion()); |
97 | 106 | // The cache key contains the schema name, user name, and the query string |
98 | | - String[] words = {currentConn.getSchema(), metadata.getUserName(), query}; |
| 107 | + String[] words = {schema, metadata.getUserName(), query}; |
99 | 108 | return String.join("_", words); |
100 | 109 | } catch (SQLException e) { |
101 | 110 | LOGGER.warning("Error getting session state: " + e.getMessage()); |
|
0 commit comments