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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations