How do you handle database concurrency, and what are the differences between optimistic and pessimistic locking?