Class DirectEpsgFactory
- All Implemented Interfaces:
AuthorityFactory,CRSAuthorityFactory,CSAuthorityFactory,DatumAuthorityFactory,Factory,CoordinateOperationAuthorityFactory,Factory,RegistrableFactory
- Direct Known Subclasses:
FactoryUsingSQL
The EPSG database is freely available at http://www.epsg.org. Current version of this class requires EPSG database version 6.6 or above.
This factory doesn't cache any result. Any call to a createFoo method will send a new query to the EPSG
database. For caching, this factory should be wrapped in some buffered factory like ThreadedEpsgFactory.
This class is abstract - please see the subclasses for dialect specific implementations:
AccessDialectEpsgFactoryAnsiDialectEpsgFactoryOracleDialectEpsgFactory
"27581" both fetchs the same object. However, names may be ambiguous since the same name may be used for more
than one object. This is the case of "WGS 84" for example. If such an ambiguity is found, an exception will be
thrown. If names are not wanted as a legal EPSG code, subclasses can override the isPrimaryKey(java.lang.String) method.- Since:
- 2.4
- Author:
- Yann Cézard, Martin Desruisseaux (IRD), Rueben Schulz, Matthias Basler, Andrea Aime
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumAllows to switch theCoordinateOperationorder from the default accuracy first (GeoTools default) to area first (Proj default). -
Field Summary
FieldsFields inherited from class DirectAuthorityFactory
factoriesFields inherited from class ReferencingFactory
LOGGERFields inherited from class AbstractFactory
hints, MAXIMUM_PRIORITY, MINIMUM_PRIORITY, NORMAL_PRIORITY, priority -
Constructor Summary
ConstructorsConstructorDescriptionDirectEpsgFactory(Hints userHints, Connection connection) Constructs an authority factory using the specified connection.DirectEpsgFactory(Hints userHints, DataSource dataSource) Constructs an authority factory using the specified connection. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract StringInvoked when a newPreparedStatementis about to be created from a SQL string.Returns a coordinate operation from a code.Returns a coordinate reference system from a code.createCoordinateSystem(String code) Returns a coordinate system from a code.Returns a coordinate system axis from a code.createDatum(String code) Returns a datum from a code.createEllipsoid(String code) Returns an ellipsoid from a code.createExtent(String code) Returns an area of use.createFromCoordinateReferenceSystemCodes(String sourceCode, String targetCode) Creates operations from coordinate reference system codes.createObject(String code) Returns an arbitrary object from a code.createOperationMethod(String code) Returns an operation method from a code.Returns a parameter descriptor from a code.createPrimeMeridian(String code) Returns a prime meridian, relative to Greenwich.Unit<?>createUnit(String code) Returns an unit from a code.voiddispose()Disposes any resources hold by this object.protected final voidfinalize()Invokesdispose()when this factory is garbage collected.Returns the authority for this EPSG database.getAuthorityCodes(Class<? extends IdentifiedObject> type) Returns the set of authority codes of the given type.Returns a description of the database engine.protected ConnectionAccess to the connection used by this EpsgFactory.getDescriptionText(String code) Gets a description of the object corresponding to a code.getIdentifiedObjectFinder(Class<? extends IdentifiedObject> type) Returns a finder which can be used for looking up unidentified objects.Returns the implementation hints for this factory.Returns the current validation queryprotected booleanisConnectionValid(Connection conn) Tests if the connection is valid by running the user provided validation query, if any.protected booleanisPrimaryKey(String code) Returnstrueif the specified code may be a primary key in some table.static voidAllows to programmatically switch between the possible orders orders for coordinate operation priorityvoidsetValidationQuery(String validationQuery) Sets the query it's run before using connection and prepared statements in order to check the connection is still valid.protected voidshutdown(boolean active) Shutdown the database engine.Methods inherited from class AbstractAuthorityFactory
createCartesianCS, createCompoundCRS, createCylindricalCS, createDerivedCRS, createEllipsoidalCS, createEngineeringCRS, createEngineeringDatum, createGeocentricCRS, createGeodeticDatum, createGeographicCRS, createImageCRS, createImageDatum, createPolarCS, createProjectedCRS, createSphericalCS, createTemporalCRS, createTemporalDatum, createTimeCS, createVerticalCRS, createVerticalCS, createVerticalDatum, noSuchAuthorityCode, trimAuthorityMethods inherited from class ReferencingFactory
ensureNonNull, getVendorMethods inherited from class AbstractFactory
addImplementationHints, equals, getPriority, hashCode, onDeregistration, onRegistration, toStringMethods inherited from interface CRSAuthorityFactory
createCompoundCRS, createDerivedCRS, createEngineeringCRS, createGeocentricCRS, createGeographicCRS, createImageCRS, createProjectedCRS, createTemporalCRS, createVerticalCRSMethods inherited from interface CSAuthorityFactory
createCartesianCS, createCylindricalCS, createEllipsoidalCS, createPolarCS, createSphericalCS, createTimeCS, createVerticalCSMethods inherited from interface DatumAuthorityFactory
createEngineeringDatum, createGeodeticDatum, createImageDatum, createTemporalDatum, createVerticalDatum
-
Field Details
-
ORDER_KEY
- See Also:
-
-
Constructor Details
-
DirectEpsgFactory
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.
-
DirectEpsgFactory
Constructs an authority factory using the specified connection.- Parameters:
userHints- The underlying factories used for objects creation.dataSource- The data source connecting to the underlying EPSG database
-
-
Method Details
-
setOperationOrder
Allows to programmatically switch between the possible orders orders for coordinate operation priority- Parameters:
order-
-
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- Specified by:
getAuthorityin classAbstractAuthorityFactory- Returns:
- The organization reponsible for definition of the database.
-
getBackingStoreDescription
Returns a description of the database engine.- Overrides:
getBackingStoreDescriptionin classAbstractAuthorityFactory- Returns:
- The description of the underlying backing store, or
null. - Throws:
FactoryException- if the database's metadata can't be fetched.
-
getImplementationHints
Returns the implementation hints for this factory. The returned map contains all the values specified in subclass, with the addition ofVERSION.- Specified by:
getImplementationHintsin interfaceFactory- Overrides:
getImplementationHintsin classDirectAuthorityFactory- Returns:
- The map of hints, or an empty map if none.
-
getAuthorityCodes
public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type) throws FactoryException Returns the set of authority codes of the given type.NOTE: This method returns a living connection to the underlying database. This means that the returned set can executes efficiently idioms like the following one:
But do not keep the returned reference for a long time. The returned set should stay valid even if retained for a long time (as long as this factory has not been disposed), but the existence of those long-living connections may prevent this factory to release some resources. If the set of codes is needed for a long time, copy their values in an other collection object.getAuthorityCodes(type</var).containsAll(others)
- Specified by:
getAuthorityCodesin interfaceAuthorityFactory- Parameters:
type- The spatial reference objects type (may beObject.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 {@linkplain java.util.Collections.emptySet() empty set}.
- Throws:
FactoryException- if access to the underlying database failed.
-
getDescriptionText
Gets a description of the object corresponding to a code.- Specified by:
getDescriptionTextin interfaceAuthorityFactory- Parameters:
code- Value allocated by authority.- Returns:
- A description of the object, or
nullif the object corresponding to the specifiedcodehas no description. - Throws:
NoSuchAuthorityCodeException- if the specifiedcodewas not found.FactoryException- if the query failed for some other reason.
-
createObject
Returns an arbitrary object from a code. The default implementation invokes one ofcreateCoordinateReferenceSystem(java.lang.String),createCoordinateSystem(java.lang.String),createDatum(java.lang.String),createEllipsoid(java.lang.String), orcreateUnit(java.lang.String)methods according the object type.- Specified by:
createObjectin interfaceAuthorityFactory- Overrides:
createObjectin classAbstractAuthorityFactory- Parameters:
code- The EPSG value.- Returns:
- The object.
- 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 haveSQLExceptionas its cause.- See Also:
-
createUnit
Returns an unit from a code.- Specified by:
createUnitin interfaceCSAuthorityFactory- Overrides:
createUnitin classAbstractAuthorityFactory- Parameters:
code- Value allocated by authority.- Returns:
- The unit object.
- 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 haveSQLExceptionas its cause.
-
createEllipsoid
Returns an ellipsoid from a code.- Specified by:
createEllipsoidin interfaceDatumAuthorityFactory- Overrides:
createEllipsoidin classAbstractAuthorityFactory- Parameters:
code- The EPSG value.- Returns:
- The ellipsoid object.
- 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 haveSQLExceptionas its cause.- See Also:
-
createPrimeMeridian
Returns a prime meridian, relative to Greenwich.- Specified by:
createPrimeMeridianin interfaceDatumAuthorityFactory- Overrides:
createPrimeMeridianin classAbstractAuthorityFactory- Parameters:
code- Value allocated by authority.- Returns:
- The prime meridian object.
- 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 haveSQLExceptionas its cause.- See Also:
-
createExtent
Returns an area of use.- Overrides:
createExtentin classAbstractAuthorityFactory- 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 haveSQLExceptionas its cause.
-
createDatum
Returns a datum from a code.- Specified by:
createDatumin interfaceDatumAuthorityFactory- Overrides:
createDatumin classAbstractAuthorityFactory- Parameters:
code- Value allocated by authority.- Returns:
- The datum object.
- 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 haveSQLExceptionas its cause.- See Also:
-
createCoordinateSystemAxis
Returns a coordinate system axis from a code.- Specified by:
createCoordinateSystemAxisin interfaceCSAuthorityFactory- Overrides:
createCoordinateSystemAxisin classAbstractAuthorityFactory- Parameters:
code- Value allocated by authority.- Returns:
- The axis for the given code.
- Throws:
NoSuchAuthorityCodeException- if the specifiedcodewas not found.FactoryException- if the object creation failed for some other reason.
-
createCoordinateSystem
Returns a coordinate system from a code.- Specified by:
createCoordinateSystemin interfaceCSAuthorityFactory- Overrides:
createCoordinateSystemin classAbstractAuthorityFactory- Parameters:
code- Value allocated by authority.- Returns:
- The coordinate system object.
- 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 haveSQLExceptionas its cause.
-
createCoordinateReferenceSystem
public CoordinateReferenceSystem createCoordinateReferenceSystem(String code) throws FactoryException Returns a coordinate reference system from a code.- Specified by:
createCoordinateReferenceSystemin interfaceCRSAuthorityFactory- Overrides:
createCoordinateReferenceSystemin classAbstractAuthorityFactory- Parameters:
code- Value allocated by authority.- Returns:
- The coordinate reference system object.
- 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 haveSQLExceptionas its cause.- See Also:
-
AbstractAuthorityFactory.createGeographicCRS(java.lang.String)AbstractAuthorityFactory.createProjectedCRS(java.lang.String)AbstractAuthorityFactory.createVerticalCRS(java.lang.String)AbstractAuthorityFactory.createTemporalCRS(java.lang.String)AbstractAuthorityFactory.createCompoundCRS(java.lang.String)
-
createParameterDescriptor
Returns a parameter descriptor from a code.- Overrides:
createParameterDescriptorin classAbstractAuthorityFactory- Parameters:
code- The parameter descriptor code allocated by EPSG authority.- Returns:
- The coordinate reference system for the given code.
- 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 haveSQLExceptionas its cause.
-
createOperationMethod
Returns an operation method from a code.- Overrides:
createOperationMethodin classAbstractAuthorityFactory- Parameters:
code- The operation method code allocated by EPSG authority.- Returns:
- The operation method for the given code.
- 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 haveSQLExceptionas its cause.
-
createCoordinateOperation
Returns a coordinate operation from a code. The returned object will either be a conversion or a transformation, depending on the code.- Specified by:
createCoordinateOperationin interfaceCoordinateOperationAuthorityFactory- Overrides:
createCoordinateOperationin classAbstractAuthorityFactory- Parameters:
code- Value allocated by authority.- Returns:
- The coordinate operation object.
- 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 haveSQLExceptionas its cause.
-
createFromCoordinateReferenceSystemCodes
public Set<CoordinateOperation> createFromCoordinateReferenceSystemCodes(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:
createFromCoordinateReferenceSystemCodesin interfaceCoordinateOperationAuthorityFactory- Overrides:
createFromCoordinateReferenceSystemCodesin classAbstractAuthorityFactory- Parameters:
sourceCode- Coded value of source coordinate reference system.targetCode- Coded value of target coordinate reference system.- Returns:
- Throws:
FactoryException- if the object creation failed.
-
getIdentifiedObjectFinder
public IdentifiedObjectFinder getIdentifiedObjectFinder(Class<? extends IdentifiedObject> type) throws FactoryException Returns a finder which can be used for looking up unidentified objects.- Overrides:
getIdentifiedObjectFinderin classAbstractAuthorityFactory- Parameters:
type- The type of objects to look for.- Returns:
- A finder to use for looking up unidentified objects.
- Throws:
FactoryException- if the finder can not be created.
-
adaptSQL
Invoked when a newPreparedStatementis 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
Returnstrueif 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 returnstrueif all non-space characters are digits.When this method returns
false, somecreateFoo(...)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
truein all cases, then this factory never search for matching names. In such case, an appropriate exception will be thrown increateFoo(...)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:
trueif the code is probably a primary key.- Throws:
FactoryException- if an unexpected error occured while inspecting the code.
-
dispose
Disposes any resources hold by this object.- Overrides:
disposein classAbstractAuthorityFactory- Throws:
FactoryException- if an error occured while closing the connection.
-
shutdown
Shutdown the database engine. This method is invoked twice byThreadedEpsgFactoryat JVM shutdown: one time before the connection is closed, and a second time after. This shutdown hook is usefull 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 suffisient for implementations connecting to a distant server (i.e. non-embedded database engine), for example MS-Access or PostgreSQL.
- Parameters:
active-trueif the connection is alive, orfalseotherwise. This method is invoked first withactiveset totrue, then a second time withactiveset tofalse.- Throws:
SQLException- if this method failed to shutdown the database engine.
- HSQL database engine needs to execute a
-
finalize
Invokesdispose()when this factory is garbage collected. -
getConnection
Access to the connection used by this EpsgFactory. The connection will be created as needed.- Returns:
- the connection
- Throws:
SQLException
-
isConnectionValid
Tests if the connection is valid by running the user provided validation query, if any. Subclasses may override with a more efficient connection checking method if needed. If the validation query is not set, the method returns true by default.- Parameters:
conn- The connection to be validated- Returns:
- True if the connection is alive, false if it should be replaced
-
getValidationQuery
Returns the current validation query -
setValidationQuery
Sets the query it's run before using connection and prepared statements in order to check the connection is still valid. The query should hit the database, but be as fast as possible.
-