rename id field to databaseId in LocalFolder

This commit is contained in:
Vincent Breitmoser 2017-08-23 20:33:54 +02:00
parent 311efc6675
commit 8b8ee1ea6d
6 changed files with 43 additions and 44 deletions

View file

@ -127,7 +127,7 @@ public class EmailProviderCache {
synchronized (mHiddenMessageCache) { synchronized (mHiddenMessageCache) {
for (LocalMessage message : messages) { for (LocalMessage message : messages) {
long messageId = message.getDatabaseId(); long messageId = message.getDatabaseId();
mHiddenMessageCache.put(messageId, message.getFolder().getId()); mHiddenMessageCache.put(messageId, message.getFolder().getDatabaseId());
} }
} }
@ -146,7 +146,7 @@ public class EmailProviderCache {
for (Message message : messages) { for (Message message : messages) {
LocalMessage localMessage = (LocalMessage) message; LocalMessage localMessage = (LocalMessage) message;
long messageId = localMessage.getDatabaseId(); long messageId = localMessage.getDatabaseId();
long folderId = ((LocalFolder) localMessage.getFolder()).getId(); long folderId = ((LocalFolder) localMessage.getFolder()).getDatabaseId();
Long hiddenInFolder = mHiddenMessageCache.get(messageId); Long hiddenInFolder = mHiddenMessageCache.get(messageId);
if (hiddenInFolder != null && hiddenInFolder.longValue() == folderId) { if (hiddenInFolder != null && hiddenInFolder.longValue() == folderId) {

View file

@ -306,7 +306,7 @@ public class MessagingController {
private boolean isMessageSuppressed(LocalMessage message) { private boolean isMessageSuppressed(LocalMessage message) {
long messageId = message.getDatabaseId(); long messageId = message.getDatabaseId();
long folderId = message.getFolder().getId(); long folderId = message.getFolder().getDatabaseId();
EmailProviderCache cache = EmailProviderCache.getCache(message.getFolder().getAccountUuid(), context); EmailProviderCache cache = EmailProviderCache.getCache(message.getFolder().getAccountUuid(), context);
return cache.isMessageHidden(messageId, folderId); return cache.isMessageHidden(messageId, folderId);
@ -2721,7 +2721,7 @@ public class MessagingController {
fp.add(FetchProfile.Item.BODY); fp.add(FetchProfile.Item.BODY);
Timber.i("Scanning folder '%s' (%d) for messages to send", Timber.i("Scanning folder '%s' (%d) for messages to send",
account.getOutboxFolderName(), localFolder.getId()); account.getOutboxFolderName(), localFolder.getDatabaseId());
Transport transport = transportProvider.getTransport(K9.app, account); Transport transport = transportProvider.getTransport(K9.app, account);
@ -2836,11 +2836,11 @@ public class MessagingController {
message.setFlag(Flag.DELETED, true); message.setFlag(Flag.DELETED, true);
} else { } else {
LocalFolder localSentFolder = localStore.getFolder(account.getSentFolderName()); LocalFolder localSentFolder = localStore.getFolder(account.getSentFolderName());
Timber.i("Moving sent message to folder '%s' (%d)", account.getSentFolderName(), localSentFolder.getId()); Timber.i("Moving sent message to folder '%s' (%d)", account.getSentFolderName(), localSentFolder.getDatabaseId());
localFolder.moveMessages(Collections.singletonList(message), localSentFolder); localFolder.moveMessages(Collections.singletonList(message), localSentFolder);
Timber.i("Moved sent message to folder '%s' (%d)", account.getSentFolderName(), localSentFolder.getId()); Timber.i("Moved sent message to folder '%s' (%d)", account.getSentFolderName(), localSentFolder.getDatabaseId());
PendingCommand command = PendingAppend.create(localSentFolder.getName(), message.getUid()); PendingCommand command = PendingAppend.create(localSentFolder.getName(), message.getUid());
queuePendingCommand(account, command); queuePendingCommand(account, command);

View file

@ -78,7 +78,7 @@ public class LocalFolder extends Folder<LocalMessage> {
private String name = null; private String name = null;
private long id = -1; private long databaseId = -1;
private int visibleLimit = -1; private int visibleLimit = -1;
private String prefId = null; private String prefId = null;
@ -110,15 +110,15 @@ public class LocalFolder extends Folder<LocalMessage> {
} }
} }
public LocalFolder(LocalStore localStore, long id) { public LocalFolder(LocalStore localStore, long databaseId) {
super(); super();
this.localStore = localStore; this.localStore = localStore;
this.id = id; this.databaseId = databaseId;
attachmentInfoExtractor = localStore.getAttachmentInfoExtractor(); attachmentInfoExtractor = localStore.getAttachmentInfoExtractor();
} }
public long getId() { public long getDatabaseId() {
return id; return databaseId;
} }
public String getAccountUuid() public String getAccountUuid()
@ -161,7 +161,7 @@ public class LocalFolder extends Folder<LocalMessage> {
cursor = db.rawQuery(baseQuery + "where folders.name = ?", new String[] { name }); cursor = db.rawQuery(baseQuery + "where folders.name = ?", new String[] { name });
} else { } else {
cursor = db.rawQuery(baseQuery + "where folders.id = ?", new String[] { Long.toString( cursor = db.rawQuery(baseQuery + "where folders.id = ?", new String[] { Long.toString(
id) }); databaseId) });
} }
if (cursor.moveToFirst() && !cursor.isNull(LocalStore.FOLDER_ID_INDEX)) { if (cursor.moveToFirst() && !cursor.isNull(LocalStore.FOLDER_ID_INDEX)) {
@ -170,7 +170,7 @@ public class LocalFolder extends Folder<LocalMessage> {
open(cursor); open(cursor);
} }
} else { } else {
Timber.w("Creating folder %s with existing id %d", getName(), getId()); Timber.w("Creating folder %s with existing id %d", getName(), getDatabaseId());
create(FolderType.HOLDS_MESSAGES); create(FolderType.HOLDS_MESSAGES);
open(mode); open(mode);
} }
@ -188,7 +188,7 @@ public class LocalFolder extends Folder<LocalMessage> {
} }
void open(Cursor cursor) throws MessagingException { void open(Cursor cursor) throws MessagingException {
id = cursor.getInt(LocalStore.FOLDER_ID_INDEX); databaseId = cursor.getInt(LocalStore.FOLDER_ID_INDEX);
name = cursor.getString(LocalStore.FOLDER_NAME_INDEX); name = cursor.getString(LocalStore.FOLDER_NAME_INDEX);
visibleLimit = cursor.getInt(LocalStore.FOLDER_VISIBLE_LIMIT_INDEX); visibleLimit = cursor.getInt(LocalStore.FOLDER_VISIBLE_LIMIT_INDEX);
pushState = cursor.getString(LocalStore.FOLDER_PUSH_STATE_INDEX); pushState = cursor.getString(LocalStore.FOLDER_PUSH_STATE_INDEX);
@ -214,7 +214,7 @@ public class LocalFolder extends Folder<LocalMessage> {
@Override @Override
public boolean isOpen() { public boolean isOpen() {
return (id != -1 && name != null); return (databaseId != -1 && name != null);
} }
@Override @Override
@ -277,7 +277,7 @@ public class LocalFolder extends Folder<LocalMessage> {
@Override @Override
public void close() { public void close() {
id = -1; databaseId = -1;
} }
@Override @Override
@ -296,7 +296,7 @@ public class LocalFolder extends Folder<LocalMessage> {
cursor = db.rawQuery( cursor = db.rawQuery(
"SELECT COUNT(id) FROM messages " + "SELECT COUNT(id) FROM messages " +
"WHERE empty = 0 AND deleted = 0 and folder_id = ?", "WHERE empty = 0 AND deleted = 0 and folder_id = ?",
new String[] { Long.toString(id) }); new String[] { Long.toString(databaseId) });
cursor.moveToFirst(); cursor.moveToFirst();
return cursor.getInt(0); //messagecount return cursor.getInt(0); //messagecount
} finally { } finally {
@ -311,7 +311,7 @@ public class LocalFolder extends Folder<LocalMessage> {
@Override @Override
public int getUnreadMessageCount() throws MessagingException { public int getUnreadMessageCount() throws MessagingException {
if (id == -1) { if (databaseId == -1) {
open(OPEN_MODE_RW); open(OPEN_MODE_RW);
} }
@ -322,7 +322,7 @@ public class LocalFolder extends Folder<LocalMessage> {
int unreadMessageCount = 0; int unreadMessageCount = 0;
Cursor cursor = db.query("messages", new String[] { "COUNT(id)" }, Cursor cursor = db.query("messages", new String[] { "COUNT(id)" },
"folder_id = ? AND empty = 0 AND deleted = 0 AND read=0", "folder_id = ? AND empty = 0 AND deleted = 0 AND read=0",
new String[] { Long.toString(id) }, null, null, null); new String[] { Long.toString(databaseId) }, null, null, null);
try { try {
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
@ -342,7 +342,7 @@ public class LocalFolder extends Folder<LocalMessage> {
@Override @Override
public int getFlaggedMessageCount() throws MessagingException { public int getFlaggedMessageCount() throws MessagingException {
if (id == -1) { if (databaseId == -1) {
open(OPEN_MODE_RW); open(OPEN_MODE_RW);
} }
@ -353,7 +353,7 @@ public class LocalFolder extends Folder<LocalMessage> {
int flaggedMessageCount = 0; int flaggedMessageCount = 0;
Cursor cursor = db.query("messages", new String[] { "COUNT(id)" }, Cursor cursor = db.query("messages", new String[] { "COUNT(id)" },
"folder_id = ? AND empty = 0 AND deleted = 0 AND flagged = 1", "folder_id = ? AND empty = 0 AND deleted = 0 AND flagged = 1",
new String[] { Long.toString(id) }, null, null, null); new String[] { Long.toString(databaseId) }, null, null, null);
try { try {
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
@ -455,7 +455,7 @@ public class LocalFolder extends Folder<LocalMessage> {
} catch (MessagingException e) { } catch (MessagingException e) {
throw new WrappedException(e); throw new WrappedException(e);
} }
db.execSQL("UPDATE folders SET " + column + " = ? WHERE id = ?", new Object[] { value, id }); db.execSQL("UPDATE folders SET " + column + " = ? WHERE id = ?", new Object[] { value, databaseId });
return null; return null;
} }
}); });
@ -814,7 +814,7 @@ public class LocalFolder extends Folder<LocalMessage> {
try { try {
cursor = db.rawQuery( cursor = db.rawQuery(
"SELECT uid FROM messages WHERE id = ? AND folder_id = ?", "SELECT uid FROM messages WHERE id = ? AND folder_id = ?",
new String[] { Long.toString(id), Long.toString(LocalFolder.this.id) }); new String[] { Long.toString(id), Long.toString(LocalFolder.this.databaseId) });
if (!cursor.moveToNext()) { if (!cursor.moveToNext()) {
return null; return null;
} }
@ -851,7 +851,7 @@ public class LocalFolder extends Folder<LocalMessage> {
"LEFT JOIN message_parts ON (message_parts.id = messages.message_part_id) " + "LEFT JOIN message_parts ON (message_parts.id = messages.message_part_id) " +
"LEFT JOIN threads ON (threads.message_id = messages.id) " + "LEFT JOIN threads ON (threads.message_id = messages.id) " +
"WHERE uid = ? AND folder_id = ?", "WHERE uid = ? AND folder_id = ?",
new String[] { message.getUid(), Long.toString(id) }); new String[] { message.getUid(), Long.toString(databaseId) });
if (!cursor.moveToNext()) { if (!cursor.moveToNext()) {
return null; return null;
@ -887,7 +887,7 @@ public class LocalFolder extends Folder<LocalMessage> {
"FROM messages " + "FROM messages " +
"WHERE empty = 0 AND deleted = 0 AND " + "WHERE empty = 0 AND deleted = 0 AND " +
"folder_id = ? ORDER BY date DESC", "folder_id = ? ORDER BY date DESC",
new String[] { Long.toString(id) }); new String[] { Long.toString(databaseId) });
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
String uid = cursor.getString(0); String uid = cursor.getString(0);
@ -928,7 +928,7 @@ public class LocalFolder extends Folder<LocalMessage> {
"WHERE empty = 0 AND " + "WHERE empty = 0 AND " +
(includeDeleted ? "" : "deleted = 0 AND ") + (includeDeleted ? "" : "deleted = 0 AND ") +
"folder_id = ? ORDER BY date DESC", "folder_id = ? ORDER BY date DESC",
new String[] { Long.toString(id) }); new String[] { Long.toString(databaseId) });
} catch (MessagingException e) { } catch (MessagingException e) {
throw new WrappedException(e); throw new WrappedException(e);
} }
@ -955,7 +955,7 @@ public class LocalFolder extends Folder<LocalMessage> {
"FROM messages " + "FROM messages " +
"WHERE empty = 0 AND deleted = 0 AND " + "WHERE empty = 0 AND deleted = 0 AND " +
"folder_id = ? ORDER BY date DESC", "folder_id = ? ORDER BY date DESC",
new String[] { Long.toString(id) }); new String[] { Long.toString(databaseId) });
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
String uid = cursor.getString(0); String uid = cursor.getString(0);
@ -1042,7 +1042,7 @@ public class LocalFolder extends Folder<LocalMessage> {
Timber.d("Updating folder_id to %s for message with UID %s, " + Timber.d("Updating folder_id to %s for message with UID %s, " +
"id %d currently in folder %s", "id %d currently in folder %s",
lDestFolder.getId(), lDestFolder.getDatabaseId(),
message.getUid(), message.getUid(),
lMessage.getDatabaseId(), lMessage.getDatabaseId(),
getName()); getName());
@ -1062,7 +1062,7 @@ public class LocalFolder extends Folder<LocalMessage> {
String[] idArg = new String[] { Long.toString(msgId) }; String[] idArg = new String[] { Long.toString(msgId) };
ContentValues cv = new ContentValues(); ContentValues cv = new ContentValues();
cv.put("folder_id", lDestFolder.getId()); cv.put("folder_id", lDestFolder.getDatabaseId());
cv.put("uid", newUid); cv.put("uid", newUid);
db.update("messages", cv, "id = ?", idArg); db.update("messages", cv, "id = ?", idArg);
@ -1100,7 +1100,7 @@ public class LocalFolder extends Folder<LocalMessage> {
cv.putNull("flags"); cv.putNull("flags");
cv.put("read", 1); cv.put("read", 1);
cv.put("deleted", 1); cv.put("deleted", 1);
cv.put("folder_id", id); cv.put("folder_id", databaseId);
cv.put("empty", 0); cv.put("empty", 0);
String messageId = message.getMessageId(); String messageId = message.getMessageId();
@ -1220,7 +1220,7 @@ public class LocalFolder extends Folder<LocalMessage> {
"WHERE m.folder_id = ? AND m.message_id = ? " + "WHERE m.folder_id = ? AND m.message_id = ? " +
((onlyEmpty) ? "AND m.empty = 1 " : "") + ((onlyEmpty) ? "AND m.empty = 1 " : "") +
"ORDER BY m.id LIMIT 1"; "ORDER BY m.id LIMIT 1";
String[] selectionArgs = { Long.toString(id), messageId }; String[] selectionArgs = { Long.toString(databaseId), messageId };
Cursor cursor = db.rawQuery(sql, selectionArgs); Cursor cursor = db.rawQuery(sql, selectionArgs);
if (cursor != null) { if (cursor != null) {
@ -1353,7 +1353,7 @@ public class LocalFolder extends Folder<LocalMessage> {
cv.put("flagged", message.isSet(Flag.FLAGGED) ? 1 : 0); cv.put("flagged", message.isSet(Flag.FLAGGED) ? 1 : 0);
cv.put("answered", message.isSet(Flag.ANSWERED) ? 1 : 0); cv.put("answered", message.isSet(Flag.ANSWERED) ? 1 : 0);
cv.put("forwarded", message.isSet(Flag.FORWARDED) ? 1 : 0); cv.put("forwarded", message.isSet(Flag.FORWARDED) ? 1 : 0);
cv.put("folder_id", id); cv.put("folder_id", databaseId);
cv.put("to_list", Address.pack(message.getRecipients(RecipientType.TO))); cv.put("to_list", Address.pack(message.getRecipients(RecipientType.TO)));
cv.put("cc_list", Address.pack(message.getRecipients(RecipientType.CC))); cv.put("cc_list", Address.pack(message.getRecipients(RecipientType.CC)));
cv.put("bcc_list", Address.pack(message.getRecipients(RecipientType.BCC))); cv.put("bcc_list", Address.pack(message.getRecipients(RecipientType.BCC)));
@ -1747,7 +1747,7 @@ public class LocalFolder extends Folder<LocalMessage> {
"LEFT JOIN message_parts ON (message_parts.id = messages.message_part_id) " + "LEFT JOIN message_parts ON (message_parts.id = messages.message_part_id) " +
"LEFT JOIN threads ON (threads.message_id = messages.id) " + "LEFT JOIN threads ON (threads.message_id = messages.id) " +
"WHERE empty = 0 AND (folder_id = ? and date < ?)", "WHERE empty = 0 AND (folder_id = ? and date < ?)",
new String[] { Long.toString(id), Long.toString(cutoff) }); new String[] { Long.toString(databaseId), Long.toString(cutoff) });
for (Message message : messages) { for (Message message : messages) {
message.destroy(); message.destroy();
@ -1757,7 +1757,7 @@ public class LocalFolder extends Folder<LocalMessage> {
} }
public void clearAllMessages() throws MessagingException { public void clearAllMessages() throws MessagingException {
final String[] folderIdArg = new String[] { Long.toString(id) }; final String[] folderIdArg = new String[] { Long.toString(databaseId) };
open(OPEN_MODE_RO); open(OPEN_MODE_RO);
@ -1819,7 +1819,7 @@ public class LocalFolder extends Folder<LocalMessage> {
throw new WrappedException(e); throw new WrappedException(e);
} }
db.execSQL("DELETE FROM folders WHERE id = ?", new Object[] db.execSQL("DELETE FROM folders WHERE id = ?", new Object[]
{ Long.toString(id), }); { Long.toString(databaseId), });
return null; return null;
} }
}); });
@ -1862,7 +1862,7 @@ public class LocalFolder extends Folder<LocalMessage> {
// make it an empty message. // make it an empty message.
ContentValues cv = new ContentValues(); ContentValues cv = new ContentValues();
cv.put("id", messageId); cv.put("id", messageId);
cv.put("folder_id", getId()); cv.put("folder_id", getDatabaseId());
cv.put("deleted", 0); cv.put("deleted", 0);
cv.put("message_id", messageIdHeader); cv.put("message_id", messageIdHeader);
cv.put("empty", 1); cv.put("empty", 1);
@ -2068,7 +2068,7 @@ public class LocalFolder extends Folder<LocalMessage> {
try { try {
open(OPEN_MODE_RO); open(OPEN_MODE_RO);
cursor = db.rawQuery("SELECT MAX(uid) FROM messages WHERE folder_id=?", new String[] { Long.toString( cursor = db.rawQuery("SELECT MAX(uid) FROM messages WHERE folder_id=?", new String[] { Long.toString(
id) }); databaseId) });
if (cursor.getCount() > 0) { if (cursor.getCount() > 0) {
cursor.moveToFirst(); cursor.moveToFirst();
return cursor.getInt(0); return cursor.getInt(0);
@ -2094,7 +2094,7 @@ public class LocalFolder extends Folder<LocalMessage> {
try { try {
open(OPEN_MODE_RO); open(OPEN_MODE_RO);
cursor = db.rawQuery("SELECT MIN(date) FROM messages WHERE folder_id=?", new String[] { Long.toString( cursor = db.rawQuery("SELECT MIN(date) FROM messages WHERE folder_id=?", new String[] { Long.toString(
id) }); databaseId) });
if (cursor.getCount() > 0) { if (cursor.getCount() > 0) {
cursor.moveToFirst(); cursor.moveToFirst();
return cursor.getLong(0); return cursor.getLong(0);
@ -2154,7 +2154,7 @@ public class LocalFolder extends Folder<LocalMessage> {
// Create placeholder message in 'messages' table // Create placeholder message in 'messages' table
ContentValues cv = new ContentValues(); ContentValues cv = new ContentValues();
cv.put("message_id", reference); cv.put("message_id", reference);
cv.put("folder_id", id); cv.put("folder_id", databaseId);
cv.put("empty", 1); cv.put("empty", 1);
long newMsgId = db.insert("messages", null, cv); long newMsgId = db.insert("messages", null, cv);
@ -2235,7 +2235,7 @@ public class LocalFolder extends Folder<LocalMessage> {
StringBuilder selection = new StringBuilder(); StringBuilder selection = new StringBuilder();
selection.append("folder_id = ? AND UID IN ("); selection.append("folder_id = ? AND UID IN (");
selectionArgs.add(Long.toString(id)); selectionArgs.add(Long.toString(databaseId));
int count = Math.min(messages.size() - start, LocalStore.UID_CHECK_BATCH_SIZE); int count = Math.min(messages.size() - start, LocalStore.UID_CHECK_BATCH_SIZE);

View file

@ -5,7 +5,6 @@ import java.util.List;
import timber.log.Timber; import timber.log.Timber;
import com.fsck.k9.Account; import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Folder; import com.fsck.k9.mail.Folder;
import com.fsck.k9.mailstore.LocalFolder; import com.fsck.k9.mailstore.LocalFolder;
@ -111,7 +110,7 @@ public class SqlQueryBuilder {
LocalStore localStore = account.getLocalStore(); LocalStore localStore = account.getLocalStore();
LocalFolder folder = localStore.getFolder(folderName); LocalFolder folder = localStore.getFolder(folderName);
folder.open(Folder.OPEN_MODE_RO); folder.open(Folder.OPEN_MODE_RO);
folderId = folder.getId(); folderId = folder.getDatabaseId();
} catch (MessagingException e) { } catch (MessagingException e) {
//FIXME //FIXME
e.printStackTrace(); e.printStackTrace();

View file

@ -42,7 +42,7 @@ public class EmailProviderCacheTest {
cache = EmailProviderCache.getCache(UUID.randomUUID().toString(), RuntimeEnvironment.application); cache = EmailProviderCache.getCache(UUID.randomUUID().toString(), RuntimeEnvironment.application);
when(mockLocalMessage.getDatabaseId()).thenReturn(localMessageId); when(mockLocalMessage.getDatabaseId()).thenReturn(localMessageId);
when(mockLocalMessage.getFolder()).thenReturn(mockLocalMessageFolder); when(mockLocalMessage.getFolder()).thenReturn(mockLocalMessageFolder);
when(mockLocalMessageFolder.getId()).thenReturn(localMessageFolderId); when(mockLocalMessageFolder.getDatabaseId()).thenReturn(localMessageFolderId);
} }
@Test @Test

View file

@ -856,7 +856,7 @@ public class MessagingControllerTest {
when(account.hasSentFolder()).thenReturn(true); when(account.hasSentFolder()).thenReturn(true);
when(account.getSentFolderName()).thenReturn(SENT_FOLDER_NAME); when(account.getSentFolderName()).thenReturn(SENT_FOLDER_NAME);
when(localStore.getFolder(SENT_FOLDER_NAME)).thenReturn(sentFolder); when(localStore.getFolder(SENT_FOLDER_NAME)).thenReturn(sentFolder);
when(sentFolder.getId()).thenReturn(1L); when(sentFolder.getDatabaseId()).thenReturn(1L);
when(localFolder.exists()).thenReturn(true); when(localFolder.exists()).thenReturn(true);
when(transportProvider.getTransport(appContext, account)).thenReturn(transport); when(transportProvider.getTransport(appContext, account)).thenReturn(transport);
when(localFolder.getMessages(null)).thenReturn(Collections.singletonList(localMessageToSend1)); when(localFolder.getMessages(null)).thenReturn(Collections.singletonList(localMessageToSend1));