public int size() { if (isNil()) { return 0; } return value.get().length(); }
@Override public void insertAnnotation(MailboxId mailboxId, MailboxAnnotation mailboxAnnotation) { Preconditions.checkArgument(!mailboxAnnotation.isNil()); lock.writeLock().lock(); try { mailboxesAnnotations.put((InMemoryId)mailboxId, mailboxAnnotation.getKey().asString(), mailboxAnnotation.getValue().get()); } finally { lock.writeLock().unlock(); } }
@Override public void insertAnnotation(MailboxId mailboxId, MailboxAnnotation mailboxAnnotation) { Preconditions.checkArgument(!mailboxAnnotation.isNil()); session.execute(insertInto(CassandraAnnotationTable.TABLE_NAME) .value(CassandraAnnotationTable.MAILBOX_ID, ((CassandraId) mailboxId).asUuid()) .value(CassandraAnnotationTable.KEY, mailboxAnnotation.getKey().asString()) .value(CassandraAnnotationTable.VALUE, mailboxAnnotation.getValue().get())); }
@Test public void isNilShouldReturnTrueForNilObject() throws Exception { MailboxAnnotation nilAnnotation = MailboxAnnotation.nil(ANNOTATION_KEY); assertThat(nilAnnotation.isNil()).isTrue(); }
@Test public void isNilShouldReturnFalseForNotNilObject() throws Exception { MailboxAnnotation nilAnnotation = MailboxAnnotation.newInstance(ANNOTATION_KEY, ANNOTATION_VALUE); assertThat(nilAnnotation.isNil()).isFalse(); }
private void composeAnnotation(ImapResponseComposer composer, ImapSession session, MailboxAnnotation annotation) throws IOException { if (annotation.isNil()) { LOGGER.warn("There is nil data of key {} on store: ", annotation.getKey().asString()); } else { composer.message(annotation.getKey().asString()); composer.quote(annotation.getValue().orElse("")); } }
@Override public void insertAnnotation(MailboxId mailboxId, MailboxAnnotation mailboxAnnotation) { Preconditions.checkArgument(!mailboxAnnotation.isNil()); JPAId jpaId = (JPAId) mailboxId; if (getAnnotationsByKeys(mailboxId, ImmutableSet.of(mailboxAnnotation.getKey())).isEmpty()) { getEntityManager().persist( new JPAMailboxAnnotation(jpaId.getRawId(), mailboxAnnotation.getKey().asString(), mailboxAnnotation.getValue().orElse(null))); } else { getEntityManager().find(JPAMailboxAnnotation.class, new JPAMailboxAnnotationId(jpaId.getRawId(), mailboxAnnotation.getKey().asString())) .setValue(mailboxAnnotation.getValue().orElse(null)); } }
@Override public void updateAnnotations(MailboxPath mailboxPath, MailboxSession session, List<MailboxAnnotation> mailboxAnnotations) throws MailboxException { AnnotationMapper annotationMapper = mailboxSessionMapperFactory.getAnnotationMapper(session); MailboxId mailboxId = checkThenGetMailboxId(mailboxPath, session); annotationMapper.execute(Mapper.toTransaction(() -> { for (MailboxAnnotation annotation : mailboxAnnotations) { if (annotation.isNil()) { annotationMapper.deleteAnnotation(mailboxId, annotation.getKey()); } else if (canInsertOrUpdate(mailboxId, annotation, annotationMapper)) { annotationMapper.insertAnnotation(mailboxId, annotation); } } })); }