Class Analyzer

java.lang.Object
org.apache.sis.internal.sql.feature.Analyzer

final class Analyzer extends Object
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 Details

    • database

      final Database<?> database
      Information about the spatial database to analyze.
    • spatialInformation

      final InfoStatements spatialInformation
      A cache of statements for fetching spatial information such as geometry columns or SRID. May be null if the database is not a spatial database, e.g. because the geometry table has not been found.
    • metadata

      final DatabaseMetaData metadata
      Information about the database as a whole. Used for fetching tables, columns, primary keys etc.
    • nameFactory

      final org.opengis.util.NameFactory nameFactory
      The factory for creating FeatureType names.
    • strings

      private final Map<String,String> 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 same String instances.
      See Also:
    • escape

      final String escape
      The string to insert before wildcard characters ('_' or '%') to escape. This is used by
      invalid reference
      #escape(String)
      before to pass argument values (e.g. table name) to DatabaseMetaData methods expecting a pattern.
    • tables

      private final Map<org.opengis.util.GenericName,Table> tables
      All tables created by analysis of the database structure. A null value means that the table is in process of being created. This may happen if there is cyclic dependencies between tables.
    • warnings

      private final Set<ResourceInternationalString> warnings
      Warnings found while analyzing a database structure. Duplicated warnings are omitted.
    • catalog

      private transient String catalog
      The last catalog and schema used for creating namespace. Used for determining if namespace is still valid.
    • schema

      private transient String schema
      The last catalog and schema used for creating namespace. Used for determining if namespace is still valid.
    • namespace

      private transient org.opengis.util.NameSpace namespace
      The namespace created with catalog and schema.
      See Also:
    • customizer

      final SchemaModifier customizer
      User-specified modification to the features, or null 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 this Analyzer.
      metadata - value of connection.getMetaData() (provided because already known by caller).
      customizer - user-specified modification to the features, or null if none.
      Throws:
      SQLException
  • Method Details

    • getUniqueString

      final String getUniqueString(ResultSet reflect, String column) throws SQLException
      Reads a string from the given result set and return a unique instance of that string. This method should be invoked only for String instances that are going to be stored in Table or Relation 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

      final org.opengis.util.NameSpace namespace(String catalog, String schema)
      Returns a namespace for the given catalog and schema names, or null 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 returns null for one of the tables.
      Parameters:
      id - identification of the table to create.
      name - the value of id.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. Otherwise null.
      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

      public final Table query(org.opengis.util.GenericName name, String query) throws Exception
      Creates a virtual table for the given query. If a table already exists for the given name, then an IllegalNameException is thrown.
      Parameters:
      name - name of the resource.
      query - the query to execute.
      Returns:
      the virtual table for the given query.
      Throws:
      Exception
    • resources

      final Resources resources()
      Returns the localized resources for warnings and error messages.
    • internalError

      final String internalError()
      Returns a message for unexpected errors. Those errors are caused by a bug in this org.apache.sis.internal.sql.feature package instead of a database issue.
    • warning

      private void warning(short key, Object argument)
      Reports a warning. Duplicated warnings will be ignored.
      Parameters:
      key - one of Resources.Keys values.
      argument - the value to substitute to {0} tag in the warning message.
    • finish

      final Collection<Table> finish() throws DataStoreException
      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

      final ValueGetter<?> setValueGetter(Column column)
      Initializes the value getter on the given column. This method shall be invoked only after geometry columns have been identified.