Class WritableDataStoreDataSource
- java.lang.Object
-
- com.vividsolutions.jump.io.datasource.DataSource
-
- com.vividsolutions.jump.workbench.ui.plugin.datastore.DataStoreQueryDataSource
-
- com.vividsolutions.jump.workbench.ui.plugin.datastore.DataStoreDataSource
-
- org.openjump.core.ui.plugin.datastore.WritableDataStoreDataSource
-
- All Implemented Interfaces:
WorkbenchContextReference
- Direct Known Subclasses:
H2DataStoreDataSource,PostGISDataStoreDataSource
public abstract class WritableDataStoreDataSource extends DataStoreDataSource
Extension of DataBaseDataSource adding write capabilities.
-
-
Field Summary
Fields Modifier and Type Field Description static StringCONVERT_TO_MULTIGEOMETRY_KEYstatic StringCREATE_PKstatic StringDEFAULT_PK_NAMEprotected LinkedHashMap<Integer,Evolution>evolutionsstatic StringEXTERNAL_PK_KEYstatic StringGEOM_DIM_KEYstatic StringLIMITED_TO_VIEWstatic StringMANAGE_CONFLICTSstatic StringNAN_Z_TO_VALUE_KEYstatic StringNARROW_GEOMETRY_TYPE_KEYstatic StringNORMALIZED_COLUMN_NAMESprotected StringprimaryKeyNameprotected StringschemaNamestatic StringSRID_KEYprotected StringtableNamestatic StringTX_MANAGER_KEY-
Fields inherited from class com.vividsolutions.jump.workbench.ui.plugin.datastore.DataStoreDataSource
CACHING_KEY, context, DATASET_NAME_KEY, GEOMETRY_ATTRIBUTE_NAME_KEY, MAX_FEATURES_KEY, WHERE_CLAUSE_KEY
-
Fields inherited from class com.vividsolutions.jump.workbench.ui.plugin.datastore.DataStoreQueryDataSource
CONNECTION_DESCRIPTOR_KEY, PATTERN_FENCE, PATTERN_SELECTION, PATTERN_VIEW, PRIMARY_KEY_KEY, SQL_QUERY_KEY
-
Fields inherited from class com.vividsolutions.jump.io.datasource.DataSource
CHARSET_KEY, COMPRESSED_KEY, COORDINATE_SYSTEM_CODE, COORDINATE_SYSTEM_KEY, COORDINATE_SYSTEM_REGISTRY, FILE_KEY, URI_KEY
-
-
Constructor Summary
Constructors Constructor Description WritableDataStoreDataSource()WritableDataStoreDataSource(ConnectionDescriptor connectionDescriptor, String datasetName, String geometryAttributeName, String externalPKName, String txManager, WorkbenchContext context)Constructor with mandatory parameters for a WritableDataStoreDataSource.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddCreation(Feature feature)protected abstract voidaddDBPrimaryKey(SpatialDatabasesDSConnection conn, String primaryKey)Add an automatically named primary key constraint to the table.voidaddModification(Feature feature, Feature oldFeature)voidaddSuppression(Feature feature)protected abstract voidcreateAndPopulateTable(SpatialDatabasesDSConnection conn, FeatureCollection fc, int srid, String geometryType, boolean multi, int dim, boolean normalizedColumnNames)Create and populate a table with features from a dataset.protected abstract voiddeleteTableQuery(SpatialDatabasesDSConnection conn)Execute a query against this connection to delete the reference to this table in the PostGIS's geometry_columns table.abstract voidfinalizeUpdate(SpatialDatabasesDSConnection conn)Deprecated.ConnectiongetConnection()Creates a new Connection to this DataSource.protected static intgetGeometryDimension(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.protected static ClassgetGeometryType(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)Map<Object,Evolution>getIndexedEvolutions()Return a map with modified features indexed by their database id.protected abstract intgetTableSRID(Connection conn, String column)Collection<Evolution>getUncommittedEvolutions()protected org.locationtech.jts.geom.GeometrygetViewEnvelope()protected PreparedStatementinsertStatement(SpatialDatabasesDSConnection conn, FeatureSchema fSchema, boolean multi, boolean normalizedColumnNames)Create a statement to insert a feature into the databasebooleanisWritable()voidremoveEvolution(int fid)Remove the evolution currently recorded for feature fid.protected PreparedStatementsetAttributeValues(PreparedStatement pstmt, Feature feature, int srid, boolean multi, int dim)voidsetCoordDimension(int dbCoordDim)voidsetLimitedToView(boolean limitedToView)voidsetManageConflicts(boolean manageConflicts)voidsetMultiGeometry(boolean multi)voidsetSRID(int srid)voidsetTableAlreadyCreated(boolean tableAlreadyCreated)Add this attribute to decide if executeUpdate must write a new table or commit to an existing table.-
Methods inherited from class com.vividsolutions.jump.workbench.ui.plugin.datastore.DataStoreDataSource
createFeatureCollection, getWorkbenchContext, setMaxFeature, setWhereClause, setWorkbenchContext
-
Methods inherited from class com.vividsolutions.jump.workbench.ui.plugin.datastore.DataStoreQueryDataSource
expandQuery
-
Methods inherited from class com.vividsolutions.jump.io.datasource.DataSource
getProperties, installCoordinateSystem, isDisabled, isReadable, setDisabled, setProperties
-
-
-
-
Field Detail
-
LIMITED_TO_VIEW
public static final String LIMITED_TO_VIEW
- See Also:
- Constant Field Values
-
MANAGE_CONFLICTS
public static final String MANAGE_CONFLICTS
- See Also:
- Constant Field Values
-
EXTERNAL_PK_KEY
public static final String EXTERNAL_PK_KEY
- See Also:
- Constant Field Values
-
SRID_KEY
public static final String SRID_KEY
- See Also:
- Constant Field Values
-
GEOM_DIM_KEY
public static final String GEOM_DIM_KEY
- See Also:
- Constant Field Values
-
NAN_Z_TO_VALUE_KEY
public static final String NAN_Z_TO_VALUE_KEY
- See Also:
- Constant Field Values
-
NARROW_GEOMETRY_TYPE_KEY
public static final String NARROW_GEOMETRY_TYPE_KEY
- See Also:
- Constant Field Values
-
CONVERT_TO_MULTIGEOMETRY_KEY
public static final String CONVERT_TO_MULTIGEOMETRY_KEY
- See Also:
- Constant Field Values
-
CREATE_PK
public static final String CREATE_PK
- See Also:
- Constant Field Values
-
NORMALIZED_COLUMN_NAMES
public static final String NORMALIZED_COLUMN_NAMES
- See Also:
- Constant Field Values
-
TX_MANAGER_KEY
public static final String TX_MANAGER_KEY
- See Also:
- Constant Field Values
-
DEFAULT_PK_NAME
public static final String DEFAULT_PK_NAME
- See Also:
- Constant Field Values
-
evolutions
protected final LinkedHashMap<Integer,Evolution> evolutions
-
schemaName
protected String schemaName
-
tableName
protected String tableName
-
primaryKeyName
protected String primaryKeyName
-
-
Constructor Detail
-
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 todatasetName- dataset namegeometryAttributeName- geometry attribute nameexternalPKName- database primary key used to manage feature updatestxManager- the transaction managercontext- global context of the application
-
-
Method Detail
-
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:
isWritablein classDataStoreDataSource
-
getConnection
public Connection getConnection()
Description copied from class:DataSourceCreates a new Connection to this DataSource.- Overrides:
getConnectionin classDataStoreDataSource- 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 schemamulti- true to force geometry to be a MultiGeometrynormalizedColumnNames- 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 databasefc- featureCollection to upload to the databasesrid- srid of the geometrygeometryType- geometry typemulti- true to force geometry to be a MultiGeometrydim- geometry dimensionnormalizedColumnNames- 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 KeyprimaryKey- 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 fromdefaultDim- 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 fromnarrow- true to use a specific geometry type where possiblemulti- true to always use a MultiGeometry- Returns:
- the geometry class to be used
-
-