Browse code

[check_and_repair] ALLOA-19 Fix: create body if it does not exist, update does not upsert t_message_body

Thomas Cataldo authored on 09/07/2019 19:51:42
Showing 3 changed files
... ...
@@ -40,8 +40,8 @@ import org.junit.Test;
40 40
 import net.bluemind.backend.cyrus.replication.testhelper.CyrusGUID;
41 41
 import net.bluemind.backend.cyrus.replication.testhelper.MailboxUniqueId;
42 42
 import net.bluemind.backend.mail.api.MailboxItem.SystemFlag;
43
-import net.bluemind.backend.mail.replica.api.ImapBinding;
44 43
 import net.bluemind.backend.mail.replica.api.IMailReplicaUids;
44
+import net.bluemind.backend.mail.replica.api.ImapBinding;
45 45
 import net.bluemind.backend.mail.replica.api.MailboxRecord;
46 46
 import net.bluemind.backend.mail.replica.api.MailboxRecord.InternalFlag;
47 47
 import net.bluemind.backend.mail.replica.persistence.MailboxRecordStore;
... ...
@@ -70,8 +70,7 @@ public class MailboxRecordStoreTests {
70 70
 				securityContext);
71 71
 		String boxUniqueId = MailboxUniqueId.random();
72 72
 		String containerId = IMailReplicaUids.mboxRecords(boxUniqueId);
73
-		Container container = Container.create(containerId, IMailReplicaUids.MAILBOX_RECORDS, "test", "me",
74
-				true);
73
+		Container container = Container.create(containerId, IMailReplicaUids.MAILBOX_RECORDS, "test", "me", true);
75 74
 		container = containerHome.create(container);
76 75
 
77 76
 		assertNotNull(container);
... ...
@@ -107,9 +106,6 @@ public class MailboxRecordStoreTests {
107 106
 		itemStore.update(it.uid, null, Collections.emptyList());
108 107
 		unread = boxRecordStore.unreadItems();
109 108
 		assertFalse(unread.isEmpty());
110
-
111
-		List<ImapBinding> toUpdate = boxRecordStore.havingBodyVersionLowerThan(0);
112
-		assertTrue(toUpdate.isEmpty());
113 109
 	}
114 110
 
115 111
 	@Test
... ...
@@ -157,7 +157,11 @@ public class DbMessageBodiesService implements IDbMessageBodies {
157 157
 	@Override
158 158
 	public void update(MessageBody mb) {
159 159
 		try {
160
-			bodyStore.update(mb);
160
+			if (exists(mb.guid)) {
161
+				bodyStore.update(mb);
162
+			} else {
163
+				bodyStore.create(mb);
164
+			}
161 165
 			BodiesCache.bodies.put(mb.guid, mb);
162 166
 		} catch (SQLException e) {
163 167
 			throw ServerFault.sqlFault(e);
... ...
@@ -36,8 +36,8 @@ import net.bluemind.backend.mail.parsing.BodyStreamProcessor;
36 36
 import net.bluemind.backend.mail.replica.api.IDbMailboxRecords;
37 37
 import net.bluemind.backend.mail.replica.api.IDbMessageBodies;
38 38
 import net.bluemind.backend.mail.replica.api.IDbReplicatedMailboxes;
39
-import net.bluemind.backend.mail.replica.api.ImapBinding;
40 39
 import net.bluemind.backend.mail.replica.api.IMailReplicaUids;
40
+import net.bluemind.backend.mail.replica.api.ImapBinding;
41 41
 import net.bluemind.core.api.Stream;
42 42
 import net.bluemind.core.api.fault.ServerFault;
43 43
 import net.bluemind.core.api.report.DiagnosticReport;