Example usage for org.apache.hadoop.mapreduce.lib.db DBConfiguration URL_PROPERTY

List of usage examples for org.apache.hadoop.mapreduce.lib.db DBConfiguration URL_PROPERTY

Introduction

In this page you can find the example usage for org.apache.hadoop.mapreduce.lib.db DBConfiguration URL_PROPERTY.

Prototype

String URL_PROPERTY

To view the source code for org.apache.hadoop.mapreduce.lib.db DBConfiguration URL_PROPERTY.

Click Source Link

Document

JDBC Database access URL

Usage

From source file:co.cask.cdap.template.etl.common.ETLDBInputFormat.java

License:Apache License

@Override
public Connection getConnection() {
    if (this.connection == null) {
        Configuration conf = getConf();
        try {/*from w  w  w.  j  a v  a 2 s.c o m*/
            String url = conf.get(DBConfiguration.URL_PROPERTY);
            try {
                // throws SQLException if no suitable driver is found
                DriverManager.getDriver(url);
            } catch (SQLException e) {
                if (driverShim == null) {
                    if (driver == null) {
                        ClassLoader classLoader = conf.getClassLoader();
                        @SuppressWarnings("unchecked")
                        Class<? extends Driver> driverClass = (Class<? extends Driver>) classLoader
                                .loadClass(conf.get(DBConfiguration.DRIVER_CLASS_PROPERTY));
                        driver = driverClass.newInstance();

                        // De-register the default driver that gets registered when driver class is loaded.
                        DBUtils.deregisterAllDrivers(driverClass);
                    }
                    driverShim = new JDBCDriverShim(driver);
                    DriverManager.registerDriver(driverShim);
                    LOG.debug("Registered JDBC driver via shim {}. Actual Driver {}.", driverShim, driver);
                }
            }
            if (conf.get(DBConfiguration.USERNAME_PROPERTY) == null) {
                this.connection = DriverManager.getConnection(url);
            } else {
                this.connection = DriverManager.getConnection(url, conf.get(DBConfiguration.USERNAME_PROPERTY),
                        conf.get(DBConfiguration.PASSWORD_PROPERTY));
            }
            this.connection.setAutoCommit(false);
            this.connection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }
    return this.connection;
}

From source file:co.cask.cdap.template.etl.common.ETLDBOutputFormat.java

License:Apache License

private Connection getConnection(Configuration conf) {
    Connection connection;// w  w  w.ja v  a 2 s .c  om
    try {
        String url = conf.get(DBConfiguration.URL_PROPERTY);
        try {
            // throws SQLException if no suitable driver is found
            DriverManager.getDriver(url);
        } catch (SQLException e) {
            if (driverShim == null) {
                if (driver == null) {
                    ClassLoader classLoader = conf.getClassLoader();
                    @SuppressWarnings("unchecked")
                    Class<? extends Driver> driverClass = (Class<? extends Driver>) classLoader
                            .loadClass(conf.get(DBConfiguration.DRIVER_CLASS_PROPERTY));
                    driver = driverClass.newInstance();

                    // De-register the default driver that gets registered when driver class is loaded.
                    DBUtils.deregisterAllDrivers(driverClass);
                }

                driverShim = new JDBCDriverShim(driver);
                DriverManager.registerDriver(driverShim);
                LOG.debug("Registered JDBC driver via shim {}. Actual Driver {}.", driverShim, driver);
            }
        }

        if (conf.get(DBConfiguration.USERNAME_PROPERTY) == null) {
            connection = DriverManager.getConnection(url);
        } else {
            connection = DriverManager.getConnection(url, conf.get(DBConfiguration.USERNAME_PROPERTY),
                    conf.get(DBConfiguration.PASSWORD_PROPERTY));
        }
        connection.setAutoCommit(false);
        connection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    return connection;
}

From source file:co.cask.hydrator.plugin.db.batch.sink.ETLDBOutputFormat.java

License:Apache License

private Connection getConnection(Configuration conf) {
    Connection connection;/*from   w  ww .j  a  v a  2s . c o  m*/
    try {
        String url = conf.get(DBConfiguration.URL_PROPERTY);
        try {
            // throws SQLException if no suitable driver is found
            DriverManager.getDriver(url);
        } catch (SQLException e) {
            if (driverShim == null) {
                if (driver == null) {
                    ClassLoader classLoader = conf.getClassLoader();
                    @SuppressWarnings("unchecked")
                    Class<? extends Driver> driverClass = (Class<? extends Driver>) classLoader
                            .loadClass(conf.get(DBConfiguration.DRIVER_CLASS_PROPERTY));
                    driver = driverClass.newInstance();

                    // De-register the default driver that gets registered when driver class is loaded.
                    DBUtils.deregisterAllDrivers(driverClass);
                }

                driverShim = new JDBCDriverShim(driver);
                DriverManager.registerDriver(driverShim);
                LOG.debug("Registered JDBC driver via shim {}. Actual Driver {}.", driverShim, driver);
            }
        }

        if (conf.get(DBConfiguration.USERNAME_PROPERTY) == null) {
            connection = DriverManager.getConnection(url);
        } else {
            connection = DriverManager.getConnection(url, conf.get(DBConfiguration.USERNAME_PROPERTY),
                    conf.get(DBConfiguration.PASSWORD_PROPERTY));
        }

        boolean autoCommitEnabled = conf.getBoolean(AUTO_COMMIT_ENABLED, false);
        if (autoCommitEnabled) {
            // hack to work around jdbc drivers like the hive driver that throw exceptions on commit
            connection = new NoOpCommitConnection(connection);
        } else {
            connection.setAutoCommit(false);
        }
        connection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    return connection;
}

From source file:co.cask.hydrator.plugin.db.batch.source.DataDrivenETLDBInputFormat.java

License:Apache License

@Override
public Connection getConnection() {
    if (this.connection == null) {
        Configuration conf = getConf();
        try {/*  w ww  .j a  v  a  2  s .c  o m*/
            String url = conf.get(DBConfiguration.URL_PROPERTY);
            try {
                // throws SQLException if no suitable driver is found
                DriverManager.getDriver(url);
            } catch (SQLException e) {
                if (driverShim == null) {
                    if (driver == null) {
                        ClassLoader classLoader = conf.getClassLoader();
                        @SuppressWarnings("unchecked")
                        Class<? extends Driver> driverClass = (Class<? extends Driver>) classLoader
                                .loadClass(conf.get(DBConfiguration.DRIVER_CLASS_PROPERTY));
                        driver = driverClass.newInstance();

                        // De-register the default driver that gets registered when driver class is loaded.
                        DBUtils.deregisterAllDrivers(driverClass);
                    }
                    driverShim = new JDBCDriverShim(driver);
                    DriverManager.registerDriver(driverShim);
                    LOG.debug("Registered JDBC driver via shim {}. Actual Driver {}.", driverShim, driver);
                }
            }
            if (conf.get(DBConfiguration.USERNAME_PROPERTY) == null) {
                this.connection = DriverManager.getConnection(url);
            } else {
                this.connection = DriverManager.getConnection(url, conf.get(DBConfiguration.USERNAME_PROPERTY),
                        conf.get(DBConfiguration.PASSWORD_PROPERTY));
            }

            boolean autoCommitEnabled = conf.getBoolean(AUTO_COMMIT_ENABLED, false);
            if (autoCommitEnabled) {
                // hack to work around jdbc drivers like the hive driver that throw exceptions on commit
                this.connection = new NoOpCommitConnection(this.connection);
            } else {
                this.connection.setAutoCommit(false);
            }
            this.connection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }
    return this.connection;
}

From source file:org.apache.crunch.contrib.io.jdbc.DataBaseSource.java

License:Apache License

private DataBaseSource(Class<T> inputClass, String driverClassName, String url, String username,
        String password, String selectClause, String countClause) {
    super(new Path("dbsource"), Writables.writables(inputClass), FormatBundle.forInput(DBInputFormat.class)
            .set(DBConfiguration.DRIVER_CLASS_PROPERTY, driverClassName).set(DBConfiguration.URL_PROPERTY, url)
            .set(DBConfiguration.USERNAME_PROPERTY, username).set(DBConfiguration.PASSWORD_PROPERTY, password)
            .set(DBConfiguration.INPUT_CLASS_PROPERTY, inputClass.getCanonicalName())
            .set(DBConfiguration.INPUT_QUERY, selectClause)
            .set(DBConfiguration.INPUT_COUNT_QUERY, countClause));
}