📄 auctionworthdb.java~7~
字号:
package com.redmoon.forum.plugin.auction;
import java.sql.*;
import cn.js.fan.base.ObjectDb;
import cn.js.fan.db.Conn;
import cn.js.fan.db.PrimaryKey;
import cn.js.fan.util.ErrMsgException;
import cn.js.fan.util.ResKeyException;
import cn.js.fan.web.SkinUtil;
import java.util.Vector;
import com.redmoon.forum.plugin.ScoreMgr;
import com.redmoon.forum.plugin.ScoreUnit;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class AuctionWorthDb extends ObjectDb {
public AuctionWorthDb() {
super();
}
public AuctionWorthDb(int id) {
this.id = id;
init();
load();
}
public long[] getWorthOfAuction(long msgRootId) {
AuctionWorthCache awc = new AuctionWorthCache(this);
return awc.getWorthOfAuction(msgRootId);
}
public boolean create() throws ResKeyException {
int rowcount = 0;
Conn conn = null;
try {
conn = new Conn(connname);
PreparedStatement ps = conn.prepareStatement(this.QUERY_CREATE);
//msgRootId,moneyCode,price,dlt,referPrice,isValid
ps.setLong(1, msgRootId);
ps.setString(2, moneyCode);
ps.setDouble(3, price);
ps.setDouble(4, dlt);
ps.setDouble(5, referPrice);
ps.setInt(6, valid?1:0);
rowcount = conn.executePreUpdate();
} catch (SQLException e) {
logger.error("create:" + e.getMessage());
throw new ResKeyException(new SkinUtil(), SkinUtil.ERR_DB);
} finally {
if (conn != null) {
conn.close();
conn = null;
}
}
return rowcount>0? true:false;
}
/**
* del
*
* @return boolean
* @throws ErrMsgException
* @todo Implement this cn.js.fan.base.ObjectDb method
*/
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, id);
rowcount = conn.executePreUpdate();
} catch (SQLException e) {
logger.error(e.getMessage());
} finally {
if (conn != null) {
conn.close();
conn = null;
}
}
if (rowcount > 0) {
AuctionWorthCache cc = new AuctionWorthCache(this);
primaryKey.setValue(new Long(msgRootId));
cc.refreshDel(primaryKey);
}
return rowcount>0? true:false;
}
/**
*
* @param pk Object
* @return Object
* @todo Implement this cn.js.fan.base.ObjectDb method
*/
public ObjectDb getObjectRaw(PrimaryKey pk) {
return new AuctionWorthDb(pk.getIntValue());
}
public AuctionWorthDb getAuctionWorthDb(long id) {
return (AuctionWorthDb)getObjectDb(new Long(id));
}
/**
* load
*
* @throws ErrMsgException
* @todo Implement this cn.js.fan.base.ObjectDb method
*/
public void load() {
ResultSet rs = null;
Conn conn = new Conn(connname);
try {
PreparedStatement ps = conn.prepareStatement(this.QUERY_LOAD);
ps.setInt(1, id);
primaryKey.setValue(new Integer(id));
rs = conn.executePreQuery();
if (rs.next()) {
//moneyCode,price,dlt,referPrice,isValid
moneyCode = rs.getString(1);
price = rs.getDouble(2);
dlt = rs.getDouble(3);
referPrice = rs.getDouble(4);
valid = rs.getInt(5)==1?true:false;
msgRootId = rs.getInt(6);
loaded = true;
}
} catch (SQLException e) {
logger.error("load:" + e.getMessage());
}
finally {
if (conn!=null) {
conn.close();
conn = null;
}
}
}
/**
* 取得对应于msgRootId的所有的价格明细
* @param msgRootId int
* @return Vector
*/
public Vector list(int msgRootId) {
Vector v = new Vector();
Conn conn = new Conn(connname);
ResultSet rs = null;
String sql = "select id from " + tableName + " where msgRootId=?";
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, msgRootId);
rs = conn.executePreQuery();
if (rs != null) {
while (rs.next()) {
int id = rs.getInt(1);
v.addElement(getAuctionWorthDb(id));
}
}
} catch (SQLException e) {
logger.error("list(int msgRootId): " + e.getMessage());
} finally {
if (conn != null) {
conn.close();
conn = null;
}
}
return v;
}
/**
* save
*
* @return boolean
* @throws ErrMsgException
* @todo Implement this cn.js.fan.base.ObjectDb method
*/
public boolean save() throws ErrMsgException {
int rowcount = 0;
Conn conn = null;
try {
conn = new Conn(connname);
PreparedStatement ps = conn.prepareStatement(this.QUERY_SAVE);
ps.setString(1, moneyCode);
ps.setDouble(2, price);
ps.setDouble(3, dlt);
ps.setDouble(4, referPrice);
ps.setInt(5, valid?1:0);
ps.setInt(6, msgRootId);
ps.setInt(7, id);
rowcount = conn.executePreUpdate();
if (rowcount>0) {
AuctionWorthCache uc = new AuctionWorthCache(this);
primaryKey.setValue(new Integer(this.id));
uc.refreshSave(primaryKey);
}
} catch (SQLException e) {
logger.error("save:" + e.getMessage());
} finally {
if (conn != null) {
conn.close();
conn = null;
}
}
return rowcount>0? true:false;
}
public void setMsgRootId(int msgRootId) {
this.msgRootId = msgRootId;
}
public void setMoneyCode(String moneyCode) {
this.moneyCode = moneyCode;
}
public void setPrice(double price) {
this.price = price;
}
public void setReferPrice(double referPrice) {
this.referPrice = referPrice;
}
public void setDlt(double dlt) {
this.dlt = dlt;
}
public void setValid(boolean valid) {
this.valid = valid;
}
public void setId(int id) {
this.id = id;
}
public int getMsgRootId() {
return msgRootId;
}
public String getMoneyCode() {
return moneyCode;
}
public String getMoneyDanWei() {
ScoreMgr sm = new ScoreMgr();
ScoreUnit su = sm.getScoreUnit(moneyCode);
return su.getDanWei();
}
public String getMoneyName() {
ScoreMgr sm = new ScoreMgr();
ScoreUnit su = sm.getScoreUnit(moneyCode);
return su.getName();
}
public double getPrice() {
return price;
}
public double getReferPrice() {
return referPrice;
}
public double getDlt() {
return dlt;
}
public boolean isValid() {
return valid;
}
public int getId() {
return id;
}
private long msgRootId;
private String moneyCode;
private double price;
private double referPrice;
private double dlt;
private boolean valid = true;
private int id;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -