Implement database locking