@@ -157,6 +157,8 @@ void pstmtCacheMetrics(PstmtCache pstmtCache) {
157157 pscRem .add (pstmtCache .removeCount ());
158158 }
159159
160+
161+
160162 final class HeartBeatRunnable extends TimerTask {
161163 @ Override
162164 public void run () {
@@ -446,7 +448,20 @@ private Connection initConnection(Connection conn) throws SQLException {
446448 }
447449
448450 private Connection createConnection () throws SQLException {
449- return initConnection (source .getConnection ());
451+
452+ if (poolListener != null ) {
453+ poolListener .onBeforeCreateConnection (this );
454+ }
455+ Connection connection = initConnection (source .getConnection ());
456+ if (poolListener != null ) {
457+ poolListener .onAfterCreateConnection (this , connection );
458+ }
459+ return connection ;
460+ }
461+
462+ @ Override
463+ public int forceTrim (int trimCount ) {
464+ return queue .forceTrim (trimCount );
450465 }
451466
452467 @ Override
@@ -559,9 +574,12 @@ void removeClosedConnection(PooledConnection pooledConnection) {
559574 */
560575 private void returnTheConnection (PooledConnection pooledConnection , boolean forceClose ) {
561576 if (poolListener != null && !forceClose ) {
562- poolListener .onBeforeReturnConnection (pooledConnection );
577+ poolListener .onBeforeReturnConnection (this , pooledConnection );
563578 }
564579 queue .returnPooledConnection (pooledConnection , forceClose );
580+ if (poolListener != null && !forceClose ) {
581+ poolListener .onAfterReturnConnection (this );
582+ }
565583 }
566584
567585 void returnConnectionReset (PooledConnection pooledConnection ) {
@@ -570,6 +588,17 @@ void returnConnectionReset(PooledConnection pooledConnection) {
570588 reset ();
571589 }
572590
591+ void onBeforeCloseConnection (PooledConnection pooledConnection ) {
592+ if (poolListener != null ) {
593+ poolListener .onBeforeCloseConnection (this , pooledConnection );
594+ }
595+ }
596+
597+ void onAfterCloseConnection () {
598+ if (poolListener != null ) {
599+ poolListener .onAfterCloseConnection (this );
600+ }
601+ }
573602 /**
574603 * Grow the pool by creating a new connection. The connection can either be
575604 * added to the available list, or returned.
@@ -608,7 +637,14 @@ private void reset() {
608637 */
609638 @ Override
610639 public Connection getConnection (String username , String password ) throws SQLException {
611- return initConnection (source .getConnection (username , password ));
640+ if (poolListener != null ) {
641+ poolListener .onBeforeCreateConnection (this );
642+ }
643+ Connection connection = initConnection (source .getConnection (username , password ));
644+ if (poolListener != null ) {
645+ poolListener .onAfterCreateConnection (this , connection );
646+ }
647+ return connection ;
612648 }
613649
614650 /**
@@ -626,12 +662,15 @@ public Connection getConnection() throws SQLException {
626662 * will go into a wait if the pool has hit its maximum size.
627663 */
628664 private PooledConnection getPooledConnection () throws SQLException {
665+ if (poolListener != null ) {
666+ poolListener .onBeforeBorrowConnection (this );
667+ }
629668 PooledConnection c = queue .obtainConnection ();
630669 if (captureStackTrace ) {
631670 c .setStackTrace (Thread .currentThread ().getStackTrace ());
632671 }
633672 if (poolListener != null ) {
634- poolListener .onAfterBorrowConnection (c );
673+ poolListener .onAfterBorrowConnection (this , c );
635674 }
636675 return c ;
637676 }
0 commit comments