Class EPSGInstaller
java.lang.Object
org.apache.sis.internal.metadata.sql.ScriptRunner
org.apache.sis.referencing.factory.sql.EPSGInstaller
- All Implemented Interfaces:
AutoCloseable
Runs the SQL scripts for creating an EPSG database.
See
org.apache.sis.referencing.factory.sql.epsg.DataScriptFormatter
in the test directory for more information about how the scripts are formatted.- Since:
- 0.7
- Version:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final String
The pattern for an"UPDATE … SET … REPLACE"
instruction.private final boolean
true
if the Pilcrow character (¶ - decimal code 182) should be replaced by Line Feed (LF - decimal code 10).Fields inherited from class org.apache.sis.internal.metadata.sql.ScriptRunner
identifierQuote, isCatalogSupported, isCommentSupported, isCreateLanguageRequired, isEnumTypeSupported, isGrantOnSchemaSupported, isGrantOnTableSupported, isSchemaSupported, PUBLIC
-
Constructor Summary
ConstructorsConstructorDescriptionEPSGInstaller
(Connection connection) Creates a new runner which will execute the statements using the given connection. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
editText
(StringBuilder sql, int lower, int upper) Invoked for each text found in a SQL statement.protected int
execute
(StringBuilder sql) Modifies the SQL statement before to execute it, or omit unsupported statements.(package private) final String
Creates a message reporting the failure to create EPSG database.private static InstallationResources
lookupProvider
(Locale locale) Searches for a SQL script provider on the classpath before to fallback on the default provider.(package private) final void
prependNamespace
(String schema) Prepends the given schema or catalog to all table names.void
run
(InstallationResources scriptProvider, Locale locale) Processes to the creation of the EPSG database using the SQL scripts from the given provider.void
Creates immediately a schema of the given name in the database and remember that the"epsg_"
prefix in table names will need to be replaced by path to that schema.Methods inherited from class org.apache.sis.internal.metadata.sql.ScriptRunner
addReplacement, addStatementToSkip, close, getConnection, getReplacement, isSupported, modifyReplacements, run, run, run, status, toString
-
Field Details
-
REPLACE_STATEMENT
The pattern for an"UPDATE … SET … REPLACE"
instruction. Example: Note: this regular expression use a capturing group.- See Also:
-
replacePilcrow
private final boolean replacePilcrowtrue
if the Pilcrow character (¶ - decimal code 182) should be replaced by Line Feed (LF - decimal code 10). This is a possible workaround when the database does not support theREPLACE(column, CHAR(182), CHAR(10))
SQL statement, but accepts LF.
-
-
Constructor Details
-
EPSGInstaller
Creates a new runner which will execute the statements using the given connection. The encoding is"ISO-8859-1"
, which is the encoding used for the files provided by EPSG.- Parameters:
connection
- the connection to the database.- Throws:
SQLException
- if an error occurred while executing a SQL statement.
-
-
Method Details
-
setSchema
Creates immediately a schema of the given name in the database and remember that the"epsg_"
prefix in table names will need to be replaced by path to that schema.This method should be invoked only once. It does nothing if the database does not supports schema.
- Parameters:
schema
- the schema (usually"epsg"
).- Throws:
SQLException
- if the schema cannot be created.IOException
- if an I/O operation was required and failed.
-
prependNamespace
Prepends the given schema or catalog to all table names. -
editText
Invoked for each text found in a SQL statement. This method replaces''
byNull
. The intent is to consistently use the null value for meaning "no information", which is not the same than "information is an empty string". This replacement is okay in this particular case since there is no field in the EPSG database for which we really want an empty string.- Overrides:
editText
in classScriptRunner
- Parameters:
sql
- the whole SQL statement.lower
- index of the first character of the text insql
.upper
- index after the last character of the text insql
.
-
execute
Modifies the SQL statement before to execute it, or omit unsupported statements.- Overrides:
execute
in classScriptRunner
- Parameters:
sql
- the SQL statement to execute.- Returns:
- the number of rows added or modified as a result of the statement execution.
- Throws:
SQLException
- if an error occurred while executing the SQL statement.IOException
- if an I/O operation was required and failed.
-
run
public void run(InstallationResources scriptProvider, Locale locale) throws SQLException, IOException Processes to the creation of the EPSG database using the SQL scripts from the given provider.- Parameters:
scriptProvider
- user-provided scripts, ornull
for automatic lookup.locale
- the locale for information or warning messages, if any.- Throws:
FileNotFoundException
- if a SQL script has not been found.IOException
- if another error occurred while reading an input.SQLException
- if an error occurred while executing a SQL statement.
-
lookupProvider
Searches for a SQL script provider on the classpath before to fallback on the default provider. The returned provider will be, in preference order:- A provider from a publicly supported dependency such as
sis-epsg.jar
orsis-embedded.jar
. Users have to put one of those dependencies in the classpath themselves. This action is interpreted as an acceptance of EPSG terms of use, so no license agreement window will popup. - A provider using the SQL scripts in the
$SIS_DATA/Databases/ExternalSources
directory. Users have to put those scripts in that directory manually. This action is interpreted as an acceptance of EPSG terms of use, so no license agreement window will popup. - A provider offering users to automatically download the data. Those providers are defined by
sis-console
andsis-javafx
modules. Users must accept EPSG terms of use before the database can be installed.
- Parameters:
locale
- the locale for information or warning messages, if any.- Throws:
IOException
- A provider from a publicly supported dependency such as
-
failure
Creates a message reporting the failure to create EPSG database. This method is invoked whenEPSGFactory
caught an exception. This method completes the exception message with the file name and line number where the error occurred, if such information is available.
-