Class DuckdbDataSource
- All Implemented Interfaces:
AutoCloseable
,Wrapper
,CommonDataSource
,DataSource
,ManageableDataSource
This class extends Apache DBCP's BasicDataSource to provide connection pooling specifically for DuckDB. It uses a
custom DuckdbConnectionFactory
to create connections that leverage DuckDB's connection duplication feature.
The class accepts a list of SQL statements that are executed once to initialize the database (typically to load extensions like 'spatial' and 'parquet').
-
Field Summary
Fields inherited from class BasicDataSource
closed, connectionInitSqls, connectionPool, connectionProperties, dataSource, defaultAutoCommit, defaultCatalog, defaultReadOnly, defaultTransactionIsolation, driverClassLoader, driverClassName, initialSize, logWriter, maxActive, maxIdle, maxOpenPreparedStatements, maxWait, minEvictableIdleTimeMillis, minIdle, numTestsPerEvictionRun, password, poolPreparedStatements, testOnBorrow, testOnReturn, testWhileIdle, timeBetweenEvictionRunsMillis, url, username, validationQuery, validationQueryTimeout
-
Constructor Summary
ConstructorsConstructorDescriptionDuckdbDataSource
(List<String> databaseInitSqls) Constructs a new DuckdbDataSource. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this data source, releasing all associated resources.protected DuckdbConnectionFactory
Creates a DuckDB-specific connection factory.Methods inherited from class BasicDataSource
addConnectionProperty, createConnectionPool, createDataSource, createDataSourceInstance, createPoolableConnectionFactory, getConnection, getConnection, getConnectionInitSqls, getDefaultAutoCommit, getDefaultCatalog, getDefaultReadOnly, getDefaultTransactionIsolation, getDriverClassLoader, getDriverClassName, getInitialSize, getLogAbandoned, getLoginTimeout, getLogWriter, getMaxActive, getMaxIdle, getMaxOpenPreparedStatements, getMaxWait, getMinEvictableIdleTimeMillis, getMinIdle, getNumActive, getNumIdle, getNumTestsPerEvictionRun, getPassword, getRemoveAbandoned, getRemoveAbandonedTimeout, getTestOnBorrow, getTestOnReturn, getTestWhileIdle, getTimeBetweenEvictionRunsMillis, getUrl, getUsername, getValidationQuery, getValidationQueryTimeout, isAccessToUnderlyingConnectionAllowed, isClosed, isPoolPreparedStatements, isWrapperFor, log, removeConnectionProperty, setAccessToUnderlyingConnectionAllowed, setConnectionInitSqls, setConnectionProperties, setDefaultAutoCommit, setDefaultCatalog, setDefaultReadOnly, setDefaultTransactionIsolation, setDriverClassLoader, setDriverClassName, setInitialSize, setLogAbandoned, setLoginTimeout, setLogWriter, setMaxActive, setMaxIdle, setMaxOpenPreparedStatements, setMaxWait, setMinEvictableIdleTimeMillis, setMinIdle, setNumTestsPerEvictionRun, setPassword, setPoolPreparedStatements, setRemoveAbandoned, setRemoveAbandonedTimeout, setTestOnBorrow, setTestOnReturn, setTestWhileIdle, setTimeBetweenEvictionRunsMillis, setUrl, setUsername, setValidationQuery, setValidationQueryTimeout, unwrap, validateConnectionFactory
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface CommonDataSource
createShardingKeyBuilder
Methods inherited from interface DataSource
createConnectionBuilder, getConnection, getConnection, getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter
Methods inherited from interface Wrapper
isWrapperFor, unwrap
-
Constructor Details
-
DuckdbDataSource
Constructs a new DuckdbDataSource.- Parameters:
databaseInitSqls
- A list of SQL statements to execute once when initializing the database (typically used to load DuckDB extensions like 'spatial' and 'parquet')- Throws:
NullPointerException
- if databaseInitSqls is null
-
-
Method Details
-
createConnectionFactory
Creates a DuckDB-specific connection factory.This method overrides the parent class implementation to create a
DuckdbConnectionFactory
instead of the default one. It configures connection properties and passes the database initialization SQL statements to the factory.- Overrides:
createConnectionFactory
in classBasicDataSource
- Returns:
- The created DuckdbConnectionFactory
- Throws:
SQLException
- if there is an error creating the connection factory
-
close
Closes this data source, releasing all associated resources.This method ensures proper cleanup by first closing the underlying DuckdbConnectionFactory (which closes the sentinel connection) and then calling the parent class close method.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceManageableDataSource
- Overrides:
close
in classBasicDataSource
- Throws:
SQLException
- if there is an error closing the data source
-
getParentLogger
- Specified by:
getParentLogger
in interfaceCommonDataSource
- Throws:
SQLFeatureNotSupportedException
-