org.geotoolkit.referencing.factory.wkt
Class DirectPostgisFactory

Object
  extended by Factory
      extended by ReferencingFactory
          extended by AbstractAuthorityFactory
              extended by DirectAuthorityFactory
                  extended by WKTParsingAuthorityFactory
                      extended by DirectPostgisFactory
All Implemented Interfaces:
AuthorityFactory, CRSAuthorityFactory, Factory

public class DirectPostgisFactory
extends WKTParsingAuthorityFactory
implements CRSAuthorityFactory

An authority factory creating CRS from the "spatial_ref_sys" table in a spatial SQL database. This class is called DirectPostgisFactory because of some assumptions more suitable to PostGIS, like the default authority if none were explicitly defined. But this class should be usable with other OGC compliant spatial database as well.

This factory doesn't cache any result. Any call to a createFoo method will trig a new WKT parsing. For adding caching service, this factory needs to be wrapped in a CachingAuthorityFactory instance. The AuthorityFactoryProvider convenience class can be used for that purpose.

Since:
3.10 (derived from 2.5)
Version:
3.10
Author:
Martin Desruisseaux (Geomatys)
Module:
referencing/geotk-referencing (download)    View source code for this class

Nested Class Summary
 
Nested classes/interfaces inherited from class Factory
Factory.Availability, Factory.Organizer
 
Field Summary
static String AUTHORITY_COLUMN
          The standard name ("auth_name") of the column containing the authority names.
static String CODE_COLUMN
          The standard name ("auth_srid") of the column containing the authority codes.
static String PRIMARY_KEY
          The primary key column, which is "srid".
static String TABLE
          The standard name of the table containing CRS definitions, which is "spatial_ref_sys".
static String WKT_COLUMN
          The standard name ("srtext") of the column containing the WKT definitions.
 
Fields inherited from class DirectAuthorityFactory
factories
 
Fields inherited from class AbstractAuthorityFactory
nameFactory
 
Fields inherited from class ReferencingFactory
LOGGER
 
Fields inherited from class Factory
EMPTY_HINTS, hints
 
Constructor Summary
DirectPostgisFactory(Hints hints, Connection connection)
          Creates a factory using the given connection.
 
Method Summary
protected  void dispose(boolean shutdown)
          Closes the JDBC connection used by this factory.
 Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> category)
          Returns the authority codes defined in the database for the given type.
 String getBackingStoreDescription()
          Returns a description of the underlying backing store.
 Integer getPrimaryKey(Class<? extends IdentifiedObject> type, String code)
          Returns the primary key for the specified authority code.
 Citation getPrimaryKeyAuthority()
          Returns the authority which is responsible for the maintenance of the primary keys.
 
Methods inherited from class WKTParsingAuthorityFactory
availability, createCoordinateReferenceSystem, createObject, getAuthority, getDescriptionText, getIdentifiedObjectFinder, trimAuthority
 
Methods inherited from class DirectAuthorityFactory
getImplementationHints
 
Methods inherited from class AbstractAuthorityFactory
createCartesianCS, createCompoundCRS, createCoordinateOperation, createCoordinateSystem, createCoordinateSystemAxis, createCylindricalCS, createDatum, createDerivedCRS, createEllipsoid, createEllipsoidalCS, createEngineeringCRS, createEngineeringDatum, createExtent, createFromCoordinateReferenceSystemCodes, createGeocentricCRS, createGeodeticDatum, createGeographicCRS, createImageCRS, createImageDatum, createOperationMethod, createParameterDescriptor, createPolarCS, createPrimeMeridian, createProjectedCRS, createSphericalCS, createTemporalCRS, createTemporalDatum, createTimeCS, createUnit, createVerticalCRS, createVerticalCS, createVerticalDatum, noSuchAuthorityCode
 
Methods inherited from class ReferencingFactory
ensureNonNull, getVendor
 
Methods inherited from class Factory
equals, hasCompatibleHints, hashCode, setOrdering, toString
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface CRSAuthorityFactory
createCompoundCRS, createCoordinateReferenceSystem, createDerivedCRS, createEngineeringCRS, createGeocentricCRS, createGeographicCRS, createImageCRS, createProjectedCRS, createTemporalCRS, createVerticalCRS
 
Methods inherited from interface AuthorityFactory
createObject, getAuthority, getDescriptionText
 
Methods inherited from interface Factory
getVendor
 

Field Detail

TABLE

public static final String TABLE
The standard name of the table containing CRS definitions, which is "spatial_ref_sys".

See Also:
Constant Field Values

PRIMARY_KEY

public static final String PRIMARY_KEY
The primary key column, which is "srid".

See Also:
Constant Field Values

AUTHORITY_COLUMN

public static final String AUTHORITY_COLUMN
The standard name ("auth_name") of the column containing the authority names.

See Also:
Constant Field Values

CODE_COLUMN

public static final String CODE_COLUMN
The standard name ("auth_srid") of the column containing the authority codes.

See Also:
Constant Field Values

WKT_COLUMN

public static final String WKT_COLUMN
The standard name ("srtext") of the column containing the WKT definitions.

See Also:
Constant Field Values
Constructor Detail

DirectPostgisFactory

public DirectPostgisFactory(Hints hints,
                            Connection connection)
                     throws SQLException
Creates a factory using the given connection. The connection is closed when this factory is disposed.

Note: we recommend to avoid keeping the connection open for a long time. An easy way to get the connection created only when first needed and closed automatically after a short timeout is to instantiate this DirectPostgisFactory class only in a ThreadedAuthorityFactory. This approach also gives concurrency and caching services in bonus.

Parameters:
hints - The hints, or null if none.
connection - The connection to the database.
Throws:
SQLException - If an error occurred while fetching metadata from the database.
Method Detail

getBackingStoreDescription

public String getBackingStoreDescription()
                                  throws FactoryException
Returns a description of the underlying backing store.

Overrides:
getBackingStoreDescription in class AbstractAuthorityFactory
Returns:
The description of the underlying backing store, or null.
Throws:
FactoryException - if a failure occurs while fetching the engine description.

getPrimaryKeyAuthority

public Citation getPrimaryKeyAuthority()
Returns the authority which is responsible for the maintenance of the primary keys. Note that primary keys are not necessarily the same than authority codes. The primary keys are stored in the "srid" column, while the authority codes are defined by the "auth_name" : "auth_srid" tupples.

The default implementation returns Citations.POSTGIS in all cases.

Returns:
The authority which is reponsible for the maintenance of primary keys.
See Also:
getPrimaryKey(Class, String)

getAuthorityCodes

public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> category)
                              throws FactoryException
Returns the authority codes defined in the database for the given type.

Specified by:
getAuthorityCodes in interface AuthorityFactory
Overrides:
getAuthorityCodes in class WKTParsingAuthorityFactory
Parameters:
category - The type of objects to search for (typically CoordinateReferenceSystem.class).
Returns:
The set of available codes.
Throws:
FactoryException - if an error occurred while querying the database.

getPrimaryKey

public Integer getPrimaryKey(Class<? extends IdentifiedObject> type,
                             String code)
                      throws NoSuchAuthorityCodeException,
                             FactoryException
Returns the primary key for the specified authority code. If the supplied code contains an authority part as in "EPSG:4326", then this method searches for a row with the given authority ("EPSG") in the "auth_name" column and the given integer code (4326) in the "auth_srid" column. If such row is found, then the value of its "srid" column is returned.

If the supplied code does not contain an authority part (e.g. "4326"), then this method parses the code as an integer. This is consistent with common practice where the spatial CRS table contains entries from a single authority with primary keys identical to the authority codes. This is also consistent with the codes returned by the getAuthorityCodes(Class) method.

Parameters:
type - The type of the object being created (usually CoordinateReferenceSystem.class).
code - The authority code to convert to primary key value.
Returns:
The primary key for the supplied code. There is no guarantee that this key exists (this method may or may not query the database).
Throws:
NoSuchAuthorityCodeException - if a code can't be parsed as an integer or can't be found in the database.
FactoryException - if an error occurred while querying the database.
See Also:
getPrimaryKeyAuthority()

dispose

protected void dispose(boolean shutdown)
Closes the JDBC connection used by this factory.

Overrides:
dispose in class WKTParsingAuthorityFactory


Copyright © 2009-2011 Geotoolkit.org. All Rights Reserved.