📄 attachmentmodel.java
字号:
/*
* Copyright (c) 2003, 2004 Rafael Steil
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* 2) Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* 3) Neither the name of "Rafael Steil" nor
* the names of its contributors may be used to endorse
* or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*
* Created on Jan 17, 2005 4:36:30 PM
* The JForum Project
* http://www.jforum.net
*/
package net.jforum.drivers.generic;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.jforum.JForum;
import net.jforum.entities.Attachment;
import net.jforum.entities.AttachmentExtension;
import net.jforum.entities.AttachmentExtensionGroup;
import net.jforum.entities.AttachmentInfo;
import net.jforum.entities.QuotaLimit;
import net.jforum.util.preferences.SystemGlobals;
/**
* @author Rafael Steil
* @version $Id: AttachmentModel.java,v 1.13 2005/01/27 17:59:48 rafaelsteil Exp $
*/
public class AttachmentModel extends AutoKeys implements net.jforum.model.AttachmentModel
{
/**
* @see net.jforum.model.AttachmentModel#addQuotaLimit(net.jforum.entities.QuotaLimit)
*/
public void addQuotaLimit(QuotaLimit limit) throws Exception
{
PreparedStatement p = JForum.getConnection().prepareStatement(
SystemGlobals.getSql("AttachmentModel.addQuotaLimit"));
p.setString(1, limit.getDescription());
p.setInt(2, limit.getSize());
p.setInt(3, limit.getType());
p.executeUpdate();
p.close();
}
/**
* @see net.jforum.model.AttachmentModel#updateQuotaLimit(net.jforum.entities.QuotaLimit)
*/
public void updateQuotaLimit(QuotaLimit limit) throws Exception
{
PreparedStatement p = JForum.getConnection().prepareStatement(
SystemGlobals.getSql("AttachmentModel.updateQuotaLimit"));
p.setString(1, limit.getDescription());
p.setInt(2, limit.getSize());
p.setInt(3, limit.getType());
p.setInt(4, limit.getId());
p.executeUpdate();
p.close();
}
/**
* @see net.jforum.model.AttachmentModel#cleanGroupQuota()
*/
public void cleanGroupQuota() throws Exception
{
PreparedStatement p = JForum.getConnection().prepareStatement(
SystemGlobals.getSql("AttachmentModel.deleteGroupQuota"));
p.executeUpdate();
p.close();
}
/**
* @see net.jforum.model.AttachmentModel#setGroupQuota(int, int)
*/
public void setGroupQuota(int groupId, int quotaId) throws Exception
{
PreparedStatement p = JForum.getConnection().prepareStatement(
SystemGlobals.getSql("AttachmentModel.setGroupQuota"));
p.setInt(1, groupId);
p.setInt(2, quotaId);
p.executeUpdate();
p.close();
}
/**
* @see net.jforum.model.AttachmentModel#removeQuotaLimit(int)
*/
public void removeQuotaLimit(int id) throws Exception
{
this.removeQuotaLimit(new String[] { Integer.toString(id) });
}
/**
* @see net.jforum.model.AttachmentModel#removeQuotaLimit(java.lang.String[])
*/
public void removeQuotaLimit(String[] ids) throws Exception
{
PreparedStatement p = JForum.getConnection().prepareStatement(
SystemGlobals.getSql("AttachmentModel.removeQuotaLimit"));
for (int i = 0; i < ids.length; i++) {
p.setInt(1, Integer.parseInt(ids[i]));
p.executeUpdate();
}
p.close();
}
/**
* @see net.jforum.model.AttachmentModel#selectQuotaLimit()
*/
public List selectQuotaLimit() throws Exception
{
List l = new ArrayList();
PreparedStatement p = JForum.getConnection().prepareStatement(
SystemGlobals.getSql("AttachmentModel.selectQuotaLimit"));
ResultSet rs = p.executeQuery();
while (rs.next()) {
l.add(this.getQuotaLimit(rs));
}
rs.close();
p.close();
return l;
}
/**
* @see net.jforum.model.AttachmentModel#selectQuotaLimit()
*/
public QuotaLimit selectQuotaLimitByGroup(int groupId) throws Exception
{
QuotaLimit ql = null;
PreparedStatement p = JForum.getConnection().prepareStatement(
SystemGlobals.getSql("AttachmentModel.selectQuotaLimitByGroup"));
p.setInt(1, groupId);
ResultSet rs = p.executeQuery();
if (rs.next()) {
ql = this.getQuotaLimit(rs);
}
rs.close();
p.close();
return ql;
}
/**
* @see net.jforum.model.AttachmentModel#selectGroupsQuotaLimits()
*/
public Map selectGroupsQuotaLimits() throws Exception
{
Map m = new HashMap();
PreparedStatement p = JForum.getConnection().prepareStatement(
SystemGlobals.getSql("AttachmentModel.selectGroupsQuotaLimits"));
ResultSet rs = p.executeQuery();
while (rs.next()) {
m.put(new Integer(rs.getInt("group_id")), new Integer(rs.getInt("quota_limit_id")));
}
return m;
}
protected QuotaLimit getQuotaLimit(ResultSet rs) throws Exception
{
QuotaLimit ql = new QuotaLimit();
ql.setDescription(rs.getString("quota_desc"));
ql.setId(rs.getInt("quota_limit_id"));
ql.setSize(rs.getInt("quota_limit"));
ql.setType(rs.getInt("quota_type"));
return ql;
}
/**
* @see net.jforum.model.AttachmentModel#addExtensionGroup(net.jforum.entities.AttachmentExtensionGroup)
*/
public void addExtensionGroup(AttachmentExtensionGroup g) throws Exception
{
PreparedStatement p = JForum.getConnection().prepareStatement(
SystemGlobals.getSql("AttachmentModel.addExtensionGroup"));
p.setString(1, g.getName());
p.setInt(2, g.isAllow() ? 1 : 0);
p.setString(3, g.getUploadIcon());
p.setInt(4, g.getDownloadMode());
p.executeUpdate();
p.close();
}
/**
* @see net.jforum.model.AttachmentModel#removeExtensionGroups(java.lang.String[])
*/
public void removeExtensionGroups(String[] ids) throws Exception
{
PreparedStatement p = JForum.getConnection().prepareStatement(
SystemGlobals.getSql("AttachmentModel.removeExtensionGroups"));
for (int i = 0; i < ids.length; i++) {
p.setInt(1, Integer.parseInt(ids[i]));
p.executeUpdate();
}
p.close();
}
/**
* @see net.jforum.model.AttachmentModel#selectExtensionGroups()
*/
public List selectExtensionGroups() throws Exception
{
List l = new ArrayList();
PreparedStatement p = JForum.getConnection().prepareStatement(
SystemGlobals.getSql("AttachmentModel.selectExtensionGroups"));
ResultSet rs = p.executeQuery();
while (rs.next()) {
l.add(this.getExtensionGroup(rs));
}
rs.close();
p.close();
return l;
}
/**
* @see net.jforum.model.AttachmentModel#extensionsForSecurity()
*/
public Map extensionsForSecurity() throws Exception
{
Map m = new HashMap();
PreparedStatement p = JForum.getConnection().prepareStatement(
SystemGlobals.getSql("AttachmentModel.extensionsForSecurity"));
ResultSet rs = p.executeQuery();
while (rs.next()) {
int allow = rs.getInt("group_allow");
if (allow == 1) {
allow = rs.getInt("allow");
}
m.put(rs.getString("extension"), new Boolean(allow == 1));
}
rs.close();
p.close();
return m;
}
/**
* @see net.jforum.model.AttachmentModel#updateExtensionGroup(net.jforum.entities.AttachmentExtensionGroup)
*/
public void updateExtensionGroup(AttachmentExtensionGroup g) throws Exception
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -