Search in sources :

Example 36 with DatabaseException

use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.

the class GenericCategoryDAO method delete.

/**
	 * @see net.jforum.dao.CategoryDAO#delete(int)
	 */
public void delete(int categoryId) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("CategoryModel.delete"));
        p.setInt(1, categoryId);
        p.executeUpdate();
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(p);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 37 with DatabaseException

use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.

the class GenericCategoryDAO method setOrder.

/**
	 * @param category Category
	 * @param otherCategory Category
	 */
private void setOrder(Category category, Category otherCategory) {
    int tmpOrder = otherCategory.getOrder();
    otherCategory.setOrder(category.getOrder());
    category.setOrder(tmpOrder);
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("CategoryModel.setOrderById"));
        p.setInt(1, otherCategory.getOrder());
        p.setInt(2, otherCategory.getId());
        p.executeUpdate();
        p.close();
        p = null;
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("CategoryModel.setOrderById"));
        p.setInt(1, category.getOrder());
        p.setInt(2, category.getId());
        p.executeUpdate();
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(p);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 38 with DatabaseException

use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.

the class GenericCategoryDAO method addNew.

/**
	 * @see net.jforum.dao.CategoryDAO#addNew(net.jforum.entities.Category)
	 */
public int addNew(Category category) {
    int order = 1;
    ResultSet rs = null;
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("CategoryModel.getMaxOrder"));
        rs = p.executeQuery();
        if (rs.next()) {
            order = rs.getInt(1) + 1;
        }
        rs.close();
        rs = null;
        p.close();
        p = null;
        p = this.getStatementForAutoKeys("CategoryModel.addNew");
        p.setString(1, category.getName());
        p.setInt(2, order);
        p.setInt(3, category.isModerated() ? 1 : 0);
        this.setAutoGeneratedKeysQuery(SystemGlobals.getSql("CategoryModel.lastGeneratedCategoryId"));
        int id = this.executeAutoKeysQuery(p);
        category.setId(id);
        category.setOrder(order);
        return id;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 39 with DatabaseException

use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.

the class GenericConfigDAO method update.

/**
	 * @see net.jforum.dao.ConfigDAO#update(net.jforum.entities.Config)
	 */
public void update(Config config) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ConfigModel.update"));
        p.setString(1, config.getValue());
        p.setString(2, config.getName());
        p.executeUpdate();
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(p);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 40 with DatabaseException

use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.

the class GenericApiDAO method isValid.

/**
	 * @see net.jforum.dao.ApiDAO#isValid(java.lang.String)
	 */
public boolean isValid(String apiKey) {
    boolean status = false;
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ApiModel.isValid"));
        p.setString(1, apiKey);
        rs = p.executeQuery();
        status = rs.next();
    } catch (Exception e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
    return status;
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException) DatabaseException(net.jforum.exceptions.DatabaseException)

Aggregations

DatabaseException (net.jforum.exceptions.DatabaseException)264 PreparedStatement (java.sql.PreparedStatement)255 SQLException (java.sql.SQLException)254 ResultSet (java.sql.ResultSet)138 List (java.util.List)64 ArrayList (java.util.ArrayList)63 Timestamp (java.sql.Timestamp)17 User (net.jforum.entities.User)15 Iterator (java.util.Iterator)12 Post (net.jforum.entities.Post)9 Date (java.util.Date)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Topic (net.jforum.entities.Topic)8 Connection (java.sql.Connection)5 Bookmark (net.jforum.entities.Bookmark)5 KarmaStatus (net.jforum.entities.KarmaStatus)4 SimpleDateFormat (java.text.SimpleDateFormat)3 PrivateMessage (net.jforum.entities.PrivateMessage)3 Ranking (net.jforum.entities.Ranking)3