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

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

Introduction

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

Prototype

String URL_PROPERTY

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

Click Source Link

Document

JDBC Database access URL

Usage

From source file:infinidb.hadoop.db.InfiniDBConfiguration.java

License:Apache License

/**
 * Sets the DB access related fields in the JobConf.  
 * @param job the job/*from w w w . jav a 2s .  c  om*/
 * @param driverClass JDBC Driver class name
 * @param dbUrl JDBC DB access URL. 
 * @param userName DB access username 
 * @param passwd DB access passwd
 */
public static void configureDB(JobConf job, String driverClass, String dbUrl, String userName, String passwd) {

    job.set(DBConfiguration.DRIVER_CLASS_PROPERTY, driverClass);
    job.set(DBConfiguration.URL_PROPERTY, dbUrl);
    if (userName != null)
        job.set(DBConfiguration.USERNAME_PROPERTY, userName);
    if (passwd != null)
        job.set(DBConfiguration.PASSWORD_PROPERTY, passwd);
}

From source file:infinidb.hadoop.db.InfiniDBConfiguration.java

License:Apache License

/** Returns a connection object o the DB 
 * @throws ClassNotFoundException //from   w  w w . j  av a  2  s. c o  m
 * @throws SQLException
 */
Connection getConnection() throws IOException {
    try {
        Class.forName(job.get(DBConfiguration.DRIVER_CLASS_PROPERTY));
    } catch (ClassNotFoundException exception) {
        throw new IOException("Conection driver can not be loaded", exception);
    }

    try {
        if (job.get(DBConfiguration.USERNAME_PROPERTY) == null) {
            return DriverManager.getConnection(job.get(DBConfiguration.URL_PROPERTY));
        } else {
            return DriverManager.getConnection(job.get(DBConfiguration.URL_PROPERTY),
                    job.get(DBConfiguration.USERNAME_PROPERTY), job.get(DBConfiguration.PASSWORD_PROPERTY));
        }
    } catch (SQLException exception) {
        throw new IOException("Conection can not be established", exception);
    }
}

From source file:org.apache.sqoop.mapreduce.sqlserver.SqlServerUpsertOutputFormatTest.java

License:Apache License

@SuppressWarnings("unchecked")
@Test// w  w w  .  j a  va2 s  .co m
public void Merge_statement_is_parameterized_correctly() throws Exception {
    Configuration conf = new Configuration();
    conf.set(DBConfiguration.DRIVER_CLASS_PROPERTY, org.hsqldb.jdbcDriver.class.getName());
    conf.set(DBConfiguration.URL_PROPERTY, "jdbc:hsqldb:.");
    conf.set(ExportJobBase.SQOOP_EXPORT_UPDATE_COL_KEY, "");
    conf.set(DBConfiguration.OUTPUT_FIELD_NAMES_PROPERTY, "");
    String tableName = "#myTable";
    String[] columnNames = { "FirstColumn", "SecondColumn", "ThirdColumn" };
    String[] updateKeyColumns = { "FirstColumn" };
    conf.set(DBConfiguration.OUTPUT_TABLE_NAME_PROPERTY, tableName);
    conf.set(DBConfiguration.OUTPUT_FIELD_NAMES_PROPERTY, StringUtils.join(columnNames, ','));
    conf.set(ExportJobBase.SQOOP_EXPORT_UPDATE_COL_KEY, StringUtils.join(updateKeyColumns, ','));
    conf.set(SQLServerManager.IDENTITY_INSERT_PROP, "true");
    TaskAttemptContext context = null;
    Class cls = null;
    try {
        cls = Class.forName("org.apache.hadoop.mapreduce.task.TaskAttemptContextImpl");
    } catch (ClassNotFoundException cnfe) {
        // Not hadoop 2.0
    }
    if (cls == null) {
        try {
            cls = Class.forName("org.apache.hadoop.mapreduce.task.TaskAttemptContext");
        } catch (ClassNotFoundException cnfe) {
            // Something wrong
        }
    }
    assertNotNull(cls);
    Constructor c = cls.getConstructor(Configuration.class, TaskAttemptID.class);
    context = (TaskAttemptContext) c.newInstance(conf, new TaskAttemptID());
    SqlServerUpsertOutputFormat outputFormat = new SqlServerUpsertOutputFormat();
    SqlServerUpsertRecordWriter recordWriter = outputFormat.new SqlServerUpsertRecordWriter(context);
    assertEquals(
            "SET IDENTITY_INSERT #myTable ON " + "MERGE INTO #myTable AS _target USING ( VALUES ( ?, ?, ? ) )"
                    + " AS _source ( FirstColumn, SecondColumn, ThirdColumn ) ON "
                    + "_source.FirstColumn = _target.FirstColumn"
                    + "  WHEN MATCHED THEN UPDATE SET _target.SecondColumn = "
                    + "_source.SecondColumn, _target.ThirdColumn = _source.ThirdColumn"
                    + "  WHEN NOT MATCHED THEN INSERT ( FirstColumn, SecondColumn," + " ThirdColumn ) VALUES "
                    + "( _source.FirstColumn, _source.SecondColumn, _source.ThirdColumn );",
            recordWriter.getUpdateStatement());
}