net.sf.farrago.namespace.flatfile
Class FlatFileParams

java.lang.Object
  extended by net.sf.farrago.plugin.FarragoAbstractPluginBase
      extended by net.sf.farrago.namespace.impl.MedAbstractBase
          extended by net.sf.farrago.namespace.flatfile.FlatFileParams

 class FlatFileParams
extends MedAbstractBase

Decodes options used for a flat file data server. An instance of this class must be initialized with decode() before calling its other methods. The conventions for parameters are as follows:

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/namespace/flatfile/FlatFileParams.java#2 $
Author:
John Pham

Nested Class Summary
static class FlatFileParams.SchemaType
          Enumeration for schema types used by the flat file reader.
 
Field Summary
private  String controlFileExtension
           
private  String dateFormat
           
protected static String DEFAULT_CONTROL_FILE_EXTENSION
           
protected static String DEFAULT_ESCAPE_CHAR
           
protected static String DEFAULT_FIELD_DELIMITER
           
protected static String DEFAULT_FILE_EXTENSION
           
protected static boolean DEFAULT_LENIENT
           
protected static String DEFAULT_LINE_DELIMITER
           
protected static boolean DEFAULT_MAPPED
           
protected static int DEFAULT_NUM_ROWS_SCAN
           
protected static String DEFAULT_QUOTE_CHAR
           
protected static boolean DEFAULT_TRIM
           
protected static boolean DEFAULT_WITH_HEADER
           
protected static boolean DEFAULT_WITH_LOGGING
           
private  String directory
           
private  char escapeChar
           
private  char fieldDelimiter
           
static String FILE_EXTENSION_PREFIX
           
private  String fileExtension
           
private  boolean lenient
           
private  char lineDelimiter
           
static String LOG_FILE_EXTENSION
           
private  String logDirectory
           
private  boolean mapped
           
private  int numRowsScan
           
static String PROP_CONTROL_FILE_EXTENSION
           
static String PROP_DATE_FORMAT
           
static String PROP_DIRECTORY
           
static String PROP_ESCAPE_CHAR
           
static String PROP_FIELD_DELIMITER
           
static String PROP_FILE_EXTENSION
           
static String PROP_LENIENT
           
static String PROP_LINE_DELIMITER
           
static String PROP_LOG_DIRECTORY
           
static String PROP_MAPPED
           
static String PROP_NUM_ROWS_SCAN
           
static String PROP_QUOTE_CHAR
           
static String PROP_TIME_FORMAT
           
static String PROP_TIMESTAMP_FORMAT
           
static String PROP_TRIM
           
static String PROP_WITH_HEADER
           
static String PROP_WITH_LOGGING
           
private  Properties props
           
private  char quoteChar
           
private  String timeFormat
           
private  String timestampFormat
           
private  boolean trim
           
private  boolean withHeader
           
private  boolean withLogging
           
 
Fields inherited from class net.sf.farrago.plugin.FarragoAbstractPluginBase
BOOLEAN_CHOICES_DEFAULT_FALSE, BOOLEAN_CHOICES_DEFAULT_TRUE, EMPTY_DRIVER_PROPERTIES
 
Constructor Summary
FlatFileParams(Properties props)
          Constructs an uninitialized FlatFileParams.
 
Method Summary
 void decode()
          The main entry point into paremter decoding.
private  String decodeDatetimeFormat(String format)
           
private  char decodeDelimiter(String delim)
          Decodes a delimiter string into a canonical delimiter character.
private  String decodeDirectory(String directory)
          Decodes a directory name into a useful format.
private  String decodeExtension(String extension)
           
private  char decodeSpecialChar(String specialChar, String defaultChar)
          Decodes a quote or escape character.
 String getControlFileExtenstion()
           
 String getDateFormat()
           
 String getDirectory()
           
 char getEscapeChar()
           
 char getFieldDelimiter()
           
 String getFileExtenstion()
           
 boolean getLenient()
           
 char getLineDelimiter()
           
 String getLogDirectory()
           
 boolean getMapped()
           
 int getNumRowsScan()
           
 char getQuoteChar()
           
static FlatFileParams.SchemaType getSchemaType(String schemaName, boolean queryDefault)
          Lookup the type of a schema based upon it's schema name.
 String getTimeFormat()
           
 String getTimestampFormat()
           
 boolean getTrim()
           
 boolean getWithHeader()
           
 boolean getWithLogging()
           
 
Methods inherited from class net.sf.farrago.plugin.FarragoAbstractPluginBase
getBooleanProperty, getByteProperty, getDoubleProperty, getFloatProperty, getIntProperty, getLongProperty, getShortProperty, requireProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_DIRECTORY

public static final String PROP_DIRECTORY
See Also:
Constant Field Values

PROP_FILE_EXTENSION

public static final String PROP_FILE_EXTENSION
See Also:
Constant Field Values

PROP_CONTROL_FILE_EXTENSION

public static final String PROP_CONTROL_FILE_EXTENSION
See Also:
Constant Field Values

PROP_FIELD_DELIMITER

public static final String PROP_FIELD_DELIMITER
See Also:
Constant Field Values

PROP_LINE_DELIMITER

public static final String PROP_LINE_DELIMITER
See Also:
Constant Field Values

PROP_QUOTE_CHAR

public static final String PROP_QUOTE_CHAR
See Also:
Constant Field Values

PROP_ESCAPE_CHAR

public static final String PROP_ESCAPE_CHAR
See Also:
Constant Field Values

PROP_WITH_HEADER

public static final String PROP_WITH_HEADER
See Also:
Constant Field Values

PROP_NUM_ROWS_SCAN

public static final String PROP_NUM_ROWS_SCAN
See Also:
Constant Field Values

PROP_WITH_LOGGING

public static final String PROP_WITH_LOGGING
See Also:
Constant Field Values

PROP_LOG_DIRECTORY

public static final String PROP_LOG_DIRECTORY
See Also:
Constant Field Values

PROP_DATE_FORMAT

public static final String PROP_DATE_FORMAT
See Also:
Constant Field Values

PROP_TIME_FORMAT

public static final String PROP_TIME_FORMAT
See Also:
Constant Field Values

PROP_TIMESTAMP_FORMAT

public static final String PROP_TIMESTAMP_FORMAT
See Also:
Constant Field Values

PROP_LENIENT

public static final String PROP_LENIENT
See Also:
Constant Field Values

PROP_TRIM

public static final String PROP_TRIM
See Also:
Constant Field Values

PROP_MAPPED

public static final String PROP_MAPPED
See Also:
Constant Field Values

FILE_EXTENSION_PREFIX

public static final String FILE_EXTENSION_PREFIX
See Also:
Constant Field Values

LOG_FILE_EXTENSION

public static final String LOG_FILE_EXTENSION
See Also:
Constant Field Values

DEFAULT_FILE_EXTENSION

protected static final String DEFAULT_FILE_EXTENSION
See Also:
Constant Field Values

DEFAULT_CONTROL_FILE_EXTENSION

protected static final String DEFAULT_CONTROL_FILE_EXTENSION
See Also:
Constant Field Values

DEFAULT_FIELD_DELIMITER

protected static final String DEFAULT_FIELD_DELIMITER
See Also:
Constant Field Values

DEFAULT_LINE_DELIMITER

protected static final String DEFAULT_LINE_DELIMITER
See Also:
Constant Field Values

DEFAULT_QUOTE_CHAR

protected static final String DEFAULT_QUOTE_CHAR
See Also:
Constant Field Values

DEFAULT_ESCAPE_CHAR

protected static final String DEFAULT_ESCAPE_CHAR
See Also:
Constant Field Values

DEFAULT_WITH_HEADER

protected static final boolean DEFAULT_WITH_HEADER
See Also:
Constant Field Values

DEFAULT_NUM_ROWS_SCAN

protected static final int DEFAULT_NUM_ROWS_SCAN
See Also:
Constant Field Values

DEFAULT_WITH_LOGGING

protected static final boolean DEFAULT_WITH_LOGGING
See Also:
Constant Field Values

DEFAULT_LENIENT

protected static final boolean DEFAULT_LENIENT
See Also:
Constant Field Values

DEFAULT_TRIM

protected static final boolean DEFAULT_TRIM
See Also:
Constant Field Values

DEFAULT_MAPPED

protected static final boolean DEFAULT_MAPPED
See Also:
Constant Field Values

props

private Properties props

directory

private String directory

logDirectory

private String logDirectory

fileExtension

private String fileExtension

controlFileExtension

private String controlFileExtension

fieldDelimiter

private char fieldDelimiter

lineDelimiter

private char lineDelimiter

quoteChar

private char quoteChar

escapeChar

private char escapeChar

withHeader

private boolean withHeader

withLogging

private boolean withLogging

numRowsScan

private int numRowsScan

lenient

private boolean lenient

trim

private boolean trim

mapped

private boolean mapped

dateFormat

private String dateFormat

timeFormat

private String timeFormat

timestampFormat

private String timestampFormat
Constructor Detail

FlatFileParams

public FlatFileParams(Properties props)
Constructs an uninitialized FlatFileParams. The method decode() must be called before the object is used.

Parameters:
props - foreign server parameters
Method Detail

decode

public void decode()
            throws SQLException
The main entry point into paremter decoding. Throws an exception when there are error parsing parameters.

Throws:
SQLException

decodeDelimiter

private char decodeDelimiter(String delim)
Decodes a delimiter string into a canonical delimiter character. This method recognizes the escape sequences \t, \r, \n. Combinations of the two line characters \r and \n are all reduced to universal line character \n.

This function comes from legacy code and is based on odd heuristics.

REVIEW: this behavior seems overly complex and awkward

Parameters:
delim - delimiter string
Returns:
canonical delimiter character represented by delimiter string

decodeSpecialChar

private char decodeSpecialChar(String specialChar,
                               String defaultChar)
Decodes a quote or escape character. While a null value is converted to the default character, an empty value is interpreted as 0.

Parameters:
specialChar - string containing special character, may be empty
defaultChar - default string, must not be empty
Returns:
the first character of specialChar or defaultChar

decodeDirectory

private String decodeDirectory(String directory)
Decodes a directory name into a useful format. If the name is null, returns an empty string. Otherwise, ensures the directory name ends with File.separator.

Parameters:
directory - directory name, may be null
Returns:
empty string or directory name, ending with File.separator

decodeExtension

private String decodeExtension(String extension)

decodeDatetimeFormat

private String decodeDatetimeFormat(String format)

getDirectory

public String getDirectory()

getFileExtenstion

public String getFileExtenstion()

getControlFileExtenstion

public String getControlFileExtenstion()

getFieldDelimiter

public char getFieldDelimiter()

getLineDelimiter

public char getLineDelimiter()

getQuoteChar

public char getQuoteChar()

getEscapeChar

public char getEscapeChar()

getWithHeader

public boolean getWithHeader()

getNumRowsScan

public int getNumRowsScan()

getWithLogging

public boolean getWithLogging()

getLogDirectory

public String getLogDirectory()

getDateFormat

public String getDateFormat()

getTimeFormat

public String getTimeFormat()

getTimestampFormat

public String getTimestampFormat()

getLenient

public boolean getLenient()

getTrim

public boolean getTrim()

getMapped

public boolean getMapped()

getSchemaType

public static FlatFileParams.SchemaType getSchemaType(String schemaName,
                                                      boolean queryDefault)
Lookup the type of a schema based upon it's schema name. The queryDefault parameter allows the type to default to QUERY when the schema name is unrecognized. This is useful for foreign tables, which use a local schema name.

Parameters:
schemaName - name of schema to lookup
queryDefault - whether to make a query the default type