|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.j256.ormlite.support.BaseConnectionSource
com.j256.ormlite.jdbc.JdbcConnectionSource
com.j256.ormlite.jdbc.JdbcPooledConnectionSource
public class JdbcPooledConnectionSource
Implementation of the ConnectionSource interface that supports basic pooled connections. New connections are created on demand only if there are no dormant connections otherwise released connections will be reused. This class is reentrant and can handle requests from multiple threads.
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.
Field Summary |
---|
Fields inherited from class com.j256.ormlite.jdbc.JdbcConnectionSource |
---|
databaseType, initialized |
Constructor Summary | |
---|---|
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)
|
Method Summary | |
---|---|
void |
clearSpecialConnection(com.j256.ormlite.support.DatabaseConnection connection)
|
void |
close()
|
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()
|
com.j256.ormlite.support.DatabaseConnection |
getReadWriteConnection()
|
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()
|
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)
|
void |
setUsesTransactions(boolean usesTransactions)
Deprecated. No longer supported and can be removed. |
Methods inherited from class com.j256.ormlite.jdbc.JdbcConnectionSource |
---|
closeQuietly, getDatabaseType, getUrl, makeConnection, setDatabaseType, setPassword, setUrl, setUsername |
Methods inherited from class com.j256.ormlite.support.BaseConnectionSource |
---|
clearSpecial, getSavedConnection, getSpecialConnection, isSavedConnection, saveSpecial |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.j256.ormlite.support.ConnectionSource |
---|
closeQuietly, getDatabaseType, getSpecialConnection |
Constructor Detail |
---|
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
Method Detail |
---|
public void initialize() throws SQLException
JdbcConnectionSource
initialize
in class JdbcConnectionSource
SQLException
- If the driver associated with the database URL is not found in the classpath.public void close() throws SQLException
close
in interface com.j256.ormlite.support.ConnectionSource
close
in class JdbcConnectionSource
SQLException
public com.j256.ormlite.support.DatabaseConnection getReadOnlyConnection() throws SQLException
getReadOnlyConnection
in interface com.j256.ormlite.support.ConnectionSource
getReadOnlyConnection
in class JdbcConnectionSource
SQLException
public com.j256.ormlite.support.DatabaseConnection getReadWriteConnection() throws SQLException
getReadWriteConnection
in interface com.j256.ormlite.support.ConnectionSource
getReadWriteConnection
in class JdbcConnectionSource
SQLException
public void releaseConnection(com.j256.ormlite.support.DatabaseConnection connection) throws SQLException
releaseConnection
in interface com.j256.ormlite.support.ConnectionSource
releaseConnection
in class JdbcConnectionSource
SQLException
public boolean saveSpecialConnection(com.j256.ormlite.support.DatabaseConnection connection) throws SQLException
saveSpecialConnection
in interface com.j256.ormlite.support.ConnectionSource
saveSpecialConnection
in class JdbcConnectionSource
SQLException
public void clearSpecialConnection(com.j256.ormlite.support.DatabaseConnection connection)
clearSpecialConnection
in interface com.j256.ormlite.support.ConnectionSource
clearSpecialConnection
in class JdbcConnectionSource
public boolean isOpen()
isOpen
in interface com.j256.ormlite.support.ConnectionSource
isOpen
in class JdbcConnectionSource
@Deprecated public void setUsesTransactions(boolean usesTransactions)
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()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |