Search in sources :

Example 1 with Config

use of net.jforum.entities.Config in project jforum2 by rafaelsteil.

the class ForumRepository method updateMostUsersEverOnline.

/**
	 * Update the value of most online users ever.
	 * 
	 * @param m MostUsersEverOnline The new value to store. Generally it
	 * will be a bigger one.
	 */
public static void updateMostUsersEverOnline(MostUsersEverOnline m) {
    ConfigDAO cm = DataAccessDriver.getInstance().newConfigDAO();
    Config config = cm.selectByName(ConfigKeys.MOST_USERS_EVER_ONLINE);
    if (config == null) {
        // Total
        config = new Config();
        config.setName(ConfigKeys.MOST_USERS_EVER_ONLINE);
        config.setValue(Integer.toString(m.getTotal()));
        cm.insert(config);
        // Date
        config.setName(ConfigKeys.MOST_USER_EVER_ONLINE_DATE);
        config.setValue(Long.toString(m.getTimeInMillis()));
        cm.insert(config);
    } else {
        // Total
        config.setValue(Integer.toString(m.getTotal()));
        cm.update(config);
        // Date
        config.setName(ConfigKeys.MOST_USER_EVER_ONLINE_DATE);
        config.setValue(Long.toString(m.getTimeInMillis()));
        cm.update(config);
    }
    cache.add(FQN, MOST_USERS_ONLINE, m);
}
Also used : Config(net.jforum.entities.Config) ConfigDAO(net.jforum.dao.ConfigDAO)

Example 2 with Config

use of net.jforum.entities.Config in project jforum2 by rafaelsteil.

the class ForumRepository method loadMostUsersEverOnline.

private MostUsersEverOnline loadMostUsersEverOnline(ConfigDAO cm) {
    Config config = cm.selectByName(ConfigKeys.MOST_USERS_EVER_ONLINE);
    MostUsersEverOnline mostUsersEverOnline = new MostUsersEverOnline();
    if (config != null) {
        mostUsersEverOnline.setTotal(Integer.parseInt(config.getValue()));
        // We're assuming that, if we have one key, the another one
        // will always exist
        config = cm.selectByName(ConfigKeys.MOST_USER_EVER_ONLINE_DATE);
        mostUsersEverOnline.setTimeInMillis(Long.parseLong(config.getValue()));
    }
    cache.add(FQN, MOST_USERS_ONLINE, mostUsersEverOnline);
    return mostUsersEverOnline;
}
Also used : Config(net.jforum.entities.Config) MostUsersEverOnline(net.jforum.entities.MostUsersEverOnline)

Example 3 with Config

use of net.jforum.entities.Config in project jforum2 by rafaelsteil.

the class GenericConfigDAO method selectByName.

/**
	 * @see net.jforum.dao.ConfigDAO#selectByName(java.lang.String)
	 */
public Config selectByName(String name) {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ConfigModel.selectByName"));
        p.setString(1, name);
        rs = p.executeQuery();
        Config c = null;
        if (rs.next()) {
            c = this.makeConfig(rs);
        }
        return c;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : SQLException(java.sql.SQLException) Config(net.jforum.entities.Config) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 4 with Config

use of net.jforum.entities.Config in project jforum2 by rafaelsteil.

the class GenericConfigDAO method makeConfig.

protected Config makeConfig(ResultSet rs) throws SQLException {
    Config c = new Config();
    c.setId(rs.getInt("config_id"));
    c.setName(rs.getString("config_name"));
    c.setValue(rs.getString("config_value"));
    return c;
}
Also used : Config(net.jforum.entities.Config)

Aggregations

Config (net.jforum.entities.Config)4 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ConfigDAO (net.jforum.dao.ConfigDAO)1 MostUsersEverOnline (net.jforum.entities.MostUsersEverOnline)1 DatabaseException (net.jforum.exceptions.DatabaseException)1