public final class SingletonConnectionPoolComponent extends Object implements ConnectionPoolComponent
ConnectionPoolComponent that uses a
semaphore to make sure that only one connection is able to communicate with
the database at a time. This is useful for file based databases where locking
is an issue.
To enable the SingletonConnectionPoolComponent, add the following to
the Speedment application builder:
var app = new DemoApplicationBuilder()
.withComponent(SingletonConnectionPoolComponent.class)
.build();
It will automatically replace the default connection pool. There are two
modes in which the pool can work. It can either block until a connection
becomes available or throw an exception. To control this behaviour, use the
configuration flag connectionpool.blocking=true. The default value is
false, meaning that the pool will throw an exception instead of
blocking if multiple connections to the same Dbms are requested.| Constructor and Description |
|---|
SingletonConnectionPoolComponent() |
| Modifier and Type | Method and Description |
|---|---|
PoolableConnection |
getConnection(com.speedment.runtime.config.Dbms dbms)
Returns a {link PoolableConnection} from this connection pool.
|
PoolableConnection |
getConnection(String uri,
String user,
char[] password)
Returns a {link PoolableConnection} from this connection pool.
|
long |
getMaxAge()
Returns the maximum age for recyclable connections.
|
int |
getMaxRetainSize()
Returns the maximum number of connection this pool will retain when
connections are returned.
|
int |
leaseSize()
Returns the current number of leased connections from the pool.
|
Connection |
newConnection(com.speedment.runtime.config.Dbms dbms)
Creates and returns a new
Connection for the given parameters. |
Connection |
newConnection(String uri,
String user,
char[] password)
Creates and returns a new
Connection for the given parameters. |
int |
poolSize()
Returns the current number of idle connections in the pool.
|
void |
returnConnection(PoolableConnection poolableConnection)
Returns a
PoolableConnection to the pool. |
public PoolableConnection getConnection(com.speedment.runtime.config.Dbms dbms)
ConnectionPoolComponentgetConnection in interface ConnectionPoolComponentdbms - the dbms to connect toPoolableConnection from this connection poolpublic PoolableConnection getConnection(String uri, String user, char[] password)
ConnectionPoolComponentgetConnection in interface ConnectionPoolComponenturi - the connection URI for the connectoruser - the user for the connectorpassword - the password for the connectorPoolableConnection from this connection poolpublic Connection newConnection(String uri, String user, char[] password)
ConnectionPoolComponentConnection for the given parameters.
This method is called whenever the pool needs to allocate a new
Connection.newConnection in interface ConnectionPoolComponenturi - the connection URI for the connectoruser - the user for the connectorpassword - the password for the connectorConnection for the given parameterspublic Connection newConnection(com.speedment.runtime.config.Dbms dbms)
ConnectionPoolComponentConnection for the given parameters.
This method is called whenever the pool needs to allocate a new
Connection.newConnection in interface ConnectionPoolComponentdbms - the dbms to connect toConnection for the given parameterspublic void returnConnection(PoolableConnection poolableConnection)
ConnectionPoolComponentPoolableConnection to the pool. If the
PoolableConnection has expired or has a closed underlying connection, it
will be discarded from the pool.returnConnection in interface ConnectionPoolComponentpoolableConnection - to return to the poolpublic int poolSize()
ConnectionPoolComponentpoolSize in interface ConnectionPoolComponentpublic int leaseSize()
ConnectionPoolComponentleaseSize in interface ConnectionPoolComponentpublic int getMaxRetainSize()
ConnectionPoolComponentgetMaxRetainSize in interface ConnectionPoolComponentpublic long getMaxAge()
ConnectionPoolComponentgetMaxAge in interface ConnectionPoolComponentCopyright © 2019 Speedment, Inc.. All rights reserved.