Optimize hazard curve insertion

Addresses https://bugs.launchpad.net/openquake/+bug/1100332.

To make this optimization, the bulk of the select/transform/insert functionality for this phase has been moved into a DB function. See bug notes for details.