001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019package org.apache.hadoop.mapred.lib.db; 020 021import org.apache.hadoop.classification.InterfaceAudience; 022import org.apache.hadoop.classification.InterfaceStability; 023import org.apache.hadoop.mapred.JobConf; 024 025@InterfaceAudience.Public 026@InterfaceStability.Stable 027public class DBConfiguration extends 028 org.apache.hadoop.mapreduce.lib.db.DBConfiguration { 029 /** The JDBC Driver class name */ 030 public static final String DRIVER_CLASS_PROPERTY = 031 org.apache.hadoop.mapreduce.lib.db.DBConfiguration.DRIVER_CLASS_PROPERTY; 032 033 /** JDBC Database access URL */ 034 public static final String URL_PROPERTY = 035 org.apache.hadoop.mapreduce.lib.db.DBConfiguration.URL_PROPERTY; 036 037 /** User name to access the database */ 038 public static final String USERNAME_PROPERTY = 039 org.apache.hadoop.mapreduce.lib.db.DBConfiguration.USERNAME_PROPERTY; 040 041 /** Password to access the database */ 042 public static final String PASSWORD_PROPERTY = 043 org.apache.hadoop.mapreduce.lib.db.DBConfiguration.PASSWORD_PROPERTY; 044 045 /** Input table name */ 046 public static final String INPUT_TABLE_NAME_PROPERTY = org.apache.hadoop. 047 mapreduce.lib.db.DBConfiguration.INPUT_TABLE_NAME_PROPERTY; 048 049 /** Field names in the Input table */ 050 public static final String INPUT_FIELD_NAMES_PROPERTY = org.apache.hadoop. 051 mapreduce.lib.db.DBConfiguration.INPUT_FIELD_NAMES_PROPERTY; 052 053 /** WHERE clause in the input SELECT statement */ 054 public static final String INPUT_CONDITIONS_PROPERTY = org.apache.hadoop. 055 mapreduce.lib.db.DBConfiguration.INPUT_CONDITIONS_PROPERTY; 056 057 /** ORDER BY clause in the input SELECT statement */ 058 public static final String INPUT_ORDER_BY_PROPERTY = org.apache.hadoop. 059 mapreduce.lib.db.DBConfiguration.INPUT_ORDER_BY_PROPERTY; 060 061 /** Whole input query, exluding LIMIT...OFFSET */ 062 public static final String INPUT_QUERY = 063 org.apache.hadoop.mapreduce.lib.db.DBConfiguration.INPUT_QUERY; 064 065 /** Input query to get the count of records */ 066 public static final String INPUT_COUNT_QUERY = 067 org.apache.hadoop.mapreduce.lib.db.DBConfiguration.INPUT_COUNT_QUERY; 068 069 /** Class name implementing DBWritable which will hold input tuples */ 070 public static final String INPUT_CLASS_PROPERTY = 071 org.apache.hadoop.mapreduce.lib.db.DBConfiguration.INPUT_CLASS_PROPERTY; 072 073 /** Output table name */ 074 public static final String OUTPUT_TABLE_NAME_PROPERTY = org.apache.hadoop. 075 mapreduce.lib.db.DBConfiguration.OUTPUT_TABLE_NAME_PROPERTY; 076 077 /** Field names in the Output table */ 078 public static final String OUTPUT_FIELD_NAMES_PROPERTY = org.apache.hadoop. 079 mapreduce.lib.db.DBConfiguration.OUTPUT_FIELD_NAMES_PROPERTY; 080 081 /** Number of fields in the Output table */ 082 public static final String OUTPUT_FIELD_COUNT_PROPERTY = org.apache.hadoop. 083 mapreduce.lib.db.DBConfiguration.OUTPUT_FIELD_COUNT_PROPERTY; 084 085 086 /** 087 * Sets the DB access related fields in the JobConf. 088 * @param job the job 089 * @param driverClass JDBC Driver class name 090 * @param dbUrl JDBC DB access URL. 091 * @param userName DB access username 092 * @param passwd DB access passwd 093 */ 094 public static void configureDB(JobConf job, String driverClass, String dbUrl 095 , String userName, String passwd) { 096 097 job.set(DRIVER_CLASS_PROPERTY, driverClass); 098 job.set(URL_PROPERTY, dbUrl); 099 if(userName != null) 100 job.set(USERNAME_PROPERTY, userName); 101 if(passwd != null) 102 job.set(PASSWORD_PROPERTY, passwd); 103 } 104 105 /** 106 * Sets the DB access related fields in the JobConf. 107 * @param job the job 108 * @param driverClass JDBC Driver class name 109 * @param dbUrl JDBC DB access URL. 110 */ 111 public static void configureDB(JobConf job, String driverClass, String dbUrl) { 112 configureDB(job, driverClass, dbUrl, null, null); 113 } 114 115 DBConfiguration(JobConf job) { 116 super(job); 117 } 118 119} 120