com.mockrunner.jdbc
Class FileResultSetFactory

java.lang.Object
  extended by com.mockrunner.jdbc.FileResultSetFactory
All Implemented Interfaces:
ResultSetFactory

public class FileResultSetFactory
extends java.lang.Object
implements ResultSetFactory

Can be used to create a ResultSet based on a table specified in a CSV file. You can specify the delimiter of the columns (default is ;). Furthermore you can specify if the first line contains the column names (default is false) and if the column entries should be trimmed (default is true). With setUseTemplates(boolean) you can enable template replacement in the files (default is false, i.e. templates are disabled). The file can be specified directly or by its name. The class tries to find the file in the absolut or relative path and (if not found) by calling getResource. Note that the file must exist in the local file system and cannot be loaded from inside a jar archive.


Constructor Summary
FileResultSetFactory(java.io.File file)
           
FileResultSetFactory(java.lang.String fileName)
           
 
Method Summary
 MockResultSet create(java.lang.String id)
           
 java.io.File getFile()
          Get the File being used to read in the ResultSet.
 void setDefaultTemplateConfiguration()
          This method sets the default template configuration.
 void setDelimiter(java.lang.String delimiter)
          Set the delimiter.
 void setFirstLineContainsColumnNames(boolean firstLineContainsColumnNames)
          Set if the first line contains the column names.
 void setTemplateConfiguration(java.lang.String marker, java.util.Map templates)
          This method sets a custom template configuration.
 void setTrim(boolean trim)
          Set if the column entries should be trimmed.
 void setUseTemplates(boolean useTemplates)
          Set this to true to allow the use of templates in data files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileResultSetFactory

public FileResultSetFactory(java.lang.String fileName)

FileResultSetFactory

public FileResultSetFactory(java.io.File file)
Method Detail

getFile

public java.io.File getFile()
Get the File being used to read in the ResultSet. Throws a RuntimeException if the file does not exist.

Returns:
the file

setDelimiter

public void setDelimiter(java.lang.String delimiter)
Set the delimiter. Default is ";".

Parameters:
delimiter - the delimiter

setFirstLineContainsColumnNames

public void setFirstLineContainsColumnNames(boolean firstLineContainsColumnNames)
Set if the first line contains the column names. Default is false.


setTrim

public void setTrim(boolean trim)
Set if the column entries should be trimmed. Default is true.


setUseTemplates

public void setUseTemplates(boolean useTemplates)
Set this to true to allow the use of templates in data files. A template is identified by a marker followed by a label. The template is replaced by a predefined string in the corresponding data file. E.g. with the default configuration, $defaultString is replaced by an empty string in the file. The default configuration which is automatically set uses $ as a marker. See setDefaultTemplateConfiguration() for details. You can also set a custom template configuration using setTemplateConfiguration(String, Map). Default is false, i.e. templates are disabled.

Parameters:
useTemplates - set true to enable templates.

setTemplateConfiguration

public void setTemplateConfiguration(java.lang.String marker,
                                     java.util.Map templates)
This method sets a custom template configuration. See setUseTemplates(boolean) for an explanation how templates work. marker + map key is replaced by the corresponding map value in the data files. Please use setDefaultTemplateConfiguration() to set a default configuration.

Parameters:
marker - the custom marker replacing the default $
templates - the custom template map

setDefaultTemplateConfiguration

public void setDefaultTemplateConfiguration()
This method sets the default template configuration. See setUseTemplates(boolean) for an explanation how templates work. The default marker is $ and the default templates are:

$defaultString is replaced by an empty string
$defaultDate is replaced by 1970-01-01
$defaultInteger is replaced by 0

Please use setTemplateConfiguration(String, Map) to set a custom marker and custom templates.


create

public MockResultSet create(java.lang.String id)
Specified by:
create in interface ResultSetFactory