The codebase I've been handed to work with features a databse class that inherits from MDB2. This forms the basis for the MVC framework in use (a custom built affair) and the models in turn inherit from db.
As I'm sure some of you have noticed, this leads to a rather big problem. Every time you instantiate a model, the result is a new database connection being created. This is obviously quite wasteful. It also means that I'm unable to use transactions as intended, because if a transaction starts in one instance of a model, its effects are invisible to the other instances until a commit occurs.
My plan is to change the db class to encapsulate MDB2 instead of inheriting from it, and then have it maintain a single instance of MDB2 via its singleton functionality.
However, MDB2 is a big library with a lot of methods, and a lot of stuff higher up in the code base depends on being able to access MDB2 methods.
Is there a way to encapsulate the MDB2 class and pass calls to it without modifying the higher layers, and without having to write a wrapper method for every method in MDB2?