⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 attachmentmodel.java

📁 个人认为是最好的Java论坛源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		PreparedStatement p = JForum.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();
		p.close();
	}
	
	protected AttachmentExtensionGroup getExtensionGroup(ResultSet rs) throws Exception
	{
		AttachmentExtensionGroup g = new AttachmentExtensionGroup();
		g.setId(rs.getInt("extension_group_id"));
		g.setName(rs.getString("name"));
		g.setUploadIcon(rs.getString("upload_icon"));
		g.setAllow(rs.getInt("allow") == 1);
		g.setDownloadMode(rs.getInt("download_mode"));
		
		return g;
	}
	
	/**
	 * @see net.jforum.model.AttachmentModel#addExtension(net.jforum.entities.AttachmentExtension)
	 */
	public void addExtension(AttachmentExtension e) throws Exception
	{
		PreparedStatement p = JForum.getConnection().prepareStatement(
				SystemGlobals.getSql("AttachmentModel.addExtension"));
		p.setInt(1, e.getExtensionGroupId());
		p.setString(2, e.getComment());
		p.setString(3, e.getUploadIcon());
		p.setString(4, e.getExtension().toLowerCase());
		p.setInt(5, e.isAllow() ? 1 : 0);
		p.executeUpdate();
		p.close();
	}
	
	/**
	 * @see net.jforum.model.AttachmentModel#removeExtensions(java.lang.String[])
	 */
	public void removeExtensions(String[] ids) throws Exception
	{
		PreparedStatement p = JForum.getConnection().prepareStatement(
				SystemGlobals.getSql("AttachmentModel.removeExtension"));
		for (int i = 0; i < ids.length; i++) {
			p.setInt(1, Integer.parseInt(ids[i]));
			p.executeUpdate();
		}
		p.close();
	}
	
	/**
	 * @see net.jforum.model.AttachmentModel#selectExtensions()
	 */
	public List selectExtensions() throws Exception
	{
		List l = new ArrayList();
		
		PreparedStatement p = JForum.getConnection().prepareStatement(
				SystemGlobals.getSql("AttachmentModel.selectExtensions"));
		
		ResultSet rs = p.executeQuery();
		while (rs.next()) {
			l.add(this.getExtension(rs));
		}
		
		rs.close();
		p.close();
		
		return l;
	}
	
	/**
	 * @see net.jforum.model.AttachmentModel#updateExtension(net.jforum.entities.AttachmentExtension)
	 */
	public void updateExtension(AttachmentExtension e) throws Exception
	{
		PreparedStatement p = JForum.getConnection().prepareStatement(
				SystemGlobals.getSql("AttachmentModel.updateExtension"));
		p.setInt(1, e.getExtensionGroupId());
		p.setString(2, e.getComment());
		p.setString(3, e.getUploadIcon());
		p.setString(4, e.getExtension().toLowerCase());
		p.setInt(5, e.isAllow() ? 1 : 0);
		p.setInt(6, e.getId());
		p.executeUpdate();
		p.close();
	}
	
	/**
	 * @see net.jforum.model.AttachmentModel#selectExtension(java.lang.String)
	 */
	public AttachmentExtension selectExtension(String extension) throws Exception
	{
		return this.searchExtension("extension", extension);
	}
	
	private AttachmentExtension selectExtension(int extensionId) throws Exception
	{
		return this.searchExtension("extension_id", new Integer(extensionId));
	}
	
	private AttachmentExtension searchExtension(String paramName, Object paramValue) throws Exception
	{
		String sql = SystemGlobals.getSql("AttachmentModel.selectExtension");
		sql = sql.replaceAll("\\$field", paramName);
		
		PreparedStatement p = JForum.getConnection().prepareStatement(sql);
		p.setObject(1, paramValue);
		
		AttachmentExtension e = new AttachmentExtension();
		
		ResultSet rs = p.executeQuery();
		if (rs.next()) {
			e = this.getExtension(rs);
		}
		else {
			e.setUnknown(true);
		}
		
		rs.close();
		p.close();
		
		return e;
	}
	
	protected AttachmentExtension getExtension(ResultSet rs) throws Exception
	{
		AttachmentExtension e = new AttachmentExtension();
		e.setAllow(rs.getInt("allow") == 1);
		e.setComment(rs.getString("description"));
		e.setExtension(rs.getString("extension"));
		e.setExtensionGroupId(rs.getInt("extension_group_id"));
		e.setId(rs.getInt("extension_id"));
		
		String icon = rs.getString("upload_icon");
		if (icon == null || icon.equals("")) {
			icon = rs.getString("group_icon");
		}
		
		e.setUploadIcon(icon);
		
		return e;
	}
	
	/**
	 * @see net.jforum.model.AttachmentModel#addAttachment(net.jforum.entities.Attachment)
	 */
	public void addAttachment(Attachment a) throws Exception
	{
		PreparedStatement p = this.getStatementForAutoKeys("AttachmentModel.addAttachment");
		p.setInt(1, a.getPostId());
		p.setInt(2, a.getPrivmsgsId());
		p.setInt(3, a.getUserId());
		
		int id = this.executeAutoKeysQuery(p);
		p.close();
		
		p = JForum.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();
		p.close();
		
		this.updatePost(a.getPostId(), 1);
	}
	
	protected void updatePost(int postId, int count) throws Exception
	{
		PreparedStatement p = JForum.getConnection().prepareStatement(
				SystemGlobals.getSql("AttachmentModel.updatePost"));
		p.setInt(1, count);
		p.setInt(2, postId);
		p.executeUpdate();
		p.close();
	}
	
	/**
	 * @see net.jforum.model.AttachmentModel#removeAttachment(int, int)
	 */
	public void removeAttachment(int id, int postId) throws Exception
	{
		PreparedStatement p = JForum.getConnection().prepareStatement(
				SystemGlobals.getSql("AttachmentModel.removeAttachmentInfo"));
		p.setInt(1, id);
		p.executeUpdate();
		p.close();
		
		p = JForum.getConnection().prepareStatement(
				SystemGlobals.getSql("AttachmentModel.removeAttachment"));
		p.setInt(1, id);
		p.executeUpdate();
		p.close();
		
		p = JForum.getConnection().prepareStatement(
				SystemGlobals.getSql("AttachmentModel.countPostAttachments"));
		p.setInt(1, postId);

		ResultSet rs = p.executeQuery();
		if (rs.next()) {
			this.updatePost(postId, rs.getInt(1));
		}
		
		rs.close();
		p.close();
	}
	
	/**
	 * @see net.jforum.model.AttachmentModel#updateAttachment(net.jforum.entities.Attachment)
	 */
	public void updateAttachment(Attachment a) throws Exception
	{
		PreparedStatement p = JForum.getConnection().prepareStatement(
				SystemGlobals.getSql("AttachmentModel.updateAttachment"));
		p.setString(1, a.getInfo().getComment());
		p.setInt(2, a.getInfo().getDownloadCount());
		p.setInt(3, a.getId());
		p.executeUpdate();
		p.close();
	}
	
	/**
	 * @see net.jforum.model.AttachmentModel#selectAttachments(int)
	 */
	public List selectAttachments(int postId) throws Exception
	{
		List l = new ArrayList();
		
		PreparedStatement p = JForum.getConnection().prepareStatement(
				SystemGlobals.getSql("AttachmentModel.selectAttachments"));
		p.setInt(1, postId);
		
		ResultSet rs = p.executeQuery();
		while (rs.next()) {
			l.add(this.getAttachment(rs));
		}
		
		return l;
	}
	
	protected Attachment getAttachment(ResultSet rs) throws Exception
	{
		Attachment a = new Attachment();
		a.setId(rs.getInt("attach_id"));
		a.setPostId(rs.getInt("post_id"));
		a.setPrivmsgsId(rs.getInt("privmsgs_id"));
		
		AttachmentInfo ai = new AttachmentInfo();
		ai.setComment(rs.getString("description"));
		ai.setDownloadCount(rs.getInt("download_count"));
		ai.setFilesize(rs.getLong("filesize"));
		ai.setMimetype(rs.getString("mimetype"));
		ai.setPhysicalFilename(rs.getString("physical_filename"));
		ai.setRealFilename(rs.getString("real_filename"));
		ai.setUploadTime(rs.getTimestamp("upload_time"));
		ai.setExtension(this.selectExtension(rs.getInt("extension_id")));
		
		a.setInfo(ai);
		
		return a;
	}
	
	/**
	 * @see net.jforum.model.AttachmentModel#selectAttachmentById(int)
	 */
	public Attachment selectAttachmentById(int attachId) throws Exception
	{
		Attachment e = null;
		
		PreparedStatement p = JForum.getConnection().prepareStatement(
				SystemGlobals.getSql("AttachmentModel.selectAttachmentById"));
		p.setInt(1, attachId);
		
		ResultSet rs = p.executeQuery();
		if (rs.next()) {
			e = this.getAttachment(rs);
		}
		
		rs.close();
		p.close();
		
		return e;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -