Class Relation
java.lang.Object
org.apache.sis.internal.sql.feature.TableReference
org.apache.sis.internal.sql.feature.Relation
Description of a relation between two tables, as defined by foreigner keys.
Each
Table may contain an arbitrary number of relations.
Relations are defined in two directions:
Relation.Direction.IMPORT: primary keys of other tables are referenced by the foreigner keys of the table containing thisRelation.Relation.Direction.EXPORT: foreigner keys of other tables are referencing the primary keys of the table containing thisRelation.
getImportedKeys
or getExportedKeys with (catalog, schema, table) parameters.- Since:
- 1.0
- Version:
- 1.2
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enumWhether another table is using or is used by the table containing theRelation. -
Field Summary
FieldsModifier and TypeFieldDescriptionThe columns of the other table that constitute a primary or foreigner key.(package private) static final Relation[]An empty array used when there are no relations.(package private) booleanWhether this relation should be omitted from the list of feature type properties.(package private) StringThe name of the feature property where the association tosearchTabletable will be stored.private TableThe other table identified byTableReference.catalog,TableReference.schemaandTableReference.tablenames.private booleanWhether thecolumnsmap include all primary key columns.Fields inherited from class org.apache.sis.internal.sql.feature.TableReference
catalog, freeText, schema, table -
Constructor Summary
ConstructorsConstructorDescriptionRelation(Analyzer analyzer, Relation.Direction dir, ResultSet reflect) Creates a new relation for an imported key. -
Method Summary
Modifier and TypeMethodDescription(package private) voidappendTo(TreeTable.Node parent, String arrow) Creates a tree representation of this relation for debugging purpose.(package private) final voidendFollowing(List<Relation> following) Removes this relation from the given list, making sure that this relation was at the tail.(package private) final Collection<String>Returns the foreigner key columns of the table that contains this relation.(package private) final StringReturns the name of the feature property where the association to the search table will be stored.(package private) final Collection<String>Returns the columns of the search table which will need to appear in theWHEREclause.(package private) final TableReturns the other table identified byTableReference.catalog,TableReference.schemaandTableReference.tablenames.(package private) final booleanisInverseOf(Relation other) Returnstrueif this relation is the inverse of the given relation.(package private) final booleanReturns whethersetSearchTable(…)needs to be invoked.(package private) final voidsetPropertyName(String column, int count) Invoked after construction for setting the name of the feature property of the enclosing table where to store association to the feature instances read from the search table.(package private) final voidsetSearchTable(Analyzer analyzer, Table search, PrimaryKey primaryKey, Relation.Direction direction) Invoked after construction for setting the table identified byTableReference.catalog,TableReference.schemaandTableReference.tablenames.(package private) final voidstartFollowing(List<Relation> following) Adds this relation to the given list, making sure that the relation has not already been added.toString()Formats a graphical representation of this relation for debugging purpose.(package private) final booleanReturnstrueif this relation includes all required primary key columns.
-
Field Details
-
EMPTY
An empty array used when there are no relations. -
columns
The columns of the other table that constitute a primary or foreigner key. Keys are the columns of the other table and values are columns of the table containing thisRelation. -
searchTable
The other table identified byTableReference.catalog,TableReference.schemaandTableReference.tablenames. This is set duringTableconstruction and should not be modified after that point.- See Also:
-
propertyName
String propertyNameThe name of the feature property where the association tosearchTabletable will be stored. If the foreigner key uses exactly one column, then this is the name of that column. -
useFullKey
private boolean useFullKeyWhether thecolumnsmap include all primary key columns. This field is set tofalseif the foreigner key uses only a subset of the primary key columns, in which case the referenced rows may not be unique.- See Also:
-
excluded
boolean excludedWhether this relation should be omitted from the list of feature type properties. This is a temporary information used only atFeatureTypeconstruction time. A relation is excluded if table A is a dependency of table B (defined by foreigner keys) and the relation is pointing back to A.- Since:
- 1.2
-
-
Constructor Details
-
Relation
Relation(Analyzer analyzer, Relation.Direction dir, ResultSet reflect) throws SQLException, DataStoreContentException Creates a new relation for an imported key. The givenResultSetmust be positioned on the first row ofDatabaseMetaData.getImportedKeys(catalog, schema, table)result, and the result must be sorted in the order of the given keys: Note that JDBC specification ensures this order ifRelation.Direction.IMPORTis used with the result ofgetImportedKeysandRelation.Direction.EXPORTis used with the result ofgetExportedKeys.After construction, the
ResultSetwill be positioned on the first row of the next relation, or be closed if the last row has been reached. This constructor always moves the given result set by at least one row, unless an exception occurs.- Parameters:
analyzer- the object which is analyzing the database schema for inferring feature types.dir- whether another table is using or is used by the table containing this relation.reflect- metadata about foreigner keys, with cursor already on the first row.- Throws:
SQLExceptionDataStoreContentException
-
-
Method Details
-
setPropertyName
Invoked after construction for setting the name of the feature property of the enclosing table where to store association to the feature instances read from the search table. If the foreigner key use exactly one column, we can use the name of that column. Otherwise we don't know which column has the most appropriate name (often there is none), so we fallback on the foreigner key name.- Parameters:
column- a foreigner key column.count- number of names previously created from that column.
-
getPropertyName
Returns the name of the feature property where the association to the search table will be stored. If the foreigner key uses exactly one column, then this is the name of that column. -
setSearchTable
final void setSearchTable(Analyzer analyzer, Table search, PrimaryKey primaryKey, Relation.Direction direction) throws DataStoreException Invoked after construction for setting the table identified byTableReference.catalog,TableReference.schemaandTableReference.tablenames. Shall be invoked exactly once.- Parameters:
analyzer- the object which is analyzing the database schema for inferring feature types.search- the other table containing the primary key (Relation.Direction.IMPORT) or the foreigner key (Relation.Direction.EXPORT) of this relation.primaryKey- the primary key columns of the relation. May be the primary key columns of this table or the primary key columns of the other table, depending onRelation.Direction.direction-this.direction(see comment in field declarations).- Throws:
DataStoreException
-
getSearchTable
Returns the other table identified byTableReference.catalog,TableReference.schemaandTableReference.tablenames. This is the table where the search operations will be performed. In other words, this is part of the following pseudo-query:SELECT * FROM <search table> WHERE <search columns> = ...- Throws:
InternalDataStoreException
-
isSearchTableDeferred
final boolean isSearchTableDeferred()Returns whethersetSearchTable(…)needs to be invoked. -
getSearchColumns
Returns the columns of the search table which will need to appear in theWHEREclause. ForRelation.Direction.IMPORT, they are primary key columns. ForRelation.Direction.EXPORT, they are foreigner key columns. -
getOwnerColumns
Returns the foreigner key columns of the table that contains this relation. ForRelation.Direction.IMPORT, this is the foreigner keys in the enclosing table. ForRelation.Direction.EXPORT, this is the primary keys in the dependency table. This method returns only the columns known to this relation; this is not necessarily all the enclosing table foreigner keys. Some columns may be used in more than one relation. -
useFullKey
final boolean useFullKey()Returnstrueif this relation includes all required primary key columns. Returnsfalseif the foreigner key uses only a subset of the primary key columns, in which case the referenced rows may not be unique. -
isInverseOf
Returnstrueif this relation is the inverse of the given relation. If two relations are inverse, then following those relations recursively would result in an infinite loop.This method tests only the column names; the table names shall be verified by the caller. Table names can be verified as below (see comment in field declarations for meaning of "owner"):
this.equals(other.owner.name): the target of this relation is the source of other relation.this.owner.name.equals(other): the source of this relation is the target of other relation.
- Parameters:
other- the other relation to check for inverse relationship.
-
startFollowing
Adds this relation to the given list, making sure that the relation has not already been added. The check for previous existence ofthisrelation is for preventing infinite recursivity.- Throws:
InternalDataStoreException
-
endFollowing
Removes this relation from the given list, making sure that this relation was at the tail.- Throws:
InternalDataStoreException
-
appendTo
Creates a tree representation of this relation for debugging purpose.- Parameters:
parent- the parent node where to add the tree representation.arrow- the symbol to use for relating the columns of two tables in a foreigner key.
-
toString
Formats a graphical representation of this relation for debugging purpose. This representation can be printed to the standard output stream (for example) if the output device uses a monospaced font and supports Unicode.- Overrides:
toStringin classTableReference- Returns:
- a string representation of this table reference.
-