@Test public void testUndeleteTabRestoresTabToItsOriginalPosition() throws TabUndeletionException { final int expectedTabCountBeforeUndelete = 3; TabGroup tabGroup = jpaTabGroupMapper.findById(fordsStartPageId); assertEquals("Expected 3 tabs in Ford's first tabGroup before undeleting the previously-deleted tab.", expectedTabCountBeforeUndelete, tabGroup.getTabs().size()); jpaTabGroupMapper.undeleteTab(fordsDeletedTabId); jpaTabGroupMapper.flush(); tabGroup = jpaTabGroupMapper.findById(fordsStartPageId); assertEquals("Expected 4 tabs in Ford's third tabGroup after undeleting the previously-deleted tab.", expectedTabCountBeforeUndelete + 1, tabGroup.getTabs().size()); assertEquals( "Expected the previously 1st tab to still be 1st after deleting and undeleting the original 2nd tab", fordsFirstTabId, tabGroup.getTabs().get(0).getId()); assertEquals("Expected the undeleted original 2nd tab to be 2nd again.", fordsDeletedTabId, tabGroup.getTabs() .get(1).getId()); assertEquals("Expected the previously 2nd tab to be 3rd after deleting and undeleting the original 2nd tab", fordsSecondTabId, tabGroup.getTabs().get(2).getId()); assertEquals("Expected the previously 3rd tab to be 4th after deleting and undeleting the original 2nd tab", fordsThirdTabId, tabGroup.getTabs().get(3).getId()); }
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);  }