Database access refactoring to get rid of case class per entity anti-pattern.

Please please please triple check this code. I shouldn't be checking in at 1:48 am after having only had 4 hours of sleep the previous night. :-)