src/main/java/org/embulk/input/PostgreSQLInputPlugin.java in embulk-input-postgresql-0.8.4 vs src/main/java/org/embulk/input/PostgreSQLInputPlugin.java in embulk-input-postgresql-0.8.5

- old
+ new

@@ -1,31 +1,33 @@ package org.embulk.input; -import java.util.Map; import java.util.Properties; import java.sql.Connection; -import java.sql.Driver; +import java.sql.DriverManager; import java.sql.SQLException; import org.embulk.config.Config; import org.embulk.config.ConfigDefault; import org.embulk.input.jdbc.AbstractJdbcInputPlugin; -import org.embulk.input.jdbc.JdbcColumnOption; import org.embulk.input.jdbc.getter.ColumnGetterFactory; import org.embulk.input.postgresql.PostgreSQLInputConnection; import org.embulk.input.postgresql.getter.PostgreSQLColumnGetterFactory; import org.embulk.spi.PageBuilder; import org.joda.time.DateTimeZone; +import com.google.common.base.Optional; + public class PostgreSQLInputPlugin extends AbstractJdbcInputPlugin { - private static final Driver driver = new org.postgresql.Driver(); - public interface PostgreSQLPluginTask extends PluginTask { + @Config("driver_path") + @ConfigDefault("null") + public Optional<String> getDriverPath(); + @Config("host") public String getHost(); @Config("port") @ConfigDefault("5432") @@ -63,10 +65,12 @@ @Override protected PostgreSQLInputConnection newConnection(PluginTask task) throws SQLException { PostgreSQLPluginTask t = (PostgreSQLPluginTask) task; + loadDriver("org.postgresql.Driver", t.getDriverPath()); + String url = String.format("jdbc:postgresql://%s:%d/%s", t.getHost(), t.getPort(), t.getDatabase()); Properties props = new Properties(); props.setProperty("user", t.getUser()); @@ -88,10 +92,10 @@ props.setProperty("ApplicationName", t.getApplicationName()); props.putAll(t.getOptions()); - Connection con = driver.connect(url, props); + Connection con = DriverManager.getConnection(url, props); try { PostgreSQLInputConnection c = new PostgreSQLInputConnection(con, t.getSchema()); con = null; return c; } finally {