Datalog and Constraint Satisfaction with Infinite Templates