Sha256: 29872d399f20e8e055fa8648e4c5ee6ab1461944e0d6b1740a89fcda9add484c
Contents?: true
Size: 1.6 KB
Versions: 3
Compression:
Stored size: 1.6 KB
Contents
package org.embulk.output; import com.google.common.base.Throwables; import java.sql.*; import java.util.Properties; /** * Created by kakusuke on 2015/03/21. */ public class PostgresUDFConnector { private static final Driver driver = new org.postgresql.Driver(); private final String url; private final Properties properties; private final String schemaName; public PostgresUDFConnector(String url, Properties properties, String schemaName) { this.url = url; this.properties = properties; this.schemaName = schemaName; } public ConnectionWrapper connect(boolean autoCommit) throws SQLException { Connection c = createConnection(); try { ConnectionWrapper con = new ConnectionWrapper(c, schemaName, autoCommit); c = null; return con; } finally { if (c != null) { c.close(); } } } private Connection createConnection() throws SQLException { SQLException firstException = null; int count = 0; while(count < 10) { count++; try { return driver.connect(url, properties); } catch (SQLRecoverableException | SQLTimeoutException e) { if (firstException == null) { firstException = e; } try { Thread.sleep(300); } catch (InterruptedException e2) { throw Throwables.propagate(e2); } } } throw firstException; } }
Version data entries
3 entries across 3 versions & 1 rubygems