-
- All Implemented Interfaces:
-
org.osmdroid.tileprovider.modules.IFilesystemCache,org.osmdroid.util.SplashScreenable
public class SqlTileWriter implements IFilesystemCache, SplashScreenable
An implementation of IFilesystemCache based on the original TileWriter. It writes tiles to a sqlite database cache. It supports expiration timestamps if provided by the server from which the tile was downloaded. Trimming of expired
If the database exceeds getInstance cache exceeds 600 Mb then it will be trimmed to 500 Mb by deleting files that expire first.
-
-
Field Summary
Fields Modifier and Type Field Description public final static StringDATABASE_FILENAMEpublic final static StringCOLUMN_EXPIRESpublic final static StringCOLUMN_EXPIRES_INDEXprivate final static StringprimaryKey
-
Constructor Summary
Constructors Constructor Description SqlTileWriter()
-
Method Summary
Modifier and Type Method Description static StringgetPrimaryKey()static voidsetCleanupOnStart(boolean value)voidrunCleanupOperation()this could be a long running operation, don't run on the UI thread unless necessary.This function prunes the database for old or expired tiles. booleansaveFile(ITileSource pTileSourceInfo, long pMapTileIndex, InputStream pStream, Long pExpirationTime)Save an InputStream as the specified tile in the file system cache for the specified tilesource. booleanexists(String pTileSource, long pMapTileIndex)Returns true if the given tile source and tile coordinates exist in the cache booleanexists(ITileSource pTileSource, long pMapTileIndex)Returns true if the given tile source and tile coordinates exist in the cache voidonDetach()Now we use only one static instance of database, which should never be closed booleanpurgeCache()purges and deletes everything from the cache database booleanpurgeCache(String mTileSourceName)purges and deletes all tiles from the given tile source name from the cache database Array<int>importFromFileCache(boolean removeFromFileSystem)a helper method to import file system stored map tiles into the sql tile cacheon successful import, the tiles are removed from the file system. booleanremove(ITileSource pTileSourceInfo, long pMapTileIndex)Removes a specific tile from the cache longgetRowCount(String tileSourceName)Returns the number of tiles in the cache for the specified tile source name longgetRowCount(String pTileSourceName, int pZoom, Collection<Rect> pInclude, Collection<Rect> pExclude)Count cache tiles longgetSize()Returns the size of the database file in bytes. longgetFirstExpiry()Returns the expiry time of the tile that expires first. static longgetIndex(long pX, long pY, long pZ)static longgetIndex(long pMapTileIndex)Gets the single column index value for a map tileUnluckily, "map tile index" and "sql pk" don't match LonggetExpirationTimestamp(ITileSource pTileSource, long pMapTileIndex)Gets the cache expiration timestamp of a tile static Array<String>getPrimaryKeyParameters(long pIndex, ITileSource pTileSourceInfo)static Array<String>getPrimaryKeyParameters(long pIndex, String pTileSourceInfo)CursorgetTileCursor(Array<String> pPrimaryKeyParameters, Array<String> pColumns)DrawableloadTile(ITileSource pTileSource, long pMapTileIndex)Gets the tile drawable voidrunCleanupOperation(long pToBeDeleted, int pBulkSize, long pPauseMillis, boolean pIncludeUnexpired)voidrefreshDb()static booleanisFunctionalException(SQLiteException pSQLiteException)voidrunDuringSplashScreen()longdelete(String pTileSourceName, int pZoom, Collection<Rect> pInclude, Collection<Rect> pExclude)Delete cache tiles -
-
Method Detail
-
getPrimaryKey
static String getPrimaryKey()
-
setCleanupOnStart
static void setCleanupOnStart(boolean value)
-
runCleanupOperation
void runCleanupOperation()
this could be a long running operation, don't run on the UI thread unless necessary.This function prunes the database for old or expired tiles.
-
saveFile
boolean saveFile(ITileSource pTileSourceInfo, long pMapTileIndex, InputStream pStream, Long pExpirationTime)
Save an InputStream as the specified tile in the file system cache for the specified tilesource.
- Parameters:
pTileSourceInfo- a tile sourcepMapTileIndex- a tilepStream- an InputStream
-
exists
boolean exists(String pTileSource, long pMapTileIndex)
Returns true if the given tile source and tile coordinates exist in the cache
-
exists
boolean exists(ITileSource pTileSource, long pMapTileIndex)
Returns true if the given tile source and tile coordinates exist in the cache
-
onDetach
void onDetach()
Now we use only one static instance of database, which should never be closed
-
purgeCache
boolean purgeCache()
purges and deletes everything from the cache database
-
purgeCache
boolean purgeCache(String mTileSourceName)
purges and deletes all tiles from the given tile source name from the cache database
-
importFromFileCache
Array<int> importFromFileCache(boolean removeFromFileSystem)
a helper method to import file system stored map tiles into the sql tile cacheon successful import, the tiles are removed from the file system.
This can take a long time, so consider running this off of the main thread.
-
remove
boolean remove(ITileSource pTileSourceInfo, long pMapTileIndex)
Removes a specific tile from the cache
-
getRowCount
long getRowCount(String tileSourceName)
Returns the number of tiles in the cache for the specified tile source name
-
getRowCount
long getRowCount(String pTileSourceName, int pZoom, Collection<Rect> pInclude, Collection<Rect> pExclude)
Count cache tiles
- Parameters:
pTileSourceName- the tile source name (possibly null)pZoom- the zoom levelpInclude- a collection of bounding boxes to include (possibly null/empty)pExclude- a collection of bounding boxes to exclude (possibly null/empty)
-
getSize
long getSize()
Returns the size of the database file in bytes.
-
getFirstExpiry
long getFirstExpiry()
Returns the expiry time of the tile that expires first.
-
getIndex
static long getIndex(long pX, long pY, long pZ)
-
getIndex
static long getIndex(long pMapTileIndex)
Gets the single column index value for a map tileUnluckily, "map tile index" and "sql pk" don't match
-
getExpirationTimestamp
Long getExpirationTimestamp(ITileSource pTileSource, long pMapTileIndex)
Gets the cache expiration timestamp of a tile
-
getPrimaryKeyParameters
static Array<String> getPrimaryKeyParameters(long pIndex, ITileSource pTileSourceInfo)
-
getPrimaryKeyParameters
static Array<String> getPrimaryKeyParameters(long pIndex, String pTileSourceInfo)
-
loadTile
Drawable loadTile(ITileSource pTileSource, long pMapTileIndex)
Gets the tile drawable
-
runCleanupOperation
void runCleanupOperation(long pToBeDeleted, int pBulkSize, long pPauseMillis, boolean pIncludeUnexpired)
- Parameters:
pToBeDeleted- Amount of bytes to delete (as tile blob size)pBulkSize- Number of tiles to delete in bulkpPauseMillis- Pause between bulk actions, in order not to play it not aggressive on the CPUpIncludeUnexpired- Should we also delete tiles that are not expired?
-
refreshDb
void refreshDb()
-
isFunctionalException
static boolean isFunctionalException(SQLiteException pSQLiteException)
-
runDuringSplashScreen
void runDuringSplashScreen()
-
delete
long delete(String pTileSourceName, int pZoom, Collection<Rect> pInclude, Collection<Rect> pExclude)
Delete cache tiles
- Parameters:
pTileSourceName- the tile source name (possibly null)pZoom- the zoom levelpInclude- a collection of bounding boxes to include (possibly null/empty)pExclude- a collection of bounding boxes to exclude (possibly null/empty)
-
-
-
-