Abstracted out common Dao functionality.

Also minor unit test work.