@LcdService(service=ILcdModelDecoder.class, priority=20000) public class TLcdDB2SpatialModelDecoder extends Object implements ILcdModelDecoder
File | Required | Entry point | Description |
---|---|---|---|
*.db2 | x | Java properties file containing all the necessary properties to access the spatial data |
Alternatively, a Properties
object can be constructed
programmatically and passed to the model decoder.
The common properties needed to establish a connection are:
driver
(default = com.ibm.db2.jcc.DB2Driver
):
the JDBC driver that will be used to connect to the database.
url
: the database URL.
user
: the database user name.
password
: the user's password.
The properties that identify the tables, columns, rows, etc. within the database are:
table
: the name of the table containing the geometries. The
table name may be qualified by prepending the database schema.
spatialColumn
: the column containing the geometries.
spatialQueryColumn
: an optional column containing the
geometries that should be used in spatial queries. By default, this
column is equal to the spatialColumn
. It should not be
changed for most typical applications.
featureNames.0
, ...: the column names that should be retrieved
as object features in the model. For read-only models, more complex SQL
expressions, or columns from selection tables (see below) are accepted too.
featureDisplayNames.0
, ...: optional display names
corresponding to the feature names.
primaryFeatureIndex
(default = 0): the index of the feature
that serves as a primary key.
primaryFeatureAutoGenerated
(default = false
):
specifies whether the database automatically generates the primary key
whenever a geometry is inserted into the spatial table. The primary
feature on the java side will then be updated with this generated value.
selectionTables
(default = null
): an optional
comma-separated list of tables required to constrain the geometries of the
model. These tables will be added after the main table in the FROM parts
of SELECT queries. Note that any column names that are ambiguous
(because they occur in multiple tables), have to be prefixed with the
suitable table names.
selectionFilter
(default = null
): an optional
SQL select query to constrain the geometries of the model. This query
will be added after the spatial query in the WHERE parts of SELECT
queries.
SRID
(default = null
): the spatial reference
identifier to be used. If not specified, the SRID is computed from the
EPSG property, from the db2gse.ST_GEOMETRY_COLUMNS catalog view or from
the first geometry object.
EPSG
(default = null
): an optional EPSG code
corresponding to the model reference. If the SRID property is present,
the EPSG propery is ignored.
bounds
(default = null
): specifies the
x,y,width
and height
of the model bounds. If not
specified, the model bounds are computed from the database.
useSHP
(default=false): specifies whether the format of
the geometry queries will use the ESRI Shape representation or the WKB
(well-known binary) representation.
ILcd2DBoundsIndexedModel
.TLcdDB2SpatialModelDescriptor
.sourceName
(default = the source name that is passed to the
model decoder): the source name of the model descriptor.
typeName
(default = the display name of the model decoder):
the type name of the model descriptor. The type name is also used when
composing the name of the data model.
displayName
(default = the spatial table name): the display
name of the model descriptor. The display name is also used when
composing the name of the data model and the name of the data type.
setDefaultModelReference(com.luciad.model.ILcdModelReference)
).
ILcdShape
objects:
FROM Geometry | TOILcdShape |
---|---|
POINT | ILcdShapeList with an ILcdPoint object |
POLYLINE | ILcdShapeList with an ILcdPolyline object |
POLYGON | ILcdShapeList with an TLcdComplexPolygon object |
MULTI_POINT | ILcdShapeList with an ILcdPolypoint object |
MULTI_LINESTRING | ILcdShapeList with an ILcdPolyline object |
MULTI_POLYGON | ILcdShapeList with an ILcdComplexPolygon object |
ILcdFeatured
interface and the
ILcdDataObject
interface, providing access to their features.useSHP
property is true
, the returned
shapes may be 2D or 3D shapes, possibly implementing
ILcdSHPMeasure
or
ILcdSHPMeasureList
interface, depending on the database geometry type.readOnly
can be set to specify
whether the model will be used as a read-only model.
ILcdModelDecoder decoder =
new TLcdDB2SpatialModelDecoder(true);
ILcdModel model = decoder.decode("countries.db2");
The file countries.db2
could for instance contain the following
properties:
# The basic database connection properties.
driver = com.ibm.db2.jcc.DB2Driver
url = jdbc:db2://host_name:50002/database_name
user = db2inst1
password = db2inst1
# The data of interest.
table = COUNTRIES
spatialColumn = GEOM
# The feature columns to be decoded.
featureNames.0 = ID
# The index of the feature that can be used as primary key.
primaryFeatureIndex = 0
# Optional extra tables and SQL condition to restrict the database elements.
# Note that the above feature names also have to be prefixed with the table
# name if the column names are ambiguous, like the ID column below.
#selectionTables = POPULATION
#selectionFilter = COUNTRIES.ID = POPULATION.ID AND POPULATION.VALUE > 1e7
# Optional maximum cache size (expressed as number of objects, default is 100).
maxCacheSize = 500
# Optionally close the database connection after each query.
# Only advisable when using a connection pooling database driver.
#alwaysCloseConnection = false
# Optionally override the SRID specified in the database.
#SRID = 1003
# Optionally specify the model bounds: x,y,width,height.
#bounds=0,0,25,25
alwaysCloseConnection
(default = false
): an
optional boolean to specify that the database connection should be closed
after each query. Setting this flag can be useful for database drivers
that pool connections, so the connections are reused instead of really
being closed.maxCacheSize
(default = 100, or the value set on the
decoder): the maximum number of objects in the cache. Using a cache will
improve performance if transferring and decoding geometries and their
features is relatively expensive compared to performing the original
SQL queries. The current implementation of the decoder will then perform
queries in two passes, first retrieving the relevant primary keys and
then retrieving and decoding the actual geometries and features that
are not in the cache. On the other hand, setting the cache size to 0 may
be better if performing SQL queries is relatively expensive. The current
implementation of the decoder will then perform queries in a single
pass, retrieving and decoding the relevant geometries every time.useSHP
option is enabled.Constructor and Description |
---|
TLcdDB2SpatialModelDecoder()
Creates a new, read-write, DB2 Spatial model decoder.
|
TLcdDB2SpatialModelDecoder(boolean aReadOnly)
Creates a new DB2 Spatial model 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.
|
int |
getDefaultMaxCacheSize()
Returns the default maximum size of the cache.
|
ILcdModelReference |
getDefaultModelReference()
Returns the default model reference to be assigned to decoded models.
|
String |
getDisplayName()
Returns a short, displayable name for the format that is decoded by this
ILcdModelDecoder . |
boolean |
getReadOnly()
Returns true if the decoded model is read-only, false otherwise.
|
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 based on information from the database.
|
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 TLcdDB2SpatialModelDecoder()
public TLcdDB2SpatialModelDecoder(boolean aReadOnly)
aReadOnly
- specifies the type of models the decoder should construct.setReadOnly(boolean)
public void setDefaultModelReference(ILcdModelReference aDefaultModelReference)
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 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 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