Thames Water has secured a £3bn injection to avoid running out of cash.