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 in
ReferencingFactoryFinder. 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
FieldsModifier and TypeFieldDescriptionprotected DataSourceThe data source, ornullif the connection has not yet been etablished.static final StringThe default JDBC data source name in JNDI.protected booleanWhether the DataSource is created along with the backing store, or it's a stable, long lived oneprotected static final intThe default priority level for this factory.Fields inherited from class ReferencingFactory
LOGGERFields inherited from class AbstractFactory
hints, MAXIMUM_PRIORITY, MINIMUM_PRIORITY, NORMAL_PRIORITY, priority -
Constructor Summary
ConstructorsConstructorDescriptionConstructs 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
Modifier and TypeMethodDescriptionprotected booleancanDisposeBackingStore(AbstractAuthorityFactory backingStore) Returnstrueif the backing store can be disposed now.protected AbstractAuthorityFactoryCreates the backing store authority factory.protected AbstractAuthorityFactorycreateBackingStore(Hints hints) Creates the backing store for the specified data source.protected DataSourceSetup a data source for a connection to the EPSG database.voiddispose()Releases resources immediately instead of waiting for the garbage collector.protected voidDisposes of the backing storeReturns the authority for this EPSG database.final DataSourceReturns the data source for the EPSG database.voidsetDataSource(DataSource datasource) Set the data source for the EPSG database.Methods inherited from class DeferredAuthorityFactory
exit, getBackingStore, isAvailable, isConnected, setTimeoutMethods 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, getVendorMethods inherited from class AbstractAuthorityFactory
noSuchAuthorityCode, trimAuthorityMethods inherited from class ReferencingFactory
ensureNonNullMethods inherited from class AbstractFactory
addImplementationHints, equals, getImplementationHints, getPriority, hashCode, onDeregistration, onRegistration, toStringMethods inherited from interface AuthorityFactory
createObject, getAuthorityCodes, getDescriptionTextMethods inherited from interface CoordinateOperationAuthorityFactory
createCoordinateOperation, createFromCoordinateReferenceSystemCodesMethods inherited from interface CRSAuthorityFactory
createCompoundCRS, createCoordinateReferenceSystem, createDerivedCRS, createEngineeringCRS, createGeocentricCRS, createGeographicCRS, createImageCRS, createProjectedCRS, createTemporalCRS, createVerticalCRSMethods inherited from interface CSAuthorityFactory
createCartesianCS, createCoordinateSystem, createCoordinateSystemAxis, createCylindricalCS, createEllipsoidalCS, createPolarCS, createSphericalCS, createTimeCS, createUnit, createVerticalCSMethods inherited from interface DatumAuthorityFactory
createDatum, createEllipsoid, createEngineeringDatum, createGeodeticDatum, createImageDatum, createPrimeMeridian, createTemporalDatum, createVerticalDatumMethods inherited from interface Factory
getImplementationHints
-
Field Details
-
DATASOURCE_NAME
The default JDBC data source name in JNDI. This is the name used if no other name were specified through theEPSG_DATA_SOURCEhint.- See Also:
-
PRIORITY
protected static final int PRIORITYThe default priority level for this factory.- See Also:
-
datasource
The data source, ornullif the connection has not yet been etablished. -
dynamicDataSource
protected boolean dynamicDataSourceWhether the DataSource is created along with the backing store, or it's a stable, long lived one
-
-
Constructor Details
-
ThreadedEpsgFactory
public ThreadedEpsgFactory()Constructs an authority factory using the default set of factories. -
ThreadedEpsgFactory
Constructs an authority factory with the default priority. -
ThreadedEpsgFactory
Constructs an authority factory using a set of factories created from the specified hints. This constructor recognizes theCRS,CS,DATUMandMATH_TRANSFORMFACTORYhints, in addition ofEPSG_DATA_SOURCE.- Parameters:
userHints- An optional set of hints, ornullif none.priority- The priority for this factory, as a number betweenMINIMUM_PRIORITYandMAXIMUM_PRIORITYinclusive.
-
-
Method Details
-
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:
getAuthorityin interfaceAuthorityFactory- Overrides:
getAuthorityin classBufferedAuthorityFactory- Returns:
- The organization reponsible for definition of the database.
-
getDataSource
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
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
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 aDataSourceinstance binded to theHints.EPSG_DATA_SOURCEname ("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-accessdefines 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
nullif none where found. - Throws:
SQLException- if an error occured while creating the data source.
-
createBackingStore
Creates the backing store for the specified data source. This method usually returns a new instance ofAccessDialectEpsgFactoryorAnsiDialectEpsgFactory. 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 toDirectEpsgFactoryconstructor.- Returns:
- The EPSG factory using SQL queries appropriate for this data source.
- Throws:
SQLException- if connection to the database failed.
-
createBackingStore
Creates the backing store authority factory.- Specified by:
createBackingStorein 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 aSQLExceptionas its cause.
-
canDisposeBackingStore
Returnstrueif 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:
canDisposeBackingStorein classDeferredAuthorityFactory- Parameters:
backingStore- The backing store in process of being disposed.
-
disposeBackingStore
protected void disposeBackingStore()Description copied from class:DeferredAuthorityFactoryDisposes of the backing store- Overrides:
disposeBackingStorein classDeferredAuthorityFactory
-
dispose
Description copied from class:DeferredAuthorityFactoryReleases 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:
disposein classDeferredAuthorityFactory- Throws:
FactoryException- if an error occured while disposing the factory.
-