www.pudn.com > Community_open20061104.rar > AuctionDb.java~5~
package com.redmoon.forum.plugin.auction; import java.sql.*; import java.sql.Date; import java.util.*; import javax.servlet.http.HttpServletRequest; import cn.js.fan.base.ObjectDb; import cn.js.fan.db.Conn; import cn.js.fan.db.PrimaryKey; import cn.js.fan.util.*; import cn.js.fan.web.SkinUtil; /** * *Title:
* *Description:存放情人路贴子的属性,msgRootId,state等
* *Copyright: Copyright (c) 2005
* *Company:
* * @author not attributable * @version 1.0 */ public class AuctionDb extends ObjectDb { public static final int STATE_SELLOUT = 1; // 销售完 public static final int STATE_SELLING = 0; // 销售中 public static final int USER_TYPE_SHOP = 0; public static final int USER_TYPE_PERSON = 1; public static final int SELL_TYPE_AUCTION = 0; public static final int SELL_TYPE_SELL = 1; public static final int NONE_ORDER = -1; public static final int DEFAULT_RECOMMAND_MAX = 6; public AuctionDb() { super(); } public AuctionDb(long msgRootId) { this.msgRootId = msgRootId; init(); load(); } private int state; public void setmsgRootId(long msgRootId) { this.msgRootId = msgRootId; } public void setState(int state) { this.state = state; } public void setName(String name) { this.name = name; } public void setSpouse(String spouse) { this.spouse = spouse; } public void setUserType(int userType) { this.userType = userType; } public void setCount(int count) { this.count = count; } public void setUserName(String userName) { this.userName = userName; } public void setSellType(int sellType) { this.sellType = sellType; } public void setShopDir(String shopDir) { this.shopDir = shopDir; } public void setBeginDate(java.util.Date beginDate) { this.beginDate = beginDate; } public void setEndDate(java.util.Date endDate) { this.endDate = endDate; } public void setCurBidPrice(double curBidPrice) { this.curBidPrice = curBidPrice; } public void setOrderId(int orderId) { this.orderId = orderId; } public void setRecommand(boolean recommand) { this.recommand = recommand; } public void setCatalogCode(String catalogCode) { this.catalogCode = catalogCode; } public void setShow(boolean show) { this.show = show; } public void setImage(String image) { this.image = image; } public long getMsgRootId() { return msgRootId; } public int getState() { return state; } public String getStateDesc(HttpServletRequest request) { return getStateDesc(request, state); } public String getStateDesc(HttpServletRequest request, int state) { String str = ""; switch (state) { case STATE_SELLOUT: str = AuctionSkin.LoadString(request, "STATE_SELLOUT"); break; case STATE_SELLING: str = AuctionSkin.LoadString(request, "STATE_SELLING"); break; default: } return str; } public String getSellTypeDesc(HttpServletRequest request) { String str = ""; switch (sellType) { case SELL_TYPE_AUCTION: str = AuctionSkin.LoadString(request, "sell_type_auction"); break; case SELL_TYPE_SELL: str = AuctionSkin.LoadString(request, "sell_type_sell"); break; default: } return str; } public String getName() { return name; } public String getSpouse() { return spouse; } public int getUserType() { return userType; } public int getCount() { return count; } public String getUserName() { return userName; } public int getSellType() { return sellType; } public java.util.Date getBeginDate() { return beginDate; } public java.util.Date getEndDate() { return endDate; } public String getShopDir() { return shopDir; } public double getCurBidPrice() { return curBidPrice; } public int getOrderId() { return orderId; } public boolean isRecommand() { return recommand; } public String getCatalogCode() { return catalogCode; } public boolean isShow() { return show; } public String getImage() { return image; } public boolean del() throws ErrMsgException { int rowcount = 0; Conn conn = null; try { conn = new Conn(connname); PreparedStatement ps = conn.prepareStatement(this.QUERY_DEL); ps.setInt(1, msgRootId); rowcount = conn.executePreUpdate(); } catch (SQLException e) { logger.error("del:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } if (rowcount > 0) { AuctionCache cc = new AuctionCache(this); primaryKey.setValue(new Integer(msgRootId)); cc.refreshDel(primaryKey); // 删除其附带的所有的AuctionWorthDb AuctionWorthDb aw = new AuctionWorthDb(); long[] ids = aw.getWorthOfAuction(msgRootId); if (ids!=null) { int len = ids.length; for (int i=0; i0? true:false; } public int getRecommandCount(String userName) { String sql = "select count(*) from " + tableName + " where userName=? and recommand=1"; Conn conn = new Conn(connname); int count = 0; try { PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, userName); ResultSet rs = conn.executePreQuery(); while (rs.next()) { count = rs.getInt(1); } } catch (SQLException e) { logger.error("getRecommandCount:" + e.getMessage()); } finally { if (conn!=null) { conn.close(); conn = null; } } return count; } public boolean save() { int rowcount = 0; Conn conn = null; try { conn = new Conn(connname); PreparedStatement ps = conn.prepareStatement(this.QUERY_SAVE); ps.setString(1, name); ps.setInt(2, userType); ps.setInt(3, count); ps.setInt(4, state); ps.setString(5, userName); ps.setInt(6, sellType); if (beginDate==null) beginDate = new java.util.Date(); ps.setString(7, DateUtil.toLongString(beginDate)); if (endDate==null) endDate = new java.util.Date(); ps.setString(8, DateUtil.toLongString(endDate)); ps.setString(9, shopDir); ps.setDouble(10, curBidPrice); ps.setInt(11, orderId); ps.setInt(12, recommand?1:0); ps.setString(13, catalogCode); ps.setInt(14, show?1:0); ps.setString(15, image); ps.setInt(16, msgRootId); rowcount = conn.executePreUpdate(); if (rowcount>0) { AuctionCache uc = new AuctionCache(this); primaryKey.setValue(new Integer(this.msgRootId)); uc.refreshSave(primaryKey); } } catch (SQLException e) { logger.error("save:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return rowcount>0? true:false; } private int sellType; public AuctionDb getAuctionDb(int msgRootId) { return (AuctionDb)getObjectDb(new Integer(msgRootId)); } public void load() { ResultSet rs = null; Conn conn = new Conn(connname); try { PreparedStatement ps = conn.prepareStatement(this.QUERY_LOAD); ps.setInt(1, msgRootId); primaryKey.setValue(new Integer(msgRootId)); rs = conn.executePreQuery(); if (rs.next()) { name = rs.getString(1); userType = rs.getInt(2); count = rs.getInt(3); state = rs.getInt(4); userName = rs.getString(5); sellType = rs.getInt(6); beginDate = DateUtil.parse(rs.getString(7)); endDate = DateUtil.parse(rs.getString(8)); shopDir = rs.getString(9); curBidPrice = rs.getDouble(10); orderId = rs.getInt(11); recommand = rs.getInt(12)==1?true:false; catalogCode = rs.getString(13); show = rs.getInt(14)==1?true:false; image = rs.getString(15); loaded = true; } } catch (SQLException e) { logger.error("load:" + e.getMessage()); } finally { if (conn!=null) { conn.close(); conn = null; } } } public Vector listRecommand(String userName) { Vector v = new Vector(); Conn conn = new Conn(connname); ResultSet rs = null; String sql = "select msgRootId from " + tableName + " where userName=? and recommand=1 and state=" + this.STATE_SELLING + " order by beginDate desc"; try { PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, userName); rs = conn.executePreQuery(); if (rs != null) { while (rs.next()) { int msgRootId = rs.getInt(1); v.addElement(getAuctionDb(msgRootId)); } } } catch (SQLException e) { logger.error("listRecommand(String userName): " + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return v; } public Vector list(String userName) { Vector v = new Vector(); Conn conn = new Conn(connname); ResultSet rs = null; String sql = "select msgRootId from " + tableName + " where userName=? order by recommand desc, beginDate desc"; try { PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, userName); rs = conn.executePreQuery(); if (rs != null) { while (rs.next()) { int msgRootId = rs.getInt(1); v.addElement(getAuctionDb(msgRootId)); } } } catch (SQLException e) { logger.error("list(String userName, String shopDir): " + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return v; } public Vector list(String userName, String shopDir) { Vector v = new Vector(); Conn conn = new Conn(connname); ResultSet rs = null; String sql = "select msgRootId from " + tableName + " where userName=? and shopDir=? order by recommand desc, beginDate desc"; try { PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, userName); ps.setString(2, shopDir); rs = conn.executePreQuery(); if (rs != null) { while (rs.next()) { int msgRootId = rs.getInt(1); v.addElement(getAuctionDb(msgRootId)); } } } catch (SQLException e) { logger.error("list(String userName, String shopDir): " + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return v; } private long msgRootId; private String name; private String spouse; private int userType; private int count; private String userName; private java.util.Date beginDate; private java.util.Date endDate; private String shopDir; private double curBidPrice; private int orderId; private boolean recommand; private String catalogCode; private boolean show = false; private String image; }