Class Initializer
java.lang.Object
org.apache.sis.internal.metadata.sql.Initializer
- Direct Known Subclasses:
DatabaseListener
Manages the unique
DataSource instance to the $SIS_DATA/Databases/SpatialMetadata database.
This includes initialization of a new database if none existed. The schemas will be created by subclasses of
this Initializer class, which must be registered in the following file:
Initializer implementations should define the following methods:
createSchema(Connection)— invoked when a new database is created.dataSourceChanged()— invoked when the data source changed.
DataSource instance, through JNDI or otherwise.- Since:
- 0.7
- Version:
- 1.2
- Author:
- Martin Desruisseaux (Geomatys)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic LogRecordconnected(DatabaseMetaData metadata) Prepares a log record saying that a connection to the spatial metadata database has been created.protected abstract voidcreateSchema(Connection connection) Invoked for populating an initially empty database.protected abstract voidInvoked when the JNDI data source associated to"jdbc/SpatialMetadata"changed.static DataSourceReturns the data source for the SIS-wide "SpatialMetadata" database.static booleanhasJNDI()Returnstrueif SIS will try to fetch theDataSourcefrom JNDI.static booleansetDefault(Supplier<DataSource> ds) Specifies the data source to use if there is no JNDI environment or if no data source is binded tojdbc/SpatialMetadata.static Objectunspecified(Locale locale, boolean asLog) Returns a message for unspecified data source.
-
Field Details
-
DATABASE
Name of the database to open in the$SIS_DATA/Databasesdirectory or the directory given by thederby.system.homeproperty.Note: this field is public for the needs ofnon-free:sis-embedded-datamodule.- See Also:
-
JNDI
Name of the JNDI resource to lookup in the"java:comp/env"context.- See Also:
-
-
Constructor Details
-
Initializer
protected Initializer()For subclasses only.
-
-
Method Details
-
createSchema
Invoked for populating an initially empty database.- Parameters:
connection- connection to the empty database.- Throws:
SQLException- if an error occurred while populating the database.
-
dataSourceChanged
protected abstract void dataSourceChanged()Invoked when the JNDI data source associated to"jdbc/SpatialMetadata"changed. -
setDefault
Specifies the data source to use if there is no JNDI environment or if no data source is binded tojdbc/SpatialMetadata. Data source specified by JNDI has precedence over this supplier in order to let users control their data source. This method does nothing if the data source has already been initialized.Initializerwill not register any shutdown process for user supplied data source. We presume that database life cycle is managed by the caller.- Parameters:
ds- supplier of data source to set, ornullfor removing previous supplier. This supplier may returnnull, in which case it will be ignored.- Returns:
- whether the given data source supplier has been successfully set.
- Since:
- 1.0
- See Also:
-
getDataSource
Returns the data source for the SIS-wide "SpatialMetadata" database. This method returns the first of the following steps that succeed:- If a JNDI context exists, use the data source registered under the
"jdbc/SpatialMetadata"name. - Otherwise if a default data source has been supplied, use that data source.
- Otherwise if the
SIS_DATAenvironment variable is defined, use the data source for"jdbc:derby:$SIS_DATA/Databases/SpatialMetadata". That database will be created if it does not exist. Note that this is the only case where Apache SIS may create the database since it is located in the directory managed by Apache SIS. - Otherwise if the
non-free:sis-embedded-datamodule is present on the classpath, use the embedded database. - Otherwise if the
"derby.system.home"property is defined, use the data source for"jdbc:derby:SpatialMetadata". This database will not be created if it does not exist. - Otherwise (no JNDI, no environment variable, no Derby property set),
null.
- Returns:
- the data source for the
$SIS_DATA/Databases/SpatialMetadataor equivalent database, ornullif none. - Throws:
NamingException- if an error occurred while fetching the data source from a JNDI context.MalformedURLException- if an error occurred while converting thederby.jarfile to URL.ClassNotFoundException- ifderby.jarhas not been found on the JDK installation directory.InstantiationException- if an error occurred while creatingorg.apache.derby.jdbc.EmbeddedDataSource.NoSuchMethodException- if a JDBC bean property has not been found on the data source.IllegalAccessException- if a JDBC bean property of the data source is not public.InvocationTargetException- if an error occurred while setting a data source bean property.Exception- for any other kind of errors. This includeRuntimeExceptionnot documented above likeIllegalArgumentException,ClassCastException,SecurityException, etc.- See Also:
- If a JNDI context exists, use the data source registered under the
-
hasJNDI
public static boolean hasJNDI()Returnstrueif SIS will try to fetch theDataSourcefrom JNDI.- Returns:
trueif a JNDI environment seems to be present.
-
connected
Prepares a log record saying that a connection to the spatial metadata database has been created. This method can be invoked afterDataSource.getConnection(). When invoked for the first time, the record level is set toLevel.CONFIG. On next calls, the level becomeLevel.FINE.- Parameters:
metadata- the value ofDataSource.getConnection().getMetaData()or equivalent.- Returns:
- the record to log. Caller should set the source class name and source method name.
- Throws:
SQLException- if an error occurred while fetching the database URL.- Since:
- 0.8
-
unspecified
Returns a message for unspecified data source. The message will depend on whether a JNDI context exists or not. This message can be used for constructing an exception whengetDataSource()returnednull.
-