public class MetadataSource extends Object implements AutoCloseable
MetadataSource metadata = MetadataSource.getProvided(); Format format = source.lookup(Format.class, "PNG");where
id
is the primary key value for the desired record in the MD_Format
table.
MetadataSource
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. |
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.Defined in the sis-metadata
module
Modifier and Type | Field and Description |
---|---|
protected MetadataStandard |
standard
The metadata standard to be used for constructing the database schema.
|
Constructor and Description |
---|
MetadataSource(MetadataSource source)
Creates a new metadata source with the same configuration than the given source.
|
MetadataSource(MetadataStandard standard,
DataSource dataSource,
String schema,
Map<String,?> properties)
Creates a new metadata source.
|
Modifier and Type | Method and Description |
---|---|
void |
addWarningListener(WarningListener<? super MetadataSource> listener)
Adds a listener to be notified when a warning occurred while reading from or writing metadata.
|
void |
close()
Closes the database connection used by this object.
|
static MetadataSource |
getProvided()
Returns the metadata source connected to the
"jdbc/SpatialMetadata" database. |
<T> T |
lookup(Class<T> type,
String identifier)
Returns an implementation of the specified metadata interface filled with the data referenced
by the specified identifier.
|
void |
removeWarningListener(WarningListener<? super MetadataSource> listener)
Removes a previously registered listener.
|
String |
search(Object metadata)
Searches for the given metadata in the database.
|
protected final MetadataStandard standard
public MetadataSource(MetadataStandard standard, DataSource dataSource, String schema, Map<String,?> properties)
null
.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, or null
if none.properties
- additional options, or null
if none. See class javadoc for a description.public MetadataSource(MetadataSource source)
MetadataSource
instances will share the same DataSource
but will use their own Connection
.
This constructor is useful when concurrency is desired.
The new MetadataSource
initially contains all warning listeners
declared in the given source
. But listeners added or removed in a MetadataSource
after the
construction will not impact the other MetadataSource
instance.
source
- the source from which to copy the configuration.public static MetadataSource getProvided() throws MetadataStoreException
"jdbc/SpatialMetadata"
database.
In a default Apache SIS installation, this metadata source contains pre-defined records
for some commonly used citations and formats
among others."jdbc/SpatialMetadata"
database.MetadataStoreException
- if this method can not connect to the database.public String search(Object metadata) throws MetadataStoreException
null
.metadata
- the metadata to search for.null
if none.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.public <T> T lookup(Class<T> type, String identifier) throws MetadataStoreException
CodeList
or
Enum
element.T
- the parameterized type of the type
argument.type
- the interface to implement (e.g. Citation
),
or the ControlledVocabulary
type (CodeList
or some Enum
).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.MetadataStoreException
- if a SQL query failed.public void addWarningListener(WarningListener<? super MetadataSource> listener) throws IllegalArgumentException
Level.WARNING
.try
… finally
block if the MetadataSource
lifetime is longer than the listener lifetime, as below:
source.addWarningListener(listener); try { // Do some work... } finally { source.removeWarningListener(listener); }
listener
- the listener to add.IllegalArgumentException
- if the given listener is already registered in this metadata source.public void removeWarningListener(WarningListener<? super MetadataSource> listener) throws NoSuchElementException
listener
- the listener to remove.NoSuchElementException
- if the given listener is not registered in this metadata source.public void close() throws MetadataStoreException
close
in interface AutoCloseable
MetadataStoreException
- if an error occurred while closing the connection.Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.