net.sf.farrago.namespace.flatfile
Class FlatFileDataServer

java.lang.Object
  extended by net.sf.farrago.plugin.FarragoAbstractPluginBase
      extended by net.sf.farrago.namespace.impl.MedAbstractBase
          extended by net.sf.farrago.namespace.impl.MedAbstractDataServer
              extended by net.sf.farrago.namespace.flatfile.FlatFileDataServer
All Implemented Interfaces:
FarragoMedDataServer, FarragoAllocation, ClosableAllocation

 class FlatFileDataServer
extends MedAbstractDataServer

FlatFileDataServer provides an implementation of the FarragoMedDataServer interface.

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

Field Summary
private static int DESCRIBE_COLUMN_LENGTH
           
private static String DESCRIBE_COLUMN_NAME
           
(package private)  FlatFileParams params
           
private static String QUALIFIED_NAME_SEPARATOR
           
private static String SQL_QUOTE_CHARACTER
           
private static Logger tracer
           
private  MedAbstractDataWrapper wrapper
           
 
Fields inherited from class net.sf.farrago.plugin.FarragoAbstractPluginBase
BOOLEAN_CHOICES_DEFAULT_FALSE, BOOLEAN_CHOICES_DEFAULT_TRUE, EMPTY_DRIVER_PROPERTIES
 
Fields inherited from interface net.sf.farrago.namespace.FarragoMedDataServer
PROP_SERVER_NAME, PROP_SERVER_TYPE, PROP_SERVER_VERSION
 
Constructor Summary
FlatFileDataServer(MedAbstractDataWrapper wrapper, String serverMofId, Properties props)
           
 
Method Summary
 void closeAllocation()
          Closes this object.
(package private)  RelDataType createRowType(FarragoTypeFactory typeFactory, RelDataType[] types, String[] names)
           
private  RelDataType deriveRowType(FarragoTypeFactory typeFactory, FlatFileParams.SchemaType schemaType, String[] localName, String filename, FlatFileBcpFile bcpFile)
          Derives the row type of a table when other type information is not available.
private  String getDescribeQuery(String[] localName)
          Constructs an internal query to describe the results of sampling
private  List<Integer> getFieldSizes(String[] localName)
          Returns the sizes of a flat file's fields, based upon an internal describe query.
 FarragoMedNameDirectory getNameDirectory()
          Gets a FarragoMedNameDirectory corresponding to this server.
private  String getQualifiedName(String[] localName)
          Constructs a qualified (multi-part) name
 Object getRuntimeSupport(Object param)
          Gets an object needed for runtime support.
private  String getSampleQuery(String[] localName)
          Constructs an internal query to sample
private  String getSchemaName(String[] localName)
          Returns the second to last name of localName.
private  String getTableName(String[] localName)
          Returns the last name of localName.
(package private)  MedAbstractDataWrapper getWrapper()
           
(package private)  void initialize()
           
 FarragoMedColumnSet newColumnSet(String[] localName, Properties tableProps, FarragoTypeFactory typeFactory, RelDataType rowType, Map<String,Properties> columnPropMap)
          Creates an instance of a FarragoMedColumnSet corresponding to row data identified by properties rather than container name.
private  String quoteName(String name)
          Constructs a quoted name
 void registerRules(RelOptPlanner planner)
          Gives this wrapper a chance to register any special optimization rules.
 long sampleAndCreateBcp(String[] localName, FlatFileBcpFile bcpFile)
          Creates the given control file based on an internal sample query.
private  String[] setSchemaName(String[] localName, String schemaName)
          Sets the second to last name of localName.
 
Methods inherited from class net.sf.farrago.namespace.impl.MedAbstractDataServer
getLoopbackDataSource, getProperties, getServerMofId, registerRelMetadataProviders, releaseResources, setLoopbackDataSource
 
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

tracer

private static final Logger tracer

DESCRIBE_COLUMN_LENGTH

private static int DESCRIBE_COLUMN_LENGTH

DESCRIBE_COLUMN_NAME

private static String DESCRIBE_COLUMN_NAME

QUALIFIED_NAME_SEPARATOR

private static String QUALIFIED_NAME_SEPARATOR

SQL_QUOTE_CHARACTER

private static String SQL_QUOTE_CHARACTER

wrapper

private MedAbstractDataWrapper wrapper

params

FlatFileParams params
Constructor Detail

FlatFileDataServer

FlatFileDataServer(MedAbstractDataWrapper wrapper,
                   String serverMofId,
                   Properties props)
Method Detail

initialize

void initialize()
          throws SQLException
Throws:
SQLException

getNameDirectory

public FarragoMedNameDirectory getNameDirectory()
                                         throws SQLException
Description copied from interface: FarragoMedDataServer
Gets a FarragoMedNameDirectory corresponding to this server.

Specified by:
getNameDirectory in interface FarragoMedDataServer
Overrides:
getNameDirectory in class MedAbstractDataServer
Returns:
directory, or null if this server does not have the required metadata capability
Throws:
SQLException - if directory access is unsuccessful (but not if directory access is unsupported)

newColumnSet

public FarragoMedColumnSet newColumnSet(String[] localName,
                                        Properties tableProps,
                                        FarragoTypeFactory typeFactory,
                                        RelDataType rowType,
                                        Map<String,Properties> columnPropMap)
                                 throws SQLException
Description copied from interface: FarragoMedDataServer
Creates an instance of a FarragoMedColumnSet corresponding to row data identified by properties rather than container name. This supports the SQL/MED CREATE FOREIGN TABLE statement. As much validation as possible should be performed, including accessing representative data.

Parameters:
localName - the qualified name to assign to the column set within Farrago; this should NOT be used for finding the actual data, since it can be set arbitrarily by the caller; instead, it should be used to implement the RelOptTable.getQualifiedName() method, and can be useful for correlation during debugging
tableProps - properties to use for data location and access
typeFactory - FarragoTypeFactory to use for defining types
rowType - type to impose on the rows of this column set (including column names and types), or null to infer row type; if this is non-null, it must be saved for use by the getRowType() returned from FarragoMedColumnSet
columnPropMap - map from column name to column-specific Properties; this is optional and may only be specified when rowType is also specified (the field names in rowType are used as the keys for columnPropMap)
Returns:
new FarragoMedColumnSet
Throws:
SQLException - if data access is unsuccessful

getRuntimeSupport

public Object getRuntimeSupport(Object param)
                         throws SQLException
Description copied from interface: FarragoMedDataServer
Gets an object needed for runtime support. Typically, this will be called from code generated by this server. The meaning of this is entirely dependent on the server implementation. If the returned object implements FarragoAllocation, its closeAllocation() method will be called automatically as soon as it is no longer needed.

Specified by:
getRuntimeSupport in interface FarragoMedDataServer
Overrides:
getRuntimeSupport in class MedAbstractDataServer
Parameters:
param - parameter supplied at runtime
Returns:
support object
Throws:
SQLException

registerRules

public void registerRules(RelOptPlanner planner)
Description copied from interface: FarragoMedDataServer
Gives this wrapper a chance to register any special optimization rules. This method may be called more than once, each time with a different planner instance.

Specified by:
registerRules in interface FarragoMedDataServer
Overrides:
registerRules in class MedAbstractDataServer
Parameters:
planner - the planner in which the rules should be registered

closeAllocation

public void closeAllocation()
Description copied from interface: ClosableAllocation
Closes this object.

Specified by:
closeAllocation in interface ClosableAllocation
Overrides:
closeAllocation in class MedAbstractDataServer

getWrapper

MedAbstractDataWrapper getWrapper()

createRowType

RelDataType createRowType(FarragoTypeFactory typeFactory,
                          RelDataType[] types,
                          String[] names)

deriveRowType

private RelDataType deriveRowType(FarragoTypeFactory typeFactory,
                                  FlatFileParams.SchemaType schemaType,
                                  String[] localName,
                                  String filename,
                                  FlatFileBcpFile bcpFile)
                           throws SQLException
Derives the row type of a table when other type information is not available. Also derives the row type of internal queries.

Throws:
SQLException

getFieldSizes

private List<Integer> getFieldSizes(String[] localName)
                             throws SQLException
Returns the sizes of a flat file's fields, based upon an internal describe query.

Throws:
SQLException

sampleAndCreateBcp

public long sampleAndCreateBcp(String[] localName,
                               FlatFileBcpFile bcpFile)
                        throws SQLException
Creates the given control file based on an internal sample query.

Throws:
SQLException

getDescribeQuery

private String getDescribeQuery(String[] localName)
Constructs an internal query to describe the results of sampling


getSampleQuery

private String getSampleQuery(String[] localName)
Constructs an internal query to sample


getQualifiedName

private String getQualifiedName(String[] localName)
Constructs a qualified (multi-part) name


quoteName

private String quoteName(String name)
Constructs a quoted name


getTableName

private String getTableName(String[] localName)
Returns the last name of localName. TODO: move this into a better place


getSchemaName

private String getSchemaName(String[] localName)
Returns the second to last name of localName. TODO: move this into a better place


setSchemaName

private String[] setSchemaName(String[] localName,
                               String schemaName)
Sets the second to last name of localName. TODO: move this into a better place