org.geotoolkit.referencing.factory.epsg
Class EpsgInstaller

Object
  extended by EpsgInstaller
All Implemented Interfaces:
Callable<EpsgInstaller.Result>

@ThreadSafe
public class EpsgInstaller
extends Object
implements Callable<EpsgInstaller.Result>

Installs the EPSG database. By default this class performs the following operations:

  1. Gets the default URL to the EPSG database on the local machine. This database doesn't need to exist.
  2. Gets a connection to that database, which is assumed empty.
  3. Executes the SQL scripts embedded in the geotk-epsg module. Those scripts are derived from the ones distributed on the www.epsg.org web site.

This default behavior can be changed by the setter methods defined in this class. They allow to use a different set of scripts, or to execute them on a different database (for example PostgreSQL).

The scripts are read and the database is created only when the call() method is invoked. This method can be run in a background thread by an executor service.

Since:
3.00
Version:
3.11
Author:
Martin Desruisseaux (Geomatys)
Module:
referencing/geotk-referencing (download)    View source code for this class

Nested Class Summary
static class EpsgInstaller.Result
          A simple data structure holding the result of an EPSG database creation.
 
Field Summary
static String DEFAULT_SCHEMA
          The schema where the installer will create the tables in the JavaDB database.
 
Constructor Summary
EpsgInstaller()
          Creates a new installer.
 
Method Summary
 EpsgInstaller.Result call()
          Processes to the creation of the EPSG database.
 boolean exists()
          Verifies if the database exists.
 void setDatabase(Connection connection)
          Sets the connection to the database.
 void setDatabase(String url)
          Sets the URL to the database, using the JDBC syntax.
 void setDatabase(String url, String user, String password)
          Sets the URL to the database, together with the user and password.
 void setSchema(String schema)
          Sets the schema where the installer will create the tables.
 void setScriptDirectory(File directory)
          Sets the directory which contain the SQL scripts to execute.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SCHEMA

public static final String DEFAULT_SCHEMA
The schema where the installer will create the tables in the JavaDB database. The value is "epsg". When the geotk-epsg.jar file is reachable on the classpath, the referencing module will look for this schema in order to decide if it needs to install the EPSG database or not.

See Also:
setSchema(String), Constant Field Values
Constructor Detail

EpsgInstaller

public EpsgInstaller()
Creates a new installer. By default, the scripts will be read from the geotk-epsg.jar file and the database is created on the local machine using JavaDB.

Method Detail

setScriptDirectory

public void setScriptDirectory(File directory)
Sets the directory which contain the SQL scripts to execute. This directory should contain at least files similar to the following ones (files without ".sql" extension are ignored):

The suffix may be different (for example "_MySQL.sql" instead of "_PostgreSQL.sql") and the version number may be different. If the directory contrains the scripts for different versions of the database, then the scripts for the latest version are used.

If this method is never invoked or if the given directory is null, then the scripts will be read from the geotk-epsg.jar file. If that JAR is not reachable, then an exception will be thrown at call() invocation time.

Parameters:
directory - The directory of the EPSG SQL scripts to execute, or null

setDatabase

public void setDatabase(String url)
Sets the URL to the database, using the JDBC syntax. If this method is never invoked or if the given URL is null, then the default URL is used. If this method is invoked with any URL different than the default one, then a configuration file will need to be provided explicitly after the database creation in order to get the referencing module to use that database.

If the given scripts are aimed to be executed verbatism, then the setSchema(String) method should be invoked with a null argument in order to prevent this installer to move the tables in the "epsg" schema.

If the given scripts were downloaded from www.epsg.org, then consider adding the Indexes.sql file in the scripts directory, for performance raisons.

If a user and password were previously defined, they are left unchanged.

Parameters:
url - The URL to the database, or null for JavaDB on the local machine.

setDatabase

public void setDatabase(String url,
                        String user,
                        String password)
Sets the URL to the database, together with the user and password. The URL to the database is handled in the same way than setDatabase(String).

Parameters:
url - The URL to the database, or null for JavaDB on the local machine.
user - The user, or null if none.
password - The password, or null if none.

setDatabase

public void setDatabase(Connection connection)
                 throws SQLException
Sets the connection to the database. This method is exclusive with the other setMetadata methods, in that invoking this method resets the database URL and user name to values fetched from the given connection.

It is the caller's responsibility to close the given connection when it is no longer needed.

Parameters:
connection - The connection to use for installing the EPSG database.
Throws:
SQLException - If the given connection can not be used.
Since:
3.11

setSchema

public void setSchema(String schema)
Sets the schema where the installer will create the tables. The default value is "epsg". If a different schema is specified, then consider providing explicitly a configuration file after the database creation.

Parameters:
schema - The schema where to create the tables, or null if none.

exists

public boolean exists()
               throws FactoryException
Verifies if the database exists. This method does not verify if the database content is consistent. It merely tests if the database contains at least one table in the EPSG schema.

Returns:
true if the database exists, or false otherwise.
Throws:
FactoryException - If an error occurred while querying the database.
Since:
3.05

call

public EpsgInstaller.Result call()
                          throws FactoryException
Processes to the creation of the EPSG database.

Specified by:
call in interface Callable<EpsgInstaller.Result>
Returns:
The result of the EPSG database creation.
Throws:
FactoryException - If an error occurred while running the scripts.


Copyright © 2009-2011 Geotoolkit.org. All Rights Reserved.