Class Analyzer
java.lang.Object
org.apache.sis.internal.sql.feature.Analyzer
Helper methods for creating
FeatureTypes from database structure.
An instance of this class is created temporarily when starting the analysis
of a database structure, and discarded after the analysis is finished.- Since:
- 1.0
- Version:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringThe last catalog and schema used for creatingnamespace.(package private) final SchemaModifierUser-specified modification to the features, ornullif none.(package private) final Database<?>Information about the spatial database to analyze.(package private) final StringThe string to insert before wildcard characters ('_'or'%') to escape.(package private) final DatabaseMetaDataInformation about the database as a whole.(package private) final org.opengis.util.NameFactoryThe factory for creatingFeatureTypenames.private org.opengis.util.NameSpaceprivate StringThe last catalog and schema used for creatingnamespace.(package private) final InfoStatementsA cache of statements for fetching spatial information such as geometry columns or SRID.A pool of strings read from database metadata.All tables created by analysis of the database structure.private final Set<ResourceInternationalString>Warnings found while analyzing a database structure. -
Constructor Summary
ConstructorsConstructorDescriptionAnalyzer(Database<?> database, Connection connection, DatabaseMetaData metadata, SchemaModifier customizer) Creates a new analyzer for the database described by given metadata. -
Method Summary
Modifier and TypeMethodDescription(package private) final Collection<Table>finish()Invoked after we finished to create all tables.(package private) final StringgetUniqueString(ResultSet reflect, String column) Reads a string from the given result set and return a unique instance of that string.(package private) final StringReturns a message for unexpected errors.(package private) final org.opengis.util.NameSpaceReturns a namespace for the given catalog and schema names, ornullif all arguments are null.final TableCreates a virtual table for the given query.(package private) final ResourcesReturns the localized resources for warnings and error messages.(package private) final ValueGetter<?>setValueGetter(Column column) Initializes the value getter on the given column.final Tabletable(TableReference id, org.opengis.util.GenericName name, TableReference dependencyOf) Returns the table of the given name if it exists, or creates it otherwise.private voidReports a warning.
-
Field Details
-
database
Information about the spatial database to analyze. -
spatialInformation
A cache of statements for fetching spatial information such as geometry columns or SRID. May benullif the database is not a spatial database, e.g. because the geometry table has not been found. -
metadata
Information about the database as a whole. Used for fetching tables, columns, primary keys etc. -
nameFactory
final org.opengis.util.NameFactory nameFactoryThe factory for creatingFeatureTypenames. -
strings
A pool of strings read from database metadata. Those strings are mostly catalog, schema and column names. The same names are repeated often (in primary keys, foreigner keys, etc.), and using a pool allows us to replace equal character strings by the sameStringinstances.- See Also:
-
escape
The string to insert before wildcard characters ('_'or'%') to escape. This is used by#escape(String)before to pass argument values (e.g. table name) toDatabaseMetaDatamethods expecting a pattern. -
tables
All tables created by analysis of the database structure. Anullvalue means that the table is in process of being created. This may happen if there is cyclic dependencies between tables. -
warnings
Warnings found while analyzing a database structure. Duplicated warnings are omitted. -
catalog
-
schema
-
namespace
private transient org.opengis.util.NameSpace namespace- See Also:
-
customizer
User-specified modification to the features, ornullif none.
-
-
Constructor Details
-
Analyzer
Analyzer(Database<?> database, Connection connection, DatabaseMetaData metadata, SchemaModifier customizer) throws SQLException Creates a new analyzer for the database described by given metadata.- Parameters:
database- information about the spatial database.connection- an existing connection to the database, used only for the lifetime of thisAnalyzer.metadata- value ofconnection.getMetaData()(provided because already known by caller).customizer- user-specified modification to the features, ornullif none.- Throws:
SQLException
-
-
Method Details
-
getUniqueString
Reads a string from the given result set and return a unique instance of that string. This method should be invoked only forStringinstances that are going to be stored inTableorRelationstructures; there is no point to invoke this method for example before to parse the string as a boolean.- Parameters:
reflect- the result set from which to read a string.column- the column to read.- Returns:
- the value in the given column, returned as a unique string.
- Throws:
SQLException
-
namespace
Returns a namespace for the given catalog and schema names, ornullif all arguments are null. The namespace sets the name separator to'.'instead of':'. -
table
public final Table table(TableReference id, org.opengis.util.GenericName name, TableReference dependencyOf) throws Exception Returns the table of the given name if it exists, or creates it otherwise. This method may be invoked recursively if the table to create is a dependency of another table. If a cyclic dependency is detected, then this method returnsnullfor one of the tables.- Parameters:
id- identification of the table to create.name- the value ofid.getName(analyzer)(as an argument for avoiding re-computation when already known by the caller).dependencyOf- if the analyzed table is imported/exported by foreigner keys, the table that "contains" this table. Otherwisenull.- Returns:
- the table, or
nullif there is a cyclic dependency and the table of the given name is already in process of being created. - Throws:
Exception
-
query
Creates a virtual table for the given query. If a table already exists for the given name, then anIllegalNameExceptionis thrown.- Parameters:
name- name of the resource.query- the query to execute.- Returns:
- the virtual table for the given query.
- Throws:
Exception
-
resources
Returns the localized resources for warnings and error messages. -
internalError
Returns a message for unexpected errors. Those errors are caused by a bug in thisorg.apache.sis.internal.sql.featurepackage instead of a database issue. -
warning
Reports a warning. Duplicated warnings will be ignored.- Parameters:
key- one ofResources.Keysvalues.argument- the value to substitute to {0} tag in the warning message.
-
finish
Invoked after we finished to create all tables. This method flushes the warnings (omitting duplicated warnings), then returns all tables including dependencies.- Throws:
DataStoreException
-
setValueGetter
Initializes the value getter on the given column. This method shall be invoked only after geometry columns have been identified.
-