Class GenericJdbcConnectionFactory
- java.lang.Object
-
- com.amazonaws.athena.connectors.jdbc.connection.GenericJdbcConnectionFactory
-
- All Implemented Interfaces:
JdbcConnectionFactory,AutoCloseable
- Direct Known Subclasses:
HiveJdbcConnectionFactory,SnowflakeConnectionFactory
public class GenericJdbcConnectionFactory extends Object implements JdbcConnectionFactory
Provides a generic jdbc connection factory that can be used to connect to standard databases. When running as a Glue managed connection (configOptions containsfas_token), uses direct DriverManager connections instead of HikariCP connection pooling.
-
-
Field Summary
Fields Modifier and Type Field Description protected DatabaseConnectionConfigdatabaseConnectionConfigprotected DatabaseConnectionInfodatabaseConnectionInfoprotected PropertiesjdbcPropertiesprotected static PatternSECRET_NAME_PATTERN
-
Constructor Summary
Constructors Constructor Description GenericJdbcConnectionFactory(DatabaseConnectionConfig databaseConnectionConfig, Map<String,String> properties, DatabaseConnectionInfo databaseConnectionInfo)Existing constructor — defaults to no configOptions (no Glue managed connection).GenericJdbcConnectionFactory(DatabaseConnectionConfig databaseConnectionConfig, Map<String,String> properties, DatabaseConnectionInfo databaseConnectionInfo, Map<String,String> configOptions)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the connection pool, releasing pooled connections and their background threads.ConnectiongetConnection(CredentialsProvider credentialsProvider)Retrieves database connection for a database type.protected ConnectiongetConnectionFromManagedPool(CredentialsProvider credentialsProvider)Returns a connection from the HikariCP connection pool, initializing the pool on first call.
-
-
-
Field Detail
-
SECRET_NAME_PATTERN
protected static final Pattern SECRET_NAME_PATTERN
-
databaseConnectionConfig
protected final DatabaseConnectionConfig databaseConnectionConfig
-
jdbcProperties
protected final Properties jdbcProperties
-
databaseConnectionInfo
protected final DatabaseConnectionInfo databaseConnectionInfo
-
-
Constructor Detail
-
GenericJdbcConnectionFactory
public GenericJdbcConnectionFactory(DatabaseConnectionConfig databaseConnectionConfig, Map<String,String> properties, DatabaseConnectionInfo databaseConnectionInfo)
Existing constructor — defaults to no configOptions (no Glue managed connection).
-
GenericJdbcConnectionFactory
public GenericJdbcConnectionFactory(DatabaseConnectionConfig databaseConnectionConfig, Map<String,String> properties, DatabaseConnectionInfo databaseConnectionInfo, Map<String,String> configOptions)
- Parameters:
databaseConnectionConfig- database connection configurationDatabaseConnectionConfigproperties- JDBC connection properties.databaseConnectionInfo- Contains JDBC driver and default port details.configOptions- environment/config options; whenfas_tokenis present, uses direct DriverManager connections.
-
-
Method Detail
-
getConnection
public Connection getConnection(CredentialsProvider credentialsProvider) throws Exception
Description copied from interface:JdbcConnectionFactoryRetrieves database connection for a database type.- Specified by:
getConnectionin interfaceJdbcConnectionFactory- Parameters:
credentialsProvider- jdbc user and password provider.- Returns:
- JDBC connection. See
Connection. - Throws:
Exception
-
getConnectionFromManagedPool
protected Connection getConnectionFromManagedPool(CredentialsProvider credentialsProvider) throws SQLException
Returns a connection from the HikariCP connection pool, initializing the pool on first call. Subclasses can call this directly to bypass theuseDirectConnectioncheck.- Parameters:
credentialsProvider- jdbc user and password provider, or null if no credentials.- Returns:
- JDBC connection from the pool.
- Throws:
SQLException- if a connection cannot be obtained.
-
close
public void close()
Closes the connection pool, releasing pooled connections and their background threads. The factory stays usable: a latergetConnectionrebuilds the pool, so closing a handler that is subsequently reused does not permanently break it.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceJdbcConnectionFactory
-
-