Search in sources :

Example 26 with SQLiteConnection

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 ");
        }
    }
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection) SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor)

Example 27 with SQLiteConnection

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");
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection)

Example 28 with SQLiteConnection

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");
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection)

Example 29 with SQLiteConnection

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;
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection)

Example 30 with SQLiteConnection

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;
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection)

Aggregations

SQLiteConnection (net.osmand.plus.api.SQLiteAPI.SQLiteConnection)34 SQLiteCursor (net.osmand.plus.api.SQLiteAPI.SQLiteCursor)12 Nullable (android.support.annotation.Nullable)3 ArrayList (java.util.ArrayList)3 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)3 SQLiteDiskIOException (android.database.sqlite.SQLiteDiskIOException)2 LinkedHashMap (java.util.LinkedHashMap)2 FavouritePoint (net.osmand.data.FavouritePoint)2 Bitmap (android.graphics.Bitmap)1 NonNull (android.support.annotation.NonNull)1 Interpreter (bsh.Interpreter)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 QuadRect (net.osmand.data.QuadRect)1 MapMarkersGroup (net.osmand.plus.MapMarkersHelper.MapMarkersGroup)1