public class JdbcPooledConnectionSource extends JdbcConnectionSource implements com.j256.ormlite.support.ConnectionSource
NOTE: If you are using the Spring type wiring in Java, initialize()
should be called after all of the
set methods. In Spring XML, init-method="initialize" should be used.
NOTE: This class spawns a thread to test the pooled connections that are in the free-list as a keep-alive
mechanism. It will test any dormant connections every so often to see if they are still valid. If this is not the
behavior that you want then call setCheckConnectionsEveryMillis(long)
with 0 to disable the thread. You can
also call setTestBeforeGet(boolean)
and set it to true to test the connection before it is handed back to
you.
Modifier and Type | Class and Description |
---|---|
protected static class |
JdbcPooledConnectionSource.ConnectionMetaData
Class to hold the connection and its meta data.
|
Modifier and Type | Field and Description |
---|---|
protected Map<com.j256.ormlite.support.DatabaseConnection,JdbcPooledConnectionSource.ConnectionMetaData> |
connectionMap |
connection, databaseType, initialized, url
Constructor and Description |
---|
JdbcPooledConnectionSource() |
JdbcPooledConnectionSource(String url) |
JdbcPooledConnectionSource(String url,
com.j256.ormlite.db.DatabaseType databaseType) |
JdbcPooledConnectionSource(String url,
String username,
String password) |
JdbcPooledConnectionSource(String url,
String username,
String password,
com.j256.ormlite.db.DatabaseType databaseType) |
Modifier and Type | Method and Description |
---|---|
void |
clearSpecialConnection(com.j256.ormlite.support.DatabaseConnection connection) |
void |
close() |
protected void |
closeConnection(com.j256.ormlite.support.DatabaseConnection connection)
This should be inside of synchronized (lock) stanza.
|
protected void |
closeConnectionQuietly(JdbcPooledConnectionSource.ConnectionMetaData connMetaData)
Must be called inside of synchronized(lock)
|
int |
getCloseCount()
Return the approximate number of connections closed over the life of the pool.
|
int |
getCurrentConnectionsFree()
Return the number of currently freed connections in the free list.
|
int |
getCurrentConnectionsManaged()
Return the number of current connections that we are tracking.
|
int |
getMaxConnectionsEverUsed()
Return the approximate maximum number of connections in use at one time.
|
int |
getOpenCount()
Return the approximate number of connections opened over the life of the pool.
|
com.j256.ormlite.support.DatabaseConnection |
getReadOnlyConnection(String tableName) |
com.j256.ormlite.support.DatabaseConnection |
getReadWriteConnection(String tableName) |
int |
getReleaseCount()
Return the approximate number of connections released over the life of the pool.
|
int |
getTestLoopCount()
Mostly for testing purposes to see how many times our test loop ran.
|
void |
initialize()
Initialize the class after the setters have been called.
|
boolean |
isOpen(String tableName) |
boolean |
isSingleConnection(String tableName) |
void |
releaseConnection(com.j256.ormlite.support.DatabaseConnection connection) |
boolean |
saveSpecialConnection(com.j256.ormlite.support.DatabaseConnection connection) |
void |
setCheckConnectionsEveryMillis(long checkConnectionsEveryMillis)
There is an internal thread which checks each of the database connections as a keep-alive mechanism.
|
void |
setMaxConnectionAgeMillis(long maxConnectionAgeMillis)
Set the number of milliseconds that a connection can stay open before being closed.
|
void |
setMaxConnectionsFree(int maxConnectionsFree)
Set the number of connections that can be unused in the available list.
|
void |
setTestBeforeGet(boolean testBeforeGetFromPool) |
protected boolean |
testConnection(JdbcPooledConnectionSource.ConnectionMetaData connMetaData) |
makeConnection, setLoginTimeoutSecs, setPassword, setUsername
closeQuietly, getDatabaseType, getUrl, setDatabaseConnectionProxyFactory, setDatabaseType, setUrl
clearSpecial, getSavedConnection, getSpecialConnection, isSavedConnection, isSingleConnection, saveSpecial
protected final Map<com.j256.ormlite.support.DatabaseConnection,JdbcPooledConnectionSource.ConnectionMetaData> connectionMap
public JdbcPooledConnectionSource()
public JdbcPooledConnectionSource(String url) throws SQLException
SQLException
public JdbcPooledConnectionSource(String url, com.j256.ormlite.db.DatabaseType databaseType) throws SQLException
SQLException
public JdbcPooledConnectionSource(String url, String username, String password) throws SQLException
SQLException
public JdbcPooledConnectionSource(String url, String username, String password, com.j256.ormlite.db.DatabaseType databaseType) throws SQLException
SQLException
public void initialize() throws SQLException
BaseJdbcConnectionSource
initialize
in class BaseJdbcConnectionSource
SQLException
- If the driver associated with the database URL is not found in the classpath.public void close() throws Exception
close
in interface AutoCloseable
close
in class BaseJdbcConnectionSource
Exception
public com.j256.ormlite.support.DatabaseConnection getReadOnlyConnection(String tableName) throws SQLException
getReadOnlyConnection
in interface com.j256.ormlite.support.ConnectionSource
getReadOnlyConnection
in class BaseJdbcConnectionSource
SQLException
public com.j256.ormlite.support.DatabaseConnection getReadWriteConnection(String tableName) throws SQLException
getReadWriteConnection
in interface com.j256.ormlite.support.ConnectionSource
getReadWriteConnection
in class BaseJdbcConnectionSource
SQLException
public void releaseConnection(com.j256.ormlite.support.DatabaseConnection connection) throws SQLException
releaseConnection
in interface com.j256.ormlite.support.ConnectionSource
releaseConnection
in class BaseJdbcConnectionSource
SQLException
public boolean saveSpecialConnection(com.j256.ormlite.support.DatabaseConnection connection) throws SQLException
saveSpecialConnection
in interface com.j256.ormlite.support.ConnectionSource
saveSpecialConnection
in class BaseJdbcConnectionSource
SQLException
public void clearSpecialConnection(com.j256.ormlite.support.DatabaseConnection connection)
clearSpecialConnection
in interface com.j256.ormlite.support.ConnectionSource
clearSpecialConnection
in class BaseJdbcConnectionSource
public boolean isOpen(String tableName)
isOpen
in interface com.j256.ormlite.support.ConnectionSource
isOpen
in class BaseJdbcConnectionSource
public boolean isSingleConnection(String tableName)
isSingleConnection
in interface com.j256.ormlite.support.ConnectionSource
isSingleConnection
in class BaseJdbcConnectionSource
public void setMaxConnectionsFree(int maxConnectionsFree)
public void setMaxConnectionAgeMillis(long maxConnectionAgeMillis)
public int getOpenCount()
public int getReleaseCount()
public int getCloseCount()
public int getMaxConnectionsEverUsed()
public int getCurrentConnectionsFree()
public int getCurrentConnectionsManaged()
public void setCheckConnectionsEveryMillis(long checkConnectionsEveryMillis)
public void setTestBeforeGet(boolean testBeforeGetFromPool)
public int getTestLoopCount()
protected void closeConnection(com.j256.ormlite.support.DatabaseConnection connection) throws SQLException
SQLException
protected void closeConnectionQuietly(JdbcPooledConnectionSource.ConnectionMetaData connMetaData)
protected boolean testConnection(JdbcPooledConnectionSource.ConnectionMetaData connMetaData)
This documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.