📄 auctionshopdirdb.java
字号:
package com.redmoon.forum.plugin.auction;
import cn.js.fan.base.ObjectDb;
import cn.js.fan.db.PrimaryKey;
import cn.js.fan.db.Conn;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import cn.js.fan.web.SkinUtil;
import cn.js.fan.util.ResKeyException;
import java.util.Iterator;
import com.redmoon.forum.MsgMgr;
import com.redmoon.forum.MsgDb;
import cn.js.fan.util.ErrMsgException;
public class AuctionShopDirDb extends ObjectDb {
private String userName;
private String code;
public static final String DEFAULT = "default"; // 默认所属的目录名称
public AuctionShopDirDb() {
super();
}
public AuctionShopDirDb(String userName, String code) {
this.userName = userName;
this.code = code;
init();
load();
}
/**
* 连同目录下的商品一起删除
* @return boolean
* @throws ResKeyException
*/
public boolean delWithAuction() throws ResKeyException,ErrMsgException {
int rowcount = 0;
Conn conn = null;
try {
conn = new Conn(connname);
PreparedStatement ps = conn.prepareStatement(this.QUERY_DEL);
ps.setString(1, userName);
ps.setString(2, code);
rowcount = conn.executePreUpdate();
AuctionShopDirCache uc = new AuctionShopDirCache(this);
primaryKey.setKeyValue("userName", userName);
primaryKey.setKeyValue("code", code);
uc.refreshDel(primaryKey);
// 将目录下的商品删除
AuctionDb ad = new AuctionDb();
Iterator ir = ad.list(userName, code).iterator();
MsgMgr mm = new MsgMgr();
MsgDb md = null;
while (ir.hasNext()) {
ad = (AuctionDb) ir.next();
md = mm.getMsgDb(ad.getMsgRootId());
md.delTopic(ad.getMsgRootId(), false);
}
} catch (SQLException e) {
logger.error("save:" + e.getMessage());
throw new ResKeyException(new SkinUtil(), SkinUtil.ERR_DB);
} finally {
if (conn != null) {
conn.close();
conn = null;
}
}
return rowcount==1?true:false;
}
public boolean del() throws ResKeyException {
int rowcount = 0;
Conn conn = null;
try {
conn = new Conn(connname);
PreparedStatement ps = conn.prepareStatement(this.QUERY_DEL);
ps.setString(1, userName);
ps.setString(2, code);
rowcount = conn.executePreUpdate();
AuctionShopDirCache uc = new AuctionShopDirCache(this);
primaryKey.setKeyValue("userName", userName);
primaryKey.setKeyValue("code", code);
uc.refreshDel(primaryKey);
// 将目录下的商品转至DEFAULT目录下
AuctionDb ad = new AuctionDb();
Iterator ir = ad.list(userName, code).iterator();
while (ir.hasNext()) {
ad = (AuctionDb) ir.next();
ad.setShopDir(DEFAULT);
ad.save();
}
} catch (SQLException e) {
logger.error("save:" + e.getMessage());
throw new ResKeyException(new SkinUtil(), SkinUtil.ERR_DB);
} finally {
if (conn != null) {
conn.close();
conn = null;
}
}
return rowcount==1?true:false;
}
public int getObjectCount(String sql) {
return 0;
}
public ObjectDb getObjectRaw(PrimaryKey pk) {
return new AuctionShopDirDb(pk.getKeyStrValue("userName"), pk.getKeyStrValue("code"));
}
public boolean create() throws ResKeyException {
int rowcount = 0;
Conn conn = null;
try {
conn = new Conn(connname);
PreparedStatement ps = conn.prepareStatement(this.QUERY_CREATE);
ps.setString(1, code);
ps.setString(2, dirName);
ps.setString(3, catalogCode);
ps.setString(4, userName);
ps.setString(5, color);
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;
}
public String toOptions(String userName) {
String str = "";
Iterator ir = list(userName).iterator();
while (ir.hasNext()) {
AuctionShopDirDb asd = (AuctionShopDirDb)ir.next();
str += "<option value='" + asd.getCode() + "'>" + asd.getDirName() + "</option>";
}
return str;
}
public Vector list(String userName) {
Vector v = new Vector();
Conn conn = new Conn(connname);
ResultSet rs = null;
String sql = "select code from " + tableName + " where userName=? order by sort desc";
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, userName);
rs = conn.executePreQuery();
if (rs!=null) {
while (rs.next()) {
String code = rs.getString(1);
v.addElement(getAuctionShopDirDb(userName, code));
}
}
}
catch (SQLException e) {
logger.error("list(String userName): " + e.getMessage());
}
finally {
if (conn!=null) {
conn.close();
conn = null;
}
}
return v;
}
public boolean save() throws ResKeyException {
int rowcount = 0;
Conn conn = null;
try {
conn = new Conn(connname);
PreparedStatement ps = conn.prepareStatement(this.QUERY_SAVE);
ps.setString(1, dirName);
ps.setString(2, catalogCode);
ps.setString(3, color);
ps.setString(4, userName);
ps.setString(5, code);
rowcount = conn.executePreUpdate();
AuctionShopDirCache uc = new AuctionShopDirCache(this);
primaryKey.setKeyValue("userName", userName);
primaryKey.setKeyValue("code", code);
uc.refreshSave(primaryKey);
} catch (SQLException e) {
logger.error("save:" + e.getMessage());
throw new ResKeyException(new SkinUtil(), SkinUtil.ERR_DB);
} finally {
if (conn != null) {
conn.close();
conn = null;
}
}
return rowcount>0? true:false;
}
public AuctionShopDirDb getAuctionShopDirDb(String userName, String code) {
primaryKey.setKeyValue("userName", userName);
primaryKey.setKeyValue("code", code);
return (AuctionShopDirDb)getObjectDb(primaryKey.getKeys());
}
public void load() {
ResultSet rs = null;
Conn conn = new Conn(connname);
try {
PreparedStatement ps = conn.prepareStatement(this.QUERY_LOAD);
//name,catalogCode,color from plugin_auction_shop_dir where userName=? and code=?
primaryKey.setKeyValue("userName", userName);
primaryKey.setKeyValue("code", code);
ps.setString(1, userName);
ps.setString(2, code);
rs = conn.executePreQuery();
if (rs.next()) {
dirName = rs.getString(1);
catalogCode = rs.getString(2);
color = rs.getString(3);
loaded = true;
}
} catch (SQLException e) {
logger.error("load:" + e.getMessage());
}
finally {
if (conn!=null) {
conn.close();
conn = null;
}
}
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setCode(String code) {
this.code = code;
}
public void setDirName(String dirName) {
this.dirName = dirName;
}
public void setCatalogCode(String catalogCode) {
this.catalogCode = catalogCode;
}
public void setColor(String color) {
this.color = color;
}
public String getUserName() {
return userName;
}
public String getCode() {
return code;
}
public String getDirName() {
return dirName;
}
public String getCatalogCode() {
return catalogCode;
}
public String getColor() {
return color;
}
private String dirName;
private String catalogCode = DEFAULT;
private String color = "";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -