Refactor db_base_plugin_v2 and to remove code duplication

fixes bug 1104379

Introduce CommonDbMixin which includes utility methods
to manipulate model queries.

Change-Id: Ib3602321328cbf945358e0581ecc649e3f69d196
Merge "Refactor db_base_plugin_v2 and to remove code duplication"