Class WritableDataStoreDataSource

All Implemented Interfaces:
WorkbenchContextReference
Direct Known Subclasses:
H2DataStoreDataSource, PostGISDataStoreDataSource

public abstract class WritableDataStoreDataSource extends DataStoreDataSource
Extension of DataBaseDataSource adding write capabilities.
  • Field Details

  • Constructor Details

    • WritableDataStoreDataSource

      public WritableDataStoreDataSource()
    • WritableDataStoreDataSource

      public WritableDataStoreDataSource(ConnectionDescriptor connectionDescriptor, String datasetName, String geometryAttributeName, String externalPKName, String txManager, WorkbenchContext context)
      Constructor with mandatory parameters for a WritableDataStoreDataSource.
      Parameters:
      connectionDescriptor - descriptor of the connection this datasource is connected to
      datasetName - dataset name
      geometryAttributeName - geometry attribute name
      externalPKName - database primary key used to manage feature updates
      txManager - the transaction manager
      context - global context of the application
  • Method Details

    • setLimitedToView

      public void setLimitedToView(boolean limitedToView)
    • setManageConflicts

      public void setManageConflicts(boolean manageConflicts)
    • setMultiGeometry

      public void setMultiGeometry(boolean multi)
    • setCoordDimension

      public void setCoordDimension(int dbCoordDim)
    • setSRID

      public void setSRID(int srid)
    • setTableAlreadyCreated

      public void setTableAlreadyCreated(boolean tableAlreadyCreated)
      Add this attribute to decide if executeUpdate must write a new table or commit to an existing table. Note : I tried first to set this property in the DataSourceQuery properties, but properties are set through the "load" or "save as" dialog box and are not supposed to change (I tried to change the value at the end of an executeUpdate, but initial properties set in the dialog box are re-applied and overwrite changed value after that).
      Parameters:
      tableAlreadyCreated - true if the table already exists
    • isWritable

      public boolean isWritable()
      Overrides:
      isWritable in class DataStoreDataSource
    • getConnection

      public Connection getConnection()
      Description copied from class: DataSource
      Creates a new Connection to this DataSource.
      Overrides:
      getConnection in class DataStoreDataSource
      Returns:
      a Connection to connect to this DataSource
    • finalizeUpdate

      @Deprecated public abstract void finalizeUpdate(SpatialDatabasesDSConnection conn) throws Exception
      Deprecated.
      With some databases, it may be useful to do some cleaning after a big update. Example : perform a vacuum analyze in PostgreSQL to compact database and to update statistics (needed by ST_EstimatedExtent function)
      Parameters:
      conn - the Connection to use to finalize the update
      Throws:
      Exception - if an Exception occurs during update finalization
    • insertStatement

      protected PreparedStatement insertStatement(SpatialDatabasesDSConnection conn, FeatureSchema fSchema, boolean multi, boolean normalizedColumnNames) throws SQLException
      Create a statement to insert a feature into the database
      Parameters:
      conn - connection to the database to update.
      fSchema - feature schema
      multi - true to force geometry to be a MultiGeometry
      normalizedColumnNames - whether database column names should be normalized (lowercase) or not
      Returns:
      a PreparedStatement
      Throws:
      SQLException - if an exception occurs during insert
    • setAttributeValues

      protected PreparedStatement setAttributeValues(PreparedStatement pstmt, Feature feature, int srid, boolean multi, int dim) throws SQLException
      Throws:
      SQLException
    • getTableSRID

      protected abstract int getTableSRID(Connection conn, String column) throws SQLException
      Throws:
      SQLException
    • getViewEnvelope

      protected org.locationtech.jts.geom.Geometry getViewEnvelope()
    • addCreation

      public void addCreation(Feature feature) throws EvolutionOperationException
      Throws:
      EvolutionOperationException
    • addModification

      public void addModification(Feature feature, Feature oldFeature) throws EvolutionOperationException
      Throws:
      EvolutionOperationException
    • addSuppression

      public void addSuppression(Feature feature) throws EvolutionOperationException
      Throws:
      EvolutionOperationException
    • removeEvolution

      public void removeEvolution(int fid)
      Remove the evolution currently recorded for feature fid. To be used cautiously : this method is used by DataStoreTransactionManager to remove an evolution when the newFeature of this evolution happens to be the same as the last version updated from the server (false conflict).
      Parameters:
      fid - id of the feature to be removed in the evolution stack
    • getUncommittedEvolutions

      public Collection<Evolution> getUncommittedEvolutions()
    • getIndexedEvolutions

      public Map<Object, Evolution> getIndexedEvolutions()
      Return a map with modified features indexed by their database id. WARNING : New features are excluded from this map.
      Returns:
      a Map containing evolutions indexed by id
    • deleteTableQuery

      protected abstract void deleteTableQuery(SpatialDatabasesDSConnection conn) throws SQLException
      Execute a query against this connection to delete the reference to this table in the PostGIS's geometry_columns table.
      Parameters:
      conn - connection to use to delete the table
      Throws:
      SQLException - if the server returns an exception while deleting
    • createAndPopulateTable

      protected abstract void createAndPopulateTable(SpatialDatabasesDSConnection conn, FeatureCollection fc, int srid, String geometryType, boolean multi, int dim, boolean normalizedColumnNames) throws SQLException
      Create and populate a table with features from a dataset.
      Parameters:
      conn - connection to the database
      fc - featureCollection to upload to the database
      srid - srid of the geometry
      geometryType - geometry type
      multi - true to force geometry to be a MultiGeometry
      dim - geometry dimension
      normalizedColumnNames - whether columns names have to be normalized or not
      Throws:
      SQLException - if an exception occurs during table creation or inserts
    • addDBPrimaryKey

      protected abstract void addDBPrimaryKey(SpatialDatabasesDSConnection conn, String primaryKey) throws SQLException
      Add an automatically named primary key constraint to the table.
      Parameters:
      conn - the Connection to use to add the Primary Key
      primaryKey - the column name for th primary key
      Throws:
      SQLException - if an exception occurs during primary key addition
    • getGeometryDimension

      protected static int getGeometryDimension(FeatureCollection coll, int defaultDim)
      Return 3 if coll contains at least one 3d geometry, 2 if coll contains only 2d geometries and defaultDim if coll is empty.
      Parameters:
      coll - featureCollection to extract geometry dimension from
      defaultDim - set a default in the case coll is empty
      Returns:
      the geometry dimension of collection features
    • getGeometryType

      protected static Class getGeometryType(FeatureCollection coll, boolean narrow, boolean multi)
      Determine database geometry type according to
      • values present in the feature collection
      • narrow attribute : true means that we want to use the most specific attribute type able to represent all geometries of the collection
      • multi parameter : true means that we previously transform single geometry types into multigeometry types to be able to use the same type (multi) for geometries of same dimension (single or multi)
      Parameters:
      coll - featureCollection to extract geometry dimension from
      narrow - true to use a specific geometry type where possible
      multi - true to always use a MultiGeometry
      Returns:
      the geometry class to be used