com.cloudera.sqoop.manager
Class ConnManager

java.lang.Object
  extended by com.cloudera.sqoop.manager.ConnManager
Direct Known Subclasses:
SqlManager

public abstract class ConnManager
extends java.lang.Object

Abstract interface that manages connections to a database. The implementations of this class drive the actual discussion with the database about table formats, etc.


Constructor Summary
ConnManager()
           
 
Method Summary
abstract  void close()
          Perform any shutdown operations on the connection.
 java.lang.String escapeColName(java.lang.String colName)
          When using a column name in a generated SQL query, how (if at all) should we escape that column name? e.g., a column named "table" may need to be quoted with backtiks: "`table`".
 java.lang.String escapeTableName(java.lang.String tableName)
          When using a table name in a generated SQL query, how (if at all) should we escape that column name? e.g., a table named "table" may need to be quoted with backtiks: "`table`".
abstract  void execAndPrint(java.lang.String s)
          Execute a SQL statement 's' and print its results to stdout.
 void exportTable(ExportJobContext context)
          Export data stored in HDFS into a table in a database.
abstract  java.lang.String[] getColumnNames(java.lang.String tableName)
          Return a list of column names in a table in the order returned by the db.
abstract  java.util.Map<java.lang.String,java.lang.Integer> getColumnTypes(java.lang.String tableName)
          Return an unordered mapping from colname to sqltype for all columns in a table.
abstract  java.sql.Connection getConnection()
           
abstract  java.lang.String getDriverClass()
           
abstract  java.lang.String getPrimaryKey(java.lang.String tableName)
          Return the name of the primary key for a table, or null if there is none.
abstract  void importTable(ImportJobContext context)
          Perform an import of a table from the database into HDFS.
abstract  java.lang.String[] listDatabases()
          Return a list of all databases on a server.
abstract  java.lang.String[] listTables()
          Return a list of all tables in a database.
abstract  java.sql.ResultSet readTable(java.lang.String tableName, java.lang.String[] columns)
          Execute a SQL statement to read the named set of columns from a table.
abstract  void release()
          If a method of this ConnManager has returned a ResultSet to you, you are responsible for calling release() after you close the ResultSet object, to free internal resources.
abstract  java.lang.String toHiveType(int sqlType)
          Return hive type for SQL type.
abstract  java.lang.String toJavaType(int sqlType)
          Return java type for SQL type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnManager

public ConnManager()
Method Detail

listDatabases

public abstract java.lang.String[] listDatabases()
Return a list of all databases on a server.


listTables

public abstract java.lang.String[] listTables()
Return a list of all tables in a database.


getColumnNames

public abstract java.lang.String[] getColumnNames(java.lang.String tableName)
Return a list of column names in a table in the order returned by the db.


getPrimaryKey

public abstract java.lang.String getPrimaryKey(java.lang.String tableName)
Return the name of the primary key for a table, or null if there is none.


toJavaType

public abstract java.lang.String toJavaType(int sqlType)
Return java type for SQL type.

Parameters:
sqlType - sql type
Returns:
java type

toHiveType

public abstract java.lang.String toHiveType(int sqlType)
Return hive type for SQL type.

Parameters:
sqlType - sql type
Returns:
hive type

getColumnTypes

public abstract java.util.Map<java.lang.String,java.lang.Integer> getColumnTypes(java.lang.String tableName)
Return an unordered mapping from colname to sqltype for all columns in a table. The Integer type id is a constant from java.sql.Types


readTable

public abstract java.sql.ResultSet readTable(java.lang.String tableName,
                                             java.lang.String[] columns)
                                      throws java.sql.SQLException
Execute a SQL statement to read the named set of columns from a table. If columns is null, all columns from the table are read. This is a direct (non-parallelized) read of the table back to the current client. The client is responsible for calling ResultSet.close() when done with the returned ResultSet object, and for calling release() after that to free internal state.

Throws:
java.sql.SQLException

getConnection

public abstract java.sql.Connection getConnection()
                                           throws java.sql.SQLException
Returns:
the actual database connection.
Throws:
java.sql.SQLException

getDriverClass

public abstract java.lang.String getDriverClass()
Returns:
a string identifying the driver class to load for this JDBC connection type.

execAndPrint

public abstract void execAndPrint(java.lang.String s)
Execute a SQL statement 's' and print its results to stdout.


importTable

public abstract void importTable(ImportJobContext context)
                          throws java.io.IOException,
                                 ImportException
Perform an import of a table from the database into HDFS.

Throws:
java.io.IOException
ImportException

escapeColName

public java.lang.String escapeColName(java.lang.String colName)
When using a column name in a generated SQL query, how (if at all) should we escape that column name? e.g., a column named "table" may need to be quoted with backtiks: "`table`".

Parameters:
colName - the column name as provided by the user, etc.
Returns:
how the column name should be rendered in the sql text.

escapeTableName

public java.lang.String escapeTableName(java.lang.String tableName)
When using a table name in a generated SQL query, how (if at all) should we escape that column name? e.g., a table named "table" may need to be quoted with backtiks: "`table`".

Parameters:
tableName - the table name as provided by the user, etc.
Returns:
how the table name should be rendered in the sql text.

close

public abstract void close()
                    throws java.sql.SQLException
Perform any shutdown operations on the connection.

Throws:
java.sql.SQLException

exportTable

public void exportTable(ExportJobContext context)
                 throws java.io.IOException,
                        ExportException
Export data stored in HDFS into a table in a database.

Throws:
java.io.IOException
ExportException

release

public abstract void release()
If a method of this ConnManager has returned a ResultSet to you, you are responsible for calling release() after you close the ResultSet object, to free internal resources. ConnManager implementations do not guarantee the ability to have multiple returned ResultSets available concurrently. Requesting a new ResultSet from a ConnManager may cause other open ResulSets to close.



Copyright © 2010 Cloudera, Inc.