private void handleError(Exception exception) { Exception errProcessEx = exFiltrate(exception); if (errProcessEx instanceof SQLiteFullException) { // If the error is sqLite full exception already, no need to update it to the database // again. handleSQLiteFullException((SQLiteFullException) errProcessEx); } else { // Normal case. try { model.setStatus(FileDownloadStatus.error); model.setErrMsg(exception.toString()); database.updateError(model.getId(), errProcessEx, model.getSoFar()); } catch (SQLiteFullException fullException) { errProcessEx = fullException; handleSQLiteFullException((SQLiteFullException) errProcessEx); } } processParams.setException(errProcessEx); onStatusChanged(FileDownloadStatus.error); }
private static final void readExceptionFromParcel(Parcel reply, String msg, int code) { switch (code) { case 2: throw new IllegalArgumentException(msg); case 3: throw new UnsupportedOperationException(msg); case 4: throw new SQLiteAbortException(msg); case 5: throw new SQLiteConstraintException(msg); case 6: throw new SQLiteDatabaseCorruptException(msg); case 7: throw new SQLiteFullException(msg); case 8: throw new SQLiteDiskIOException(msg); case 9: throw new SQLiteException(msg); case 11: throw new OperationCanceledException(msg); default: reply.readException(code, msg); } }
@Override public boolean delete() throws SQLiteException { try { //drop table MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance(); SQLiteDatabase db = map.getDatabase(false); String tableDrop = "DROP TABLE IF EXISTS " + mPath.getName(); db.execSQL(tableDrop); } catch (SQLiteFullException e) { e.printStackTrace(); } return super.delete(); }
private void handleSQLiteFullException(final SQLiteFullException sqLiteFullException) { final int id = model.getId(); if (FileDownloadLog.NEED_LOG) { FileDownloadLog.d(this, "the data of the task[%d] is dirty, because the SQLite " + "full exception[%s], so remove it from the database directly.", id, sqLiteFullException.toString()); } model.setErrMsg(sqLiteFullException.toString()); model.setStatus(FileDownloadStatus.error); database.remove(id); database.removeConnections(id); }
private boolean performSetItem(String key, String value, boolean isPersistent, boolean allowRetryWhenFull) { SQLiteDatabase database = mDatabaseSupplier.getDatabase(); if (database == null) { return false; } WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE, "set k-v to storage(key:" + key + ",value:" + value + ",isPersistent:" + isPersistent + ",allowRetry:" + allowRetryWhenFull + ")"); String sql = "INSERT OR REPLACE INTO " + WXSQLiteOpenHelper.TABLE_STORAGE + " VALUES (?,?,?,?);"; SQLiteStatement statement = null; String timeStamp = WXSQLiteOpenHelper.sDateFormatter.format(new Date()); try { statement = database.compileStatement(sql); statement.clearBindings(); statement.bindString(1, key); statement.bindString(2, value); statement.bindString(3, timeStamp); statement.bindLong(4, isPersistent ? 1 : 0); statement.execute(); return true; } catch (Exception e) { WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, "DefaultWXStorage occurred an exception when execute setItem :" + e.getMessage()); if (e instanceof SQLiteFullException) { if (allowRetryWhenFull && trimToSize()) { //try again //setItem/setItemPersistent method only allow try once when occurred a sqliteFullException. WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE, "retry set k-v to storage(key:" + key + ",value:" + value + ")"); return performSetItem(key, value, isPersistent, false); } } return false; } finally { if(statement != null) { statement.close(); } } }
/** * 数据库文件已达到最大空间(数据库已满) * * @param e */ public static void printStackTrace(String TAG, SQLiteFullException e) { if (IsDebug) { e.printStackTrace(); } else { logException(TAG, e); } }
/** * Special function for writing an exception result at the header of * a parcel, to be used when returning an exception from a transaction. * exception will be re-thrown by the function in another process * * @param reply Parcel to write to * @param e The Exception to be written. * @see Parcel#writeNoException * @see Parcel#writeException */ public static final void writeExceptionToParcel(Parcel reply, Exception e) { int code = 0; boolean logException = true; if (e instanceof FileNotFoundException) { code = 1; logException = false; } else if (e instanceof IllegalArgumentException) { code = 2; } else if (e instanceof UnsupportedOperationException) { code = 3; } else if (e instanceof SQLiteAbortException) { code = 4; } else if (e instanceof SQLiteConstraintException) { code = 5; } else if (e instanceof SQLiteDatabaseCorruptException) { code = 6; } else if (e instanceof SQLiteFullException) { code = 7; } else if (e instanceof SQLiteDiskIOException) { code = 8; } else if (e instanceof SQLiteException) { code = 9; } else if (e instanceof OperationApplicationException) { code = 10; } else if (e instanceof OperationCanceledException) { code = 11; logException = false; } else { reply.writeException(e); Log.e(TAG, "Writing exception to parcel", e); return; } reply.writeInt(code); reply.writeString(e.getMessage()); if (logException) { Log.e(TAG, "Writing exception to parcel", e); } }
private boolean performSetItem(String key, String value, boolean isPersistent, boolean allowRetryWhenFull) { WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE,"set k-v to storage(key:"+ key + ",value:"+ value+",isPersistent:"+isPersistent+",allowRetry:"+allowRetryWhenFull+")"); String sql = "INSERT OR REPLACE INTO " + WXSQLiteOpenHelper.TABLE_STORAGE + " VALUES (?,?,?,?);"; SQLiteStatement statement = mDatabaseSupplier.getDatabase().compileStatement(sql); String timeStamp = WXSQLiteOpenHelper.sDateFormatter.format(new Date()); try { statement.clearBindings(); statement.bindString(1, key); statement.bindString(2, value); statement.bindString(3, timeStamp); statement.bindLong(4, isPersistent ? 1 : 0); statement.execute(); return true; } catch (Exception e) { WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE,"DefaultWXStorage occurred an exception when execute setItem :" + e.getMessage()); if(e instanceof SQLiteFullException){ if(allowRetryWhenFull && trimToSize()){ //try again //setItem/setItemPersistent method only allow try once when occurred a sqliteFullException. WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE,"retry set k-v to storage(key:"+key+",value:"+value+")"); return performSetItem(key,value,isPersistent,false); } } return false; } finally { statement.close(); } }
public static void setPicture(MediaWrapper m, Bitmap p) { Log.d(TAG, "Setting new picture for " + m.getTitle()); try { getInstance().updateMedia( m.getUri(), mediaColumn.MEDIA_PICTURE, p); } catch (SQLiteFullException e) { Log.d(TAG, "SQLiteFullException while setting picture"); } m.setPictureParsed(true); }
public static void setPicture(MediaWrapper m, Bitmap p) { Log.d(TAG, "Setting new picture for " + m.getTitle()); try { getInstance().updateMedia( m.getUri(), INDEX_MEDIA_PICTURE, p); } catch (SQLiteFullException e) { Log.d(TAG, "SQLiteFullException while setting picture"); } m.setPictureParsed(true); }
public static void setPicture(Context context, Media m, Bitmap p) { Log.d(TAG, "Setting new picture for " + m.getTitle()); try { MediaDatabase.getInstance(context).updateMedia( m.getLocation(), MediaDatabase.mediaColumn.MEDIA_PICTURE, p); } catch (SQLiteFullException e) { Log.d(TAG, "SQLiteFullException while setting picture"); } m.setPictureParsed(true); }
public static void delete(String tableName) { try { MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance(); SQLiteDatabase db = map.getDatabase(true); String tableDrop = "DROP TABLE IF EXISTS " + tableName; db.execSQL(tableDrop); } catch (SQLiteFullException e) { e.printStackTrace(); } }
public static void setPicture(Media m, Bitmap p) { Log.d(TAG, "Setting new picture for " + m.getTitle()); try { getInstance().updateMedia( m.getLocation(), mediaColumn.MEDIA_PICTURE, p); } catch (SQLiteFullException e) { Log.d(TAG, "SQLiteFullException while setting picture"); } m.setPictureParsed(true); }
private void onDiskFull(SQLiteFullException e) { mIgnoreWrites = true; }
private void onDiskFull(SQLiteFullException e) { Log.e(TAG, "Disk full, all write operations will be ignored", e); mIgnoreWrites = true; }