Search in sources :

Example 41 with DatabaseException

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

the class GenericAttachmentDAO method addAttachment.

/**
	 * @see net.jforum.dao.AttachmentDAO#addAttachment(net.jforum.entities.Attachment)
	 */
public void addAttachment(Attachment a) {
    PreparedStatement p = null;
    try {
        p = this.getStatementForAutoKeys("AttachmentModel.addAttachment");
        p.setInt(1, a.getPostId());
        p.setInt(2, a.getPrivmsgsId());
        p.setInt(3, a.getUserId());
        this.setAutoGeneratedKeysQuery(SystemGlobals.getSql("AttachmentModel.lastGeneratedAttachmentId"));
        int id = this.executeAutoKeysQuery(p);
        p.close();
        p = null;
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("AttachmentModel.addAttachmentInfo"));
        p.setInt(1, id);
        p.setString(2, a.getInfo().getPhysicalFilename());
        p.setString(3, a.getInfo().getRealFilename());
        p.setString(4, a.getInfo().getComment());
        p.setString(5, a.getInfo().getMimetype());
        p.setLong(6, a.getInfo().getFilesize());
        p.setTimestamp(7, new Timestamp(a.getInfo().getUploadTimeInMillis()));
        p.setInt(8, 0);
        p.setInt(9, a.getInfo().getExtension().getId());
        p.executeUpdate();
        this.updatePost(a.getPostId(), 1);
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(p);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 42 with DatabaseException

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

the class GenericAttachmentDAO method removeAttachment.

/**
	 * @see net.jforum.dao.AttachmentDAO#removeAttachment(int, int)
	 */
public void removeAttachment(int id, int postId) {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("AttachmentModel.removeAttachmentInfo"));
        p.setInt(1, id);
        p.executeUpdate();
        p.close();
        p = null;
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("AttachmentModel.removeAttachment"));
        p.setInt(1, id);
        p.executeUpdate();
        p.close();
        p = null;
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("AttachmentModel.countPostAttachments"));
        p.setInt(1, postId);
        rs = p.executeQuery();
        if (rs.next()) {
            this.updatePost(postId, rs.getInt(1));
        }
    } 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 43 with DatabaseException

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

the class GenericAttachmentDAO method updateExtensionGroup.

/**
	 * @see net.jforum.dao.AttachmentDAO#updateExtensionGroup(net.jforum.entities.AttachmentExtensionGroup)
	 */
public void updateExtensionGroup(AttachmentExtensionGroup g) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("AttachmentModel.updateExtensionGroups"));
        p.setString(1, g.getName());
        p.setInt(2, g.isAllow() ? 1 : 0);
        p.setString(3, g.getUploadIcon());
        p.setInt(4, g.getDownloadMode());
        p.setInt(5, g.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 44 with DatabaseException

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

the class GenericAttachmentDAO method updateExtension.

/**
	 * @see net.jforum.dao.AttachmentDAO#updateExtension(net.jforum.entities.AttachmentExtension)
	 */
public void updateExtension(AttachmentExtension extension) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("AttachmentModel.updateExtension"));
        p.setInt(1, extension.getExtensionGroupId());
        p.setString(2, extension.getComment());
        p.setString(3, extension.getUploadIcon());
        p.setString(4, extension.getExtension().toLowerCase());
        p.setInt(5, extension.isAllow() ? 1 : 0);
        p.setInt(6, extension.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 45 with DatabaseException

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

the class GenericAttachmentDAO method updatePost.

protected void updatePost(int postId, int count) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("AttachmentModel.updatePost"));
        p.setInt(1, count);
        p.setInt(2, postId);
        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)

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