public class DataSourceFactory extends Object implements PooledDataSourceFactory
ManagedDataSource
s.
Configuration Parameters:
Name | Default | Description |
url |
REQUIRED | The URL of the server. |
driverClass |
none |
The fully qualified class name of the JDBC driver class.
Only required if there were no JDBC drivers registered in META-INF/services/java.sql.Driver .
|
user |
none | The username used to connect to the server. |
password |
none | The password used to connect to the server. |
removeAbandoned |
false |
Remove abandoned connections if they exceed the removeAbandonedTimeout .
If set to true a connection is considered abandoned and eligible for removal if it has
been in use longer than the removeAbandonedTimeout and the condition for
abandonWhenPercentageFull is met.
|
removeAbandonedTimeout |
60 seconds | The time before a database connection can be considered abandoned. |
abandonWhenPercentageFull |
0 |
Connections that have been abandoned (timed out) won't get closed and reported up
unless the number of connections in use are above the percentage defined by
abandonWhenPercentageFull . The value should be between 0-100.
|
alternateUsernamesAllowed |
false |
Set to true if the call
getConnection(username,password)
is allowed. This is used for when the pool is used by an application accessing
multiple schemas. There is a performance impact turning this option on, even when not
used.
|
commitOnReturn |
false |
Set to true if you want the connection pool to commit any pending transaction when a connection is returned. |
rollbackOnReturn |
false |
Set to true if you want the connection pool to rollback any pending transaction when a connection is returned. |
autoCommitByDefault |
JDBC driver's default | The default auto-commit state of the connections. |
readOnlyByDefault |
JDBC driver's default | The default read-only state of the connections. |
properties |
none | Any additional JDBC driver parameters. |
defaultCatalog |
none | The default catalog to use for the connections. |
defaultTransactionIsolation |
JDBC driver default |
The default transaction isolation to use for the connections. Can be one of
none , default , read-uncommitted , read-committed ,
repeatable-read , or serializable .
|
useFairQueue |
true |
If true , calls to getConnection are handled in a FIFO manner.
|
initialSize |
10 |
The initial size of the connection pool. May be zero, which will allow you to start
the connection pool without requiring the DB to be up. In the latter case the minSize
must also be set to zero.
|
minSize |
10 | The minimum size of the connection pool. |
maxSize |
100 | The maximum size of the connection pool. |
initializationQuery |
none | A custom query to be run when a connection is first created. |
logAbandonedConnections |
false |
If true , logs stack traces of abandoned connections.
|
logValidationErrors |
false |
If true , logs errors when connections fail validation.
|
maxConnectionAge |
none |
If set, connections which have been open for longer than maxConnectionAge are
closed when returned.
|
maxWaitForConnection |
30 seconds | If a request for a connection is blocked for longer than this period, an exception will be thrown. |
minIdleTime |
1 minute | The minimum amount of time an connection must sit idle in the pool before it is eligible for eviction. |
validationQuery |
SELECT 1 |
The SQL query that will be used to validate connections from this pool before returning them to the caller or pool. If specified, this query does not have to return any data, it just can't throw a SQLException. |
validationQueryTimeout |
none | The timeout before a connection validation queries fail. |
checkConnectionWhileIdle |
true |
Set to true if query validation should take place while the connection is idle. |
checkConnectionOnBorrow |
false |
Whether or not connections will be validated before being borrowed from the pool. If the connection fails to validate, it will be dropped from the pool, and another will be borrowed. |
checkConnectionOnConnect |
true |
Whether or not connections will be validated before being added to the pool. If the connection fails to validate, it won't be added to the pool. |
checkConnectionOnReturn |
false |
Whether or not connections will be validated after being returned to the pool. If the connection fails to validate, it will be dropped from the pool. |
autoCommentsEnabled |
true |
Whether or not ORMs should automatically add comments. |
evictionInterval |
5 seconds | The amount of time to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing. |
validationInterval |
30 seconds | To avoid excess validation, only run validation once every interval. |
validatorClassName |
(none) |
Name of a class of a custom Validator
implementation, which will be used for validating connections.
|
jdbcInterceptors |
(none) |
A semicolon separated list of classnames extending
JdbcInterceptor
|
ignoreExceptionOnPreLoad |
false |
Flag whether ignore error of connection creation while initializing the pool. Set to true if you want to ignore error of connection creation while initializing the pool. Set to false if you want to fail the initialization of the pool by throwing exception. |
Modifier and Type | Class and Description |
---|---|
static class |
DataSourceFactory.TransactionIsolation |
Constructor and Description |
---|
DataSourceFactory() |
public boolean isAutoCommentsEnabled()
PooledDataSourceFactory
isAutoCommentsEnabled
in interface PooledDataSourceFactory
true
, if allowedpublic void setAutoCommentsEnabled(boolean autoCommentsEnabled)
@Nullable public String getDriverClass()
PooledDataSourceFactory
getDriverClass
in interface PooledDataSourceFactory
public String getUrl()
PooledDataSourceFactory
getUrl
in interface PooledDataSourceFactory
public void setUrl(String url)
public Map<String,String> getProperties()
PooledDataSourceFactory
getProperties
in interface PooledDataSourceFactory
public Duration getMaxWaitForConnection()
public void setMaxWaitForConnection(Duration maxWaitForConnection)
public Optional<String> getValidationQuery()
PooledDataSourceFactory
getValidationQuery
in interface PooledDataSourceFactory
@Deprecated public String getHealthCheckValidationQuery()
getValidationQuery()
insteadPooledDataSourceFactory
getHealthCheckValidationQuery
in interface PooledDataSourceFactory
public int getMinSize()
public void setMinSize(int minSize)
public int getMaxSize()
public void setMaxSize(int maxSize)
public boolean getCheckConnectionWhileIdle()
public void setCheckConnectionWhileIdle(boolean checkConnectionWhileIdle)
@Deprecated public boolean isDefaultReadOnly()
getReadOnlyByDefault()
instead@Deprecated public void setDefaultReadOnly(boolean defaultReadOnly)
setReadOnlyByDefault(Boolean)
instead@ValidationMethod(message=".minSize must be less than or equal to maxSize") public boolean isMinSizeLessThanMaxSize()
@ValidationMethod(message=".initialSize must be less than or equal to maxSize") public boolean isInitialSizeLessThanMaxSize()
@ValidationMethod(message=".initialSize must be greater than or equal to minSize") public boolean isInitialSizeGreaterThanMinSize()
public int getAbandonWhenPercentageFull()
public void setAbandonWhenPercentageFull(int percentage)
public boolean isAlternateUsernamesAllowed()
public void setAlternateUsernamesAllowed(boolean allow)
public boolean getCommitOnReturn()
public boolean getRollbackOnReturn()
public void setCommitOnReturn(boolean commitOnReturn)
public void setRollbackOnReturn(boolean rollbackOnReturn)
public DataSourceFactory.TransactionIsolation getDefaultTransactionIsolation()
public void setDefaultTransactionIsolation(DataSourceFactory.TransactionIsolation isolation)
public boolean getUseFairQueue()
public void setUseFairQueue(boolean fair)
public int getInitialSize()
public void setInitialSize(int initialSize)
public boolean getLogAbandonedConnections()
public void setLogAbandonedConnections(boolean log)
public boolean getLogValidationErrors()
public void setLogValidationErrors(boolean log)
public Duration getMinIdleTime()
public void setMinIdleTime(Duration time)
public boolean getCheckConnectionOnBorrow()
public void setCheckConnectionOnBorrow(boolean checkConnectionOnBorrow)
public boolean getCheckConnectionOnConnect()
public void setCheckConnectionOnConnect(boolean checkConnectionOnConnect)
public boolean getCheckConnectionOnReturn()
public void setCheckConnectionOnReturn(boolean checkConnectionOnReturn)
public Duration getEvictionInterval()
public void setEvictionInterval(Duration interval)
public Duration getValidationInterval()
public void setValidationInterval(Duration validationInterval)
public Optional<Duration> getValidationQueryTimeout()
PooledDataSourceFactory
getValidationQueryTimeout
in interface PooledDataSourceFactory
Duration
@Deprecated public Optional<Duration> getHealthCheckValidationTimeout()
getValidationQueryTimeout()
insteadPooledDataSourceFactory
getHealthCheckValidationTimeout
in interface PooledDataSourceFactory
Duration
public void setValidationQueryTimeout(@Nullable Duration validationQueryTimeout)
public boolean isRemoveAbandoned()
public void setRemoveAbandoned(boolean removeAbandoned)
public Duration getRemoveAbandonedTimeout()
public void setRemoveAbandonedTimeout(Duration removeAbandonedTimeout)
public boolean isIgnoreExceptionOnPreLoad()
public void setIgnoreExceptionOnPreLoad(boolean ignoreExceptionOnPreLoad)
public void asSingleConnectionPool()
PooledDataSourceFactory
asSingleConnectionPool
in interface PooledDataSourceFactory
public ManagedDataSource build(com.codahale.metrics.MetricRegistry metricRegistry, String name)
PooledDataSourceFactory
build
in interface PooledDataSourceFactory
metricRegistry
- the application metric registryname
- name of the connection poolManagedDataSource
Copyright © 2011. All rights reserved.