- All Superinterfaces:
CommonDataSource,DataSource,Wrapper
DataSource pool API.
DataSourcePool pool = DataSourcePool.builder()
.setName("test")
.setUrl("jdbc:h2:mem:tests")
.setUsername("sa")
.setPassword("")
.build();
Connection connection = pool.getConnection();
-
Method Summary
Modifier and TypeMethodDescriptionstatic DataSourceBuilderbuilder()Return a builder for the DataSourcePool.Returns the reason, why the dataSource is down.booleanReturn true if the pool defaults to using autocommit.booleanReturns false when the dataSource is down.booleanisOnline()Return true if the DataSource is online.name()Return the dataSource name.voidoffline()Take the DataSource offline closing all connections and stopping heart beat checking.voidonline()Bring the DataSource online ensuring min connections and start heart beat checking.voidsetMaxSize(int max) Set a new maximum size.voidshutdown()Shutdown the pool.intsize()Return the current size of the pool.status(boolean reset) Return the current status of the connection pool.Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder, getParentLoggerMethods inherited from interface javax.sql.DataSource
createConnectionBuilder, getConnection, getConnection, getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriterMethods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
-
Method Details
-
builder
Return a builder for the DataSourcePool.DataSourcePool pool = DataSourcePool.builder() .setName("test") .setUrl("jdbc:h2:mem:tests") .setUsername("sa") .setPassword("") .build(); Connection connection = pool.getConnection(); -
name
String name()Return the dataSource name. -
size
int size()Return the current size of the pool. This includes both busy and idle connections. -
isAutoCommit
boolean isAutoCommit()Return true if the pool defaults to using autocommit. -
isOnline
boolean isOnline()Return true if the DataSource is online.Effectively the same as (synonym for)
isDataSourceUp(). -
isDataSourceUp
boolean isDataSourceUp()Returns false when the dataSource is down.Effectively the same as (synonym for)
isOnline(). -
online
Bring the DataSource online ensuring min connections and start heart beat checking.- Throws:
SQLException
-
offline
void offline()Take the DataSource offline closing all connections and stopping heart beat checking. -
shutdown
void shutdown()Shutdown the pool.This will close all the free connections, and then go into a wait loop, waiting for the busy connections to be freed.
This is functionally the same as
offline()but generally we expect to only shut down the pool once whereas we can expect to make many calls to offline() and online(). -
status
Return the current status of the connection pool.With reset true, the counters are reset.
-
dataSourceDownReason
SQLException dataSourceDownReason()Returns the reason, why the dataSource is down. -
setMaxSize
void setMaxSize(int max) Set a new maximum size.The pool will apply the new maximum and not require a restart.
-