Search in sources :

Example 1 with DataAccessDriver

use of net.jforum.dao.DataAccessDriver in project jforum2 by rafaelsteil.

the class ConfigLoader method loadDaoImplementation.

public static void loadDaoImplementation() {
    // Start the dao.driver implementation
    String driver = SystemGlobals.getValue(ConfigKeys.DAO_DRIVER);
    logger.info("Loading JDBC driver " + driver);
    try {
        Class c = Class.forName(driver);
        DataAccessDriver d = (DataAccessDriver) c.newInstance();
        DataAccessDriver.init(d);
    } catch (Exception e) {
        throw new ForumException(e);
    }
}
Also used : ForumException(net.jforum.exceptions.ForumException) DataAccessDriver(net.jforum.dao.DataAccessDriver) IOException(java.io.IOException) CacheEngineStartupException(net.jforum.exceptions.CacheEngineStartupException) SchedulerException(org.quartz.SchedulerException) ForumException(net.jforum.exceptions.ForumException)

Example 2 with DataAccessDriver

use of net.jforum.dao.DataAccessDriver in project jforum2 by rafaelsteil.

the class HottestTopicsAction method showTopicsByUser.

public void showTopicsByUser() {
    DataAccessDriver da = DataAccessDriver.getInstance();
    UserDAO udao = da.newUserDAO();
    User u = udao.selectById(this.request.getIntParameter("user_id"));
    if (u.getId() == 0) {
        this.context.put("message", I18n.getMessage("User.notFound"));
        this.setTemplateName(TemplateKeys.USER_NOT_FOUND);
        return;
    }
    TopicsCommon.topicListingBase();
    int start = ViewCommon.getStartPage();
    int topicsPerPage = SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE);
    int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
    this.setTemplateName(TemplateKeys.HOTTEST_USER_TOPICS_SHOW);
    int totalTopics = da.newTopicDAO().countUserTopics(u.getId());
    this.context.put("u", u);
    this.context.put("pageTitle", I18n.getMessage("ForumListing.userTopics") + " " + u.getUsername());
    this.context.put("postsPerPage", new Integer(postsPerPage));
    List topics = da.newTopicDAO().selectByUserByLimit(u.getId(), start, topicsPerPage);
    List l = TopicsCommon.prepareTopics(topics);
    Map forums = new HashMap();
    for (Iterator iter = l.iterator(); iter.hasNext(); ) {
        Topic t = (Topic) iter.next();
        Forum f = ForumRepository.getForum(t.getForumId());
        if (f == null) {
            iter.remove();
            totalTopics--;
            continue;
        }
        forums.put(new Integer(t.getForumId()), f);
    }
    this.context.put("topics", l);
    this.context.put("forums", forums);
    ViewCommon.contextToPagination(start, totalTopics, topicsPerPage);
}
Also used : User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO) HashMap(java.util.HashMap) DataAccessDriver(net.jforum.dao.DataAccessDriver) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Topic(net.jforum.entities.Topic) HashMap(java.util.HashMap) Map(java.util.Map) Forum(net.jforum.entities.Forum)

Example 3 with DataAccessDriver

use of net.jforum.dao.DataAccessDriver in project jforum2 by rafaelsteil.

the class RecentTopicsAction method showTopicsByUser.

public void showTopicsByUser() {
    DataAccessDriver da = DataAccessDriver.getInstance();
    UserDAO udao = da.newUserDAO();
    User u = udao.selectById(this.request.getIntParameter("user_id"));
    if (u.getId() == 0) {
        this.context.put("message", I18n.getMessage("User.notFound"));
        this.setTemplateName(TemplateKeys.USER_NOT_FOUND);
        return;
    }
    TopicsCommon.topicListingBase();
    int start = ViewCommon.getStartPage();
    int topicsPerPage = SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE);
    int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
    this.setTemplateName(TemplateKeys.RECENT_USER_TOPICS_SHOW);
    int totalTopics = da.newTopicDAO().countUserTopics(u.getId());
    this.context.put("u", u);
    this.context.put("pageTitle", I18n.getMessage("ForumListing.userTopics") + " " + u.getUsername());
    this.context.put("postsPerPage", new Integer(postsPerPage));
    List topics = da.newTopicDAO().selectByUserByLimit(u.getId(), start, topicsPerPage);
    List l = TopicsCommon.prepareTopics(topics);
    Map forums = new HashMap();
    for (Iterator iter = l.iterator(); iter.hasNext(); ) {
        Topic t = (Topic) iter.next();
        Forum f = ForumRepository.getForum(t.getForumId());
        if (f == null) {
            iter.remove();
            totalTopics--;
            continue;
        }
        forums.put(new Integer(t.getForumId()), f);
    }
    this.context.put("topics", l);
    this.context.put("forums", forums);
    ViewCommon.contextToPagination(start, totalTopics, topicsPerPage);
}
Also used : User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO) HashMap(java.util.HashMap) DataAccessDriver(net.jforum.dao.DataAccessDriver) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Topic(net.jforum.entities.Topic) HashMap(java.util.HashMap) Map(java.util.Map) Forum(net.jforum.entities.Forum)

Example 4 with DataAccessDriver

use of net.jforum.dao.DataAccessDriver in project jforum2 by rafaelsteil.

the class TestCaseUtils method initDatabaseImplementation.

/**
	 * Inits the database stuff. 
	 * Must be called <b>after</b> #loadEnvironment
	 * 
	 * @throws Exception
	 */
public static void initDatabaseImplementation() throws Exception {
    SystemGlobals.loadAdditionalDefaults(SystemGlobals.getValue(ConfigKeys.DATABASE_DRIVER_CONFIG));
    SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_GENERIC));
    SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_DRIVER));
    // Start the dao.driver implementation
    String driver = SystemGlobals.getValue(ConfigKeys.DAO_DRIVER);
    Class c = Class.forName(driver);
    DataAccessDriver d = (DataAccessDriver) c.newInstance();
    DataAccessDriver.init(d);
    DBConnection.createInstance();
    DBConnection.getImplementation().init();
}
Also used : DataAccessDriver(net.jforum.dao.DataAccessDriver)

Example 5 with DataAccessDriver

use of net.jforum.dao.DataAccessDriver in project jforum2 by rafaelsteil.

the class UserAction method profile.

public void profile() {
    DataAccessDriver da = DataAccessDriver.getInstance();
    UserDAO udao = da.newUserDAO();
    User u = udao.selectById(this.request.getIntParameter("user_id"));
    if (u.getId() == 0) {
        this.userNotFound();
    } else {
        this.setTemplateName(TemplateKeys.USER_PROFILE);
        this.context.put("karmaEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_KARMA_ENABLED));
        this.context.put("rank", new RankingRepository());
        this.context.put("u", u);
        this.context.put("avatarAllowExternalUrl", SystemGlobals.getBoolValue(ConfigKeys.AVATAR_ALLOW_EXTERNAL_URL));
        int loggedId = SessionFacade.getUserSession().getUserId();
        int count = 0;
        List bookmarks = da.newBookmarkDAO().selectByUser(u.getId());
        for (Iterator iter = bookmarks.iterator(); iter.hasNext(); ) {
            Bookmark b = (Bookmark) iter.next();
            if (b.isPublicVisible() || loggedId == u.getId()) {
                count++;
            }
        }
        this.context.put("pageTitle", I18n.getMessage("UserProfile.allAbout") + " " + u.getUsername());
        this.context.put("nbookmarks", new Integer(count));
        this.context.put("ntopics", new Integer(da.newTopicDAO().countUserTopics(u.getId())));
        this.context.put("nposts", new Integer(da.newPostDAO().countUserPosts(u.getId())));
    }
}
Also used : User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO) Bookmark(net.jforum.entities.Bookmark) DataAccessDriver(net.jforum.dao.DataAccessDriver) RankingRepository(net.jforum.repository.RankingRepository) Iterator(java.util.Iterator) List(java.util.List)

Aggregations

DataAccessDriver (net.jforum.dao.DataAccessDriver)5 Iterator (java.util.Iterator)3 List (java.util.List)3 UserDAO (net.jforum.dao.UserDAO)3 User (net.jforum.entities.User)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Forum (net.jforum.entities.Forum)2 Topic (net.jforum.entities.Topic)2 IOException (java.io.IOException)1 Bookmark (net.jforum.entities.Bookmark)1 CacheEngineStartupException (net.jforum.exceptions.CacheEngineStartupException)1 ForumException (net.jforum.exceptions.ForumException)1 RankingRepository (net.jforum.repository.RankingRepository)1 SchedulerException (org.quartz.SchedulerException)1