Exemple #1
0
            public override DBConfiguration GetDBConf()
            {
                string[]        names  = new string[] { "field1", "field2" };
                DBConfiguration result = Org.Mockito.Mockito.Mock <DBConfiguration>();

                Org.Mockito.Mockito.When(result.GetInputConditions()).ThenReturn("conditions");
                Org.Mockito.Mockito.When(result.GetInputFieldNames()).ThenReturn(names);
                Org.Mockito.Mockito.When(result.GetInputTableName()).ThenReturn("table");
                return(result);
            }
Exemple #2
0
 /// <summary>
 /// <inheritDoc/>
 ///
 /// </summary>
 public virtual void SetConf(Configuration conf)
 {
     dbConf = new DBConfiguration(conf);
     try
     {
         this.connection = CreateConnection();
         DatabaseMetaData dbMeta = connection.GetMetaData();
         this.dbProductName = StringUtils.ToUpperCase(dbMeta.GetDatabaseProductName());
     }
     catch (Exception ex)
     {
         throw new RuntimeException(ex);
     }
     tableName  = dbConf.GetInputTableName();
     fieldNames = dbConf.GetInputFieldNames();
     conditions = dbConf.GetInputConditions();
 }
        /// <exception cref="System.IO.IOException"/>
        protected internal override RecordReader <LongWritable, T> CreateDBRecordReader(DBInputFormat.DBInputSplit
                                                                                        split, Configuration conf)
        {
            DBConfiguration dbConf     = GetDBConf();
            Type            inputClass = (Type)(dbConf.GetInputClass());

            try
            {
                // Use Oracle-specific db reader
                return(new OracleDataDrivenDBRecordReader <T>(split, inputClass, conf, CreateConnection
                                                                  (), dbConf, dbConf.GetInputConditions(), dbConf.GetInputFieldNames(), dbConf.GetInputTableName
                                                                  ()));
            }
            catch (SQLException ex)
            {
                throw new IOException(ex.Message);
            }
        }
        /// <exception cref="System.IO.IOException"/>
        protected internal override RecordReader <LongWritable, T> CreateDBRecordReader(DBInputFormat.DBInputSplit
                                                                                        split, Configuration conf)
        {
            DBConfiguration dbConf        = GetDBConf();
            Type            inputClass    = (Type)(dbConf.GetInputClass());
            string          dbProductName = GetDBProductName();

            Log.Debug("Creating db record reader for db product: " + dbProductName);
            try
            {
                // use database product name to determine appropriate record reader.
                if (dbProductName.StartsWith("MYSQL"))
                {
                    // use MySQL-specific db reader.
                    return(new MySQLDataDrivenDBRecordReader <T>(split, inputClass, conf, CreateConnection
                                                                     (), dbConf, dbConf.GetInputConditions(), dbConf.GetInputFieldNames(), dbConf.GetInputTableName
                                                                     ()));
                }
                else
                {
                    // Generic reader.
                    return(new DataDrivenDBRecordReader <T>(split, inputClass, conf, CreateConnection(
                                                                ), dbConf, dbConf.GetInputConditions(), dbConf.GetInputFieldNames(), dbConf.GetInputTableName
                                                                (), dbProductName));
                }
            }
            catch (SQLException ex)
            {
                throw new IOException(ex.Message);
            }
        }