Added pessimistic locking option to queries