private long saveMessagePart(SQLiteDatabase db, PartContainer partContainer, long rootMessagePartId, int order) throws IOException, MessagingException { Part part = partContainer.part; ContentValues cv = new ContentValues(); if (rootMessagePartId != -1) { cv.put("root", rootMessagePartId); } cv.put("parent", partContainer.parent); cv.put("seq", order); cv.put("server_extra", part.getServerExtra()); return updateOrInsertMessagePart(db, cv, part, INVALID_MESSAGE_PART_ID); }
@Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { long messagePartId; Cursor cursor = db.query("message_parts", new String[] { "id" }, "root = ? AND server_extra = ?", new String[] { Long.toString(message.getMessagePartId()), part.getServerExtra() }, null, null, null); try { if (!cursor.moveToFirst()) { throw new IllegalStateException("Message part not found"); } messagePartId = cursor.getLong(0); } finally { cursor.close(); } try { updateOrInsertMessagePart(db, new ContentValues(), part, messagePartId); } catch (Exception e) { Timber.e(e, "Error writing message part"); } return null; } });
private Part createPart(String serverExtra) { Part part = mock(Part.class); when(part.getServerExtra()).thenReturn(serverExtra); return part; }
checkOpen(); String partId = part.getServerExtra();