Class TLcdDatabaseModelDecoder

java.lang.Object
com.luciad.format.database.TLcdDatabaseModelDecoder
All Implemented Interfaces:
ILcdModelDecoder

public class TLcdDatabaseModelDecoder extends Object implements 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 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).
Three optional properties allow to override some metadata in the model descriptor:
  • 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.
The database factory determines which further properties are needed for decoding data, typically a database driver, a URL, a user name, a password, etc.
  • 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

      public TLcdDatabaseModelDecoder(boolean aReadOnly, ILcdDatabaseFactory aDatabaseFactory)
      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

      public void setDataSource(DataSource aDataSource)
      Sets a data source that can be used for creating connections to the database.
    • getDataSource

      public DataSource 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. If true, the decoder will create TLcdDatabaseReadOnlyModel objects. If false, the decoder will create TLcdDatabaseModel objects.
    • getReadOnly

      public boolean getReadOnly()
    • setDatabaseFactory

      public void setDatabaseFactory(ILcdDatabaseFactory aDatabaseFactory)
      Sets the database factory that has all the essential methods for accessing a particular database. If left unset, the databaseFactory 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

      public ILcdDatabaseFactory getDatabaseFactory()
    • setDefaultModelReference

      public 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.
      Parameters:
      aDefaultModelReference - the default model reference.
      See Also:
    • getDefaultModelReference

      public 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.
      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 the maxCacheSize property in the properties file.
      Parameters:
      aDefaultMaxCacheSize - the default maximum number of objects in the cache.
    • getDefaultMaxCacheSize

      public int getDefaultMaxCacheSize()
    • getDisplayName

      public String getDisplayName()
      Description copied from interface: ILcdModelDecoder
      Returns a short, displayable name for the format that is decoded by this ILcdModelDecoder.
      Specified by:
      getDisplayName in interface ILcdModelDecoder
      Returns:
      the displayable name of this ILcdModelDecoder.
    • canDecodeSource

      public boolean canDecodeSource(String aSourceAsString)
      Description copied from interface: ILcdModelDecoder
      Checks whether this model decoder can decode the specified data source. It is acceptable for this method to return 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.

      Specified by:
      canDecodeSource in interface ILcdModelDecoder
      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

      public ILcdModel decode(String aSourceName) throws IOException
      Decodes a new database model based on the properties specified in the given file.
      Specified by:
      decode in interface ILcdModelDecoder
      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

      public ILcdModel decode(Properties aProperties) throws IOException
      Decodes a new database model based on the given properties.
      Throws:
      IOException