Check permissions before adding records in optimistic transaction

Permissions are not checked for record operation created, updated and deleted when tx status == "BEGUN" which is the norm. Additionally, fixed a problem with the rule "database.bypassRestricted" which isn't found in some cases because key string for query in rules isn't converted to lower case.
Fix for permissions check isn't optimal because checkSecurity is called two times if tx status == "COMMITTING".