Skip to content

Instantly share code, notes, and snippets.

@jericks
Created April 20, 2014 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jericks/11122862 to your computer and use it in GitHub Desktop.
Save jericks/11122862 to your computer and use it in GitHub Desktop.
Auto increment min and max zoom levels when adding tiles to MBTilesFiles
/**
* Store a tile
*
* @throws IOException
*/
public void saveTile(MBTilesTile entry) throws IOException {
try {
Connection cx = connPool.getConnection();
try {
PreparedStatement ps;
if (entry.getData() != null) {
ps = prepare(cx,
format("INSERT OR REPLACE INTO %s VALUES (?,?,?,?)", TABLE_TILES))
.set(entry.getZoomLevel()).set(entry.getTileColumn())
.set(entry.getTileRow()).set(entry.getData()).log(Level.FINE)
.statement();
} else {
ps = prepare(
cx,
format("DELETE FROM %s WHERE zoom_level=? AND tile_column=? AND tile_row=?",
TABLE_TILES)).set(entry.getZoomLevel())
.set(entry.getTileColumn()).set(entry.getTileRow()).log(Level.FINE)
.statement();
}
ps.execute();
ps.close();
saveMinMaxZoomMetadata((int)Math.min(entry.getZoomLevel(), this.minZoom()), (int)Math.max(entry.getZoomLevel(), this.maxZoom()));
} finally {
cx.close();
}
} catch (SQLException e) {
throw new IOException(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment