Refactored DB layer to reduce code duplication

Instead of copying / pasting try / catch / finally blocks to every
function, a new Command Object pattern has been implemented using
Generics.
This reduces the chances of null pointer exceptions and inconsistent
behaviour between similar functions due to copy/paste errors