Class GeoPackageOutputStore
- All Implemented Interfaces:
AutoCloseable
For writing to GeoPackage files.
Note that writing to GeoPackage files uses a shared connection. It is important that
is called to close this shared connection.</p>
-
Nested Class Summary
Nested classes/interfaces inherited from class nz.org.riskscape.engine.defaults.data.jdbc.BaseJdbcOutputStore
BaseJdbcOutputStore.JdbcRiskscapeWriter, BaseJdbcOutputStore.LocalProblems, BaseJdbcOutputStore.StructMappingToColumnMapping
-
Field Summary
Fields inherited from class nz.org.riskscape.engine.defaults.data.jdbc.BaseJdbcOutputStore
DEFAULT_BATCH_INSERT_SIZE, ds, PROBLEMS, replaceExistingTables
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected BaseJdbcOutputStore.JdbcRiskscapeWriter
createJdbcWriter
(String tableName, List<BaseJdbcOutputStore.StructMappingToColumnMapping> mappings, Connection conn, URI storedAt) protected void
deleteTable
(String tableName, Connection conn) protected Connection
Get aConnection
that will be used to both create and then populate the table.getTableURI
(String tableName) Get a URI that represents the given table at the JDBC data source.protected void
initDbIfNecessary
(Connection conn) Initializes the GeoPackage with required tables should they not exist alreadyprotected void
postTableCreate
(String tableName, nz.org.riskscape.engine.output.StructFlattener.StructMapping geomMapping, Connection conn) Allow implementations to perform any other actions that may be required now that a feature table has been created.protected nz.org.riskscape.problem.ResultOrProblems<BaseJdbcOutputStore.StructMappingToColumnMapping>
toColumnMapping
(nz.org.riskscape.engine.output.StructFlattener.StructMapping structMapping, nz.org.riskscape.engine.output.StructFlattener.StructMapping firstGeomMapping, Connection conn) Provide aBaseJdbcOutputStore.StructMappingToColumnMapping
for the given structMapping.static nz.org.riskscape.problem.ResultOrProblems<nz.org.riskscape.engine.output.RiskscapeWriter>
writerFor
(File geoPackageFile, nz.org.riskscape.engine.types.Struct type, String name, boolean replaceExistingTables) Get aRiskscapeWriter
that can write the given type/name to geoPackageFile.Methods inherited from class nz.org.riskscape.engine.defaults.data.jdbc.BaseJdbcOutputStore
appendingWriterFor, doWriterFor, getExistingTableNames, prepareGeometry, quoteIdentifier, runScript, urlEncode, writerFor
-
Constructor Details
-
GeoPackageOutputStore
-
-
Method Details
-
writerFor
public static nz.org.riskscape.problem.ResultOrProblems<nz.org.riskscape.engine.output.RiskscapeWriter> writerFor(File geoPackageFile, nz.org.riskscape.engine.types.Struct type, String name, boolean replaceExistingTables) Get a
RiskscapeWriter
that can write the given type/name to geoPackageFile.Note that the GeoPackageOutputStore will be closed when the returned RiskscapeWriter is closed.
This method is only appropriate when a single layer is to be written to the GeoPackage. If multiple layers are to be written then
BaseJdbcOutputStore.writerFor(Struct, String)
should be used.- Parameters:
geoPackageFile
- the GeoPackage file to be written totype
- the type to writename
- the desired name to write toreplaceExistingTables
- true if existing tables should be replaced- Returns:
- riskscape writer or problems preventing one from being created
-
getConnection
Description copied from class:BaseJdbcOutputStore
Get a
Connection
that will be used to both create and then populate the table.Note that if this method is overridden to return a shared connection then
BaseJdbcOutputStore.createJdbcWriter(java.lang.String, java.util.List, java.sql.Connection, java.net.URI)
should also be overridden to return aBaseJdbcOutputStore.JdbcRiskscapeWriter
that will not close the shared connection. In this case the implementation will need to take other steps to ensure that the connection is closed.- Overrides:
getConnection
in classBaseJdbcOutputStore
- Throws:
SQLException
-
createJdbcWriter
protected BaseJdbcOutputStore.JdbcRiskscapeWriter createJdbcWriter(String tableName, List<BaseJdbcOutputStore.StructMappingToColumnMapping> mappings, Connection conn, URI storedAt) throws SQLException - Overrides:
createJdbcWriter
in classBaseJdbcOutputStore
- Throws:
SQLException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
toColumnMapping
protected nz.org.riskscape.problem.ResultOrProblems<BaseJdbcOutputStore.StructMappingToColumnMapping> toColumnMapping(nz.org.riskscape.engine.output.StructFlattener.StructMapping structMapping, nz.org.riskscape.engine.output.StructFlattener.StructMapping firstGeomMapping, Connection conn) throws nz.org.riskscape.problem.ProblemException Description copied from class:BaseJdbcOutputStore
Provide a
BaseJdbcOutputStore.StructMappingToColumnMapping
for the given structMapping.firstGeomMapping is also provided to allow implementations that only allow one spatial entry to map subsequent geometries, maybe to text WKT.
- Specified by:
toColumnMapping
in classBaseJdbcOutputStore
- Parameters:
structMapping
- the struct mapping to mapfirstGeomMapping
- the first geometry mapping, if one exists- Returns:
- a mapper
- Throws:
nz.org.riskscape.problem.ProblemException
-
postTableCreate
protected void postTableCreate(String tableName, nz.org.riskscape.engine.output.StructFlattener.StructMapping geomMapping, Connection conn) throws SQLException, nz.org.riskscape.problem.ProblemException Description copied from class:BaseJdbcOutputStore
Allow implementations to perform any other actions that may be required now that a feature table has been created. This could be to register the table such as a GeoPackage will register a table in 'gpkgcontents' and 'gpkggeometry_columns' for a geometry column.
- Overrides:
postTableCreate
in classBaseJdbcOutputStore
- Parameters:
tableName
- the name of the table that has been createdgeomMapping
- the first geometry mapping from that table, or null if none existconn
- a connection that can be used for further sql statements.- Throws:
SQLException
nz.org.riskscape.problem.ProblemException
-
getTableURI
Description copied from class:BaseJdbcOutputStore
Get a URI that represents the given table at the JDBC data source. Will be returned from
RiskscapeWriter.getStoredAt()
when writing is complete.- Specified by:
getTableURI
in classBaseJdbcOutputStore
- Parameters:
tableName
- the table that is being written with URL encoding- Returns:
- URI representing the table
-
initDbIfNecessary
Initializes the GeoPackage with required tables should they not exist already
- Overrides:
initDbIfNecessary
in classBaseJdbcOutputStore
- Parameters:
conn
-
-
deleteTable
- Overrides:
deleteTable
in classBaseJdbcOutputStore
- Throws:
SQLException
-
getGeoPackageFile
-