NEMO-1838 Restore logic to reuse connection pools.

(Modified for ActiveRecord 4.)