public DriverConnectionFactory(Driver driver, BaseJdbcConfig config) { this(driver, config.getConnectionUrl(), basicConnectionProperties(config)); }
public static Properties basicConnectionProperties(BaseJdbcConfig config) { Properties connectionProperties = new Properties(); if (config.getConnectionUser() != null) { connectionProperties.setProperty("user", config.getConnectionUser()); } if (config.getConnectionPassword() != null) { connectionProperties.setProperty("password", config.getConnectionPassword()); } return connectionProperties; }
@Test public void testExplicitPropertyMappings() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("connection-url", "jdbc:h2:mem:config") .put("connection-user", "user") .put("connection-password", "password") .build(); BaseJdbcConfig expected = new BaseJdbcConfig() .setConnectionUrl("jdbc:h2:mem:config") .setConnectionUser("user") .setConnectionPassword("password"); ConfigAssertions.assertFullMapping(properties, expected); } }
@Test public void testDefaults() { ConfigAssertions.assertRecordedDefaults(ConfigAssertions.recordDefaults(BaseJdbcConfig.class) .setConnectionUrl(null) .setConnectionUser(null) .setConnectionPassword(null)); }
public BaseJdbcClient(JdbcConnectorId connectorId, BaseJdbcConfig config, String identifierQuote, Driver driver) { this.connectorId = requireNonNull(connectorId, "connectorId is null").toString(); this.identifierQuote = requireNonNull(identifierQuote, "identifierQuote is null"); this.driver = requireNonNull(driver, "driver is null"); requireNonNull(config, "config is null"); connectionUrl = config.getConnectionUrl(); connectionProperties = new Properties(); if (config.getConnectionUser() != null) { connectionProperties.setProperty("user", config.getConnectionUser()); } if (config.getConnectionPassword() != null) { connectionProperties.setProperty("password", config.getConnectionPassword()); } }
public TestingDatabase() throws SQLException { String connectionUrl = "jdbc:h2:mem:test" + System.nanoTime(); jdbcClient = new BaseJdbcClient( new JdbcConnectorId(CONNECTOR_ID), new BaseJdbcConfig(), "\"", new DriverConnectionFactory(new Driver(), connectionUrl, new Properties())); connection = DriverManager.getConnection(connectionUrl); connection.createStatement().execute("CREATE SCHEMA example"); connection.createStatement().execute("CREATE TABLE example.numbers(text varchar primary key, text_short varchar(32), value bigint)"); connection.createStatement().execute("INSERT INTO example.numbers(text, text_short, value) VALUES " + "('one', 'one', 1)," + "('two', 'two', 2)," + "('three', 'three', 3)," + "('ten', 'ten', 10)," + "('eleven', 'eleven', 11)," + "('twelve', 'twelve', 12)" + ""); connection.createStatement().execute("CREATE TABLE example.view_source(id varchar primary key)"); connection.createStatement().execute("CREATE VIEW example.view AS SELECT id FROM example.view_source"); connection.createStatement().execute("CREATE SCHEMA tpch"); connection.createStatement().execute("CREATE TABLE tpch.orders(orderkey bigint primary key, custkey bigint)"); connection.createStatement().execute("CREATE TABLE tpch.lineitem(orderkey bigint primary key, partkey bigint)"); connection.createStatement().execute("CREATE SCHEMA exa_ple"); connection.createStatement().execute("CREATE TABLE exa_ple.num_ers(te_t varchar primary key, \"VA%UE\" bigint)"); connection.createStatement().execute("CREATE TABLE exa_ple.table_with_float_col(col1 bigint, col2 double, col3 float, col4 real)"); connection.commit(); }
@Test public void testDefaults() { ConfigAssertions.assertRecordedDefaults(ConfigAssertions.recordDefaults(BaseJdbcConfig.class) .setConnectionUrl(null) .setConnectionUser(null) .setConnectionPassword(null)); }
public TestingDatabase() throws SQLException { String connectionUrl = "jdbc:h2:mem:test" + System.nanoTime(); jdbcClient = new BaseJdbcClient( new JdbcConnectorId(CONNECTOR_ID), new BaseJdbcConfig(), "\"", new DriverConnectionFactory(new Driver(), connectionUrl, new Properties())); connection = DriverManager.getConnection(connectionUrl); connection.createStatement().execute("CREATE SCHEMA example"); connection.createStatement().execute("CREATE TABLE example.numbers(text varchar primary key, text_short varchar(32), value bigint)"); connection.createStatement().execute("INSERT INTO example.numbers(text, text_short, value) VALUES " + "('one', 'one', 1)," + "('two', 'two', 2)," + "('three', 'three', 3)," + "('ten', 'ten', 10)," + "('eleven', 'eleven', 11)," + "('twelve', 'twelve', 12)" + ""); connection.createStatement().execute("CREATE TABLE example.view_source(id varchar primary key)"); connection.createStatement().execute("CREATE VIEW example.view AS SELECT id FROM example.view_source"); connection.createStatement().execute("CREATE SCHEMA tpch"); connection.createStatement().execute("CREATE TABLE tpch.orders(orderkey bigint primary key, custkey bigint)"); connection.createStatement().execute("CREATE TABLE tpch.lineitem(orderkey bigint primary key, partkey bigint)"); connection.createStatement().execute("CREATE SCHEMA exa_ple"); connection.createStatement().execute("CREATE TABLE exa_ple.num_ers(te_t varchar primary key, \"VA%UE\" bigint)"); connection.createStatement().execute("CREATE TABLE exa_ple.table_with_float_col(col1 bigint, col2 double, col3 float, col4 real)"); connection.commit(); }
@Override protected void setup(Binder binder) { binder.bind(JdbcClient.class).to(MySqlClient.class).in(Scopes.SINGLETON); ensureCatalogIsEmpty(buildConfigObject(BaseJdbcConfig.class).getConnectionUrl()); configBinder(binder).bindConfig(MySqlConfig.class); }
@Test public void testExplicitPropertyMappings() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("connection-url", "jdbc:h2:mem:config") .put("connection-user", "user") .put("connection-password", "password") .build(); BaseJdbcConfig expected = new BaseJdbcConfig() .setConnectionUrl("jdbc:h2:mem:config") .setConnectionUser("user") .setConnectionPassword("password"); ConfigAssertions.assertFullMapping(properties, expected); } }
private static ConnectionFactory connectionFactory(BaseJdbcConfig config, MySqlConfig mySqlConfig) throws SQLException { Properties connectionProperties = basicConnectionProperties(config); connectionProperties.setProperty("useInformationSchema", "true"); connectionProperties.setProperty("nullCatalogMeansCurrent", "false"); connectionProperties.setProperty("useUnicode", "true"); connectionProperties.setProperty("characterEncoding", "utf8"); connectionProperties.setProperty("tinyInt1isBit", "false"); if (mySqlConfig.isAutoReconnect()) { connectionProperties.setProperty("autoReconnect", String.valueOf(mySqlConfig.isAutoReconnect())); connectionProperties.setProperty("maxReconnects", String.valueOf(mySqlConfig.getMaxReconnects())); } if (mySqlConfig.getConnectionTimeout() != null) { connectionProperties.setProperty("connectTimeout", String.valueOf(mySqlConfig.getConnectionTimeout().toMillis())); } return new DriverConnectionFactory(new Driver(), config.getConnectionUrl(), connectionProperties); }
@Override protected void setup(Binder binder) { binder.bind(JdbcClient.class).to(MySqlClient.class).in(Scopes.SINGLETON); ensureCatalogIsEmpty(buildConfigObject(BaseJdbcConfig.class).getConnectionUrl()); configBinder(binder).bindConfig(MySqlConfig.class); }
private static ConnectionFactory connectionFactory(BaseJdbcConfig config, MySqlConfig mySqlConfig) throws SQLException { Properties connectionProperties = basicConnectionProperties(config); connectionProperties.setProperty("useInformationSchema", "true"); connectionProperties.setProperty("nullCatalogMeansCurrent", "false"); connectionProperties.setProperty("useUnicode", "true"); connectionProperties.setProperty("characterEncoding", "utf8"); connectionProperties.setProperty("tinyInt1isBit", "false"); if (mySqlConfig.isAutoReconnect()) { connectionProperties.setProperty("autoReconnect", String.valueOf(mySqlConfig.isAutoReconnect())); connectionProperties.setProperty("maxReconnects", String.valueOf(mySqlConfig.getMaxReconnects())); } if (mySqlConfig.getConnectionTimeout() != null) { connectionProperties.setProperty("connectTimeout", String.valueOf(mySqlConfig.getConnectionTimeout().toMillis())); } return new DriverConnectionFactory(new Driver(), config.getConnectionUrl(), connectionProperties); }