Access token database

Refactored the code according to the comments and added test cases.
Really bad name - CustomException. You should consider creating a dedicated custom exception called DatabaseException to indicate this is a database specific error.