|
xmlBlaster 1.6.2 contributions API | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.xmlBlaster.contrib.db.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]
| 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 |
void |
erase(java.sql.Connection con)
Destroy the JDBC connection |
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. |
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 |
| 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_DbPoolinfo - 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_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)public void idleToBusy(java.lang.Object resource)
idleToBusy in interface org.xmlBlaster.util.pool.I_PoolManagerresource - The Connection objectI_PoolManager.idleToBusy(Object)public void busyToIdle(java.lang.Object resource)
busyToIdle in interface org.xmlBlaster.util.pool.I_PoolManagerresource - The Connection objectI_PoolManager.busyToIdle(Object)public java.lang.Object toCreate(java.lang.String instanceId)
toCreate in interface org.xmlBlaster.util.pool.I_PoolManagerinstanceId - A unique identifier
public void toErased(java.lang.Object resource)
toErased in interface org.xmlBlaster.util.pool.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_DbPoolorg.xmlBlaster.contrib.dbwatcher.db.I_DbPool#shutdownpublic static void main(java.lang.String[] args)
|
xmlBlaster 1.6.2 contributions API | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||