Package org.apache.sis.storage.sql
Class SQLStore
java.lang.Object
org.apache.sis.storage.DataStore
org.apache.sis.storage.sql.SQLStore
- All Implemented Interfaces:
AutoCloseable,Aggregate,Resource,Localized
A data store capable to read and create features from a spatial database.
SQLStore requires a DataSource to be specified (indirectly) at construction time.
The DataSource should provide pooled connections, because SQLStore will frequently
opens and closes them.- Since:
- 1.0
- Version:
- 1.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SchemaModifierThe user-specified method for customizing the schema inferred by table analysis.private final GeometryLibraryThe library to use for creating geometric objects, ornullfor system default.private org.opengis.metadata.MetadataThe metadata, created when first requested.private Database<?>The result of inspecting database schema for derivingFeatureTypes.private static final String[]Names of possible public getter methods for data source title, in preference order.private final ResourceDefinition[]Queries to expose as resources, or an empty array if none.private final DataSourceThe data source to use for obtaining connections to the database.private final org.opengis.util.GenericName[]Fully qualified names (including catalog and schema) of the tables to include in this store. -
Constructor Summary
ConstructorsConstructorDescriptionSQLStore(SQLStoreProvider provider, StorageConnector connector, ResourceDefinition... resources) Creates a newSQLStorefor the given data source and tables, views or queries. -
Method Summary
Modifier and TypeMethodDescription<T extends StoreEvent>
voidaddListener(Class<T> eventType, StoreListener<? super T> listener) Registers a listener to notify when the specified kind of event occurs in this data store.voidclose()Closes this SQL store and releases any underlying resources.Returns the tables (feature sets) in this SQL store.findResource(String identifier) Searches for a resource identified by the given identifier.Optional<org.opengis.util.GenericName>SQL data store root resource has no identifier.org.opengis.metadata.MetadataReturns information about the dataset as a whole.Optional<org.opengis.parameter.ParameterValueGroup>Returns the parameters used to open this netCDF data store.private Database<?>model()Returns the database model, analyzing the database schema when first needed.private Database<?>model(Connection c) Returns the database model, analyzing the database schema when first needed.Methods inherited from class org.apache.sis.storage.DataStore
getDisplayName, getLocale, getNativeMetadata, getProvider, removeListener, setLocale, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.sis.storage.Resource
removeListener
-
Field Details
-
NAME_GETTERS
Names of possible public getter methods for data source title, in preference order. -
source
The data source to use for obtaining connections to the database. -
geomLibrary
The library to use for creating geometric objects, ornullfor system default. -
model
The result of inspecting database schema for derivingFeatureTypes. Created when first needed. May be discarded and recreated if the store needs a refresh. -
tableNames
private final org.opengis.util.GenericName[] tableNamesFully qualified names (including catalog and schema) of the tables to include in this store. The names shall be qualified names of 1, 2 or 3 components. The name components can be<catalog>.<schema pattern>.<table pattern>where:<catalog>, if present, is the name of a catalog as stored in the database.<schema pattern>, if present, is the pattern of a schema. The pattern can use'_'and'%'wildcards characters.<table pattern>(mandatory) is the pattern of a table. The pattern can use'_'and'%'wildcards characters.
-
queries
Queries to expose as resources, or an empty array if none. -
metadata
private org.opengis.metadata.Metadata metadataThe metadata, created when first requested. -
customizer
The user-specified method for customizing the schema inferred by table analysis. This isnullif there is none.
-
-
Constructor Details
-
SQLStore
public SQLStore(SQLStoreProvider provider, StorageConnector connector, ResourceDefinition... resources) throws DataStoreException Creates a newSQLStorefor the given data source and tables, views or queries. The givenconnectorshall contain aDataSourceinstance. Tables or views to include in the store are specified by theresourcesargument. Only the main tables need to be specified; dependencies will be followed automatically.- Parameters:
provider- the factory that created thisDataStoreinstance, ornullif unspecified.connector- information about the storage (JDBC data source, etc).resources- tables, views or queries to include in this store.- Throws:
DataStoreException- if an error occurred while creating the data store for the given storage.- Since:
- 1.1
-
-
Method Details
-
getOpenParameters
Returns the parameters used to open this netCDF data store. The parameters are described bySQLStoreProvider.getOpenParameters()and contains at least a parameter named "location" with aDataSourcevalue.- Specified by:
getOpenParametersin classDataStore- Returns:
- parameters used for opening this data store.
- See Also:
-
getIdentifier
SQL data store root resource has no identifier.- Specified by:
getIdentifierin interfaceResource- Overrides:
getIdentifierin classDataStore- Returns:
- empty.
- Throws:
DataStoreException- if an error occurred while fetching the identifier.- See Also:
-
model
Returns the database model, analyzing the database schema when first needed.- Throws:
DataStoreException
-
model
Returns the database model, analyzing the database schema when first needed. This method performs the same work thanmodel(), but using an existing connection. Callers must own a synchronization lock onthis.- Parameters:
c- connection to the database.- Throws:
Exception
-
getMetadata
Returns information about the dataset as a whole. The returned metadata object can contain information such as the list of feature types.- Specified by:
getMetadatain interfaceResource- Specified by:
getMetadatain classDataStore- Returns:
- information about the dataset.
- Throws:
DataStoreException- if an error occurred while reading the data.- See Also:
-
components
Returns the tables (feature sets) in this SQL store. The list contains only the tables explicitly named at construction time.- Specified by:
componentsin interfaceAggregate- Returns:
- children resources that are components of this SQL store.
- Throws:
DataStoreException- if an error occurred while fetching the components.
-
findResource
Searches for a resource identified by the given identifier. The given identifier should match one of the table names. It may be one of the tables named at construction time, or one of the dependencies. The given name may be qualified with the schema name, or may be only the table name if there is no ambiguity.- Overrides:
findResourcein classDataStore- Parameters:
identifier- identifier of the resource to fetch. Must be non-null.- Returns:
- resource associated to the given identifier (never
null). - Throws:
IllegalNameException- if no resource is found for the given identifier, or if more than one resource is found.DataStoreException- if another kind of error occurred while searching resources.- See Also:
-
addListener
public <T extends StoreEvent> void addListener(Class<T> eventType, StoreListener<? super T> listener) Registers a listener to notify when the specified kind of event occurs in this data store. The current implementation of this data store can emit onlyWarningEvents; any listener specified for another kind of events will be ignored.- Specified by:
addListenerin interfaceResource- Overrides:
addListenerin classDataStore- Type Parameters:
T- compile-time value of theeventTypeargument.- Parameters:
eventType- type ofStoreEventto listen (cannot benull).listener- listener to notify about events.
-
close
Closes this SQL store and releases any underlying resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein classDataStore- Throws:
DataStoreException- if an error occurred while closing the SQL store.- See Also:
-