Review Board 1.7.22


Fix for SQOOP-1029

Review Request #10943 - Created May 4, 2013 and updated

Venkat Ranganathan
Reviewers
Sqoop
jarcec
sqoop-trunk
Provides an overridden implementation to get column names and types that obeys the way Oracle DBMetadata provides procedure metadata
Tested with Oracle 11g

Diff revision 1

This is not the most recent revision of the diff. The latest diff is revision 2. See what's changed.

1 2
1 2

  1. src/java/org/apache/sqoop/manager/OracleManager.java: Loading...
  2. src/java/org/apache/sqoop/manager/SqlManager.java: Loading...
src/java/org/apache/sqoop/manager/OracleManager.java
Revision 1999344 New Change
[20] 18 lines
[+20]
19
package org.apache.sqoop.manager;
19
package org.apache.sqoop.manager;
20

    
   
20

   
21
import java.io.IOException;
21
import java.io.IOException;
22
import java.lang.reflect.Method;
22
import java.lang.reflect.Method;
23
import java.sql.Connection;
23
import java.sql.Connection;

    
   
24
import java.sql.DatabaseMetaData;
24
import java.sql.DriverManager;
25
import java.sql.DriverManager;
25
import java.sql.PreparedStatement;
26
import java.sql.PreparedStatement;
26
import java.sql.ResultSet;
27
import java.sql.ResultSet;
27
import java.sql.SQLException;
28
import java.sql.SQLException;
28
import java.sql.Statement;
29
import java.sql.Statement;
29
import java.sql.Timestamp;
30
import java.sql.Timestamp;
30
import java.sql.Types;
31
import java.sql.Types;
31
import java.util.ArrayList;
32
import java.util.ArrayList;

    
   
33
import java.util.Arrays;
32
import java.util.HashMap;
34
import java.util.HashMap;
33
import java.util.HashSet;
35
import java.util.HashSet;
34
import java.util.LinkedHashSet;
36
import java.util.LinkedHashSet;
35
import java.util.List;
37
import java.util.List;
36
import java.util.Map;
38
import java.util.Map;
[+20] [20] 669 lines
[+20] [+] public String[] listTables() {
706

    
   
708

   
707
    return tables.toArray(new String[tables.size()]);
709
    return tables.toArray(new String[tables.size()]);
708
  }
710
  }
709

    
   
711

   
710
  @Override
712
  @Override

    
   
713
  public String[] getColumnNamesForProcedure(String procedureName) {

    
   
714
    List<String> ret = new ArrayList<String>();

    
   
715
    try {

    
   
716
      DatabaseMetaData metaData = this.getConnection().getMetaData();

    
   
717
      ResultSet results = metaData.getProcedureColumns(null, null,

    
   
718
        procedureName, null);

    
   
719
      if (null == results) {

    
   
720
        return null;

    
   
721
      }

    
   
722

   

    
   
723
      try {

    
   
724
        while (results.next()) {

    
   
725
          if (results.getInt("COLUMN_TYPE")

    
   
726
          != DatabaseMetaData.procedureColumnReturn) {

    
   
727
            int index = results.getInt("ORDINAL_POSITION");

    
   
728
            if (index < 0) {

    
   
729
              continue; // actually the return type

    
   
730
            }

    
   
731
            for (int i = ret.size(); i < index; ++i) {

    
   
732
              ret.add(null);

    
   
733
            }

    
   
734
            String name = results.getString("COLUMN_NAME");

    
   
735
            if (index == ret.size()) {

    
   
736
              ret.add(name);

    
   
737
            } else {

    
   
738
              ret.set(index, name);

    
   
739
            }

    
   
740
          }

    
   
741
        }

    
   
742
        String[] result = ret.toArray(new String[ret.size()]);

    
   
743
        LOG.debug("getColumnsNamesForProcedure returns "

    
   
744
          + Arrays.toString(ret.toArray()));

    
   
745
        return result;

    
   
746
      } finally {

    
   
747
        results.close();

    
   
748
        getConnection().commit();

    
   
749
      }

    
   
750
    } catch (SQLException e) {

    
   
751
      LoggingUtils.logAll(LOG, "Error reading procedure metadata: ", e);

    
   
752
      throw new RuntimeException("Can't fetch column names for procedure.", e);

    
   
753
    }

    
   
754
  }

    
   
755

   

    
   
756
  @Override
711
  public String[] getColumnNames(String tableName) {
757
  public String[] getColumnNames(String tableName) {
712
    Connection conn = null;
758
    Connection conn = null;
713
    PreparedStatement pStmt = null;
759
    PreparedStatement pStmt = null;
714
    ResultSet rset = null;
760
    ResultSet rset = null;
715
    List<String> columns = new ArrayList<String>();
761
    List<String> columns = new ArrayList<String>();
[+20] [20] 149 lines
src/java/org/apache/sqoop/manager/SqlManager.java
Revision 6952b9e New Change
 
  1. src/java/org/apache/sqoop/manager/OracleManager.java: Loading...
  2. src/java/org/apache/sqoop/manager/SqlManager.java: Loading...