// Copyright (c) 2007 Keith D Gregory package com.kdgregory.example.ref.phantom; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.sql.Connection; import java.sql.SQLException; /** * A wrapper for a JDBC database connection that is associated with a pool. * Closing this connection returns the wrapped connection to the pool, to * be used again. *
* This class is implemented as a reflection proxy invocation handler. There
* are two reasons for doing this. First, most of the methods simply delegate
* to an underlying connection; we'd have to write a lot of boilerplate for a
* full Connection
implementation. Second, and more important,
* the Connection
interface has changed over time, in ways that
* are neither forward nor backward compatible. A concrete implementation is
* tied to a single JDK version, which doesn't work well for example code that
* might live for many years.
*
* Given point #2, I would almost certainly choose a similar implementation in
* a production pool.