Package org.teiid.spring.annotations
Annotation Type TextTable
-
@Target(TYPE) @Retention(RUNTIME) public @interface TextTable
Use this annotation on any Entity class, to read data from any flat file like CSV, fixed format etc.
For Example if you have a CSV file like
You can parse and read the contents of this file into an entity by defining this annotation on a Entity class likeId, FirstName, LastName, Age 1, John, Doe, 20 2, Susan, Webber, 55 3, Mike, Smith, 34
Note: the getters and setter are omitted for brevity.@Entity @TextTable(file="/path/to/file.txt") public class Person { @Id private int id; @Column(name="FirstName") private String firstName; @Column(name="LastName") private String lastName; @Column(name="Age") private int age; ... }
You can define variety of other properties on this annotation to control headers, quoting, trimming and generating automatic identification numbers if your flat file does not have PK available.
For more information checkout TextTable in Teiid.
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description StringdelimiterDELIMITER sets the field delimiter character to use.charescapeESCAPE sets the escape character to use if no quoting character is in use.intheaderHEADER specifies the text line number (counting every new line) on which the column names occur.booleannotrimCan be defined table or columns, NO TRIM specified on the TEXTTABLE, it will affect all column and header values.booleanordinalOn Column ONLY, this defines the column as ordinal identity column.charquoteQUOTE sets the quote, or qualifier, character used to wrap field values.intskipSKIP specifies the number of text lines (counting every new line) to skip before parsing the contents.StringsourceSource name; If overriding theFileConnectionFactorybean then provide the name of the beanintwidthOn Column ONLY, WIDTH indicates the fixed-width length of a column in characters - not bytes.
-
-
-
Element Detail
-
file
String file
On Class ONLY, defines the file to be read. Either relative to source's parent directory or absolute path- Returns:
- file name to read
-
-
-
delimiter
String delimiter
DELIMITER sets the field delimiter character to use. Defaults to ','- Returns:
- delimiter
- Default:
- ","
-
-
-
header
int header
HEADER specifies the text line number (counting every new line) on which the column names occur. If the HEADER option for a column is specified, then that will be used as the expected header name. All lines prior to the header will be skipped. If HEADER is specified, then the header line will be used to determine the TEXTTABLE column position by case-insensitive name matching. This is especially useful in situations where only a subset of the columns are needed. If the HEADER value is not specified, it defaults to 1. If HEADER is not specified, then columns are expected to match positionally with the text contents.- Returns:
- header row number
- Default:
- 1
-
-
-
source
String source
Source name; If overriding theFileConnectionFactorybean then provide the name of the bean- Returns:
- source type
- Default:
- "file"
-
-
-
notrim
boolean notrim
Can be defined table or columns, NO TRIM specified on the TEXTTABLE, it will affect all column and header values. If NO TRIM is specified on a column, then the fixed or unqualified text value not be trimmed of leading and trailing white space.- Returns:
- true to not use trim on values; default true
- Default:
- true
-
-