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(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(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(Dbms dbms)
ConnectionPoolComponent
getConnection
in interface ConnectionPoolComponent
dbms
- the dbms to connect toPoolableConnection
from this connection poolpublic PoolableConnection getConnection(String uri, String user, char[] password)
ConnectionPoolComponent
getConnection
in interface ConnectionPoolComponent
uri
- 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)
ConnectionPoolComponent
Connection
for the given parameters.
This method is called whenever the pool needs to allocate a new
Connection.newConnection
in interface ConnectionPoolComponent
uri
- the connection URI for the connectoruser
- the user for the connectorpassword
- the password for the connectorConnection
for the given parameterspublic Connection newConnection(Dbms dbms)
ConnectionPoolComponent
Connection
for the given parameters.
This method is called whenever the pool needs to allocate a new
Connection.newConnection
in interface ConnectionPoolComponent
dbms
- the dbms to connect toConnection
for the given parameterspublic void returnConnection(PoolableConnection poolableConnection)
ConnectionPoolComponent
PoolableConnection
to the pool. If the
PoolableConnection has expired or has a closed underlying connection, it
will be discarded from the pool.returnConnection
in interface ConnectionPoolComponent
poolableConnection
- to return to the poolpublic int poolSize()
ConnectionPoolComponent
poolSize
in interface ConnectionPoolComponent
public int leaseSize()
ConnectionPoolComponent
leaseSize
in interface ConnectionPoolComponent
public int getMaxRetainSize()
ConnectionPoolComponent
getMaxRetainSize
in interface ConnectionPoolComponent
public long getMaxAge()
ConnectionPoolComponent
getMaxAge
in interface ConnectionPoolComponent
Copyright © 2019 Speedment, Inc.. All rights reserved.