@Test public void testMergingUnchangedPropertiesDoesNotCreateUpdate() throws Exception { Transaction txn = new Transaction(null, false); MessageId updateId = new MessageId(getRandomId()); Map<MessageId, BdfDictionary> messageMetadata = Collections.singletonMap(updateId, BdfDictionary.of( new BdfEntry("transportId", "foo"), new BdfEntry("version", 1), new BdfEntry("local", true) )); BdfList update = BdfList.of("foo", 1, fooPropertiesDict); context.checking(new Expectations() {{ oneOf(db).startTransaction(false); will(returnValue(txn)); oneOf(clientHelper).getMessageMetadataAsDictionary(txn, localGroup.getId()); will(returnValue(messageMetadata)); oneOf(clientHelper).getMessageAsList(txn, updateId); will(returnValue(update)); oneOf(clientHelper).parseAndValidateTransportProperties( fooPropertiesDict); will(returnValue(fooProperties)); oneOf(db).commitTransaction(txn); oneOf(db).endTransaction(txn); }}); TransportPropertyManagerImpl t = createInstance(); t.mergeLocalProperties(new TransportId("foo"), fooProperties); }
@Override public void mergeLocalProperties(TransportId t, TransportProperties p) throws DbException { try { Transaction txn = db.startTransaction(false); try { TransportProperties merged; boolean changed; LatestUpdate latest = findLatest(txn, localGroup.getId(), t, true); if (latest == null) { merged = p; changed = true; } else { BdfList message = clientHelper.getMessageAsList(txn, latest.messageId); if (message == null) throw new DbException(); TransportProperties old = parseProperties(message); merged = new TransportProperties(old); merged.putAll(p); changed = !merged.equals(old); } if (changed) { long version = latest == null ? 1 : latest.version + 1; storeMessage(txn, localGroup.getId(), t, merged, version, true, false); if (latest != null) db.removeMessage(txn, latest.messageId); for (Contact c : db.getContacts(txn)) { Group g = getContactGroup(c); latest = findLatest(txn, g.getId(), t, true); version = latest == null ? 1 : latest.version + 1; storeMessage(txn, g.getId(), t, merged, version, true, true); if (latest != null) db.removeMessage(txn, latest.messageId); } } db.commitTransaction(txn); } finally { db.endTransaction(txn); } } catch (FormatException e) { throw new DbException(e); } }
TransportPropertyManagerImpl implements TransportPropertyManager,
		Client, ContactHook, ClientVersioningHook, IncomingMessageHook { @Override public void mergeLocalProperties(TransportId t, TransportProperties p) throws DbException { try { Transaction txn = db.startTransaction(false); try { TransportProperties merged; boolean changed; LatestUpdate latest = findLatest(txn, localGroup.getId(), t, true); if (latest == null) { merged = p; changed = true; } else { BdfList message = clientHelper.getMessageAsList(txn, latest.messageId); if (message == null) throw new DbException(); TransportProperties old = parseProperties(message); merged = new TransportProperties(old); merged.putAll(p); changed = !merged.equals(old); } if (changed) { long version = latest == null ? 1 : latest.version + 1; storeMessage(txn, localGroup.getId(), t, merged, version, true, false); if (latest != null) db.removeMessage(txn, latest.messageId); for (Contact c : db.getContacts(txn)) { Group g = getContactGroup(c); latest = findLatest(txn, g.getId(), t, true); version = latest == null ? 1 : latest.version + 1; storeMessage(txn, g.getId(), t, merged, version, true, true); if (latest != null) db.removeMessage(txn, latest.messageId); } } db.commitTransaction(txn); } finally { db.endTransaction(txn); } } catch (FormatException e) { throw new DbException(e); } } }
TransportPropertyManagerImpl implements TransportPropertyManager,
		Client, ContactHook, ClientVersioningHook, IncomingMessageHook { @Override public void mergeLocalProperties(TransportId t, TransportProperties p) throws DbException { try { Transaction txn = db.startTransaction(false); try { TransportProperties merged; boolean changed; LatestUpdate latest = findLatest(txn, localGroup.getId(), t, true); if (latest == null) { merged = p; changed = true; } else { BdfList message = clientHelper.getMessageAsList(txn, latest.messageId); if (message == null) throw new DbException(); TransportProperties old = parseProperties(message); merged = new TransportProperties(old); merged.putAll(p); changed = !merged.equals(old); } if (changed) { long version = latest == null ? 1 : latest.version + 1; storeMessage(txn, localGroup.getId(), t, merged, version, true, false); if (latest != null) db.removeMessage(txn, latest.messageId); for (Contact c : db.getContacts(txn)) { Group g = getContactGroup(c); latest = findLatest(txn, g.getId(), t, true); version = latest == null ? 1 : latest.version + 1; storeMessage(txn, g.getId(), t, merged, version, true, true); if (latest != null) db.removeMessage(txn, latest.messageId); } } db.commitTransaction(txn); } finally { db.endTransaction(txn); } } catch (FormatException e) { throw new DbException(e); } } @Inject  TransportPropertyManagerImpl(DatabaseComponent db,
			ClientHelper clientHelper,
			ClientVersioningManager clientVersioningManager,
			MetadataParser metadataParser,
			ContactGroupFactory contactGroupFactory, Clock clock); }
TransportPropertyManagerImpl implements TransportPropertyManager,
		Client, ContactHook, ClientVersioningHook, IncomingMessageHook { @Override public void mergeLocalProperties(TransportId t, TransportProperties p) throws DbException { try { Transaction txn = db.startTransaction(false); try { TransportProperties merged; boolean changed; LatestUpdate latest = findLatest(txn, localGroup.getId(), t, true); if (latest == null) { merged = p; changed = true; } else { BdfList message = clientHelper.getMessageAsList(txn, latest.messageId); if (message == null) throw new DbException(); TransportProperties old = parseProperties(message); merged = new TransportProperties(old); merged.putAll(p); changed = !merged.equals(old); } if (changed) { long version = latest == null ? 1 : latest.version + 1; storeMessage(txn, localGroup.getId(), t, merged, version, true, false); if (latest != null) db.removeMessage(txn, latest.messageId); for (Contact c : db.getContacts(txn)) { Group g = getContactGroup(c); latest = findLatest(txn, g.getId(), t, true); version = latest == null ? 1 : latest.version + 1; storeMessage(txn, g.getId(), t, merged, version, true, true); if (latest != null) db.removeMessage(txn, latest.messageId); } } db.commitTransaction(txn); } finally { db.endTransaction(txn); } } catch (FormatException e) { throw new DbException(e); } } @Inject  TransportPropertyManagerImpl(DatabaseComponent db,
			ClientHelper clientHelper,
			ClientVersioningManager clientVersioningManager,
			MetadataParser metadataParser,
			ContactGroupFactory contactGroupFactory, Clock clock); @Override void createLocalState(Transaction txn); @Override void addingContact(Transaction txn, Contact c); @Override void removingContact(Transaction txn, Contact c); @Override void onClientVisibilityChanging(Transaction txn, Contact c,
			Visibility v); @Override boolean incomingMessage(Transaction txn, Message m, Metadata meta); @Override void addRemoteProperties(Transaction txn, ContactId c,
			Map<TransportId, TransportProperties> props); @Override Map<TransportId, TransportProperties> getLocalProperties(); @Override Map<TransportId, TransportProperties> getLocalProperties(
			Transaction txn); @Override TransportProperties getLocalProperties(TransportId t); @Override Map<ContactId, TransportProperties> getRemoteProperties(
			TransportId t); @Override TransportProperties getRemoteProperties(ContactId c, TransportId t); @Override void mergeLocalProperties(TransportId t, TransportProperties p); }
TransportPropertyManagerImpl implements TransportPropertyManager,
		Client, ContactHook, ClientVersioningHook, IncomingMessageHook { @Override public void mergeLocalProperties(TransportId t, TransportProperties p) throws DbException { try { Transaction txn = db.startTransaction(false); try { TransportProperties merged; boolean changed; LatestUpdate latest = findLatest(txn, localGroup.getId(), t, true); if (latest == null) { merged = p; changed = true; } else { BdfList message = clientHelper.getMessageAsList(txn, latest.messageId); if (message == null) throw new DbException(); TransportProperties old = parseProperties(message); merged = new TransportProperties(old); merged.putAll(p); changed = !merged.equals(old); } if (changed) { long version = latest == null ? 1 : latest.version + 1; storeMessage(txn, localGroup.getId(), t, merged, version, true, false); if (latest != null) db.removeMessage(txn, latest.messageId); for (Contact c : db.getContacts(txn)) { Group g = getContactGroup(c); latest = findLatest(txn, g.getId(), t, true); version = latest == null ? 1 : latest.version + 1; storeMessage(txn, g.getId(), t, merged, version, true, true); if (latest != null) db.removeMessage(txn, latest.messageId); } } db.commitTransaction(txn); } finally { db.endTransaction(txn); } } catch (FormatException e) { throw new DbException(e); } } @Inject  TransportPropertyManagerImpl(DatabaseComponent db,
			ClientHelper clientHelper,
			ClientVersioningManager clientVersioningManager,
			MetadataParser metadataParser,
			ContactGroupFactory contactGroupFactory, Clock clock); @Override void createLocalState(Transaction txn); @Override void addingContact(Transaction txn, Contact c); @Override void removingContact(Transaction txn, Contact c); @Override void onClientVisibilityChanging(Transaction txn, Contact c,
			Visibility v); @Override boolean incomingMessage(Transaction txn, Message m, Metadata meta); @Override void addRemoteProperties(Transaction txn, ContactId c,
			Map<TransportId, TransportProperties> props); @Override Map<TransportId, TransportProperties> getLocalProperties(); @Override Map<TransportId, TransportProperties> getLocalProperties(
			Transaction txn); @Override TransportProperties getLocalProperties(TransportId t); @Override Map<ContactId, TransportProperties> getRemoteProperties(
			TransportId t); @Override TransportProperties getRemoteProperties(ContactId c, TransportId t); @Override void mergeLocalProperties(TransportId t, TransportProperties p);  }