|
xmlBlaster 2.2.0 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xmlBlaster.contrib.db.DbWaitingPool
public class DbWaitingPool
Simple implementation of the database JDBC connection pool.
Following configuration paramaters are available:
db.url=jdbc:oracle:thin:@localhost:1521:orcl db.user=system db.password=manager db.maxInstances=10 db.busyToIdleTimeout=0 // How long may a query last [millis] db.idleToEraseTimeout=10*60*1000L // How long does an unused connection survive (10 min) db.maxResourceExhaustRetries=5 db.resourceExhaustSleepGap=1000 // [millis]
Field Summary | |
---|---|
private JdbcConnectionPool |
connectionPool
|
private I_DbCreateInterceptor |
createInterceptor
|
private java.lang.String |
dbPasswd
|
private java.lang.String |
dbUrl
|
private java.lang.String |
dbUser
|
private I_Info |
info
|
private int |
initCount
|
private static java.util.logging.Logger |
log
|
private int |
maxResourceExhaustRetries
If the pool is exhausted, we poll the given times |
private java.lang.Object |
meetingPoint
|
private long |
resourceExhaustSleepGap
If the pool is exhausted, we poll every given millis Please note that the current request thread will block for maxResourceExhaustRetries*resourceExhaustSleepGap millis. |
Constructor Summary | |
---|---|
DbWaitingPool()
Default constructor, you need to call init(info) thereafter. |
Method Summary | |
---|---|
void |
busyToIdle(java.lang.Object resource)
This callback does nothing (enforced by interface I_PoolManager |
private void |
destroy()
Cleanup and destroy everything. |
void |
erase(java.sql.Connection con)
Destroy the JDBC connection |
I_Info |
getInfo()
may be empty and just contains db.* properties |
java.util.Set |
getUsedPropertyKeys()
Gets all property keys which may be used by this object. |
java.lang.String |
getUser()
|
void |
idleToBusy(java.lang.Object resource)
This callback does nothing (enforced by interface I_PoolManager) |
void |
init(I_Info info)
Needs to be called after construction. |
static void |
main(java.lang.String[] args)
|
void |
release(java.sql.Connection con)
Return the JDBC connection to the pool. |
java.sql.Connection |
reserve()
Access a JDBC connection. |
java.sql.Connection |
select(java.sql.Connection connection,
java.lang.String command,
boolean autoCommit,
I_ResultCb cb)
To have full control. |
java.sql.Connection |
select(java.sql.Connection connection,
java.lang.String command,
I_ResultCb cb)
Convenience method to execute a SELECT SQL command. |
void |
select(java.lang.String command,
I_ResultCb cb)
Convenience method to execute a SELECT SQL command in auto commit mode. |
void |
shutdown()
Close all open connections and destroy the pool. |
int |
update(java.sql.Connection conn,
java.lang.String command)
|
int |
update(java.lang.String command)
Convenience method to execute a INSERT/UPDATE/CREATE or DROP SQL command in auto commit mode. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static java.util.logging.Logger log
private I_Info info
private JdbcConnectionPool connectionPool
private java.lang.String dbUrl
private java.lang.String dbUser
private java.lang.String dbPasswd
private int maxResourceExhaustRetries
private long resourceExhaustSleepGap
private final java.lang.Object meetingPoint
private int initCount
private I_DbCreateInterceptor createInterceptor
Constructor Detail |
---|
public DbWaitingPool()
Method Detail |
---|
public java.util.Set getUsedPropertyKeys()
I_ContribPlugin
getUsedPropertyKeys
in interface I_ContribPlugin
I_ContribPlugin.getUsedPropertyKeys()
public void init(I_Info info)
I_DbPool
init
in interface I_DbPool
init
in interface I_ContribPlugin
info
- The configurationorg.xmlBlaster.contrib.dbwatcher.db.I_DbPool#init(I_Info)
public java.lang.String getUser()
getUser
in interface I_DbPool
public java.sql.Connection reserve() throws java.lang.Exception
I_DbPool
reserve
in interface I_DbPool
java.lang.Exception
- of type XmlBlasterException or IllegalArgumentExceptionorg.xmlBlaster.contrib.dbwatcher.db.I_DbPool#reserve()
public void release(java.sql.Connection con) throws java.lang.Exception
I_DbPool
release
in interface I_DbPool
con
- The JDBC connection
java.lang.Exception
- of type XmlBlasterException or IllegalArgumentExceptionorg.xmlBlaster.contrib.dbwatcher.db.I_DbPool#release(java.sql.Connection)
public void erase(java.sql.Connection con) throws java.lang.IllegalArgumentException
I_DbPool
erase
in interface I_DbPool
con
- The JDBC connection
java.lang.IllegalArgumentException
org.xmlBlaster.contrib.dbwatcher.db.I_DbPool#erase(java.sql.Connection)
private void destroy()
public void idleToBusy(java.lang.Object resource)
resource
- The Connection objectI_PoolManager.idleToBusy(Object)
public void busyToIdle(java.lang.Object resource)
resource
- The Connection objectI_PoolManager.busyToIdle(Object)
public int update(java.lang.String command) throws java.lang.Exception
I_DbPool
update
in interface I_DbPool
command
- for example INSERT INTO TEST_POLL VALUES ('1', 'EDDI')
java.lang.Exception
- Typically a SQLExceptionorg.xmlBlaster.contrib.dbwatcher.db.I_DbPool#update(String)
public int update(java.sql.Connection conn, java.lang.String command) throws java.lang.Exception
update
in interface I_DbPool
java.lang.Exception
org.xmlBlaster.contrib.dbwatcher.db.I_DbPool#update(String)
public void select(java.lang.String command, I_ResultCb cb) throws java.lang.Exception
I_DbPool
select
in interface I_DbPool
command
- for example SELECT * FROM TEST_POLLcb
- The callback handle for the retrieved ResultSet
java.lang.Exception
- Typically a SQLExceptionorg.xmlBlaster.contrib.dbwatcher.db.I_DbPool#select(String, I_ResultCb)
public java.sql.Connection select(java.sql.Connection connection, java.lang.String command, I_ResultCb cb) throws java.lang.Exception
I_DbPool
On first call pass connection with null and a valid connection with an open transaction is returned by this method. You can now call this method passing the connection multiple times in the same transaction. When you are done you need to close the connection and put it back into the pool.
Example:Connection conn = null; try { conn = this.dbPool.select(conn, "SELECT A FROM B", new I_ResultCb() { public void result(ResultSet rs) throws Exception { // Processing result set } }); conn = this.dbPool.select(conn, "SELECT B FROM C", new I_ResultCb() { public void result(ResultSet rs) throws Exception { // Processing result set } }); } finally { if (conn != null) { conn.commit(); this.dbPool.release(conn); } }
select
in interface I_DbPool
connection
- If null a connection is createdcommand
- for example SELECT * FROM TEST_POLLcb
- The callback handle for the retrieved ResultSet
java.lang.Exception
- Typically a SQLExceptionorg.xmlBlaster.contrib.dbwatcher.db.I_DbPool#select(java.sql.Connection, String, I_ResultCb)
public java.sql.Connection select(java.sql.Connection connection, java.lang.String command, boolean autoCommit, I_ResultCb cb) throws java.lang.Exception
I_DbPool
select
in interface I_DbPool
connection
- If null a connection is createdcommand
- for example SELECT * FROM TEST_POLLautoCommit
- if true force auto commit and cleanup the connection, in this case we return nullcb
- The callback handle for the retrieved ResultSet
java.lang.Exception
- Typically a SQLExceptionorg.xmlBlaster.contrib.dbwatcher.db.I_DbPool#select(java.sql.Connection, String, I_ResultCb, boolean)
public void shutdown()
I_DbPool
shutdown
in interface I_DbPool
shutdown
in interface I_ContribPlugin
org.xmlBlaster.contrib.dbwatcher.db.I_DbPool#shutdown
public I_Info getInfo()
getInfo
in interface I_DbPool
public static void main(java.lang.String[] args)
|
xmlBlaster 2.2.0 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |