*/
public Tab undeleteTab(final long tabId) throws TabUndeletionException
{
// make sure the Tab exists in the input tabGroup
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");
/* get the deleted Tab from the tab group */
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
{
/*
* re-insert the undeleted tab into the collection
*/
tabGroup.getTabs().add(tabToUndelete.getTabIndex(), tabToUndelete);
/* update the status of the undeleted Tab in the database */
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());