@Test public void testUndeleteThrowsExceptionWhenNotDeleted() throws TabUndeletionException { boolean exceptionOccurred = false; try { jpaTabGroupMapper.undeleteTab(fordsFirstTabId); } catch (TabUndeletionException ex) { exceptionOccurred = true; assertEquals("TabUndeletionException was thrown, but didn't contain the " + " tab id that the caller was trying to delete from.", fordsFirstTabId, ex.getTabId()); } assertTrue("TabUndeletionException didn't occur when trying to delete a Tab that wasn't deleted.", exceptionOccurred); }
public Tab undeleteTab(final long tabId) throws TabUndeletionException { TabGroup tabGroup = null; long start; try { start = System.currentTimeMillis(); logger.debug("***Getting tab group by tab Id"); tabGroup = getTabGroupByTabId(tabId, true); logger.debug("***Done getting tab group by tab Id (" + (System.currentTimeMillis() - start) + "ms"); } catch (Exception ex) { throw new TabUndeletionException("Could not find either the specified Tab or tabGroup for TabId=" + tabId, tabId); } start = System.currentTimeMillis(); logger.debug("***Getting tab to undelete by tab Id and status"); Tab tabToUndelete = (Tab) getEntityManager().createQuery("from Tab where id = :TabId and deleted = true") .setParameter("TabId", tabId).getSingleResult(); logger.debug("***Done Getting tab to undelete by tab Id and status (" + (System.currentTimeMillis() - start) + "ms"); if (tabToUndelete == null) { throw new TabUndeletionException("Failure when trying to get Tab with id=" + tabId, tabId); } try { tabGroup.getTabs().add(tabToUndelete.getTabIndex(), tabToUndelete); start = System.currentTimeMillis(); logger.debug("***Update tab status"); getEntityManager() .createQuery( "update versioned Tab set deleted = false, " + "dateDeleted = null, tabGroupId = :tabGroupId " + "where id = :TabId") .setParameter("TabId", tabToUndelete.getId()).setParameter("tabGroupId", tabGroup.getId()) .executeUpdate(); logger.debug("***Done Update tab status (" + (System.currentTimeMillis() - start) + "ms)"); logger.debug("Un-deleted the tab with id=" + tabToUndelete.getId()); start = System.currentTimeMillis(); logger.debug("***Update tab template status"); getEntityManager() .createQuery( "update versioned TabTemplate set deleted = false, " + "dateDeleted = null " + "where id = :TabTemplateId") .setParameter("TabTemplateId", tabToUndelete.getTemplate().getId()).executeUpdate(); logger.debug("***Done Update tab template status (" + (System.currentTimeMillis() - start) + "ms)"); logger.debug("Un-deleted the tab template with id=" + tabToUndelete.getTemplate().getId()); start = System.currentTimeMillis(); logger.debug("***Update tab template's gadgets status"); getEntityManager() .createQuery( "update versioned Gadget set deleted = false, " + "dateDeleted = null " + "where template.id = :TabTemplateId") .setParameter("TabTemplateId", tabToUndelete.getTemplate().getId()).executeUpdate(); logger.debug( "***Done Update tab template's gadgets status (" + (System.currentTimeMillis() - start) + "ms)"); logger.debug("Un-deleted gadgets belonging to tab template with id=" + tabToUndelete.getTemplate().getId()); start = System.currentTimeMillis(); logger.debug("***entity manager flush"); getEntityManager().flush(); getEntityManager().clear(); logger.debug("***Done entity manager flush (" + (System.currentTimeMillis() - start) + "ms)"); start = System.currentTimeMillis(); logger.debug("***Getting tab to return by tab Id and status"); tabToUndelete = (Tab) getEntityManager() .createQuery("from Tab t left join fetch t.template where t.id = :tabId and t.deleted = 'false'") .setParameter("tabId", tabId).getSingleResult(); tabToUndelete.getGadgets().size(); logger.debug("***Done Getting tab to return by tab Id and status (" + (System.currentTimeMillis() - start) + "ms)"); return tabToUndelete; } catch (Exception ex) { throw new TabUndeletionException("An error occurred while trying to undelete the Tab with TabId=" + tabId, tabId); } }
TabGroupMapper extends DomainEntityMapper<TabGroup> { public Tab undeleteTab(final long tabId) throws TabUndeletionException { TabGroup tabGroup = null; long start; try { start = System.currentTimeMillis(); logger.debug("***Getting tab group by tab Id"); tabGroup = getTabGroupByTabId(tabId, true); logger.debug("***Done getting tab group by tab Id (" + (System.currentTimeMillis() - start) + "ms"); } catch (Exception ex) { throw new TabUndeletionException("Could not find either the specified Tab or tabGroup for TabId=" + tabId, tabId); } start = System.currentTimeMillis(); logger.debug("***Getting tab to undelete by tab Id and status"); Tab tabToUndelete = (Tab) getEntityManager().createQuery("from Tab where id = :TabId and deleted = true") .setParameter("TabId", tabId).getSingleResult(); logger.debug("***Done Getting tab to undelete by tab Id and status (" + (System.currentTimeMillis() - start) + "ms"); if (tabToUndelete == null) { throw new TabUndeletionException("Failure when trying to get Tab with id=" + tabId, tabId); } try { tabGroup.getTabs().add(tabToUndelete.getTabIndex(), tabToUndelete); start = System.currentTimeMillis(); logger.debug("***Update tab status"); getEntityManager() .createQuery( "update versioned Tab set deleted = false, " + "dateDeleted = null, tabGroupId = :tabGroupId " + "where id = :TabId") .setParameter("TabId", tabToUndelete.getId()).setParameter("tabGroupId", tabGroup.getId()) .executeUpdate(); logger.debug("***Done Update tab status (" + (System.currentTimeMillis() - start) + "ms)"); logger.debug("Un-deleted the tab with id=" + tabToUndelete.getId()); start = System.currentTimeMillis(); logger.debug("***Update tab template status"); getEntityManager() .createQuery( "update versioned TabTemplate set deleted = false, " + "dateDeleted = null " + "where id = :TabTemplateId") .setParameter("TabTemplateId", tabToUndelete.getTemplate().getId()).executeUpdate(); logger.debug("***Done Update tab template status (" + (System.currentTimeMillis() - start) + "ms)"); logger.debug("Un-deleted the tab template with id=" + tabToUndelete.getTemplate().getId()); start = System.currentTimeMillis(); logger.debug("***Update tab template's gadgets status"); getEntityManager() .createQuery( "update versioned Gadget set deleted = false, " + "dateDeleted = null " + "where template.id = :TabTemplateId") .setParameter("TabTemplateId", tabToUndelete.getTemplate().getId()).executeUpdate(); logger.debug( "***Done Update tab template's gadgets status (" + (System.currentTimeMillis() - start) + "ms)"); logger.debug("Un-deleted gadgets belonging to tab template with id=" + tabToUndelete.getTemplate().getId()); start = System.currentTimeMillis(); logger.debug("***entity manager flush"); getEntityManager().flush(); getEntityManager().clear(); logger.debug("***Done entity manager flush (" + (System.currentTimeMillis() - start) + "ms)"); start = System.currentTimeMillis(); logger.debug("***Getting tab to return by tab Id and status"); tabToUndelete = (Tab) getEntityManager() .createQuery("from Tab t left join fetch t.template where t.id = :tabId and t.deleted = 'false'") .setParameter("tabId", tabId).getSingleResult(); tabToUndelete.getGadgets().size(); logger.debug("***Done Getting tab to return by tab Id and status (" + (System.currentTimeMillis() - start) + "ms)"); return tabToUndelete; } catch (Exception ex) { throw new TabUndeletionException("An error occurred while trying to undelete the Tab with TabId=" + tabId, tabId); } } }
TabGroupMapper extends DomainEntityMapper<TabGroup> { public Tab undeleteTab(final long tabId) throws TabUndeletionException { TabGroup tabGroup = null; long start; try { start = System.currentTimeMillis(); logger.debug("***Getting tab group by tab Id"); tabGroup = getTabGroupByTabId(tabId, true); logger.debug("***Done getting tab group by tab Id (" + (System.currentTimeMillis() - start) + "ms"); } catch (Exception ex) { throw new TabUndeletionException("Could not find either the specified Tab or tabGroup for TabId=" + tabId, tabId); } start = System.currentTimeMillis(); logger.debug("***Getting tab to undelete by tab Id and status"); Tab tabToUndelete = (Tab) getEntityManager().createQuery("from Tab where id = :TabId and deleted = true") .setParameter("TabId", tabId).getSingleResult(); logger.debug("***Done Getting tab to undelete by tab Id and status (" + (System.currentTimeMillis() - start) + "ms"); if (tabToUndelete == null) { throw new TabUndeletionException("Failure when trying to get Tab with id=" + tabId, tabId); } try { tabGroup.getTabs().add(tabToUndelete.getTabIndex(), tabToUndelete); start = System.currentTimeMillis(); logger.debug("***Update tab status"); getEntityManager() .createQuery( "update versioned Tab set deleted = false, " + "dateDeleted = null, tabGroupId = :tabGroupId " + "where id = :TabId") .setParameter("TabId", tabToUndelete.getId()).setParameter("tabGroupId", tabGroup.getId()) .executeUpdate(); logger.debug("***Done Update tab status (" + (System.currentTimeMillis() - start) + "ms)"); logger.debug("Un-deleted the tab with id=" + tabToUndelete.getId()); start = System.currentTimeMillis(); logger.debug("***Update tab template status"); getEntityManager() .createQuery( "update versioned TabTemplate set deleted = false, " + "dateDeleted = null " + "where id = :TabTemplateId") .setParameter("TabTemplateId", tabToUndelete.getTemplate().getId()).executeUpdate(); logger.debug("***Done Update tab template status (" + (System.currentTimeMillis() - start) + "ms)"); logger.debug("Un-deleted the tab template with id=" + tabToUndelete.getTemplate().getId()); start = System.currentTimeMillis(); logger.debug("***Update tab template's gadgets status"); getEntityManager() .createQuery( "update versioned Gadget set deleted = false, " + "dateDeleted = null " + "where template.id = :TabTemplateId") .setParameter("TabTemplateId", tabToUndelete.getTemplate().getId()).executeUpdate(); logger.debug( "***Done Update tab template's gadgets status (" + (System.currentTimeMillis() - start) + "ms)"); logger.debug("Un-deleted gadgets belonging to tab template with id=" + tabToUndelete.getTemplate().getId()); start = System.currentTimeMillis(); logger.debug("***entity manager flush"); getEntityManager().flush(); getEntityManager().clear(); logger.debug("***Done entity manager flush (" + (System.currentTimeMillis() - start) + "ms)"); start = System.currentTimeMillis(); logger.debug("***Getting tab to return by tab Id and status"); tabToUndelete = (Tab) getEntityManager() .createQuery("from Tab t left join fetch t.template where t.id = :tabId and t.deleted = 'false'") .setParameter("tabId", tabId).getSingleResult(); tabToUndelete.getGadgets().size(); logger.debug("***Done Getting tab to return by tab Id and status (" + (System.currentTimeMillis() - start) + "ms)"); return tabToUndelete; } catch (Exception ex) { throw new TabUndeletionException("An error occurred while trying to undelete the Tab with TabId=" + tabId, tabId); } } TabGroupMapper(final QueryOptimizer inQueryOptimizer); }
TabGroupMapper extends DomainEntityMapper<TabGroup> { public Tab undeleteTab(final long tabId) throws TabUndeletionException { TabGroup tabGroup = null; long start; try { start = System.currentTimeMillis(); logger.debug("***Getting tab group by tab Id"); tabGroup = getTabGroupByTabId(tabId, true); logger.debug("***Done getting tab group by tab Id (" + (System.currentTimeMillis() - start) + "ms"); } catch (Exception ex) { throw new TabUndeletionException("Could not find either the specified Tab or tabGroup for TabId=" + tabId, tabId); } start = System.currentTimeMillis(); logger.debug("***Getting tab to undelete by tab Id and status"); Tab tabToUndelete = (Tab) getEntityManager().createQuery("from Tab where id = :TabId and deleted = true") .setParameter("TabId", tabId).getSingleResult(); logger.debug("***Done Getting tab to undelete by tab Id and status (" + (System.currentTimeMillis() - start) + "ms"); if (tabToUndelete == null) { throw new TabUndeletionException("Failure when trying to get Tab with id=" + tabId, tabId); } try { tabGroup.getTabs().add(tabToUndelete.getTabIndex(), tabToUndelete); start = System.currentTimeMillis(); logger.debug("***Update tab status"); getEntityManager() .createQuery( "update versioned Tab set deleted = false, " + "dateDeleted = null, tabGroupId = :tabGroupId " + "where id = :TabId") .setParameter("TabId", tabToUndelete.getId()).setParameter("tabGroupId", tabGroup.getId()) .executeUpdate(); logger.debug("***Done Update tab status (" + (System.currentTimeMillis() - start) + "ms)"); logger.debug("Un-deleted the tab with id=" + tabToUndelete.getId()); start = System.currentTimeMillis(); logger.debug("***Update tab template status"); getEntityManager() .createQuery( "update versioned TabTemplate set deleted = false, " + "dateDeleted = null " + "where id = :TabTemplateId") .setParameter("TabTemplateId", tabToUndelete.getTemplate().getId()).executeUpdate(); logger.debug("***Done Update tab template status (" + (System.currentTimeMillis() - start) + "ms)"); logger.debug("Un-deleted the tab template with id=" + tabToUndelete.getTemplate().getId()); start = System.currentTimeMillis(); logger.debug("***Update tab template's gadgets status"); getEntityManager() .createQuery( "update versioned Gadget set deleted = false, " + "dateDeleted = null " + "where template.id = :TabTemplateId") .setParameter("TabTemplateId", tabToUndelete.getTemplate().getId()).executeUpdate(); logger.debug( "***Done Update tab template's gadgets status (" + (System.currentTimeMillis() - start) + "ms)"); logger.debug("Un-deleted gadgets belonging to tab template with id=" + tabToUndelete.getTemplate().getId()); start = System.currentTimeMillis(); logger.debug("***entity manager flush"); getEntityManager().flush(); getEntityManager().clear(); logger.debug("***Done entity manager flush (" + (System.currentTimeMillis() - start) + "ms)"); start = System.currentTimeMillis(); logger.debug("***Getting tab to return by tab Id and status"); tabToUndelete = (Tab) getEntityManager() .createQuery("from Tab t left join fetch t.template where t.id = :tabId and t.deleted = 'false'") .setParameter("tabId", tabId).getSingleResult(); tabToUndelete.getGadgets().size(); logger.debug("***Done Getting tab to return by tab Id and status (" + (System.currentTimeMillis() - start) + "ms)"); return tabToUndelete; } catch (Exception ex) { throw new TabUndeletionException("An error occurred while trying to undelete the Tab with TabId=" + tabId, tabId); } } TabGroupMapper(final QueryOptimizer inQueryOptimizer); void setUndeleteTabWindowInMinutes(final int undeleteWindowInMinutes); void deleteTab(final Tab tab); Tab undeleteTab(final long tabId); TabGroup getTabGroupByTabId(final long tabId, final boolean isDeleted); long getTabCountForTemplate(final TabTemplate template); }
TabGroupMapper extends DomainEntityMapper<TabGroup> { public Tab undeleteTab(final long tabId) throws TabUndeletionException { TabGroup tabGroup = null; long start; try { start = System.currentTimeMillis(); logger.debug("***Getting tab group by tab Id"); tabGroup = getTabGroupByTabId(tabId, true); logger.debug("***Done getting tab group by tab Id (" + (System.currentTimeMillis() - start) + "ms"); } catch (Exception ex) { throw new TabUndeletionException("Could not find either the specified Tab or tabGroup for TabId=" + tabId, tabId); } start = System.currentTimeMillis(); logger.debug("***Getting tab to undelete by tab Id and status"); Tab tabToUndelete = (Tab) getEntityManager().createQuery("from Tab where id = :TabId and deleted = true") .setParameter("TabId", tabId).getSingleResult(); logger.debug("***Done Getting tab to undelete by tab Id and status (" + (System.currentTimeMillis() - start) + "ms"); if (tabToUndelete == null) { throw new TabUndeletionException("Failure when trying to get Tab with id=" + tabId, tabId); } try { tabGroup.getTabs().add(tabToUndelete.getTabIndex(), tabToUndelete); start = System.currentTimeMillis(); logger.debug("***Update tab status"); getEntityManager() .createQuery( "update versioned Tab set deleted = false, " + "dateDeleted = null, tabGroupId = :tabGroupId " + "where id = :TabId") .setParameter("TabId", tabToUndelete.getId()).setParameter("tabGroupId", tabGroup.getId()) .executeUpdate(); logger.debug("***Done Update tab status (" + (System.currentTimeMillis() - start) + "ms)"); logger.debug("Un-deleted the tab with id=" + tabToUndelete.getId()); start = System.currentTimeMillis(); logger.debug("***Update tab template status"); getEntityManager() .createQuery( "update versioned TabTemplate set deleted = false, " + "dateDeleted = null " + "where id = :TabTemplateId") .setParameter("TabTemplateId", tabToUndelete.getTemplate().getId()).executeUpdate(); logger.debug("***Done Update tab template status (" + (System.currentTimeMillis() - start) + "ms)"); logger.debug("Un-deleted the tab template with id=" + tabToUndelete.getTemplate().getId()); start = System.currentTimeMillis(); logger.debug("***Update tab template's gadgets status"); getEntityManager() .createQuery( "update versioned Gadget set deleted = false, " + "dateDeleted = null " + "where template.id = :TabTemplateId") .setParameter("TabTemplateId", tabToUndelete.getTemplate().getId()).executeUpdate(); logger.debug( "***Done Update tab template's gadgets status (" + (System.currentTimeMillis() - start) + "ms)"); logger.debug("Un-deleted gadgets belonging to tab template with id=" + tabToUndelete.getTemplate().getId()); start = System.currentTimeMillis(); logger.debug("***entity manager flush"); getEntityManager().flush(); getEntityManager().clear(); logger.debug("***Done entity manager flush (" + (System.currentTimeMillis() - start) + "ms)"); start = System.currentTimeMillis(); logger.debug("***Getting tab to return by tab Id and status"); tabToUndelete = (Tab) getEntityManager() .createQuery("from Tab t left join fetch t.template where t.id = :tabId and t.deleted = 'false'") .setParameter("tabId", tabId).getSingleResult(); tabToUndelete.getGadgets().size(); logger.debug("***Done Getting tab to return by tab Id and status (" + (System.currentTimeMillis() - start) + "ms)"); return tabToUndelete; } catch (Exception ex) { throw new TabUndeletionException("An error occurred while trying to undelete the Tab with TabId=" + tabId, tabId); } } TabGroupMapper(final QueryOptimizer inQueryOptimizer); void setUndeleteTabWindowInMinutes(final int undeleteWindowInMinutes); void deleteTab(final Tab tab); Tab undeleteTab(final long tabId); TabGroup getTabGroupByTabId(final long tabId, final boolean isDeleted); long getTabCountForTemplate(final TabTemplate template);  }