Retrieval Augmented Generation or Long-Context LLMs? A Comprehensive Study and Hybrid Approach