DataSource class

Package: com.tecit.TFORMer.Repository

Abstract class for a DataSource.

Usage and notes

Overview

TFORMer Designer allows to define a DataSource as part of a FormLayout. Such an user-defined DataSource can be used for printing directly from within TFORmer Designer or may be re-used by TFORmer SDK for providing JobData (see JobDataDataSource).

A DataSource defines how data is retrieved (e.g. from an ODBC database), the field-mappings (see DSFieldMapping), computed fields (see ComputedField) and optional data source parameters (see DataSourceParameter). Each DataSource is identified by its unique name. Optional DataSourceParameters can be defined to control certain aspects (like filenames, SQL statement or an ODBC-DSN) during runtime.

By default TFORMer Designer creates a DataSource named _Default_. This DataSource is used for printing as long as neither a DataSource is specified for JobData nor the FormLayout has an active DataSource set in design. This DataSource retrieves the data from the file that is stored along with the FormLayout file (extension .xml) and contains the DataField values entered during the last TFORMer Designer session.

The available data-source types are DataSourceCsv, DataSourceOdbc and DataSourceXml.

Escape Sequences

For a configured DataSource, escape-sequence handling is controlled by the source definition. Configure this behavior in TFORMer Designer. It is separate from the direct-input JobData setting. See Escape Sequences for the supported sequences.

Record Copies

Each Record of a DataSource is usually considered exactly once for generating output. Use DataSource.setCopyColumnName to select the source field containing the copy count. This feature is helpful whenever a single Record of a DataSource should be printed multiple times (e.g. if a certain number of identical labels should be printed).

Computed Fields

Computations can be centralized in the DataSource instead of performing the computations in the FormLayout. The result of a ComputedField is available in the DataSource like any other source-field.

Examples

Sample code that iterates all DataSource of a given Repository:

static void IterateDataSourcesProject (Project project) throws TFormerException
{
  // Iterate all DataSources of the Project
  for (DataSource ds = project.getFirstDataSource(); ds != null; ds = ds.getNext())
  {
    System.out.println (ds.toString());

    // Print information for the DataSourceParameters of the DataSource
    for (DataSourceParameter dsParam = ds.getFirstParameter(); dsParam != null; dsParam = dsParam.getNext())
      System.out.println (dsParam.toString());

    // Print information for the ComputedFields of the DataSource
    for (ComputedField dsComp = ds.getFirstComputedField(); dsComp != null; dsComp = dsComp.getNext())
      System.out.println (dsComp.toString());

    // Print the mapping between source fields and DataFields
    for (DSFieldMapping dsFieldmap = ds.getFirstDSFieldMapping(); dsFieldmap != null; dsFieldmap = dsFieldmap.getNext())
      System.out.println (dsFieldmap.toString());
  }
}
  // Create a new Repository instance using a Repository (extension *.tfr)
  // Examples are usually installed in
  // - Windows Vista: C:/Program Data/TEC-IT/TFORMer/9/Examples
  // - Older Microsoft Windows versions: C:/Documents and Settings/All Users/Application Data/TEC-IT/TFORMer/9/Examples
  Repository repository = new Repository("C:/Documents and Settings/All Users/Application Data/TEC-IT/TFORMer/9/Examples/Demo Repository/Demos.tfr", false, true);
  // Iterate the DataSources of the global Project
  // If a Repository is used, the global Project and additional user-defined Projects may exist
  System.out.println ("Global project");
  IterateDataSourcesProject (repository.getGlobalProject ());

  // Iterate additional Projects
  // Additional Projects are only possible when using a Repository
  for (Project project = repository.getFirstProject (); project != null; project = project.getNext()) 
  {
    System.out.println (project.toString());

    // Iterate the DataSources of the Project
    IterateDataSourcesProject (project);    
  } 

Sample code that iterates all DataSource-objects of a given stand-alone FormLayout:

static void IterateDataSourcesProject (Project project) throws TFormerException
{
  // Iterate all DataSources of the Project
  for (DataSource ds = project.getFirstDataSource(); ds != null; ds = ds.getNext())
  {
    System.out.println (ds.toString());

    // Print information for the DataSourceParameters of the DataSource
    for (DataSourceParameter dsParam = ds.getFirstParameter(); dsParam != null; dsParam = dsParam.getNext())
      System.out.println (dsParam.toString());

    // Print information for the ComputedFields of the DataSource
    for (ComputedField dsComp = ds.getFirstComputedField(); dsComp != null; dsComp = dsComp.getNext())
      System.out.println (dsComp.toString());

    // Print the mapping between source fields and DataFields
    for (DSFieldMapping dsFieldmap = ds.getFirstDSFieldMapping(); dsFieldmap != null; dsFieldmap = dsFieldmap.getNext())
      System.out.println (dsFieldmap.toString());
  }
}
  // Create a new Repository instance using a stand-alone FormLayout (extension *.tff)
  // Examples are usually installed in
  // - Windows Vista or later: C:/Program Data/TEC-IT/TFORMer/9/Examples
  // - Older Microsoft Windows versions: C:/Documents and Settings/All Users/Application Data/TEC-IT/TFORMer/9/Examples
  Repository repository = new Repository("C:/Documents and Settings/All Users/Application Data/TEC-IT/TFORMer/9/Examples/Command Line/ODBCReportPDF/ODBCReportPDF.tff", false, true);
  // Iterate the DataSources of the global Project
  // If a stand-alone FormLayout is used, the global Project is the only Project
  System.out.println ("Global project");  
  IterateDataSourcesProject (repository.getGlobalProject ());  

More Information

See also

ComputedField

Related documentation:

Note

Thread-safety: A single instance of this class must not be used by different threads.

Derived types: DataSourceCsv, DataSourceOdbc, DataSourceXml

Methods

MemberDescription
addComputedField(String)Returns: ComputedField

Creates and adds a ComputedField to the DataSource.

addFieldMapping(String)Returns: DSFieldMapping

Creates and adds a DSFieldMapping to the DataSource.

addParameter(String)Returns: DataSourceParameter

Creates and adds a DataSourceParameter to the DataSource.

dispose()Returns: void

Releases the resources allocated by the instance.

dump(PrintStream)Returns: void

Dumps the current instance into a text stream.

getComment()Returns: String

Gets the comment for the DataSource.

getComputedField(String)Returns: ComputedField

Gets a ComputedField defined in the DataSource.

getCopyColumnName()Returns: String

Gets the CopyColumnName of the DataSource.

getDescription()Returns: String

Gets the description of the DataSource.

getFieldMapping(String)Returns: DSFieldMapping

Gets a DSFieldMapping defined in the DataSource.

getFirstComputedField()Returns: ComputedField

Gets the first ComputedField defined in the DataSource.

getFirstDSFieldMapping()Returns: DSFieldMapping

Gets the first DSFieldMapping defined in the DataSource.

getFirstParameter()Returns: DataSourceParameter

Gets the first DataSourceParameter defined in the DataSource.

getName()Returns: String

Gets the name of the DataSource.

getNext()Returns: DataSource

Gets the next DataSource instance defined in the Project.

getNumberOfComputedFields()Returns: int

Gets the number of ComputedFields defined in the DataSource.

getNumberOfFieldMappings()Returns: int

Gets the number of DSFieldMappings defined in the DataSource.

getNumberOfParameters()Returns: int

Gets the number of DataSourceParameters defined in the DataSource.

getParameter(String)Returns: DataSourceParameter

Gets a DataSourceParameter defined in the DataSource.

getType()Returns: DataSourceType

Gets the type of the DataSource.

isDefault()Returns: boolean

Gets a value indicating whether this object stores the default DataSource.

isHandleEscapeSequences()Returns: boolean

Gets if escape sequences should be translated on data retrieval or not.

removeComputedField(ComputedField)Returns: void

Removes the ComputedField from the DataSource.

removeComputedField(String)Returns: void

Removes the ComputedField from the DataSource.

removeFieldMapping(DSFieldMapping)Returns: void

Removes the DSFieldMapping from the DataSource.

removeFieldMapping(String)Returns: void

Removes the DSFieldMapping from the DataSource.

removeParameter(DataSourceParameter)Returns: void

Removes the DataSourceParameter from the DataSource.

removeParameter(String)Returns: void

Removes the DataSourceParameter from the DataSource.

setComment(String)Returns: void

Sets the comment for the DataSource.

setCopyColumnName(String)Returns: void

Sets the CopyColumnName of the DataSource.

setDescription(String)Returns: void

Sets the description of the DataSource.

setHandleEscapeSequences(boolean)Returns: void

Sets if escape sequences should be translated on data retrieval or not.

setName(String)Returns: void

Sets the name of the DataSource.

toString()Returns: String

Returns a string representation of the instance.

Search documentation

Search in
More scopes
Additional scopes

All contents