private void removeWebsiteContents(WebsiteData website)
throws HibernateException, RollerException {
Session session = this.strategy.getSession();
BookmarkManager bmgr = RollerFactory.getRoller().getBookmarkManager();
WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
// remove tags
Criteria tagQuery = session.createCriteria(WeblogEntryTagData.class)
.add(Expression.eq("weblog.id", website.getId()));
for(Iterator iter = tagQuery.list().iterator(); iter.hasNext();) {
WeblogEntryTagData tagData = (WeblogEntryTagData) iter.next();
this.strategy.remove(tagData);
}
// remove site tag aggregates
List tags = wmgr.getTags(website, null, null, -1);
for(Iterator iter = tags.iterator(); iter.hasNext();) {
TagStat stat = (TagStat) iter.next();
Query query = session.createQuery("update WeblogEntryTagAggregateData set total = total - ? where name = ? and weblog is null");
query.setParameter(0, new Integer(stat.getCount()));
query.setParameter(1, stat.getName());
query.executeUpdate();
}
// delete all weblog tag aggregates
session.createQuery("delete from WeblogEntryTagAggregateData where weblog = ?")
.setParameter(0, website).executeUpdate();
// delete all bad counts
session.createQuery("delete from WeblogEntryTagAggregateData where total <= 0").executeUpdate();
// Remove the website's ping queue entries
Criteria criteria = session.createCriteria(PingQueueEntryData.class);
criteria.add(Expression.eq("website", website));
List queueEntries = criteria.list();
// Remove the website's auto ping configurations
AutoPingManager autoPingMgr = RollerFactory.getRoller().getAutopingManager();
List autopings = autoPingMgr.getAutoPingsByWebsite(website);
Iterator it = autopings.iterator();
while(it.hasNext()) {
this.strategy.remove((AutoPingData) it.next());
}
// Remove the website's custom ping targets
PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
List pingtargets = pingTargetMgr.getCustomPingTargets(website);
it = pingtargets.iterator();
while(it.hasNext()) {
this.strategy.remove((PingTargetData) it.next());
}
// remove entries
Criteria entryQuery = session.createCriteria(WeblogEntryData.class);
entryQuery.add(Expression.eq("website", website));
List entries = entryQuery.list();
for (Iterator iter = entries.iterator(); iter.hasNext();) {
WeblogEntryData entry = (WeblogEntryData) iter.next();
this.strategy.remove(entry);
}
// remove associated referers
Criteria refererQuery = session.createCriteria(RefererData.class);
refererQuery.add(Expression.eq("website", website));
List referers = refererQuery.list();
for (Iterator iter = referers.iterator(); iter.hasNext();) {
RefererData referer = (RefererData) iter.next();
this.strategy.remove(referer);
}
// remove associated pages
Criteria pageQuery = session.createCriteria(WeblogTemplate.class);
pageQuery.add(Expression.eq("website", website));
List pages = pageQuery.list();
for (Iterator iter = pages.iterator(); iter.hasNext();) {
WeblogTemplate page = (WeblogTemplate) iter.next();
this.strategy.remove(page);
}
// remove folders (including bookmarks)
FolderData rootFolder = bmgr.getRootFolder(website);
if (null != rootFolder) {
this.strategy.remove(rootFolder);
// Still cannot get all Bookmarks cleared!
Iterator allFolders = bmgr.getAllFolders(website).iterator();
while (allFolders.hasNext()) {
FolderData aFolder = (FolderData)allFolders.next();
bmgr.removeFolderContents(aFolder);
this.strategy.remove(aFolder);
}
}
// remove categories