public class SqlTileWriter extends Object implements IFilesystemCache
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 Configuration#getInstance()#getTileFileSystemCacheTrimBytes()
cache exceeds 600 Mb then it will be trimmed to 500 Mb by deleting files that expire first.
DatabaseFileArchive
,
SqliteArchiveTileWriter
Modifier and Type | Field and Description |
---|---|
static String |
COLUMN_EXPIRES |
static String |
DATABASE_FILENAME |
protected SQLiteDatabase |
db |
protected File |
db_file |
(package private) static boolean |
hasInited |
protected long |
lastSizeCheck |
(package private) long |
tileSize
mean tile size computed on first use.
|
Constructor and Description |
---|
SqlTileWriter() |
Modifier and Type | Method and Description |
---|---|
boolean |
exists(ITileSource pTileSource,
long pMapTileIndex)
Returns true if the given tile source and tile coordinates exist in the cache
|
boolean |
exists(String pTileSource,
long pMapTileIndex)
Returns true if the given tile source and tile coordinates exist in the cache
|
Long |
getExpirationTimestamp(ITileSource pTileSource,
long pMapTileIndex)
Gets the cache expiration timestamp of a tile
|
long |
getFirstExpiry()
Returns the expiry time of the tile that expires first.
|
static long |
getIndex(long pMapTileIndex)
Gets the single column index value for a map tile
Unluckily, "map tile index" and "sql pk" don't match
|
static long |
getIndex(long pX,
long pY,
long pZ) |
static String |
getPrimaryKey() |
static String[] |
getPrimaryKeyParameters(long pIndex,
ITileSource pTileSourceInfo) |
static String[] |
getPrimaryKeyParameters(long pIndex,
String pTileSourceInfo) |
long |
getRowCount(String tileSourceName)
Returns the number of tiles in the cache for the specified tile source name
|
long |
getSize()
Returns the size of the database file in bytes.
|
Cursor |
getTileCursor(String[] pPrimaryKeyParameters,
String[] pColumns) |
int[] |
importFromFileCache(boolean removeFromFileSystem)
a helper method to import file system stored map tiles into the sql tile cache
on successful import, the tiles are removed from the file system.
|
Drawable |
loadTile(ITileSource pTileSource,
long pMapTileIndex)
Gets the tile drawable
|
void |
onDetach()
Used when the map engine is shutdown, use it to perform any clean up activities and to terminate
any background threads
|
boolean |
purgeCache()
purges and deletes everything from the cache database
|
boolean |
purgeCache(String mTileSourceName)
purges and deletes all tiles from the given tile source name from the cache database
|
boolean |
remove(ITileSource pTileSourceInfo,
long pMapTileIndex)
Removes a specific tile from the cache
|
void |
runCleanupOperation()
this could be a long running operation, don't run on the UI thread unless necessary.
|
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 tile
source.
|
static void |
setCleanupOnStart(boolean value) |
public static final String DATABASE_FILENAME
public static final String COLUMN_EXPIRES
protected File db_file
protected SQLiteDatabase db
protected long lastSizeCheck
long tileSize
static boolean hasInited
public static void setCleanupOnStart(boolean value)
public void runCleanupOperation()
public boolean saveFile(ITileSource pTileSourceInfo, long pMapTileIndex, InputStream pStream, Long pExpirationTime)
IFilesystemCache
saveFile
in interface IFilesystemCache
pTileSourceInfo
- a tile sourcepMapTileIndex
- a tilepStream
- an InputStreampublic boolean exists(String pTileSource, long pMapTileIndex)
public boolean exists(ITileSource pTileSource, long pMapTileIndex)
exists
in interface IFilesystemCache
public void onDetach()
IFilesystemCache
onDetach
in interface IFilesystemCache
public boolean purgeCache()
public boolean purgeCache(String mTileSourceName)
public int[] importFromFileCache(boolean removeFromFileSystem)
This can take a long time, so consider running this off of the main thread.
public boolean remove(ITileSource pTileSourceInfo, long pMapTileIndex)
remove
in interface IFilesystemCache
public long getRowCount(String tileSourceName)
tileSourceName
- public long getSize()
public long getFirstExpiry()
public static long getIndex(long pX, long pY, long pZ)
pX
- pY
- pZ
- public static long getIndex(long pMapTileIndex)
pMapTileIndex
- public Long getExpirationTimestamp(ITileSource pTileSource, long pMapTileIndex)
IFilesystemCache
getExpirationTimestamp
in interface IFilesystemCache
public static String getPrimaryKey()
public static String[] getPrimaryKeyParameters(long pIndex, ITileSource pTileSourceInfo)
pIndex
- pTileSourceInfo
- public static String[] getPrimaryKeyParameters(long pIndex, String pTileSourceInfo)
pIndex
- pTileSourceInfo
- public Cursor getTileCursor(String[] pPrimaryKeyParameters, String[] pColumns)
pPrimaryKeyParameters
- pColumns
- public Drawable loadTile(ITileSource pTileSource, long pMapTileIndex) throws Exception
IFilesystemCache
loadTile
in interface IFilesystemCache
Exception