public class Table extends Object
| Modifier and Type | Field and Description |
|---|---|
static Table |
AGENCY |
static Table |
CALENDAR |
static Table |
CALENDAR_DATES |
static Table |
FARE_ATTRIBUTES |
static Table |
FARE_RULES |
static Table |
FEED_INFO |
Field[] |
fields |
static Table |
FREQUENCIES |
boolean |
hasUniqueKeyField
Indicates whether the table has unique key field.
|
String |
name |
static Table |
PATTERN_STOP |
static Table |
PATTERNS |
static Table |
ROUTES |
static Table |
SCHEDULE_EXCEPTIONS |
static Table |
SHAPES |
static Table |
STOP_TIMES |
static Table |
STOPS |
static Table[] |
tablesInOrder
List of tables in order needed for checking referential integrity during load stage.
|
static Table |
TRANSFERS |
static Table |
TRIPS |
| Constructor and Description |
|---|
Table(String name,
Class<? extends Entity> entityClass,
Requirement required,
Field... fields) |
| Modifier and Type | Method and Description |
|---|---|
Table |
addPrimaryKey()
Fluent method that indicates that the integer ID field should be made a primary key.
|
static String |
commaSeparatedNames(List<Field> fieldsToJoin)
Join a list of fields with a comma + space separator.
|
static String |
commaSeparatedNames(List<Field> fieldsToJoin,
String prefix,
boolean csvOutput)
Prepend a prefix string to each field and join them with a comma + space separator.
|
void |
createIndexes(Connection connection,
String namespace)
Create indexes for table using shouldBeIndexed(), key field, and/or sequence field.
|
boolean |
createSqlTable(Connection connection) |
boolean |
createSqlTable(Connection connection,
boolean makeIdSerial) |
boolean |
createSqlTable(Connection connection,
String namespace,
boolean makeIdSerial) |
boolean |
createSqlTable(Connection connection,
String namespace,
boolean makeIdSerial,
String[] primaryKeyFields)
Create an SQL table with all the fields specified by this table object,
plus an integer CSV line number field in the first position.
|
boolean |
createSqlTableFrom(Connection connection,
String tableToClone)
Creates a SQL table from the table to clone.
|
List<Field> |
editorFields()
Get only those fields included in the official GTFS specification for this table or used by the editor.
|
String |
generateDeleteSql(String namespace) |
String |
generateDeleteSql(String namespace,
String fieldName)
Generate delete SQL string.
|
String |
generateInsertSql()
Create an SQL table that will insert a value into all the fields specified by this table object,
plus an integer CSV line number field in the first position.
|
String |
generateInsertSql(boolean setDefaultId) |
String |
generateInsertSql(String namespace,
boolean setDefaultId)
Create SQL string for use in insert statement.
|
String |
generateJoinSql(String optionalSelect,
Table joinTable,
String namespace) |
String |
generateJoinSql(String optionalSelect,
Table joinTable,
String joinType,
String namespace,
String fieldName,
boolean prefixTableName)
Constructs a join clause to use in conjunction with
generateJoinSql(com.conveyal.gtfs.loader.Table, java.lang.String, java.lang.String, boolean). |
String |
generateJoinSql(Table joinTable,
String namespace) |
String |
generateJoinSql(Table joinTable,
String namespace,
String fieldName,
boolean prefixTableName) |
String |
generateSelectAllExistingFieldsSql(Connection connection,
String namespace)
Generate a select statement from the columns that actually exist in the database table.
|
String |
generateSelectAllSql(String namespace)
Shorthand wrapper for calling
generateSelectSql(String, Requirement). |
String |
generateSelectSql(String namespace,
Requirement minimumRequirement)
Generate select all SQL string.
|
String |
generateUpdateSql(String namespace,
int id)
Create SQL string for use in update statement.
|
com.csvreader.CsvReader |
getCsvReader(ZipFile zipFile,
SQLErrorStorage sqlErrorStorage)
In GTFS feeds, all files are supposed to be in the root of the zip file, but feed producers often put them
in a subdirectory.
|
Class<? extends Entity> |
getEntityClass() |
Field |
getFieldForName(String name) |
int |
getFieldIndex(String name)
Finds the index of the field for this table given a string name.
|
Field[] |
getFieldsFromFieldHeaders(String[] headers,
SQLErrorStorage errorStorage)
|
String |
getIndexFields()
Gets index fields for the spec table.
|
int |
getKeyFieldIndex(Field[] fields)
Returns the index of the key field within the array of fields provided for a given table.
|
String |
getKeyFieldName()
Gets the key field for the table.
|
String |
getOrderFieldName()
Returns field name that defines order for grouped entities or that defines the compound key field (e.g.,
transfers#to_stop_id).
|
Table |
getParentTable() |
Table |
hasCompoundKey()
Fluent method to set whether the table has a compound key, e.g., transfers#to_stop_id.
|
boolean |
hasField(String name)
Whether a field with the provided name exists in the table's list of fields.
|
boolean |
isCascadeDeleteRestricted() |
boolean |
isRequired() |
boolean |
isSpecTable()
Checks whether the table is part of the GTFS specification, i.e., it is not an internal table used for the editor
(e.g., Patterns or PatternStops).
|
Table |
keyFieldIsNotUnique()
Fluent method to de-set the hasUniqueKeyField flag for tables which the first field should not be considered a
primary key.
|
List<Field> |
requiredFields()
Get only those fields marked as required in the official GTFS specification for this table.
|
Table |
restrictDelete()
Fluent method that restricts deletion of an entity in this table if there are references to it elsewhere.
|
List<Field> |
specFields()
Get only those fields included in the official GTFS specification for this table, i.e., filter out fields used
in the editor or extensions.
|
public final String name
public final Field[] fields
public boolean hasUniqueKeyField
public static final Table AGENCY
public static final Table CALENDAR
public static final Table SCHEDULE_EXCEPTIONS
public static final Table CALENDAR_DATES
public static final Table FARE_ATTRIBUTES
public static final Table FEED_INFO
public static final Table ROUTES
public static final Table FARE_RULES
public static final Table SHAPES
public static final Table PATTERNS
public static final Table STOPS
public static final Table PATTERN_STOP
public static final Table TRANSFERS
public static final Table TRIPS
public static final Table STOP_TIMES
public static final Table FREQUENCIES
public static final Table[] tablesInOrder
public Table(String name, Class<? extends Entity> entityClass, Requirement required, Field... fields)
public Table restrictDelete()
public Table keyFieldIsNotUnique()
public Table hasCompoundKey()
public Table addPrimaryKey()
public List<Field> editorFields()
public List<Field> requiredFields()
public List<Field> specFields()
public boolean isCascadeDeleteRestricted()
public boolean createSqlTable(Connection connection)
public boolean createSqlTable(Connection connection, boolean makeIdSerial)
public boolean createSqlTable(Connection connection, String namespace, boolean makeIdSerial)
public boolean createSqlTable(Connection connection, String namespace, boolean makeIdSerial, String[] primaryKeyFields)
public String generateInsertSql()
public String generateInsertSql(boolean setDefaultId)
public String generateInsertSql(String namespace, boolean setDefaultId)
public com.csvreader.CsvReader getCsvReader(ZipFile zipFile, SQLErrorStorage sqlErrorStorage)
public static String commaSeparatedNames(List<Field> fieldsToJoin)
public static String commaSeparatedNames(List<Field> fieldsToJoin, String prefix, boolean csvOutput)
public String generateUpdateSql(String namespace, int id)
public String generateSelectSql(String namespace, Requirement minimumRequirement)
public String generateSelectAllSql(String namespace)
generateSelectSql(String, Requirement). Note: this does not prefix field
names with the namespace, so cannot serve as a replacement for generateSelectAllExistingFieldsSql(java.sql.Connection, java.lang.String).public String generateSelectAllExistingFieldsSql(Connection connection, String namespace) throws SQLException
SQLExceptionpublic String generateJoinSql(Table joinTable, String namespace, String fieldName, boolean prefixTableName)
public String generateJoinSql(String optionalSelect, Table joinTable, String namespace)
public String generateJoinSql(String optionalSelect, Table joinTable, String joinType, String namespace, String fieldName, boolean prefixTableName)
generateJoinSql(com.conveyal.gtfs.loader.Table, java.lang.String, java.lang.String, boolean). By default the join type is "INNER
JOIN" and the join field is whatever the table instance's key field is. Both of those defaults can be overridden
with the other overloaded methods.optionalSelect - optional select query to pre-select the join tablejoinTable - the Table to join withjoinType - type of join (e.g., INNER JOIN, OUTER LEFT JOIN, etc.)namespace - feedId (or schema prefix)fieldName - the field to join on (default's to key field)prefixTableName - whether to prefix this table's name with the schema (helpful if this join follows a
previous join that renamed the table by dropping the schema/namespacepublic String generateDeleteSql(String namespace, String fieldName)
public Field getFieldForName(String name)
name - a column name from the header of a CSV filepublic String getKeyFieldName()
public String getOrderFieldName()
public String getIndexFields()
public int getFieldIndex(String name)
public boolean hasField(String name)
public boolean isRequired()
public boolean isSpecTable()
public void createIndexes(Connection connection, String namespace) throws SQLException
SQLExceptionpublic boolean createSqlTableFrom(Connection connection, String tableToClone)
public Table getParentTable()
public Field[] getFieldsFromFieldHeaders(String[] headers, SQLErrorStorage errorStorage)
public int getKeyFieldIndex(Field[] fields)
fields - array of fields (intended to be derived from the headers of a csv text file)Copyright © 2019. All rights reserved.