Class Analyzer
java.lang.Object
org.apache.sis.internal.sql.feature.Analyzer
Helper methods for creating
FeatureType
s 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 String
The last catalog and schema used for creatingnamespace
.(package private) final SchemaModifier
User-specified modification to the features, ornull
if none.(package private) final Database
<?> Information about the spatial database to analyze.(package private) final String
The string to insert before wildcard characters ('_'
or'%'
) to escape.(package private) final DatabaseMetaData
Information about the database as a whole.(package private) final org.opengis.util.NameFactory
The factory for creatingFeatureType
names.private org.opengis.util.NameSpace
private String
The last catalog and schema used for creatingnamespace
.(package private) final InfoStatements
A 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 String
getUniqueString
(ResultSet reflect, String column) Reads a string from the given result set and return a unique instance of that string.(package private) final String
Returns a message for unexpected errors.(package private) final org.opengis.util.NameSpace
Returns a namespace for the given catalog and schema names, ornull
if all arguments are null.final Table
Creates a virtual table for the given query.(package private) final Resources
Returns the localized resources for warnings and error messages.(package private) final ValueGetter
<?> setValueGetter
(Column column) Initializes the value getter on the given column.final Table
table
(TableReference id, org.opengis.util.GenericName name, TableReference dependencyOf) Returns the table of the given name if it exists, or creates it otherwise.private void
Reports 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 benull
if 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 creatingFeatureType
names. -
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 sameString
instances.- See Also:
-
escape
The string to insert before wildcard characters ('_'
or'%'
) to escape. This is used byinvalid reference
#escape(String)
DatabaseMetaData
methods expecting a pattern. -
tables
All tables created by analysis of the database structure. Anull
value 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, ornull
if 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, ornull
if 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 forString
instances that are going to be stored inTable
orRelation
structures; 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, ornull
if 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 returnsnull
for 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
null
if 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 anIllegalNameException
is 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.feature
package instead of a database issue. -
warning
Reports a warning. Duplicated warnings will be ignored.- Parameters:
key
- one ofResources.Keys
values.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.
-