Class AbstractEpsgFactory

    • Field Detail

      • dataSource

        protected DataSource dataSource
        A DataSource to the EPSG database being used.
    • Constructor Detail

      • AbstractEpsgFactory

        public AbstractEpsgFactory​(Hints userHints,
                                   DataSource dataSource)
      • AbstractEpsgFactory

        public AbstractEpsgFactory​(Hints userHints,
                                   Connection connection)
        Constructs an authority factory using the specified connection.
        Parameters:
        userHints - The underlying factories used for objects creation.
        connection - The connection to the underlying EPSG database.
    • Method Detail

      • getImplementationHints

        public Map<RenderingHints.Key,​?> getImplementationHints()
        Returns the implementation hints for this factory. The returned map contains all the values specified in subclass, with the addition of VERSION.
        Specified by:
        getImplementationHints in interface Factory
        Overrides:
        getImplementationHints in class AbstractFactory
        Returns:
        The map of hints, or an empty map if none.
      • generateAuthorityCodes

        protected Set<String> generateAuthorityCodes​(Class type)
                                              throws FactoryException
        Returns the set of authority codes of the given type.
        Specified by:
        generateAuthorityCodes in class AbstractCachedAuthorityFactory
        Parameters:
        type - The spatial reference objects type (may be Object.class).
        Returns:
        The set of authority codes for spatial reference objects of the given type. If this factory doesn't contains any object of the given type, then this method returns an empty set.
        Throws:
        FactoryException - if access to the underlying database failed.
      • generateExtent

        public Extent generateExtent​(String code)
                              throws FactoryException
        Returns an area of use.
        Parameters:
        code - Value allocated by authority.
        Returns:
        The area of use.
        Throws:
        NoSuchAuthorityCodeException - if this method can't find the requested code.
        FactoryException - if some other kind of failure occured in the backing store. This exception usually have SQLException as its cause.
      • generateParameterDescriptor

        public ParameterDescriptor<?> generateParameterDescriptor​(String code)
                                                           throws FactoryException
        Returns a parameter descriptor from a code.
        Parameters:
        code - The parameter descriptor code allocated by EPSG authority.
        Throws:
        NoSuchAuthorityCodeException - if this method can't find the requested code.
        FactoryException - if some other kind of failure occured in the backing store. This exception usually have SQLException as its cause.
      • generateOperationMethod

        public OperationMethod generateOperationMethod​(String code)
                                                throws FactoryException
        Returns an operation method from a code.
        Parameters:
        code - The operation method code allocated by EPSG authority.
        Throws:
        NoSuchAuthorityCodeException - if this method can't find the requested code.
        FactoryException - if some other kind of failure occured in the backing store. This exception usually have SQLException as its cause.
      • generateFromCoordinateReferenceSystemCodes

        public Set generateFromCoordinateReferenceSystemCodes​(String sourceCode,
                                                              String targetCode)
                                                       throws FactoryException
        Creates operations from coordinate reference system codes. The returned set is ordered with the most accurate operations first.
        Specified by:
        generateFromCoordinateReferenceSystemCodes in class AbstractCachedAuthorityFactory
        Parameters:
        sourceCode - Coded value of source coordinate reference system.
        targetCode - Coded value of target coordinate reference system.
        Throws:
        FactoryException - if the object creation failed.
      • adaptSQL

        protected abstract String adaptSQL​(String statement)
        Invoked when a new PreparedStatement is about to be created from a SQL string. Since the EPSG database is available mainly in MS-Access format, SQL statements are formatted using some syntax specific to this particular database software (for example "SELECT * FROM [Coordinate Reference System]"). When prociding subclass targeting another database vendor, then this method should be overridden in order to adapt the local SQL syntax.

        For example a subclass connecting to a PostgreSQL database could replace all spaces (" ") between watching braces ("[" and "]") by underscore ("_").

        Parameters:
        statement - The statement in MS-Access syntax.
        Returns:
        The SQL statement to use. The default implementation returns the string unchanged.
      • isPrimaryKey

        protected boolean isPrimaryKey​(String code)
                                throws FactoryException
        Returns true if the specified code may be a primary key in some table. This method do not needs to checks any entry in the database. It should just checks from the syntax if the code looks like a valid EPSG identifier. The default implementation returns true if all non-space characters are digits.

        When this method returns false, some createFoo(...) methods look for the code in the name column instead of the primary key column. This allows to accept the "NTF (Paris) / France I" string (for example) in addition to the "27581" primary key. Both should fetch the same object.

        If this method returns true in all cases, then this factory never search for matching names. In such case, an appropriate exception will be thrown in createFoo(...) methods if the code is not found in the primary key column. Subclasses can overrides this method that way if this is the intended behavior.

        Parameters:
        code - The code the inspect.
        Returns:
        true if the code is probably a primary key.
        Throws:
        FactoryException - if an unexpected error occured while inspecting the code.
      • disconnect

        public void disconnect()
                        throws FactoryException
        Disconnect from the database, and remain idle. We will still keep our internal data structures, we are not going to hold onto a database connection unless we are going to be used.
        Throws:
        FactoryException
      • getConnection

        protected Connection getConnection()
                                    throws SQLException
        Access to the connection used by this EpsgFactory. The connection will be created as needed.
        Returns:
        the connection
        Throws:
        SQLException
      • shutdown

        protected void shutdown​(boolean active)
                         throws SQLException
        Shutdown the database engine. This method is invoked twice by ThreadedEpsgFactory at JVM shutdown: one time before the connection is closed, and a second time after. This shutdown hook is useful for embedded database engine starting a server process in addition to the client process. Just closing the connection is not enough for them. Example:

        • HSQL database engine needs to execute a "SHUTDOWN" statement using the connection before it is closed.
        • Derby database engine needs to instruct the driver manager after all connections have been closed.

        The default implementation does nothing, which is sufficient for implementations connecting to a distant server (i.e. non-embedded database engine), for example MS-Access or PostgreSQL.

        Parameters:
        active - true if the connection is alive, or false otherwise. This method is invoked first with active set to true, then a second time with active set to false.
        Throws:
        SQLException - if this method failed to shutdown the database engine.
      • finalize

        protected final void finalize()
                               throws Throwable
        Invokes dispose() when this factory is garbage collected.
        Overrides:
        finalize in class Object
        Throws:
        Throwable - if an error occurred while closing the connection.