public class TLcdDatabaseModelDecoder extends Object implements ILcdModelDecoder
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 of
ILcdDatabaseFactory
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 and Description |
---|
TLcdDatabaseModelDecoder(boolean aReadOnly)
Creates a new database decoder.
|
TLcdDatabaseModelDecoder(boolean aReadOnly,
ILcdDatabaseFactory aDatabaseFactory)
Creates a new database decoder.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canDecodeSource(String aSourceAsString)
Checks whether this model decoder can decode the specified data source.
|
ILcdModel |
decode(Properties aProperties)
Decodes a new database model based on the given properties.
|
ILcdModel |
decode(String aSourceName)
Decodes a new database model based on the properties specified in the given
file.
|
ILcdDatabaseFactory |
getDatabaseFactory() |
DataSource |
getDataSource() |
int |
getDefaultMaxCacheSize() |
ILcdModelReference |
getDefaultModelReference()
Returns the default (fallback) model reference that will be assigned to decoded models if no
model reference can be created by the factory.
|
String |
getDisplayName()
Returns a short, displayable name for the format that is decoded by this
ILcdModelDecoder . |
boolean |
getReadOnly() |
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 the
ILcdDatabaseFactory used by this decoder. |
void |
setReadOnly(boolean aReadOnly)
Specifies whether the decoded models should be read-only or not.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
canDecodeSource, decodeModelMetadata, decodeModelMetadata, decodeSource, discoverDataSources
public TLcdDatabaseModelDecoder(boolean aReadOnly)
aReadOnly
- specifies the type of models the decoder should construct:
read-only models or read-write models.public TLcdDatabaseModelDecoder(boolean aReadOnly, ILcdDatabaseFactory aDatabaseFactory)
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.public void setDataSource(DataSource aDataSource)
public DataSource getDataSource()
public void setReadOnly(boolean aReadOnly)
aReadOnly
- specifies the type of models the decoder should construct.
If true
, the decoder will create TLcdDatabaseReadOnlyModel
objects.
If false
, the decoder will create TLcdDatabaseModel
objects.public boolean getReadOnly()
public void setDatabaseFactory(ILcdDatabaseFactory aDatabaseFactory)
databaseFactory
property in the properties file must specify the class name of the database
factory.aDatabaseFactory
- specifies the factory that implements the support
for a particular database.public ILcdDatabaseFactory getDatabaseFactory()
public void setDefaultModelReference(ILcdModelReference aDefaultModelReference)
ILcdDatabaseFactory
used by this decoder.aDefaultModelReference
- the default model reference.getDefaultModelReference()
public ILcdModelReference getDefaultModelReference()
setDefaultModelReference(com.luciad.model.ILcdModelReference)
public void setDefaultMaxCacheSize(int aDefaultMaxCacheSize)
maxCacheSize
property in the
properties file.aDefaultMaxCacheSize
- the default maximum number of objects in the
cache.public int getDefaultMaxCacheSize()
public String getDisplayName()
ILcdModelDecoder
ILcdModelDecoder
.getDisplayName
in interface ILcdModelDecoder
ILcdModelDecoder
.public boolean canDecodeSource(String aSourceAsString)
ILcdModelDecoder
true
for a source name while decode
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.
canDecodeSource
in interface ILcdModelDecoder
aSourceAsString
- the data source to be verified; typically a file name or a URL.true
if this decoder can likely decode the data specified by the source name, false
otherwise.ILcdModelDecoder.decode(String)
,
ILcdModelDecoder.decodeModelMetadata(String)
public ILcdModel decode(String aSourceName) throws IOException
decode
in interface ILcdModelDecoder
aSourceName
- the data source to be decoded; typically a file name or a URL.null
is allowed, implementors are advised to throw an error instead.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);
}
}
InterruptedIOException
- When the thread on which this method is called is interrupted: it is recommended to stop the decoding
and throw an InterruptedIOException
.
This same exception can also be used if the decoder shows UI to the user, and the user cancels the decoding
through the UI.ILcdModelDecoder.canDecodeSource(String)
public ILcdModel decode(Properties aProperties) throws IOException
IOException