You might save some performance by doing this connection in the init method, and then only check if you need to reconnect (catch an exception?) on every document.