public class ConnectionProperties extends Object
| Constructor and Description |
|---|
ConnectionProperties()
Constructs an empty set of connection properties, with most values being set to
null, 0, or empty
(depending on the type of the property). |
ConnectionProperties(ConnectionProperties properties)
Creates a set of connection properties from an exist set of connection properties, making a defensive copy.
|
| Modifier and Type | Method and Description |
|---|---|
Map<String,String> |
getAdditionalProperties() |
int |
getDefaultTransactionIsolation() |
String |
getDriver() |
long |
getMaxConnLifetimeMillis() |
int |
getMaxIdle() |
int |
getMaxTotal() |
long |
getMaxWaitMillis() |
long |
getMinEvictableIdleTimeMillis() |
int |
getMinIdle() |
int |
getNumTestsPerEvictionRun() |
String |
getPassword() |
long |
getSoftMinEvictableIdleTimeMillis() |
long |
getTimeBetweenEvictionRunsMillis() |
String |
getUrl() |
String |
getUsername() |
String |
getValidationQuery() |
boolean |
isCacheState() |
boolean |
isDefaultAutoCommit() |
boolean |
isDefaultReadOnly() |
boolean |
isLifo() |
boolean |
isTestOnBorrow() |
boolean |
isTestOnCreate() |
boolean |
isTestOnReturn() |
boolean |
isTestWhileIdle() |
void |
setAdditionalProperties(Map<String,String> additionalProperties)
Any additional properties which have not been parsed, and for which no getter/setter exists, but are to be
stored in this object nevertheless.
|
void |
setCacheState(boolean cacheState)
If
true, the pooled connection will cache the current readOnly and
autoCommit settings when first read or written and on all subsequent writes. |
void |
setDefaultAutoCommit(boolean defaultAutoCommit)
The default auto-commit state of connections created by the pool.
|
void |
setDefaultReadOnly(boolean defaultReadOnly)
The default read-only state of connections created by the pool.
|
void |
setDefaultTransactionIsolation(int defaultTransactionIsolation)
The default TransactionIsolation state of connections created by this pool.
|
void |
setDriver(String driver)
The JDBC database driver class
|
void |
setLifo(boolean lifo)
True means that the pool returns the most recently used ("last in") connection in the pool (if
there are idle connections available). |
void |
setMaxConnLifetimeMillis(long maxConnLifetimeMillis)
The maximum lifetime in milliseconds of a connection.
|
void |
setMaxIdle(int maxIdle)
The maximum number of connections that can remain idle in the pool, without extra ones being released, or
negative for no limit.
|
void |
setMaxTotal(int maxTotal)
The maximum number of active connections that can be allocated from this pool at the same time, or negative
for no limit.
|
void |
setMaxWaitMillis(long maxWaitMillis)
The maximum number of milliseconds that the pool will wait (when there are no available connections) for a
connection to be returned before throwing an exception, or -1 to wait indefinitely.
|
void |
setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
The minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle
object evictor (if any).
|
void |
setMinIdle(int minIdle)
The minimum number of connections that can remain idle in the pool, without extra ones being created, or zero
to create none.
|
void |
setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
The number of objects to examine during each run of the idle object evictor thread (if any).
|
void |
setPassword(String password)
The password for the connection
|
void |
setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis)
The minimum amount of time a connection may sit idle in the pool before it is eligible for eviction by the idle
connection evictor, with the extra condition that at least "
minIdle" connections remain in the pool. |
void |
setTestOnBorrow(boolean testOnBorrow)
The indication of whether objects will be validated before being borrowed from the pool.
|
void |
setTestOnCreate(boolean testOnCreate)
The indication of whether objects will be validated after creation.
|
void |
setTestOnReturn(boolean testOnReturn)
The indication of whether objects will be validated before being returned to the pool.
|
void |
setTestWhileIdle(boolean testWhileIdle)
The indication of whether objects will be validated by the idle object evictor (if any).
|
void |
setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
The number of milliseconds to sleep between runs of the idle object evictor thread.
|
void |
setUrl(String url)
The JDBC database URL of the form
jdbc:subprotocol:subname |
void |
setUsername(String username)
The username for the connection
|
void |
setValidationQuery(String validationQuery)
The SQL query that will be used to validate connections from the pool before returning them to the caller.
|
public ConnectionProperties()
null, 0, or empty
(depending on the type of the property). Usually this constructor is used if this configuration POJO is populated
in an automated fashion (e.g. injection). If you need to build them manually (possibly with defaults), use or
create a properties builder.
You can change the defaults with the setters. If you need more control over the pool than what is provided by the available setters, consider using a JNDI controlled connection pool instead.
public ConnectionProperties(ConnectionProperties properties)
properties - The set of connection properties to copyNullPointerException - When properties is nullpublic final String getDriver()
setDriver(String)public final void setDriver(String driver)
driver - The JDBC database driver classpublic final String getUrl()
jdbc:subprotocol:subnamesetUrl(String)public final void setUrl(String url)
jdbc:subprotocol:subnameurl - The JDBC database URLpublic final String getUsername()
setUsername(String)public final void setUsername(String username)
username - The username for the connectionpublic final String getPassword()
setUrl(String)public final void setPassword(String password)
password - The password for the connectionpublic final int getMaxTotal()
setMaxTotal(int)public final void setMaxTotal(int maxTotal)
maxTotal - the maximum numbers of active connectionspublic final int getMaxIdle()
setMaxIdle(int)public final void setMaxIdle(int maxIdle)
maxIdle - the maximum number of idle connectionspublic final int getMinIdle()
setMinIdle(int)public final void setMinIdle(int minIdle)
minIdle - the minimum number of idle connectionsIllegalArgumentException - When the provided value of minIdle is out of rangepublic final long getMaxWaitMillis()
setMaxWaitMillis(long)public final void setMaxWaitMillis(long maxWaitMillis)
maxWaitMillis - the maximum number of milliseconds that the pool will wait for a connectionIllegalArgumentException - When the provided value of maxWaitMillis is out of rangepublic final boolean isTestOnCreate()
setTestOnCreate(boolean)public final void setTestOnCreate(boolean testOnCreate)
testOnCreate - the indication of whether objects will be validated after creationpublic final boolean isTestOnBorrow()
setTestOnBorrow(boolean)public final void setTestOnBorrow(boolean testOnBorrow)
testOnBorrow - the indication of whether objects will be validated before being borrowed from the poolpublic final boolean isTestOnReturn()
setTestOnReturn(boolean)public final void setTestOnReturn(boolean testOnReturn)
testOnReturn - the indication of whether objects will be validated before being returned to the poolpublic final boolean isTestWhileIdle()
setTestWhileIdle(boolean)public final void setTestWhileIdle(boolean testWhileIdle)
testWhileIdle - the indication of whether objects will be validated by the idle object evictor (if any)public final long getTimeBetweenEvictionRunsMillis()
setTimeBetweenEvictionRunsMillis(long)public final void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
timeBetweenEvictionRunsMillis - the number of milliseconds to sleep between runs of the idle object evictor
threadpublic final int getNumTestsPerEvictionRun()
setNumTestsPerEvictionRun(int)public final void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
numTestsPerEvictionRun - the number of objects to examine during each run of the idle object evictor thread
(if any)IllegalArgumentException - When the provided value of numTestsPerEvictionRun is out of rangepublic final long getMinEvictableIdleTimeMillis()
setMinEvictableIdleTimeMillis(long)public final void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
minEvictableIdleTimeMillis - minimum amount of time an object may sit idle in the pool before it is
eligable for eviction by the idle object evictor (if any).public final long getSoftMinEvictableIdleTimeMillis()
setSoftMinEvictableIdleTimeMillis(long)public final void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis)
minIdle" connections remain in the pool.
When miniEvictableIdleTimeMillis is set to a positive value,
miniEvictableIdleTimeMillis is examined first by the idle connection evictor - i.e. when idle
connections are visited by the evictor, idle time is first compared against
miniEvictableIdleTimeMillis (without considering the number of idle connections in the pool) and
then against softMinEvictableIdleTimeMillis, including the minIdle constraint.softMinEvictableIdleTimeMillis - minimum amount of time a connection may sit idle in the pool before it is
eligible for eviction by the idle connection evictor, with the extra
condition that at least "minIdle" connections remain in the pool.public final boolean isLifo()
true if the pool returns the most recently used ("last in") connection, false
the pool behaves as a FIFO queuesetLifo(boolean)public final void setLifo(boolean lifo)
True means that the pool returns the most recently used ("last in") connection in the pool (if
there are idle connections available). False means that the pool behaves as a FIFO queue -
connections are taken from the idle instance pool in the order that they are returned to the pool.lifo - true if the pool returns the most recently used ("last in") connection,
false the pool behaves as a FIFO queuepublic final boolean isDefaultAutoCommit()
setDefaultAutoCommit(boolean)public final void setDefaultAutoCommit(boolean defaultAutoCommit)
defaultAutoCommit - The default auto-commit state of connections created by the poolpublic final boolean isDefaultReadOnly()
setDefaultReadOnly(boolean)public final void setDefaultReadOnly(boolean defaultReadOnly)
Note that some drivers do not support read only mode.
defaultReadOnly - The default read-only state of connections created by the poolpublic final int getDefaultTransactionIsolation()
setDefaultTransactionIsolation(int)public final void setDefaultTransactionIsolation(int defaultTransactionIsolation)
The following values are allowed:
defaultTransactionIsolation - The default TransactionIsolation state of connections created by this poolConnectionpublic final boolean isCacheState()
true, the pooled connection will cache the current readOnly and
autoCommit settings when first read or written and on all subsequent writessetCacheState(boolean)public final void setCacheState(boolean cacheState)
true, the pooled connection will cache the current readOnly and
autoCommit settings when first read or written and on all subsequent writes. This removes the need
for additional database queries for any further calls to the getter. If the underlying connection is accessed
directly and the readOnly and/or autoCommit settings changed the cached values will not reflect the
current state. In this case, caching should be disabled by setting this attribute to false.cacheState - If true, the pooled connection will cache the current readOnly and
autoCommit settings when first read or written and on all subsequent writespublic final String getValidationQuery()
setValidationQuery(String)public final void setValidationQuery(String validationQuery)
null), connections will be validation by calling the isValid() method.validationQuery - The SQL query that will be used to validate connections from the pool before returning
them to the callerpublic final long getMaxConnLifetimeMillis()
setMaxConnLifetimeMillis(long)public final void setMaxConnLifetimeMillis(long maxConnLifetimeMillis)
maxConnLifetimeMillis - The maximum lifetime in milliseconds of a connectionpublic final Map<String,String> getAdditionalProperties()
setAdditionalProperties(Map)public final void setAdditionalProperties(Map<String,String> additionalProperties)
This property is commonly used to preserve original properties from upstream components that are to be passed on to downstream components unchanged. This properties set may or may not include properties that have been extracted from the map, and been made available through this POJO.
Note that these additional properties may be null or empty, even in a fully populated POJO where
other properties commonly have values assigned to.
additionalProperties - The additional properties to storeCopyright © 2014–2015 Michael Beiter