Object
MetadataSource
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
MetadataWriter
A connection to a metadata database in read-only mode. It can be either the database
provided by Apache SIS with predefined ISO 19115 metadata,
or another database specified at construction time.
Metadata instances can be obtained as in the example below:
where
MetadataSource metadata = MetadataSource.getProvided();
Format format = source.lookup(Format.class, "PNG");
id
is the primary key value for the desired record in the Format
table.
Properties
The constructor expects three Java arguments (the metadata standard, the data source and the database schema) completed by an arbitrary amount of optional arguments given as a map of properties. The following keys are recognized byMetadataSource
and all other entries are ignored:
Key | Value type | Description |
---|---|---|
"catalog" | String | The database catalog where the metadata schema is stored. |
"classloader" | ClassLoader | The class loader to use for creating Proxy instances. |
"maxStatements" | Integer | Maximal number of PreparedStatement s that can be kept simultaneously open. |
Concurrency
MetadataSource
is thread-safe but is not concurrent. If concurrency is desired,
multiple instances of MetadataSource
can be created for the same DataSource
.
The MetadataSource(MetadataSource)
convenience constructor can be used for this purpose.- Since:
- 0.8
-
Field Summary
Modifier and TypeFieldDescriptionprotected final MetadataStandard
The metadata standard to be used for constructing the database schema. -
Constructor Summary
ConstructorDescriptionMetadataSource
(MetadataStandard standard, DataSource dataSource, String schema, Map<String, ?> properties) Creates a new metadata source.MetadataSource
(MetadataSource source) Creates a new metadata source with the same configuration than the given source. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the database connection used by this object.static MetadataSource
Returns the metadata source connected to the"jdbc/SpatialMetadata"
database.Returns the current warning filter.<T> T
Returns an implementation of the specified metadata interface filled with the data referenced by the specified identifier.Searches for the given metadata in the database.setWarningFilter
(Filter filter) Sets a filter to be notified when a warning occurred while reading from or writing metadata.
-
Field Details
-
standard
The metadata standard to be used for constructing the database schema.
-
-
Constructor Details
-
MetadataSource
public MetadataSource(MetadataStandard standard, DataSource dataSource, String schema, Map<String, ?> properties) Creates a new metadata source. The metadata standard to implement (typically ISO 19115, but not necessarily) and the database source are mandatory information. All other information are optional and can benull
.- Parameters:
standard
- the metadata standard to implement.dataSource
- the source for getting a connection to the database.schema
- the database schema were metadata tables are stored, ornull
if none.properties
- additional options, ornull
if none. See class javadoc for a description.
-
MetadataSource
Creates a new metadata source with the same configuration than the given source. The twoMetadataSource
instances will share the sameDataSource
but will use their ownConnection
. This constructor is useful when concurrency is desired.The new
MetadataSource
initially contains the warning filter declared in the givensource
.- Parameters:
source
- the source from which to copy the configuration.
-
-
Method Details
-
getProvided
Returns the metadata source connected to the"jdbc/SpatialMetadata"
database. In a default Apache SIS installation, this metadata source contains predefined records for some commonly used citations and formats among others.If connection to the metadata database cannot be established, then this method returns a fallback with a few hard-coded values.
- Returns:
- source of predefined metadata records from the
"jdbc/SpatialMetadata"
database.
-
search
Searches for the given metadata in the database. If such metadata is found, then its identifier (primary key) is returned. Otherwise this method returnsnull
.- Parameters:
metadata
- the metadata to search for.- Returns:
- the identifier of the given metadata, or
null
if none. - Throws:
MetadataStoreException
- if the metadata object does not implement a metadata interface of the expected package, or if an error occurred while searching in the database.
-
lookup
Returns an implementation of the specified metadata interface filled with the data referenced by the specified identifier. Alternatively, this method can also return aCodeList
orEnum
element.- Type Parameters:
T
- the parameterized type of thetype
argument.- Parameters:
type
- the interface to implement (e.g.Citation
), or theControlledVocabulary
type (CodeList
or someEnum
).identifier
- the identifier of the record for the metadata entity to be created. This is usually the primary key of the record to search for.- Returns:
- an implementation of the required interface, or the code list element.
- Throws:
MetadataStoreException
- if a SQL query failed or if the metadata has not been found.
-
setWarningFilter
Sets a filter to be notified when a warning occurred while reading from or writing metadata. When a warning occurs, there is a choice:- If this metadata source has no warning filter, or if the filter returns
true
, then the warning is logged atLevel.WARNING
. - Otherwise the warning is not logged by this metadata source instance. The filter implementation is free to keep a reference to the given record, for example in order to display it in a graphical user interface.
- Parameters:
filter
- the filter to set, ornull
for removing the filter.- Returns:
- the previous filter, or
null
if none. - Since:
- 1.1
- If this metadata source has no warning filter, or if the filter returns
-
getWarningFilter
Returns the current warning filter.- Returns:
- the current filter, or
null
if none. - Since:
- 1.1
-
close
Closes the database connection used by this object.- Specified by:
close
in interfaceAutoCloseable
- Throws:
MetadataStoreException
- if an error occurred while closing the connection.
-