📄 dbelite.java
字号:
package com.laoer.bbscs.bbs.business;
import com.laoer.bbscs.db.*;
import java.util.List;
import com.laoer.bbscs.exception.ObjectException;
import com.laoer.bbscs.exception.ObjectNoExistException;
import com.laoer.bbscs.sysinfo.*;
import com.laoer.bbscs.util.*;
import java.util.List;
import java.sql.*;
import org.apache.log4j.*;
import java.io.*;
/**
* <p>Title: 天乙社区V5.0</p>
* <p>Description: BBS-CS天乙社区V5.0</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: laoer.com</p>
* @author 龚天乙
* @version 5.0
*/
public class DBElite
extends Elite
implements DBInf {
String SQL = "";
ResultSet rs = null;
private static final String INSERT_ELITE = "insert into elite (ID,PID,RootID,Rlitename,CreateUser,OpUser,Elitetime,Orders) values (?,?,?,?,?,?,?,?)";
private static final String LOAD_ELITE = "select * from elite where ID = ?";
private static final String LOAD_ELITE_PID =
"select * from elite where PID = ? order by Orders";
private static final String LOADS_ELITE =
"select * from elite where PID = ? and RootID = ? order by Orders";
private static final String DELETE_ELITE = "delete from elite where ID = ?";
private static final String UPDATE_ELITE =
"update elite set Rlitename = ? ,Orders = ? where ID = ?";
static Logger logger = Logger.getLogger(DBElite.class.getName());
public DBElite() {
}
public String getEliteDH(TranContext aTranContext, String pid, String bid,
String fileName) {
String strDH = "";
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
this.myEliteInfo.setID(Long.parseLong(pid));
this.loadDB(myDBTrans, "ID", true);
strDH = ">> <a href='" + fileName + "&bid=" + bid + "&pid=" + pid + "'>" +
this.myEliteInfo.getRlitename() + "</a> " + strDH;
strDH = this.getEliteDH(myDBTrans, String.valueOf(this.myEliteInfo.getPID()),
bid, fileName) + strDH;
}
catch (ObjectException e) {
logger.error(e);
return strDH;
}
catch (ObjectNoExistException e) {
return strDH;
}
finally {
if (aTranContext == null && myDBTrans != null) {
myDBTrans.freeCon();
}
}
return strDH;
}
public int getElite(TranContext aTranContext, String key, boolean isLoad) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
this.loadDB(myDBTrans, key, isLoad);
return Sys.RESULT_RIGHT;
}
catch (ObjectException e) {
logger.error(e);
return Sys.RESULT_OBJECTEXCEPTION;
}
catch (ObjectNoExistException e) {
return Sys.RESULT_OBJECTNOEXISTEXCEPTION;
}
finally {
if (aTranContext == null && myDBTrans != null) {
myDBTrans.freeCon();
}
}
}
public int changeElite(TranContext aTranContext, EliteInfo[] EliteInfos) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
int len = EliteInfos.length;
for (int i = 0; i < len; i++) {
this.myEliteInfo = (EliteInfo) EliteInfos[i];
this.updateDB(myDBTrans, "ID");
}
return Sys.RESULT_RIGHT;
}
catch (ObjectException e) {
logger.error(e);
return Sys.RESULT_OBJECTEXCEPTION;
}
finally {
if (aTranContext == null && myDBTrans != null) {
myDBTrans.freeCon();
}
}
}
public List getEliteList(TranContext aTranContext, String key) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
List alist = null;
alist = this.loadDBs(myDBTrans, key);
return alist;
}
catch (ObjectException e) {
logger.error(e);
return (List) Sys.RESULT_NULL;
}
finally {
if (aTranContext == null && myDBTrans != null) {
myDBTrans.freeCon();
}
}
}
public int delEliteDirs(TranContext aTranContext, ForumInfo fi,
String[] parm2) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
int len = 0;
String sPostIDs = "";
len = parm2.length;
StringBuffer sb = new StringBuffer();
Forum f = ForumFactory.getInstance();
EliteInfo ei = new EliteInfo();
Elite el = EliteFactory.getInstance();
for (int i = 0; i < len; i++) {
ei.setPID(Long.parseLong(parm2[i]));
el.setEliteInfo(ei);
int result = el.getElite(myDBTrans, "PID", false);
if (result == Sys.RESULT_OBJECTNOEXISTEXCEPTION) {
fi.setEliteID(this.myEliteInfo.getPID());
fi.setElite(Long.parseLong(parm2[i]));
f.setForumInfo(fi);
f.updatePost(myDBTrans, "delEliteDir");
sb.append(parm2[i] + ",");
}
}
sPostIDs = sb.toString();
if (sPostIDs.endsWith(",")) {
sPostIDs = sPostIDs.substring(0, sPostIDs.length() - 1);
}
this.sElites = sPostIDs;
try {
this.delDB(myDBTrans, "delDirs");
return Sys.RESULT_RIGHT;
}
catch (ObjectException e) {
logger.error(e);
return Sys.RESULT_OBJECTEXCEPTION;
}
finally {
if (aTranContext == null && myDBTrans != null) {
myDBTrans.freeCon();
}
}
}
public int createElite(TranContext aTranContext) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
this.insertDB(myDBTrans);
return Sys.RESULT_RIGHT;
}
catch (ObjectException e) {
logger.error(e);
return Sys.RESULT_OBJECTEXCEPTION;
}
finally {
if (aTranContext == null && myDBTrans != null) {
myDBTrans.freeCon();
}
}
}
public void loadDB(TranContext myDB, String key, boolean isLoad) throws
ObjectException, ObjectNoExistException {
try {
if (key.equals("ID")) {
myDB.prepareStatement(LOAD_ELITE);
myDB.setLong(1, this.myEliteInfo.getID());
}
if (key.equals("PID")) {
myDB.prepareStatement(LOAD_ELITE_PID);
myDB.setLong(1, this.myEliteInfo.getPID());
}
rs = myDB.executeQuery();
if (rs.next()) {
if (isLoad) {
this.myEliteInfo.setID(rs.getLong("ID"));
this.myEliteInfo.setPID(rs.getLong("PID"));
this.myEliteInfo.setRootID(rs.getLong("RootID"));
this.myEliteInfo.setRlitename(rs.getString("Rlitename"));
this.myEliteInfo.setCreateUser(rs.getString("CreateUser"));
this.myEliteInfo.setOpUser(rs.getString("OpUser"));
this.myEliteInfo.setElitetime(rs.getLong("Elitetime"));
this.myEliteInfo.setOrders(rs.getInt("Orders"));
}
}
else {
throw new ObjectNoExistException();
}
}
catch (SQLException e) {
throw new ObjectException(e.toString());
}
finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
}
catch (SQLException e) {
}
try {
if (myDB != null) {
myDB.close();
}
}
catch (SQLException e) {
}
}
}
public List loadDBs(TranContext myDB, String key) throws ObjectException {
List alist = ListFactory.getInstance(2);
EliteInfo aEliteInfo = null;
try {
if (key.equals("Dir")) {
myDB.prepareStatement(LOADS_ELITE);
myDB.setLong(1, this.myEliteInfo.getPID());
myDB.setLong(2, this.myEliteInfo.getRootID());
}
rs = myDB.executeQuery();
while (rs.next()) {
aEliteInfo = new EliteInfo();
aEliteInfo.setID(rs.getLong("ID"));
aEliteInfo.setPID(rs.getLong("PID"));
aEliteInfo.setRootID(rs.getLong("RootID"));
aEliteInfo.setRlitename(rs.getString("Rlitename"));
aEliteInfo.setCreateUser(rs.getString("CreateUser"));
aEliteInfo.setOpUser(rs.getString("OpUser"));
aEliteInfo.setElitetime(rs.getLong("Elitetime"));
aEliteInfo.setOrders(rs.getInt("Orders"));
alist.add(aEliteInfo);
aEliteInfo = null;
}
return alist;
}
catch (SQLException e) {
throw new ObjectException(e.toString());
}
finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
}
catch (SQLException e) {
}
try {
if (myDB != null) {
myDB.close();
}
}
catch (SQLException e) {
}
}
}
public void insertDB(TranContext myDB) throws ObjectException {
try {
myDB.prepareStatement(INSERT_ELITE);
myDB.setLong(1, this.myEliteInfo.getID());
myDB.setLong(2, this.myEliteInfo.getPID());
myDB.setLong(3, this.myEliteInfo.getRootID());
myDB.setString(4, this.myEliteInfo.getRlitename());
myDB.setString(5, this.myEliteInfo.getCreateUser());
myDB.setString(6, this.myEliteInfo.getOpUser());
myDB.setLong(7, this.myEliteInfo.getElitetime());
myDB.setInt(8, this.myEliteInfo.getOrders());
myDB.executeUpdate();
}
catch (SQLException e) {
throw new ObjectException(e.toString());
}
finally {
try {
if (myDB != null) {
myDB.close();
}
}
catch (SQLException e) {
}
}
}
public void updateDB(TranContext myDB, String key) throws ObjectException {
try {
if (key.equals("ID")) {
myDB.prepareStatement(UPDATE_ELITE);
myDB.setString(1, this.myEliteInfo.getRlitename());
myDB.setInt(2, this.myEliteInfo.getOrders());
myDB.setLong(3, this.myEliteInfo.getID());
myDB.executeUpdate();
}
}
catch (SQLException e) {
throw new ObjectException(e.toString());
}
finally {
try {
if (myDB != null) {
myDB.close();
}
}
catch (SQLException e) {
}
}
}
public void delDB(TranContext myDB, String key) throws ObjectException {
try {
if (key.equals("delDir")) {
myDB.prepareStatement(DELETE_ELITE);
myDB.setLong(1, this.myEliteInfo.getID());
}
if (key.equals("delDirs")) {
SQL = "delete from elite where ID in (" + this.sElites + ")";
myDB.prepareStatement(SQL);
}
myDB.executeUpdate();
}
catch (SQLException e) {
throw new ObjectException(e.toString());
}
finally {
try {
if (myDB != null) {
myDB.close();
}
}
catch (SQLException e) {
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -