Class ThreadedEpsgFactory
-
- All Implemented Interfaces:
AuthorityFactory
,CRSAuthorityFactory
,CSAuthorityFactory
,DatumAuthorityFactory
,Factory
,CoordinateOperationAuthorityFactory
,BufferedFactory
,Factory
,OptionalFactory
,RegistrableFactory
- Direct Known Subclasses:
ThreadedHsqlEpsgFactory
,ThreadedPostgreSQLEpsgFactory
public class ThreadedEpsgFactory extends DeferredAuthorityFactory implements CRSAuthorityFactory, CSAuthorityFactory, DatumAuthorityFactory, CoordinateOperationAuthorityFactory
Base class for EPSG factories to be registered inReferencingFactoryFinder
. Various subclasses are defined for different database backends: Access, PostgreSQL, HSQL, etc..This class has the following responsibilities:
- aquire a DataSource (using JNDI or otherwise)
- specify a worker class that will talk to the database in the event of a cache miss. The class will be specific to the delect of SQL used by the database hosting the EPSG tables.
Subclasses should override the following methods:
- createDataSource() used to aquire a DataSource
createBackingStore(org.geotools.util.factory.Hints)
instance capable to speak that database syntax
Users should not creates instance of this class directly. They should invoke one of
ReferencingFactoryFinder.getFooAuthorityFactory("EPSG")
methods instead.- Since:
- 2.4
- Author:
- Martin Desruisseaux (IRD)
-
-
Field Summary
Fields Modifier and Type Field Description protected DataSource
datasource
The data source, ornull
if the connection has not yet been etablished.static String
DATASOURCE_NAME
The default JDBC data source name in JNDI.protected boolean
dynamicDataSource
Whether the DataSource is created along with the backing store, or it's a stable, long lived oneprotected static int
PRIORITY
The default priority level for this factory.-
Fields inherited from class ReferencingFactory
LOGGER
-
Fields inherited from class AbstractFactory
hints, MAXIMUM_PRIORITY, MINIMUM_PRIORITY, NORMAL_PRIORITY, priority
-
-
Constructor Summary
Constructors Constructor Description ThreadedEpsgFactory()
Constructs an authority factory using the default set of factories.ThreadedEpsgFactory(Hints userHints)
Constructs an authority factory with the default priority.ThreadedEpsgFactory(Hints userHints, int priority)
Constructs an authority factory using a set of factories created from the specified hints.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
canDisposeBackingStore(AbstractAuthorityFactory backingStore)
Returnstrue
if the backing store can be disposed now.protected AbstractAuthorityFactory
createBackingStore()
Creates the backing store authority factory.protected AbstractAuthorityFactory
createBackingStore(Hints hints)
Creates the backing store for the specified data source.protected DataSource
createDataSource()
Setup a data source for a connection to the EPSG database.void
dispose()
Releases resources immediately instead of waiting for the garbage collector.protected void
disposeBackingStore()
Disposes of the backing storeCitation
getAuthority()
Returns the authority for this EPSG database.DataSource
getDataSource()
Returns the data source for the EPSG database.void
setDataSource(DataSource datasource)
Set the data source for the EPSG database.-
Methods inherited from class DeferredAuthorityFactory
exit, getBackingStore, isAvailable, isConnected, setTimeout
-
Methods inherited from class BufferedAuthorityFactory
createCartesianCS, createCompoundCRS, createCoordinateOperation, createCoordinateReferenceSystem, createCoordinateSystem, createCoordinateSystemAxis, createCylindricalCS, createDatum, createDerivedCRS, createEllipsoid, createEllipsoidalCS, createEngineeringCRS, createEngineeringDatum, createExtent, createFromCoordinateReferenceSystemCodes, createGeocentricCRS, createGeodeticDatum, createGeographicCRS, createImageCRS, createImageDatum, createObject, createOperationMethod, createParameterDescriptor, createPolarCS, createPrimeMeridian, createProjectedCRS, createSphericalCS, createTemporalCRS, createTemporalDatum, createTimeCS, createUnit, createVerticalCRS, createVerticalCS, createVerticalDatum, getAuthorityCodes, getBackingStoreDescription, getDescriptionText, getIdentifiedObjectFinder, getVendor
-
Methods inherited from class AbstractAuthorityFactory
noSuchAuthorityCode, trimAuthority
-
Methods inherited from class ReferencingFactory
ensureNonNull
-
Methods inherited from class AbstractFactory
addImplementationHints, equals, getImplementationHints, getPriority, hashCode, onDeregistration, onRegistration, toString
-
Methods inherited from interface AuthorityFactory
createObject, getAuthorityCodes, getDescriptionText
-
Methods inherited from interface CoordinateOperationAuthorityFactory
createCoordinateOperation, createFromCoordinateReferenceSystemCodes
-
Methods inherited from interface CRSAuthorityFactory
createCompoundCRS, createCoordinateReferenceSystem, createDerivedCRS, createEngineeringCRS, createGeocentricCRS, createGeographicCRS, createImageCRS, createProjectedCRS, createTemporalCRS, createVerticalCRS
-
Methods inherited from interface CSAuthorityFactory
createCartesianCS, createCoordinateSystem, createCoordinateSystemAxis, createCylindricalCS, createEllipsoidalCS, createPolarCS, createSphericalCS, createTimeCS, createUnit, createVerticalCS
-
Methods inherited from interface DatumAuthorityFactory
createDatum, createEllipsoid, createEngineeringDatum, createGeodeticDatum, createImageDatum, createPrimeMeridian, createTemporalDatum, createVerticalDatum
-
Methods inherited from interface Factory
getImplementationHints
-
-
-
-
Field Detail
-
DATASOURCE_NAME
public static final String DATASOURCE_NAME
The default JDBC data source name in JNDI. This is the name used if no other name were specified through theEPSG_DATA_SOURCE
hint.- See Also:
createDataSource()
, Constant Field Values
-
PRIORITY
protected static final int PRIORITY
The default priority level for this factory.- See Also:
- Constant Field Values
-
datasource
protected DataSource datasource
The data source, ornull
if the connection has not yet been etablished.
-
dynamicDataSource
protected boolean dynamicDataSource
Whether the DataSource is created along with the backing store, or it's a stable, long lived one
-
-
Constructor Detail
-
ThreadedEpsgFactory
public ThreadedEpsgFactory()
Constructs an authority factory using the default set of factories.
-
ThreadedEpsgFactory
public ThreadedEpsgFactory(Hints userHints)
Constructs an authority factory with the default priority.
-
ThreadedEpsgFactory
public ThreadedEpsgFactory(Hints userHints, int priority)
Constructs an authority factory using a set of factories created from the specified hints. This constructor recognizes theCRS
,CS
,DATUM
andMATH_TRANSFORM
FACTORY
hints, in addition ofEPSG_DATA_SOURCE
.- Parameters:
userHints
- An optional set of hints, ornull
if none.priority
- The priority for this factory, as a number betweenMINIMUM_PRIORITY
andMAXIMUM_PRIORITY
inclusive.
-
-
Method Detail
-
getAuthority
public Citation getAuthority()
Returns the authority for this EPSG database. This authority will contains the database version in the edition attribute, together with the edition date.- Specified by:
getAuthority
in interfaceAuthorityFactory
- Overrides:
getAuthority
in classBufferedAuthorityFactory
- Returns:
- The organization reponsible for definition of the database.
-
getDataSource
public final DataSource getDataSource() throws SQLException
Returns the data source for the EPSG database. If no data source has been previously set, then this method invokescreateDataSource()
. Note: invoking this method may force immediate connection to the EPSG database.- Returns:
- The data source.
- Throws:
SQLException
- if the connection to the EPSG database failed.- See Also:
setDataSource(javax.sql.DataSource)
,createDataSource()
-
setDataSource
public void setDataSource(DataSource datasource) throws SQLException
Set the data source for the EPSG database. If an other EPSG database was already in use, it will be disconnected. Users should not invoke this method on the factory returned byReferencingFactoryFinder
, since it could have a system-wide effect.- Parameters:
datasource
- The new datasource.- Throws:
SQLException
- if an error occured.
-
createDataSource
protected DataSource createDataSource() throws SQLException
Setup a data source for a connection to the EPSG database. This method is invoked bygetDataSource()
when no data source has been explicitly set. The default implementation searchs for aDataSource
instance binded to theHints.EPSG_DATA_SOURCE
name ("java:comp/env/jdbc/EPSG"
by default) using Java Naming and Directory Interfaces (JNDI). If no data source were found, then this method returnsnull
.Subclasses override this method in order to initialize a default data source when none were found with JNDI. For example
plugin/epsg-access
defines a default data source using the JDBC-ODBC bridge, which expects an "EPSG
" database registered as an ODBC data source (see the package javadoc for installation instructions). Example for a PostgreSQL data source:protected DataSource createDataSource() throws SQLException { DataSource candidate = super.createDataSource(); if (candidate instanceof Jdbc3SimpleDataSource) { return candidate; } Jdbc3SimpleDataSource ds = new Jdbc3SimpleDataSource(); ds.setServerName("localhost"); ds.setDatabaseName("EPSG"); ds.setUser("postgre"); return ds; }
- Returns:
- The EPSG data source, or
null
if none where found. - Throws:
SQLException
- if an error occured while creating the data source.
-
createBackingStore
protected AbstractAuthorityFactory createBackingStore(Hints hints) throws SQLException
Creates the backing store for the specified data source. This method usually returns a new instance ofAccessDialectEpsgFactory
orAnsiDialectEpsgFactory
. Subclasses may override this method in order to returns an instance tuned for the SQL syntax of the underlying database. Example for a PostgreSQL data source:protected AbstractAuthorityFactory createBackingStore(Hints hints) throws SQLException { return new AnsiDialectEpsgFactory(hints, getDataSource().getConnection()); }
- Parameters:
hints
- A map of hints, including the low-level factories to use for CRS creation. This argument should be given unchanged toDirectEpsgFactory
constructor.- Returns:
- The EPSG factory using SQL queries appropriate for this data source.
- Throws:
SQLException
- if connection to the database failed.
-
createBackingStore
protected AbstractAuthorityFactory createBackingStore() throws FactoryException
Creates the backing store authority factory.- Specified by:
createBackingStore
in classDeferredAuthorityFactory
- Returns:
- The backing store to uses in
createXXX(...)
methods. - Throws:
FactoryException
- if the constructor failed to connect to the EPSG database. This exception usually has aSQLException
as its cause.
-
canDisposeBackingStore
protected boolean canDisposeBackingStore(AbstractAuthorityFactory backingStore)
Returnstrue
if the backing store can be disposed now. This method is invoked automatically after the amount of time specified byDeferredAuthorityFactory.setTimeout(long)
if the factory were not used during that time.- Overrides:
canDisposeBackingStore
in classDeferredAuthorityFactory
- Parameters:
backingStore
- The backing store in process of being disposed.
-
disposeBackingStore
protected void disposeBackingStore()
Description copied from class:DeferredAuthorityFactory
Disposes of the backing store- Overrides:
disposeBackingStore
in classDeferredAuthorityFactory
-
dispose
public void dispose() throws FactoryException
Description copied from class:DeferredAuthorityFactory
Releases resources immediately instead of waiting for the garbage collector. This method disposes the backing store regardeless ofDeferredAuthorityFactory.canDisposeBackingStore(org.geotools.referencing.factory.AbstractAuthorityFactory)
value.- Overrides:
dispose
in classDeferredAuthorityFactory
- Throws:
FactoryException
- if an error occured while disposing the factory.
-
-