refactor(persistence): consistent flush ordering

- introduce new DbEntityManager, DbEntityCache and DbOperationManager
- flush is ordered as follows:
  * INSERTs
  * UPDATEs + DELETEs
- Within each category, operations are orderd by
  * entity type (respecting foreign key constrains between entities of
    different types)
  * foreign key constraints (references within a type)
  * id

related to #CAM-1971