public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
String name = method.getName();
if ("close".equals(name)) {
ConnectionEvent event = new ConnectionEvent(SQLitePooledConnection.this);
for (int i = listeners.size() - 1; i >= 0; i--) {
listeners.get(i).connectionClosed(event);
}
if (!physicalConn.getAutoCommit()) {
physicalConn.rollback();
}
physicalConn.setAutoCommit(true);
isClosed = true;
return null; // don't close physical connection
}
else if ("isClosed".equals(name)) {
if (!isClosed)
isClosed = ((Boolean)method.invoke(physicalConn, args)).booleanValue();
return isClosed;
}
if (isClosed) {
throw new SQLException ("Connection is closed");
}
return method.invoke(physicalConn, args);
}
catch (SQLException e){
if ("database connection closed".equals(e.getMessage())) {
ConnectionEvent event = new ConnectionEvent(SQLitePooledConnection.this, e);
for (int i = listeners.size() - 1; i >= 0; i--) {
listeners.get(i).connectionErrorOccurred(event);
}
}