use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.
the class SQLiteTileSource method getBytes.
public byte[] getBytes(int x, int y, int zoom, String dirWithTiles, long[] timeHolder) throws IOException {
SQLiteConnection db = getDatabase();
if (db == null) {
return null;
}
long ts = System.currentTimeMillis();
try {
if (zoom <= maxZoom) {
// return the normal tile if exists
String[] params = new String[] { x + "", y + "", getFileZoom(zoom) + "" };
boolean queryTime = timeHolder != null && timeHolder.length > 0 && timeSupported;
SQLiteCursor cursor = db.rawQuery("SELECT image " + (queryTime ? ", time" : "") + " FROM tiles WHERE x = ? AND y = ? AND z = ?", // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
params);
byte[] blob = null;
if (cursor.moveToFirst()) {
blob = cursor.getBlob(0);
if (queryTime) {
timeHolder[0] = cursor.getLong(1);
}
}
cursor.close();
return blob;
}
return null;
} finally {
if (LOG.isDebugEnabled()) {
LOG.debug("Load tile " + x + "/" + y + "/" + zoom + " for " + (System.currentTimeMillis() - ts) + " ms ");
}
}
}
use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.
the class SQLiteTileSource method deleteTiles.
@Override
public void deleteTiles(String path) {
SQLiteConnection db = getDatabase();
if (db == null || db.isReadOnly() || onlyReadonlyAvailable) {
return;
}
db.execSQL("TRUNCATE TABLE tiles");
}
use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.
the class SQLiteTileSource method clearOld.
public void clearOld() {
SQLiteConnection db = getDatabase();
if (db == null || db.isReadOnly()) {
return;
}
LOG.debug("DELETE FROM tiles WHERE time<" + (System.currentTimeMillis() - getExpirationTimeMillis()));
// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
db.execSQL("DELETE FROM tiles WHERE time<" + (System.currentTimeMillis() - getExpirationTimeMillis()));
// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
db.execSQL("VACUUM");
}
use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.
the class GPXDatabase method updateSplit.
public boolean updateSplit(GpxDataItem item, int splitType, double splitInterval) {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
String fileName = getFileName(item.file);
String fileDir = getFileDir(item.file);
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SPLIT_TYPE + " = ?, " + GPX_COL_SPLIT_INTERVAL + " = ? " + " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", new Object[] { splitType, splitInterval, fileName, fileDir });
item.splitType = splitType;
item.splitInterval = splitInterval;
} finally {
db.close();
}
return true;
}
return false;
}
use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.
the class GPXDatabase method updateLastModifiedTime.
private boolean updateLastModifiedTime(GpxDataItem item) {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
String fileName = getFileName(item.file);
String fileDir = getFileDir(item.file);
long fileLastModifiedTime = item.file.lastModified();
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_FILE_LAST_MODIFIED_TIME + " = ? " + " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", new Object[] { fileLastModifiedTime, fileName, fileDir });
item.fileLastModifiedTime = fileLastModifiedTime;
} finally {
db.close();
}
return true;
}
return false;
}
Aggregations