Search in sources :

Example 1 with DriverConnectionFactory

use of io.prestosql.plugin.jdbc.DriverConnectionFactory in project hetu-core by openlookeng.

the class MySqlClientModule method createConnectionFactory.

@Provides
@Singleton
public static ConnectionFactory createConnectionFactory(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(), Optional.ofNullable(config.getUserCredentialName()), Optional.ofNullable(config.getPasswordCredentialName()), connectionProperties);
}
Also used : DriverConnectionFactory(io.prestosql.plugin.jdbc.DriverConnectionFactory) Driver(com.mysql.jdbc.Driver) Properties(java.util.Properties) DriverConnectionFactory.basicConnectionProperties(io.prestosql.plugin.jdbc.DriverConnectionFactory.basicConnectionProperties) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 2 with DriverConnectionFactory

use of io.prestosql.plugin.jdbc.DriverConnectionFactory in project hetu-core by openlookeng.

the class TestDataSourceTableSplitManager method initSplitDatabase.

private void initSplitDatabase() throws SQLException {
    String connectionUrl;
    connectionUrl = "jdbc:h2:mem:test" + System.nanoTime() + ThreadLocalRandom.current().nextLong();
    jdbcClient = new BaseJdbcClient(new BaseJdbcConfig(), "\"", new DriverConnectionFactory(new Driver(), connectionUrl, Optional.empty(), Optional.empty(), new Properties()));
    connection = DriverManager.getConnection(connectionUrl);
}
Also used : BaseJdbcClient(io.prestosql.plugin.jdbc.BaseJdbcClient) DriverConnectionFactory(io.prestosql.plugin.jdbc.DriverConnectionFactory) Driver(org.h2.Driver) Properties(java.util.Properties) BaseJdbcConfig(io.prestosql.plugin.jdbc.BaseJdbcConfig)

Example 3 with DriverConnectionFactory

use of io.prestosql.plugin.jdbc.DriverConnectionFactory in project hetu-core by openlookeng.

the class ClickHouseClientModule method createConnectionFactory.

@Provides
@Singleton
public static ConnectionFactory createConnectionFactory(BaseJdbcConfig config, ClickHouseConfig clickHouseConfig) {
    Properties connectionProperties = basicConnectionProperties(config);
    connectionProperties.setProperty(ClickHouseConnectionSettings.SOCKET_TIMEOUT.getKey(), String.valueOf(clickHouseConfig.getSocketTimeout()));
    return new DriverConnectionFactory(new ClickHouseDriver(), config.getConnectionUrl(), Optional.ofNullable(config.getUserCredentialName()), Optional.ofNullable(config.getPasswordCredentialName()), connectionProperties);
}
Also used : ClickHouseDriver(ru.yandex.clickhouse.ClickHouseDriver) DriverConnectionFactory(io.prestosql.plugin.jdbc.DriverConnectionFactory) Properties(java.util.Properties) DriverConnectionFactory.basicConnectionProperties(io.prestosql.plugin.jdbc.DriverConnectionFactory.basicConnectionProperties) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 4 with DriverConnectionFactory

use of io.prestosql.plugin.jdbc.DriverConnectionFactory in project hetu-core by openlookeng.

the class OracleClientModule method getConnectionFactory.

/**
 * getConnectionFactory
 *
 * @param config config
 * @return ConnectionFactory
 */
@Provides
@Singleton
public static ConnectionFactory getConnectionFactory(BaseJdbcConfig config, OracleConfig oracleConfig) {
    Properties connectionProperties = basicConnectionProperties(config);
    connectionProperties.setProperty(Constants.ORACLE_PROPERTY_INCLUDE_SYNONYMS, String.valueOf(oracleConfig.isSynonymsEnabled()));
    Driver driver;
    try {
        driver = (Driver) Class.forName(Constants.ORACLE_JDBC_DRIVER_CLASS_NAME).getConstructor(((Class<?>[]) null)).newInstance();
    } catch (InstantiationException | ClassNotFoundException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
        throw new PrestoException(JDBC_ERROR, e);
    }
    return new DriverConnectionFactory(driver, config.getConnectionUrl(), Optional.ofNullable(config.getUserCredentialName()), Optional.ofNullable(config.getPasswordCredentialName()), connectionProperties);
}
Also used : Driver(java.sql.Driver) DriverConnectionFactory(io.prestosql.plugin.jdbc.DriverConnectionFactory) PrestoException(io.prestosql.spi.PrestoException) Properties(java.util.Properties) DriverConnectionFactory.basicConnectionProperties(io.prestosql.plugin.jdbc.DriverConnectionFactory.basicConnectionProperties) InvocationTargetException(java.lang.reflect.InvocationTargetException) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 5 with DriverConnectionFactory

use of io.prestosql.plugin.jdbc.DriverConnectionFactory in project hetu-core by openlookeng.

the class HanaClientModule method getConnectionFactory.

/**
 * createConnectionFactory
 *
 * @param config BaseJdbcConfig
 * @param hanaConfig HanaConfig
 * @return ConnectionFactory
 */
@Provides
@Singleton
public static ConnectionFactory getConnectionFactory(BaseJdbcConfig config, HanaConfig hanaConfig) {
    Properties connectionProperties = basicConnectionProperties(config);
    connectionProperties.setProperty("autocommit", String.valueOf(hanaConfig.isAutoCommit()));
    connectionProperties.setProperty("communicationTimeout", String.valueOf(hanaConfig.getCommunicationTimeout()));
    connectionProperties.setProperty("encrypt", String.valueOf(hanaConfig.isEncrypt()));
    connectionProperties.setProperty("packetsize", String.valueOf(hanaConfig.getPacketSize()));
    connectionProperties.setProperty("readOnly", String.valueOf(hanaConfig.isReadOnly()));
    connectionProperties.setProperty("reconnect", String.valueOf(hanaConfig.isReconnect()));
    log.info("Hana connection properties: %s", connectionProperties);
    Driver driver = null;
    try {
        driver = (Driver) Class.forName(HanaConstants.SAP_HANA_JDBC_DRIVER_CLASS_NAME).getConstructor(((Class<?>[]) null)).newInstance();
    } catch (InstantiationException e) {
        throw new PrestoException(JDBC_ERROR, e);
    } catch (IllegalAccessException e) {
        throw new PrestoException(JDBC_ERROR, e);
    } catch (ClassNotFoundException e) {
        throw new PrestoException(JDBC_ERROR, e);
    } catch (InvocationTargetException e) {
        throw new PrestoException(JDBC_ERROR, e);
    } catch (NoSuchMethodException e) {
        throw new PrestoException(JDBC_ERROR, e);
    }
    return new DriverConnectionFactory(driver, config.getConnectionUrl(), Optional.ofNullable(config.getUserCredentialName()), Optional.ofNullable(config.getPasswordCredentialName()), connectionProperties);
}
Also used : Driver(java.sql.Driver) DriverConnectionFactory(io.prestosql.plugin.jdbc.DriverConnectionFactory) PrestoException(io.prestosql.spi.PrestoException) Properties(java.util.Properties) DriverConnectionFactory.basicConnectionProperties(io.prestosql.plugin.jdbc.DriverConnectionFactory.basicConnectionProperties) InvocationTargetException(java.lang.reflect.InvocationTargetException) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Aggregations

DriverConnectionFactory (io.prestosql.plugin.jdbc.DriverConnectionFactory)5 Properties (java.util.Properties)5 Provides (com.google.inject.Provides)4 Singleton (com.google.inject.Singleton)4 DriverConnectionFactory.basicConnectionProperties (io.prestosql.plugin.jdbc.DriverConnectionFactory.basicConnectionProperties)4 PrestoException (io.prestosql.spi.PrestoException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Driver (java.sql.Driver)2 Driver (com.mysql.jdbc.Driver)1 BaseJdbcClient (io.prestosql.plugin.jdbc.BaseJdbcClient)1 BaseJdbcConfig (io.prestosql.plugin.jdbc.BaseJdbcConfig)1 Driver (org.h2.Driver)1 ClickHouseDriver (ru.yandex.clickhouse.ClickHouseDriver)1