Lock batch function

This solves the permissions issues with the FOR UPDATE locks.