use of net.jforum.entities.Category in project jforum2 by rafaelsteil.
the class ForumRepository method loadForums.
/**
* Loads all forums.
* @param fm ForumDAO
*/
private void loadForums(ForumDAO fm) {
List l = fm.selectAll();
Map m = (Map) cache.get(FQN, RELATION);
if (m == null) {
m = new HashMap();
}
int lastId = 0;
Category c = null;
String catId = null;
for (Iterator iter = l.iterator(); iter.hasNext(); ) {
Forum f = (Forum) iter.next();
if (f.getCategoryId() != lastId) {
if (c != null) {
cache.add(FQN, catId, c);
}
lastId = f.getCategoryId();
catId = Integer.toString(f.getCategoryId());
c = (Category) cache.get(FQN, catId);
}
if (c == null) {
throw new CategoryNotFoundException("Category for forum #" + f.getId() + " not found");
}
String forumId = Integer.toString(f.getId());
c.addForum(f);
m.put(forumId, catId);
}
if (c != null) {
cache.add(FQN, catId, c);
}
cache.add(FQN, RELATION, m);
}
use of net.jforum.entities.Category in project jforum2 by rafaelsteil.
the class ForumRepository method loadCategories.
/**
* Loads all categories.
* @param cm CategoryDAO
*/
private void loadCategories(CategoryDAO cm) {
List categories = cm.selectAll();
Set categoriesSet = new TreeSet(new CategoryOrderComparator());
for (Iterator iter = categories.iterator(); iter.hasNext(); ) {
Category c = (Category) iter.next();
cache.add(FQN, Integer.toString(c.getId()), c);
categoriesSet.add(c);
}
cache.add(FQN, CATEGORIES_SET, categoriesSet);
}
use of net.jforum.entities.Category in project jforum2 by rafaelsteil.
the class ForumRepository method refreshForum.
public static synchronized void refreshForum(Forum forum) {
Category c = retrieveCategory(forum.getCategoryId());
c.addForum(forum);
refreshCategory(c);
}
use of net.jforum.entities.Category in project jforum2 by rafaelsteil.
the class ForumRepository method getAllCategories.
/**
* Gets all categories from the cache.
*
* @param userId int
* @return <code>List</code> with the categories. Each entry is a <code>Category</code> object.
*/
public static List getAllCategories(int userId) {
PermissionControl pc = SecurityRepository.get(userId);
List l = new ArrayList();
Set categoriesSet = (Set) cache.get(FQN, CATEGORIES_SET);
if (categoriesSet == null) {
synchronized (ForumRepository.instance) {
if (categoriesSet == null) {
logger.warn("Categories set returned null from the cache. Trying to reload");
try {
ForumRepository.instance.loadCategories(DataAccessDriver.getInstance().newCategoryDAO());
ForumRepository.instance.loadForums(DataAccessDriver.getInstance().newForumDAO());
} catch (Exception e) {
throw new CategoryNotFoundException("Failed to get the category", e);
}
categoriesSet = (Set) cache.get(FQN, CATEGORIES_SET);
if (categoriesSet == null) {
throw new CategoryNotFoundException("Could not find all categories. There must be a problem with the cache");
}
}
}
}
for (Iterator iter = categoriesSet.iterator(); iter.hasNext(); ) {
Category c = getCategory(pc, ((Category) iter.next()).getId());
if (c != null) {
l.add(c);
}
}
return l;
}
use of net.jforum.entities.Category in project jforum2 by rafaelsteil.
the class ForumRepository method reloadForum.
/**
* Reloads a forum.
* The forum should already be in the cache and <b>SHOULD NOT</b>
* have its order changed. If the forum's order was changed,
* then you <b>MUST CALL</b> @link Category#changeForumOrder(Forum) <b>BEFORE</b>
* calling this method.
*
* @param forumId int The forum to reload its information
*/
public static synchronized void reloadForum(int forumId) {
Forum f = DataAccessDriver.getInstance().newForumDAO().selectById(forumId);
if (((Map) cache.get(FQN, RELATION)).containsKey(Integer.toString(forumId))) {
String id = Integer.toString(f.getCategoryId());
Category c = (Category) cache.get(FQN, id);
f.setLastPostInfo(null);
f.setLastPostInfo(ForumRepository.getLastPostInfo(f));
c.reloadForum(f);
cache.add(FQN, id, c);
Set s = (Set) cache.get(FQN, CATEGORIES_SET);
cache.add(FQN, CATEGORIES_SET, s);
}
getTotalMessages(true);
}
Aggregations