Package com.luciad.format.database
Class TLcdDatabaseModelDecoder
java.lang.Object
com.luciad.format.database.TLcdDatabaseModelDecoder
- All Implemented Interfaces:
ILcdModelDecoder
This
ILcdModelDecoder
decodes generic spatial databases into
TLcdDatabaseModel
or TLcdDatabaseReadOnlyModel
objects.
You typically don't need to use this. Instead, use LuciadLightspeed's Database Connectors component, for example for Oracle Spatial or Postgresql PostGIS.
A spatial database is accessed based on a set of properties. The properties
can be passed in a Properties
object, or using a properties file
with extension dbp
. The properties below can also be set
directly on the ILcdModelDecoder
.
The common property needed to establish a connection is:
databaseFactory
: the class name of the implementation ofILcdDatabaseFactory
that is needed to decode the database correctly. The user can provide an implementation, or the Database Connectors components can do this, e.g. for Oracle Spatial or for Informix Geodetic.
One optional property can help for tuning the database decoding:
maxCacheSize
: the maximum number of objects in the cache (default = 100, or the value set on the decoder).
sourceName
: the source name of the model descriptor (default = the source name that is passed to the model decoder).typeName
: the type name of the model descriptor (default = the display name of the model decoder). The type name is also used when composing the name of the data model.displayName
: the display name of the model descriptor (default = the spatial table name). The display name is also used when composing the name of the data model and the name of the data type.
-
Constructor Summary
ConstructorDescriptionTLcdDatabaseModelDecoder
(boolean aReadOnly) Creates a new database decoder.TLcdDatabaseModelDecoder
(boolean aReadOnly, ILcdDatabaseFactory aDatabaseFactory) Creates a new database decoder. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canDecodeSource
(String aSourceAsString) Checks whether this model decoder can decode the specified data source.Decodes a new database model based on the properties specified in the given file.decode
(Properties aProperties) Decodes a new database model based on the given properties.int
Returns the default (fallback) model reference that will be assigned to decoded models if no model reference can be created by the factory.Returns a short, displayable name for the format that is decoded by thisILcdModelDecoder
.boolean
void
setDatabaseFactory
(ILcdDatabaseFactory aDatabaseFactory) Sets the database factory that has all the essential methods for accessing a particular database.void
setDataSource
(DataSource aDataSource) Sets a data source that can be used for creating connections to the database.void
setDefaultMaxCacheSize
(int aDefaultMaxCacheSize) Sets the default maximum size of the cache.void
setDefaultModelReference
(ILcdModelReference aDefaultModelReference) Sets the default model reference to be assigned to decoded models if no model reference can be created by theILcdDatabaseFactory
used by this decoder.void
setReadOnly
(boolean aReadOnly) Specifies whether the decoded models should be read-only or not.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.luciad.model.ILcdModelDecoder
canDecodeSource, decodeModelMetadata, decodeModelMetadata, decodeSource, discoverDataSources
-
Constructor Details
-
TLcdDatabaseModelDecoder
public TLcdDatabaseModelDecoder(boolean aReadOnly) Creates a new database decoder.- Parameters:
aReadOnly
- specifies the type of models the decoder should construct: read-only models or read-write models.
-
TLcdDatabaseModelDecoder
Creates a new database decoder.- Parameters:
aReadOnly
- specifies the type of models the decoder should construct: read-only models or read-write models.aDatabaseFactory
- specifies the factory that implements the support for a particular database.
-
-
Method Details
-
setDataSource
Sets a data source that can be used for creating connections to the database. -
getDataSource
-
setReadOnly
public void setReadOnly(boolean aReadOnly) Specifies whether the decoded models should be read-only or not.- Parameters:
aReadOnly
- specifies the type of models the decoder should construct. Iftrue
, the decoder will createTLcdDatabaseReadOnlyModel
objects. Iffalse
, the decoder will createTLcdDatabaseModel
objects.
-
getReadOnly
public boolean getReadOnly() -
setDatabaseFactory
Sets the database factory that has all the essential methods for accessing a particular database. If left unset, thedatabaseFactory
property in the properties file must specify the class name of the database factory.- Parameters:
aDatabaseFactory
- specifies the factory that implements the support for a particular database.
-
getDatabaseFactory
-
setDefaultModelReference
Sets the default model reference to be assigned to decoded models if no model reference can be created by theILcdDatabaseFactory
used by this decoder.- Parameters:
aDefaultModelReference
- the default model reference.- See Also:
-
getDefaultModelReference
Returns the default (fallback) model reference that will be assigned to decoded models if no model reference can be created by the factory.- Returns:
- the default model reference.
- See Also:
-
setDefaultMaxCacheSize
public void setDefaultMaxCacheSize(int aDefaultMaxCacheSize) Sets the default maximum size of the cache. It is possible to override this value by means of themaxCacheSize
property in the properties file.- Parameters:
aDefaultMaxCacheSize
- the default maximum number of objects in the cache.
-
getDefaultMaxCacheSize
public int getDefaultMaxCacheSize() -
getDisplayName
Description copied from interface:ILcdModelDecoder
Returns a short, displayable name for the format that is decoded by thisILcdModelDecoder
.- Specified by:
getDisplayName
in interfaceILcdModelDecoder
- Returns:
- the displayable name of this
ILcdModelDecoder
.
-
canDecodeSource
Description copied from interface:ILcdModelDecoder
Checks whether this model decoder can decode the specified data source. It is acceptable for this method to returntrue
for a source name whiledecode
throws an exception for that same source name.For performance reasons, we strongly recommend that this will only be a simple test. For example: check the file extension of a file, but not that the file exists or contains expected content.
- Specified by:
canDecodeSource
in interfaceILcdModelDecoder
- Parameters:
aSourceAsString
- the data source to be verified; typically a file name or a URL.- Returns:
true
if this decoder can likely decode the data specified by the source name,false
otherwise.- See Also:
-
decode
Decodes a new database model based on the properties specified in the given file.- Specified by:
decode
in interfaceILcdModelDecoder
- Parameters:
aSourceName
- the data source to be decoded; typically a file name or a URL.- Returns:
- A model containing the decoded data. While
null
is allowed, implementors are advised to throw an error instead. - Throws:
IOException
- for any exceptions caused by IO problems or invalid data. Since decoding invalid data almost always results in RunTimeExceptions (NullPointerException, IndexOutOfBoundsException, IllegalArgumentException, ...) on unexpected places, implementations are advised to catch RuntimeExceptions in their decode() method, and wrap them into an IOException, as illustrated in the code snippet below.public ILcdModel decode( String aSourceName ) throws IOException { try (InputStream input = fInputStreamFactory.createInputStream(aSourceName)) { // Perform decoding ... } catch (RuntimeException e) { throw new IOException(e); } }
- See Also:
-
decode
Decodes a new database model based on the given properties.- Throws:
IOException
-