Fix an use-after-statement-closed error with USING PERIODIC COMMIT
Merge pull request #3706 from jakub-/user-after-statement-closed

Fix an use-after-statement-closed error with USING PERIODIC COMMIT
Fix forceClose() and refactor around closing in KernelStatement.

Using the forceClose() method did nothing and resources could leak.
Added a test for it.