Class TableSpec

java.lang.Object
ca.spatial.table.TableSpec
Direct Known Subclasses:
TableSpec.AppendSpec, TableSpec.CoverageSpec, TableSpec.CrosstabSpec, TableSpec.CSVSpec, TableSpec.DBaseSpec, TableSpec.ExcelSpec, TableSpec.FlattenSpec, TableSpec.InfoSpec, TableSpec.JDBCSpec, TableSpec.RamAttributeStoreSpec, TableSpec.RelationSpec, TableSpec.ShapefileSpec, TableSpec.SnapshotSpec, TableSpec.SummarySpec, TableSpec.TransposePeriodSpec, TableSpec.TransposeRowSpec, TableSpec.TransposeSpec, TableSpec.VirtualSpec

public abstract class TableSpec extends Object
This class implements a portable way to describe complex data table configurations in a simple string.

A TableSpec is string that describes how to open a dataset. The open() method will parse the TableSpec string and return the opened table.

The thing that makes TableSpec's interesting is that they can be used to compose several tables in ways that otherwise would have to be done with executable script code. For example, the configuration of a relation of several joined tables can be captured as a TableSpec string, and the string can later be used to exactly reconstitute the original configuration.

In addition, TableSpec string can capture optional values, such as the character encoding. For complex tables, such as CrosstabStore and AppendStore, the TableSpec captures the complete set of parameters that define the table.

In many case TableSpec strings are not required: the Patchworks code generation wizards will provde BeanShell code that uses the Patchworks API to create the tables. There are some situations, such as providing files to the <curvetable> and <table> elements in the ForestModel where the BeanShell environment is not available, and TableSpec strings make a great replacement.

Usage

Obtain a TableSpec string from any open table:

 spec = myTable.getTablespec().toString();
 
Open a file using a TabeSpec string:

 newTable = TableSpec.open(spec);
 

See the for documentation of each sub classes fo the syntax details of the TableSpec strings. The syntax format used in these sections is

  • bare word are required as is
  • words in braces are to be substituted with the appropriate value
  • symbols followed by a question mark are optional and may be excluded
  • symbols followed by ... may be repeated as neccesary
  • values that have embedded blanks must be enclosed in double quotes
  • the [] characters enclose another TableSpec string, and in this way tables can be composed of other tables. The [] characters are a required part of the syntax.
Here is an example of a TableSpec string that represents a join of two tables:

 Relate [blocks.shp] StdID [../analysis/BRU001_initialSchedule_yr1_6.csv] BLOCK
 
In the above, the keyword Relate identifies the TableSpec type. The first element within [] characters represents the primary table, StdID represents the foreign key, the second element within [] represents the secondary table, and BLOCK represents the primary key.

This relate expression could itself be enclosed within [] characters, and composed in to another TableSpec, and so on.

  • Constructor Details

    • TableSpec

      public TableSpec()
  • Method Details

    • open

      public abstract AttributeStore open() throws Exception
      Open the data table described by this TableSpec.
      Throws:
      Exception
    • getTableName

      public abstract String getTableName()
      Get the name of the table described by this TableSpec.
    • getFlavour

      public abstract String getFlavour()
      Get the type of table described by this TableSpec.
    • isPlain

      public boolean isPlain()
      Does this specification describe a plain file?
    • isGeoRelational

      public boolean isGeoRelational()
      Does this specification describe GeoRelationalStore data?
    • getCanonicalName

      public String getCanonicalName()
      Get the unique and unequivocal identifier for this TableSpec.
    • open

      public static AttributeStore open(String spec, String encoding) throws Exception
      Try to find a data set that matches this description in the cache. If it exists then return the handle to the cached version, If it is not already open and in the cache, then try to open it. Don't automatically add it to the cache.
      Parameters:
      spec - A file name or table specification.
      encoding - The encoding type to be used to open this file. This only applies to some file types (e.g. DBaseAttributeStore, ShapeStore, CSVStore).
      Returns:
      A handle to the opened file.
      Throws:
      Exception - An exception if the file cannot be opened.
    • open

      public static AttributeStore open(String spec) throws Exception
      Throws:
      Exception
    • decode

      public static TableSpec decode(String tableSpec, String encoding) throws Exception
      Throws:
      Exception
    • isDefaultEncoding

      public static boolean isDefaultEncoding(String encoding)
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • quoteIfRequired

      public static String quoteIfRequired(String value)
    • quoteExprIfRequired

      public static String quoteExprIfRequired(String value)