Class JMapServerDataManager

java.lang.Object
com.kheops.jmap.server.JMapServerDataManager

public class JMapServerDataManager extends Object
This class on the server sides manages the data. It updates the datasource and retrieves the appropriate data upon request.
  • Method Details

    • createIndex

      public void createIndex(int dataSourceId, String[] fields)
      Creates an index to improve query efficiency on the corresponding field.
      Parameters:
      dataSourceId - the data source unique id.
      fields - the array string containing the fields to be indexed.
    • indexExists

      public boolean indexExists(int dataSourceId, String field)
      Checks if an index exist for the specified fields
      Parameters:
      dataSourceId - the data source unique id.
      field - a field name.
      Returns:
      true if the index already exists false otherwise.
    • deleteIndex

      public boolean deleteIndex(int dataSourceId, String[] fields)
      Deletes an existing index.
      Parameters:
      dataSourceId - the data source unique id.
      fields - the array string containing the specified fields.
    • containsDataSource

      public boolean containsDataSource(int dataSourceId)
      Checks if the data manager contains a certain data source.
      Parameters:
      dataSourceId - the data source unique id.
      Returns:
      true if the data manager contains the data source, false otherwise.
    • getDataSource

      public SpatialDataSource getDataSource(int dataSourceId)
      Gets the spatial datasource having the specified id.
      Parameters:
      dataSourceId - the data source unique id.
      Returns:
      an instance of the SpatialDataSource having the corresponding id.
    • getDataSource

      public SpatialDataSource getDataSource(String name)
      Gets the spatial data source having the specified name.
      Parameters:
      name - the specified name.
      Returns:
      an instance of the SpatialDataSource having the corresponding name.
    • dataSources

      public Iterator<SpatialDataSource> dataSources()
      Returns an unmodifiable iterator of all spatial data sources.
      Returns:
      an unmodifiable iterator of all spatial data sources.
    • deleteAllDataSources

      public boolean deleteAllDataSources()
      Deletes all spatial data sources.
    • dropOldJMapServerTables

      public void dropOldJMapServerTables(Connection conn, String schema)
    • createJMapServerTables

      protected void createJMapServerTables() throws SQLException
      Throws:
      SQLException
    • deleteDataSource

      public boolean deleteDataSource(int dataSourceId)
      Deletes the specified spatial data source.
      Parameters:
      dataSourceId - the id of the spatial data source to be deleted.
    • flushCache

      public void flushCache(int dataSourceId)
      Removes the cache data related to all layers based on the specified spatial data source id.
      Parameters:
      dataSourceId - the spatial data source id
    • flushCache

      public void flushCache(int projectId, int layerId)
      Removes from all caches the data that matches the specified id.
      Parameters:
      projectId - the unique identifier of the project.
      layerId - the layerId which data will be deleted.
    • flushCache

      public void flushCache(int projectId, int layerId, int tileId)
      Removes a specific tile from the cache.
      Parameters:
      projectId - the unique identifier of the project.
      layerId - the unique identifier of the layer.
      tileId - the tileId which data will be deleted.
    • cancelDataSourceJob

      public void cancelDataSourceJob(int dataSourceId)
    • cancelServerLayerJob

      public void cancelServerLayerJob(int projetId, int layerId)
    • getWorkerThreadManager

      public WorkerThreadManagerFacade getWorkerThreadManager()
      Job manager interface to add background job to data manager.
      Returns:
      WorkerThreadManagerFacade
    • updateDataSource

      public void updateDataSource(SpatialDataSourceInfo dataSourceInfo)
      Updates the datasource.
      Parameters:
      dataSourceInfo - the corresponding JMapServerLayer instance.
    • updateStatistics

      public void updateStatistics(JMapServerProject project, JMapServerLayer layer, Attribute[] attributes)
    • updateCache

      public void updateCache(JMapServerProject project, JMapServerLayer layer)
    • addDataSource

      public void addDataSource(SpatialDataSourceInfo dataSourceInfo) throws Exception
      Adds a new spatial data source in the data manager. The new data source will not be updated until a call to method updateDataSource().
      Parameters:
      dataSourceInfo - the corresponding spatial data source info instance.
      Throws:
      Exception
    • addDataSource

      public void addDataSource(SpatialDataSource ds) throws Exception
      Adds a new datasource in the data manager. The new data source will not be indexed until a call to method updateDataSource().
      Parameters:
      ds - the corresponding SpatialDataSource to be added.
      Throws:
      Exception
    • extractTiles

      public Vector<byte[]> extractTiles(JMapServerProject project, JMapServerVectorLayer vectorLayer, int[] tiles) throws Exception
      This method returns a Vector containing the requested tiles specified in parameter tiles.
      Parameters:
      project - the project
      vectorLayer - the vector layer info.
      tiles - an array of tile id's.
      Returns:
      a Vector containing serialized tiles, ordered exactly the same way they were requested.
      Throws:
      Exception
    • extractTilesFromCache

      protected List<byte[]> extractTilesFromCache(JMapServerProject project, JMapServerVectorLayer vectorLayer, int[] tiles) throws Exception
      WARNING!!! THIS METHOD FETCH TILE FROM CACHE ONLY! IT DOESN'T CREATE NEW TILES!!! THIS IS USED FOR DEBUGGING!
      Parameters:
      project - the project
      vectorLayer - the vector layer info.
      tiles - an array of tile id's.
      Returns:
      a Vector containing serialized tiles, ordered exactly the same way they were requested.
      Throws:
      Exception
    • flushCache

      public void flushCache()
      Removes all entries which were cached in the memory and the disk cache.
    • flushDiskCache

      public void flushDiskCache()
      Flushes the disk cache.
    • getSpatialDatasourceTableName

      public String getSpatialDatasourceTableName(int dataSourceId)
      Returns the table name of the specified SpatialDatasource id. null is returned if the SpatialDatasource is a ServerDataSource.
      Parameters:
      dataSourceId - the data source unique id.
      Returns:
      tableName; null if not found or if the SpatialDatasource is a ServerDataSource
    • preProcessQuery

      public String preProcessQuery(String sqlQuery)
    • extractAttributes

      public DataSet extractAttributes(JMapServerProject project, JMapServerVectorLayer vectorLayer, QueryFilter[] queryFilters, Attribute[] attributes, Map<String,?> extraParameters) throws Exception
      This method extracts attributes from a vector layer. Only the elements that satisfy the specified query filters are returned. If the specified layer is not based on a spatial data source that is a subtype of SQLDataSource, SQL filters are ignored.
      Parameters:
      project - The project enclosing the layer to query
      vectorLayer - The layer to query
      queryFilters - the filters to apply
      attributes - the list of attributes to return.
      extraParameters - mapped parameters.
      Returns:
      the extracted attributes
      Throws:
      Exception
    • editElements

      public EditionResult[][] editElements(JMapServerProject serverProject, JMapServerVectorLayer serverVectorLayer, EditionTransaction[] transactions, Projection projection)
    • addElements

      public EditionResult[] addElements(JMapServerProject project, JMapServerVectorLayer vectorLayer, EditionTransaction.Insert transaction, Projection currentProjection)
    • addElements

      public EditionResult[] addElements(JMapServerProject project, JMapServerVectorLayer vectorLayer, EditionTransaction.Insert transaction)
    • updateElements

      public EditionResult[] updateElements(JMapServerProject project, JMapServerVectorLayer vectorLayer, EditionTransaction.Update transaction, Projection currentProjection)
    • updateElements

      public EditionResult[] updateElements(JMapServerProject project, JMapServerVectorLayer vectorLayer, EditionTransaction.Update transaction)
    • deleteElements

      public EditionResult[] deleteElements(JMapServerProject project, JMapServerVectorLayer vectorLayer, EditionTransaction.Delete transaction)
    • extractElements

      public JMapGeoElement[] extractElements(JMapServerProject project, JMapServerVectorLayer vectorLayer, QueryFilter[] queryFilters, Attribute[] attributes, Projection projection) throws Exception
      This method extracts JMapGeoElement objects from a vector layer. Only the elements that satisfy the specified query filters are returned. If the specified layer is not based on a spatial data source that is a subtype of SQLDataSource, SQL filters are ignored.
      Parameters:
      project - The project enclosing the layer to query
      vectorLayer - The layer to query
      queryFilters - the filters to apply
      attributes - the list of attributes to include in the returned elements
      projection - the projection used to extract the element, if null project's projection is used
      Returns:
      JMapGeoElement[] the extracted elements
      Throws:
      Exception
    • extractElements

      public JMapGeoElement[] extractElements(JMapServerProject serverProject, JMapServerVectorLayer serverVectorLayer, QueryFilter[] queryFilters, Attribute[] attributes, Projection targetProjection, int pageSize, int offset) throws Exception
      This method extracts JMapGeoElement objects from a vector layer. Only the elements that satisfy the specified query filters are returned. If the specified layer is not based on a spatial data source that is a subtype of SQLDataSource, SQL filters are ignored.
      Parameters:
      serverProject - The project enclosing the layer to query
      serverVectorLayer - The layer to query
      queryFilters - the filters to apply
      attributes - the list of attributes to include in the returned elements
      targetProjection - the projection used to extract the element, if null project's projection is used
      pageSize - the maximum number of elements that will be returned (0 = no limit)
      offset - the number of features to skip from the result set when extracting elements
      Returns:
      JMapGeoElement[] the extracted elements
      Throws:
      Exception
    • extractElements

      public JMapGeoElement[] extractElements(JMapServerProject project, JMapServerVectorLayer vectorLayer, long[] elementIds) throws Exception
      Throws:
      Exception
    • extractElements

      public JMapGeoElement[] extractElements(JMapServerProject project, JMapServerVectorLayer vectorLayer, long[] elementIds, Projection projection) throws Exception
      Throws:
      Exception
    • extractElements

      public JMapGeoElement[] extractElements(JMapServerProject project, JMapServerVectorLayer vectorLayer, QueryFilter[] queryFilters, Attribute[] attributes) throws Exception
      Throws:
      Exception
    • extractElements

      public JMapGeoElement[] extractElements(String query) throws Exception
      This method extracts the JMapGeoElement objects that satisfy the specified pseudo-SQL query.

      Syntax: select $element from $source{ $project{project name} $layer{layer name}} where ... select $element from $join{$source{$project{project name} $layer{layer name} $field{layer field name}} and $database{$name{database name} $query{select * from ...} $field{database field name}}}

      The attributes included in the returned elements correspond to the list of bound attributes for the specified layer of the specified project.

      Parameters:
      query - the query to execute
      Returns:
      JMapGeoElement[] the matching elements
      Throws:
      Exception
    • extractElements

      public JMapGeoElement[] extractElements(String query, long[] jmapIds) throws Exception
      This method extracts the K2DElement objects that satisfy the specified pseudo-SQL query. Only the elements that have their id included in the specified list are returned.

      Syntax: select $element from $source{ $project{project name} $layer{layer name}} where ... select $element from $join{$source{$project{project name} $layer{layer name} $field{layer field name}} and $database{$name{database name} $query{select * from ...} $field{database field name}}}

      The attributes included in the returned elements correspond to the list of bound attributes for the specified layer of the specified project.

      Parameters:
      query - the query to execute
      jmapIds - limit extraction to the specified element ids
      Returns:
      JMapGeoElement[] the matching elements
      Throws:
      Exception
    • extractElements

      public JMapGeoElement[] extractElements(String query, long[] jmapIds, OrientedRectangle extent) throws Exception
      This method extracts the K2DElement objects that satisfy the specified pseudo-SQL query. Only the elements that have their id included in the specified list are returned.

      Syntax: select $element from $source{ $project{project name} $layer{layer name}} where ... select $element from $join{$source{$project{project name} $layer{layer name} $field{layer field name}} and $database{$name{database name} $query{select * from ...} $field{database field name}}}

      The attributes included in the returned elements correspond to the list of bound attributes for the specified layer of the specified project.

      Parameters:
      query - the query to execute
      jmapIds - limit extraction to the specified element ids
      extent - the extent to search into.
      Returns:
      JMapGeoElement[] the matching elements
      Throws:
      Exception
    • extractRasterData

      public byte[] extractRasterData(RasterDataSource rasterDs, Rectangle bounds, Projection projection, int imageWidth, int imageHeight, RasterTransformationInfo[] trInfos, RasterParameters parameters) throws Exception
      Throws:
      Exception
    • extractRasterData

      public byte[] extractRasterData(JMapServerProject serverProject, JMapServerRasterLayer serverRasterLayer, Rectangle bounds, int imageWidth, int imageHeight, RasterTransformationInfo[] rasterTransformationInfos) throws Exception
      Extracts raster data (images) from the specified raster layer enclosed in the specified project. The returned image covers the specified bounds in world coordinates and has the specified width and height. The image is returned as a byte array and is encoded as specified in the raster layer parameters.
      Parameters:
      serverProject - The project enclosing the specified raster layer
      serverRasterLayer - The raster layer to query
      bounds - The world coordinate bounds (in project 'map projection') of the image to produce
      imageWidth - The width of the image (pixels)
      imageHeight - The height of the image (pixels)
      Throws:
      Exception
    • getDiskCacheMonitoringInfo

      public KDataCacheMonitoringInfo getDiskCacheMonitoringInfo()
    • getMemoryCacheMonitoringInfo

      public KDataCacheMonitoringInfo getMemoryCacheMonitoringInfo()
    • getDiskCacheMonitoringInfo

      public KDataCacheMonitoringInfo getDiskCacheMonitoringInfo(int projectId, int layerId)
    • getMemoryCacheMonitoringInfo

      public KDataCacheMonitoringInfo getMemoryCacheMonitoringInfo(int projectId, int layerId)
    • estimateLayerTiling

      public void estimateLayerTiling(JMapServerProject project, JMapServerVectorLayer serverVectorLayer, boolean launchCachingJob)
    • addDataManagerEventListener

      public void addDataManagerEventListener(JMapServerDataManagerEventListener listener)
    • removeDataManagerEventListener

      public void removeDataManagerEventListener(JMapServerDataManagerEventListener listener)
    • addDataManagerCallback

      public void addDataManagerCallback(JMapServerDataManagerCallback callbackListener)
      Adds a JMapServerDataManagerCallback to this JMapServerDataManager. A JMapServerDataManagerCallback can be used to listen to, for example, data extraction callbacks. The callback will contain the extraction event (DataSourceExtractionEvent) and this event's properties can be changed to alter the behavior or the extraction. For instance, adding or removing a Spatial or Attribute filter before the extraction actually takes place.
    • removeDataManagerCallback

      public void removeDataManagerCallback(JMapServerDataManagerCallback callbackListener)
      Removes the JMapServerDataManagerCallback from JMapServerDataManager
    • fireDataSourceAddedEvent

      public void fireDataSourceAddedEvent(int dataSourceId)
    • fireDataSourceUpdatedEvent

      public void fireDataSourceUpdatedEvent(int dataSourceId)
    • fireDataSourceDeletedEvent

      public void fireDataSourceDeletedEvent(int dataSourceId)
    • fireDataSourceExtractionCallback

      public void fireDataSourceExtractionCallback(DataSourceExtractionEvent dataSourceExtractionEvent)
      fired before a data extraction takes place. The DataSourceExtractionEvent's properties can be changed and the new properties will be used when extracting the data.