/** * Commit the transaction. If the commit fails due a conflict in a unique key constraint a {@link MailboxExistsException} * will get thrown */ @Override protected void commit() throws MailboxException { try { getEntityManager().getTransaction().commit(); } catch (PersistenceException e) { if (e instanceof EntityExistsException) { throw new MailboxExistsException(lastMailboxName); } if (e instanceof RollbackException) { Throwable t = e.getCause(); if (t != null && t instanceof EntityExistsException) { throw new MailboxExistsException(lastMailboxName); } } throw new MailboxException("Commit of transaction failed", e); } }
public String toString() { return getMessage(); }
@Override public MailboxId save(Mailbox mailbox) throws MailboxException { Preconditions.checkArgument(mailbox instanceof SimpleMailbox); SimpleMailbox cassandraMailbox = (SimpleMailbox) mailbox; CassandraId cassandraId = retrieveId(cassandraMailbox); cassandraMailbox.setMailboxId(cassandraId); boolean applied = trySave(cassandraMailbox, cassandraId).join(); if (!applied) { throw new MailboxExistsException(mailbox.generateAssociatedPath().asString()); } return cassandraId; }
@Override public MailboxId save(Mailbox mailbox) throws MailboxException { InMemoryId id = (InMemoryId) mailbox.getMailboxId(); if (id == null) { id = InMemoryId.of(mailboxIdGenerator.incrementAndGet()); mailbox.setMailboxId(id); } else { try { Mailbox mailboxWithPreviousName = findMailboxById(id); mailboxesByPath.remove(mailboxWithPreviousName.generateAssociatedPath()); } catch (MailboxNotFoundException e) { // No need to remove the previous mailbox } } Mailbox previousMailbox = mailboxesByPath.putIfAbsent(mailbox.generateAssociatedPath(), mailbox); if (previousMailbox != null) { throw new MailboxExistsException(mailbox.getName()); } return mailbox.getMailboxId(); }
@Override public void renameMailbox(MailboxPath from, MailboxPath to, MailboxSession session) throws MailboxException { LOGGER.debug("renameMailbox {} to {}", from, to); if (mailboxExists(to, session)) { throw new MailboxExistsException(to.toString()); } if (isMailboxNameTooLong(to)) { throw new TooLongMailboxNameException("Mailbox name exceed maximum size of " + MAX_MAILBOX_NAME_LENGTH + " characters"); } assertIsOwner(session, from); MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); mapper.execute(Mapper.toTransaction(() -> doRenameMailbox(from, to, session, mapper))); }
throw new MailboxExistsException(sanitizedMailboxPath.asString());
@Override public MailboxId save(Mailbox mailbox) throws MailboxException { try { if (isPathAlreadyUsedByAnotherMailbox(mailbox)) { throw new MailboxExistsException(mailbox.getName()); } this.lastMailboxName = mailbox.getName(); JPAMailbox persistedMailbox = JPAMailbox.from(mailbox); getEntityManager().persist(persistedMailbox); if (!(mailbox instanceof JPAMailbox)) { mailbox.setMailboxId(persistedMailbox.getMailboxId()); } return mailbox.getMailboxId(); } catch (PersistenceException e) { throw new MailboxException("Save of mailbox " + mailbox.getName() + " failed", e); } }