📄 auctionbiddb.java
字号:
package com.redmoon.forum.plugin.auction;
import cn.js.fan.base.ObjectDb;
import cn.js.fan.db.PrimaryKey;
import cn.js.fan.util.ErrMsgException;
import java.sql.ResultSet;
import cn.js.fan.util.ResKeyException;
import java.sql.SQLException;
import cn.js.fan.web.SkinUtil;
import cn.js.fan.db.Conn;
import java.sql.PreparedStatement;
import java.util.Vector;
import cn.js.fan.util.DateUtil;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class AuctionBidDb extends ObjectDb {
public AuctionBidDb() {
super();
}
public AuctionBidDb(int id) {
this.id = id;
init();
load();
}
public boolean del() throws ErrMsgException {
int rowcount = 0;
Conn conn = null;
try {
conn = new Conn(connname);
PreparedStatement ps = conn.prepareStatement(this.QUERY_DEL);
ps.setLong(1, msgRootId);
rowcount = conn.executePreUpdate();
} catch (SQLException e) {
logger.error(e.getMessage());
} finally {
if (conn != null) {
conn.close();
conn = null;
}
}
if (rowcount > 0) {
AuctionBidCache cc = new AuctionBidCache(this);
primaryKey.setValue(new Integer(id));
cc.refreshDel(primaryKey);
}
return rowcount>0? true:false;
}
public ObjectDb getObjectRaw(PrimaryKey pk) {
return new AuctionBidDb(pk.getIntValue());
}
public boolean create() throws ErrMsgException, ResKeyException {
int rowcount = 0;
Conn conn = null;
try {
conn = new Conn(connname);
PreparedStatement ps = conn.prepareStatement(this.QUERY_CREATE);
ps.setLong(1, msgRootId);
ps.setString(2, name);
ps.setDouble(3, price);
ps.setString(4, "" + System.currentTimeMillis());
rowcount = conn.executePreUpdate();
if (rowcount>0) {
AuctionDb ad = new AuctionDb();
ad = ad.getAuctionDb(msgRootId);
ad.setCurBidPrice(price);
ad.save();
}
} 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;
}
public boolean save() {
int rowcount = 0;
Conn conn = null;
try {
conn = new Conn(connname);
PreparedStatement ps = conn.prepareStatement(this.QUERY_SAVE);
//name=?,price=?
ps.setString(1, name);
ps.setDouble(2, price);
ps.setInt(3, id);
rowcount = conn.executePreUpdate();
if (rowcount>0) {
AuctionBidCache uc = new AuctionBidCache(this);
primaryKey.setValue(new Integer(id));
uc.refreshSave(primaryKey);
}
} catch (SQLException e) {
logger.error(e.getMessage());
} finally {
if (conn != null) {
conn.close();
conn = null;
}
}
return rowcount>0? true:false;
}
private long msgRootId;
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()) {
msgRootId = rs.getInt(1);
name = rs.getString(2);
price = rs.getDouble(3);
bidDate = DateUtil.parse(rs.getString(4));
loaded = true;
}
} catch (SQLException e) {
logger.error("load:" + e.getMessage());
}
finally {
if (conn!=null) {
conn.close();
conn = null;
}
}
}
public void setMsgRootId(long msgRootId) {
this.msgRootId = msgRootId;
}
public void setName(String name) {
this.name = name;
}
public void setPrice(double price) {
this.price = price;
}
public void setBidDate(java.util.Date bidDate) {
this.bidDate = bidDate;
}
public void setId(int id) {
this.id = id;
}
public long getMsgRootId() {
return msgRootId;
}
public String getName() {
return name;
}
public double getPrice() {
return price;
}
public java.util.Date getBidDate() {
return bidDate;
}
public int getId() {
return id;
}
public AuctionBidDb getAuctionBidDb(int id) {
return (AuctionBidDb)getObjectDb(new Integer(id));
}
public AuctionBidDb getLastBid(long msgRootId) {
Conn conn = new Conn(connname);
ResultSet rs = null;
String sql = "select id from " + tableName + " where msgRootId=? order by bidDate desc";
try {
conn.setMaxRows(1);
PreparedStatement ps = conn.prepareStatement(sql);
conn.setFetchSize(1);
ps.setLong(1, msgRootId);
rs = conn.executePreQuery();
if (rs!=null) {
while (rs.next()) {
int id = rs.getInt(1);
return getAuctionBidDb(id);
}
}
}
catch (SQLException e) {
logger.error("list: " + e.getMessage());
}
finally {
if (conn!=null) {
conn.close();
conn = null;
}
}
return null;
}
public Vector list(long msgRootId) {
Vector v = new Vector();
Conn conn = new Conn(connname);
ResultSet rs = null;
String sql = "select id from " + tableName + " where msgRootId=? order by price desc";
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setLong(1, msgRootId);
rs = conn.executePreQuery();
if (rs!=null) {
while (rs.next()) {
int id = rs.getInt(1);
v.addElement(getAuctionBidDb(id));
}
}
}
catch (SQLException e) {
logger.error("list: " + e.getMessage());
}
finally {
if (conn!=null) {
conn.close();
conn = null;
}
}
return v;
}
private String name;
private double price;
private java.util.Date bidDate;
private int id;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -