Class InstallationScriptProvider
Object
InstallationResources
InstallationScriptProvider
Provides the SQL scripts needed for creating a local copy of a geodetic dataset.
This is used mostly for automatic installation of the EPSG dataset, but could also be used for other registries.
Implementations of this class are discovered automatically by
EPSGFactory
if they are declared in the
module-info.class
file as providers of the org.apache.sis.setup.InstallationResources
service.
How this class is used
The first time that anEPSGDataAccess
needs to be instantiated,
EPSGFactory
verifies if the EPSG database exists.
If it does not, then:
EPSGFactory.install(Connection)
searches for the first instance ofInstallationResources
for which the set of authorities contains"EPSG"
.- The license will be shown to the user if the application allows that (for example, when running as a console application).
- If the user accepts the EPSG terms of use, then this class iterates over all readers provided
by
openScript(String, int)
and executes the SQL statements (not necessarily verbatim, as the installation process may adapt some SQL statements to the target database).
- Since:
- 0.7
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String
Deprecated, for removal: This API element is subject to removal in a future version.Ignored since the upgrade to version 10+ of EPSG because too dependent of the database schema.protected static final String
Deprecated, for removal: This API element is subject to removal in a future version.Ignored since the upgrade to version 10+ of EPSG because too dependent of the database schema. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
InstallationScriptProvider
(String authority, String... resources) Creates a new provider which will read script files of the given names in the given order. -
Method Summary
Modifier and TypeMethodDescriptionReturns the identifiers of the dataset installed by the SQL scripts.String[]
getResourceNames
(String authority) Returns the names of all SQL scripts to execute.openScript
(String authority, int resource) Returns a reader for the SQL script at the given index.protected abstract InputStream
openStream
(String name) Opens the input stream for the SQL script of the given name.Methods inherited from class InstallationResources
getInstructionURL, getLicense, getResource, load
-
Field Details
-
PREPARE
Deprecated, for removal: This API element is subject to removal in a future version.Ignored since the upgrade to version 10+ of EPSG because too dependent of the database schema.A sentinel value for the content of the script to execute before the SQL scripts provided by the authority. This is an Apache SIS build-in script for replacing theVARCHAR
type of some columns by enumeration types, in order to constraint the values to the codes recognized byEPSGDataAccess
. Those enumerations are not mandatory for allowingEPSGFactory
to work, but improve data integrity.- See Also:
-
FINISH
Deprecated, for removal: This API element is subject to removal in a future version.Ignored since the upgrade to version 10+ of EPSG because too dependent of the database schema.A sentinel value for the content of the script to execute after the SQL scripts provided by the authority. This is an Apache SIS build-in script for creating indexes or performing other manipulations that help SIS to use the dataset. Those indexes are not mandatory for allowingEPSGFactory
to work, but improve performances.- See Also:
-
-
Constructor Details
-
InstallationScriptProvider
Creates a new provider which will read script files of the given names in the given order. The given names are often filenames, but not necessarily (it is okay to use those names only as labels).Example of argument values Authority Resources EPSG
{"Tables.sql", "Data.sql", "FKeys.sql", "Indexes.sql"}
- Parameters:
authority
- the authority (typically"EPSG"
), ornull
if not available.resources
- names of the SQL scripts to read (typically filenames).- See Also:
-
-
Method Details
-
getAuthorities
Returns the identifiers of the dataset installed by the SQL scripts. The values currently recognized by SIS are:"EPSG"
for the EPSG geodetic dataset.
null
. An empty set means that the provider does not have all needed resources or does not have permission to distribute the installation scripts.- Specified by:
getAuthorities
in classInstallationResources
- Returns:
- identifiers of SQL scripts that this instance can distribute.
-
getResourceNames
Returns the names of all SQL scripts to execute. This is a copy of the array of names given to the constructor. Those names are often filenames, but not necessarily (they may be just labels).- Specified by:
getResourceNames
in classInstallationResources
- Parameters:
authority
- the value given at construction time (e.g."EPSG"
).- Returns:
- the names of all SQL scripts to execute.
- Throws:
IllegalArgumentException
- if the givenauthority
argument is not the expected value.IOException
- if fetching the script names required an I/O operation and that operation failed.
-
openScript
Returns a reader for the SQL script at the given index. The script may be read, for example, from a local file or from a resource in a JAR file. The returnedBufferedReader
instance shall be closed by the caller.Default implementation
The default implementation delegates toopenStream(String)
. The input stream returned byopenStream(…)
is assumed encoded in UTF-8 and is wrapped in aLineNumberReader
.- Specified by:
openScript
in classInstallationResources
- Parameters:
authority
- the value given at construction time (e.g."EPSG"
).resource
- index of the SQL script to read, from 0 inclusive togetResourceNames(authority).length
exclusive.- Returns:
- a reader for the content of SQL script to execute.
- Throws:
IllegalArgumentException
- if the givenauthority
argument is not the expected value.IndexOutOfBoundsException
- if the givenresource
argument is out of bounds.FileNotFoundException
- if the SQL script of the given name has not been found.IOException
- if an error occurred while creating the reader.
-
openStream
Opens the input stream for the SQL script of the given name. This method is invoked by the default implementation ofopenScript(String, int)
. The returned input stream does not need to be buffered.Example 1
If thisInstallationScriptProvider
instance gets the SQL scripts from files in a well-known directory and if the names given at construction time are filenames in that directory, then this method can be implemented as below:protected InputStream openStream(String name) throws IOException { return Files.newInputStream(directory.resolve(name)); }
Example 2
If thisInstallationScriptProvider
instance gets the SQL scripts from resources bundled in the same JAR file and in the same package as the subclass, this method can be implemented as below:protected InputStream openStream(String name) { return MyClass.getResourceAsStream(name); }
- Parameters:
name
- name of the script file to open. Can benull
if the resource is not found.- Returns:
- an input stream opened of the given script file.
- Throws:
IOException
- if an error occurred while opening the file.
-