|
xmlBlaster 2.1.0 API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.xmlBlaster.contrib.db.DbPool
public class DbPool
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 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 PoolManager |
poolManager
|
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 | |
|---|---|
DbPool()
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. |
private void |
initDrivers()
Load the JDBC drivers given in environment. |
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. |
java.lang.Object |
toCreate(java.lang.String instanceId)
Create a new JDBC connection, the driver must be registered already. |
void |
toErased(java.lang.Object resource)
Destroy the JDBC connection. |
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 PoolManager poolManager
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 DbPool()
| Method Detail |
|---|
public java.util.Set getUsedPropertyKeys()
I_ContribPlugin
getUsedPropertyKeys in interface I_ContribPluginI_ContribPlugin.getUsedPropertyKeys()public void init(I_Info info)
I_DbPool
init in interface I_DbPoolinit in interface I_ContribPlugininfo - The configurationorg.xmlBlaster.contrib.dbwatcher.db.I_DbPool#init(I_Info)public java.lang.String getUser()
getUser in interface I_DbPoolprivate void initDrivers()
public java.sql.Connection reserve()
throws java.lang.Exception
I_DbPool
reserve in interface I_DbPooljava.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_DbPoolcon - 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_DbPoolcon - The JDBC connection
java.lang.IllegalArgumentExceptionorg.xmlBlaster.contrib.dbwatcher.db.I_DbPool#erase(java.sql.Connection)private void destroy()
public void idleToBusy(java.lang.Object resource)
idleToBusy in interface I_PoolManagerresource - The Connection objectI_PoolManager.idleToBusy(Object)public void busyToIdle(java.lang.Object resource)
busyToIdle in interface I_PoolManagerresource - The Connection objectI_PoolManager.busyToIdle(Object)public java.lang.Object toCreate(java.lang.String instanceId)
toCreate in interface I_PoolManagerinstanceId - A unique identifier
public void toErased(java.lang.Object resource)
toErased in interface I_PoolManagerresource - The Connection object
public int update(java.lang.String command)
throws java.lang.Exception
I_DbPool
update in interface I_DbPoolcommand - 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_DbPooljava.lang.Exceptionorg.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_DbPoolcommand - 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_DbPoolOn 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_DbPoolconnection - 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_DbPoolconnection - 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_DbPoolshutdown in interface I_ContribPluginorg.xmlBlaster.contrib.dbwatcher.db.I_DbPool#shutdownpublic I_Info getInfo()
getInfo in interface I_DbPoolpublic static void main(java.lang.String[] args)
|
xmlBlaster 2.1.0 API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||