com.cloudera.sqoop.orm
Class ClassWriter

java.lang.Object
  extended by com.cloudera.sqoop.orm.ClassWriter

public class ClassWriter
extends java.lang.Object

Creates an ORM class to represent a table from a database.


Field Summary
static int CLASS_WRITER_VERSION
          This version number is injected into all generated Java classes to denote which version of the ClassWriter's output format was used to generate the class.
static java.util.HashSet<java.lang.String> JAVA_RESERVED_WORDS
           
static org.apache.commons.logging.Log LOG
           
 
Constructor Summary
ClassWriter(SqoopOptions opts, ConnManager connMgr, java.lang.String table, CompilationManager compMgr)
          Creates a new ClassWriter to generate an ORM class for a table.
 
Method Summary
 void generate()
          Generate the ORM code for the class.
 java.lang.StringBuilder generateClassForColumns(java.util.Map<java.lang.String,java.lang.Integer> columnTypes, java.lang.String[] colNames)
          Generate the ORM code for a table object containing the named columns.
static java.lang.String toIdentifier(java.lang.String candidate)
          Coerce a candidate name for an identifier into one which will definitely compile.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

public static final org.apache.commons.logging.Log LOG

JAVA_RESERVED_WORDS

public static final java.util.HashSet<java.lang.String> JAVA_RESERVED_WORDS

CLASS_WRITER_VERSION

public static final int CLASS_WRITER_VERSION
This version number is injected into all generated Java classes to denote which version of the ClassWriter's output format was used to generate the class. If the way that we generate classes changes, bump this number. This number is retrieved by the SqoopRecord.getClassFormatVersion() method.

See Also:
Constant Field Values
Constructor Detail

ClassWriter

public ClassWriter(SqoopOptions opts,
                   ConnManager connMgr,
                   java.lang.String table,
                   CompilationManager compMgr)
Creates a new ClassWriter to generate an ORM class for a table.

Parameters:
opts - program-wide options
connMgr - the connection manager used to describe the table.
table - the name of the table to read.
Method Detail

toIdentifier

public static java.lang.String toIdentifier(java.lang.String candidate)
Coerce a candidate name for an identifier into one which will definitely compile. Ensures that the returned identifier matches [A-Za-z_][A-Za-z0-9_]* and is not a reserved word.

Parameters:
candidate - A string we want to use as an identifier
Returns:
A string naming an identifier which compiles and is similar to the candidate.

generate

public void generate()
              throws java.io.IOException
Generate the ORM code for the class.

Throws:
java.io.IOException

generateClassForColumns

public java.lang.StringBuilder generateClassForColumns(java.util.Map<java.lang.String,java.lang.Integer> columnTypes,
                                                       java.lang.String[] colNames)
Generate the ORM code for a table object containing the named columns.

Parameters:
columnTypes - - mapping from column names to sql types
colNames - - ordered list of column names for table.
Returns:
- A StringBuilder that contains the text of the class code.


Copyright © 2010 Cloudera, Inc.