public interface DatabaseConnectionProxyFactory
JdbcConnectionSource or
AndroidConnectionSource using the setDatabaseConnectionProxyFactory(...) static method on each
class.
Typically you create a subclass of DatabaseConnectionProxy and override the methods that you want to wrap for
logging, monitoring, or other reason. Something like:
private static class MyConnectionProxy extends DatabaseConnectionProxy {
public ConnectionProxy(DatabaseConnection conn) {
super(conn);
}
@Override
public int insert(String statement, Object[] args, FieldType[] argfieldTypes, GeneratedKeyHolder keyHolder)
throws SQLException {
// do something here to the arguments or write to a log or something
return super.insert(statement, args, argfieldTypes, keyHolder);
}
}
Then define your own factory which constructs instances of your proxy object. For example:
JdbcConnectionSource.setDatabaseConnectionProxyFactory(new DatabaseConnectionProxyFactory() {
public DatabaseConnection createProxy(DatabaseConnection realConnection) {
return new MyConnectionProxy(realConnection);
}
});
You can also use the ReflectionDatabaseConnectionProxyFactory which takes a class and constructs your proxy
subclass using reflection.
To see a working example of the connection proxy, see the DatabaseConnectionProxyFactoryTest.
| Modifier and Type | Method and Description |
|---|---|
DatabaseConnection |
createProxy(DatabaseConnection realConnection)
Create a proxy database connection that may extend
DatabaseConnectionProxy. |
DatabaseConnection createProxy(DatabaseConnection realConnection) throws SQLException
DatabaseConnectionProxy. This method should
instantiate the proxy and set the real-connection on it.SQLExceptionThis documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.