public abstract class InstallationScriptProvider extends InstallationResources
EPSGFactory:
META-INF/services/org.apache.sis.setup.InstallationResources
EPSGDataAccess needs to be instantiated,
EPSGFactory verifies if the EPSG database exists. If it does not, then:
EPSGFactory.install(Connection) searches for the first instance of InstallationResources
(the parent of this class) for which the set of authorities contains "EPSG".openScript(String, int) and execute the SQL statements (not necessarily verbatim;
the installation process may adapt to the target database).Defined in the sis-referencing module
| Modifier and Type | Field and Description |
|---|---|
protected static String |
FINISH
A sentinel value for the content of the script to execute after the SQL scripts provided by the authority.
|
protected static String |
PREPARE
A sentinel value for the content of the script to execute before the SQL scripts provided by the authority.
|
| Modifier | Constructor and Description |
|---|---|
protected |
InstallationScriptProvider(String authority,
String... resources)
Creates a new provider which will read script files of the given names in that order.
|
| Modifier and Type | Method and Description |
|---|---|
Set<String> |
getAuthorities()
Returns the identifiers of the dataset installed by the SQL scripts.
|
String[] |
getResourceNames(String authority)
Returns the names of all SQL scripts to execute.
|
BufferedReader |
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.
|
getLicense, getResourceprotected static final String PREPARE
VARCHAR columns
to enumerations of values recognized by EPSGDataAccess. Those enumerations are not required
for proper working of EPSGFactory, but can improve data integrity.protected static final String FINISH
EPSGFactory,
but can significantly improve performances.protected InstallationScriptProvider(String authority, String... resources)
| Authority | Argument values |
|---|---|
EPSG |
{PREPARE, "EPSG_Tables.sql", "EPSG_Data.sql", "EPSG_FKeys.sql", FINISH}
|
authority - the authority (typically "EPSG"), or null if not available.resources - names of the SQL scripts to read.getResourceNames(String),
openStream(String)public Set<String> getAuthorities()
"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.getAuthorities in class InstallationResourcespublic String[] getResourceNames(String authority) throws IOException
getResourceNames in class InstallationResourcesauthority - the value given at construction time (e.g. "EPSG").IllegalArgumentException - if the given authority argument is not the expected value.IOException - if fetching the script names required an I/O operation and that operation failed.public BufferedReader openScript(String authority, int resource) throws IOException
BufferedReader instances shall be closed by the caller.
BufferedReader instances for the following files
(replace <version> by the EPSG version number and <product> by the target database) in same order.
The first and last files are provided by Apache SIS.
All other files can be downloaded from http://www.epsg.org/.
PREPARE, an optional data definition script that define the enumerations expected by EPSGDataAccess."EPSG_<version>.mdb_Tables_<product>.sql", a data definition script that create empty tables."EPSG_<version>.mdb_Data_<product>.sql", a data manipulation script that populate the tables."EPSG_<version>.mdb_FKeys_<product>.sql", a data definition script that create foreigner key constraints.FINISH, an optional data definition and data control script that create indexes and set permissions.openStream(String) – except for PREPARE and FINISH
in which case an Apache SIS build-in script is used – and wrap the result in a LineNumberReader.
The file encoding is ISO LATIN-1 (the encoding used in the scripts distributed by EPSG).openScript in class InstallationResourcesauthority - the value given at construction time (e.g. "EPSG").resource - index of the SQL script to read, from 0 inclusive to
getResourceNames(authority).length exclusive.IllegalArgumentException - if the given authority argument is not the expected value.IndexOutOfBoundsException - if the given resource 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.protected abstract InputStream openStream(String name) throws IOException
openScript(String, int)
for all scripts except PREPARE and FINISH.
InstallationScriptProvider instance gets the SQL scripts from files in a well-known directory
and if the names given at construction time are the
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));
}
InstallationScriptProvider instance rather gets the SQL scripts from resources bundled
in the same JAR files than and in the same package, then this method can be implemented as below:
protected InputStream openStream(String name) {
return MyClass.getResourceAsStream(name);
}
name - name of the script file to open. Can be null if the resource is not found.IOException - if an error occurred while opening the file.Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.