📄 dbboard.java
字号:
package com.laoer.bbscs.bbs.business;
import com.laoer.bbscs.db.*;
import java.util.List;
import java.util.Hashtable;
import java.sql.*;
import com.laoer.bbscs.exception.ObjectException;
import com.laoer.bbscs.exception.ObjectNoExistException;
import com.laoer.bbscs.sysinfo.*;
import com.laoer.bbscs.util.*;
import org.apache.log4j.*;
import com.laoer.bbscs.servlet.*;
public class DBBoard
extends Board
implements DBInf {
ResultSet rs = null;
static Logger logger = Logger.getLogger(DBBoard.class.getName());
static final String LOAD_BOARDS = "select * from board order by Orders";
static final String LOAD_BOARD = "select * from board where ID = ?";
static final String LOAD_BOARD_BYNAME =
"select * from board where BoardName = ?";
static final String LOAD_BOARD_NAME =
"select * from board where BoardName = ? or EBardName = ?";
static final String LOAD_BOARD_RENAME =
"select * from board where BoardName = ? and ID <> ?";
static final String INSERT_BOARD = "insert into board (ID,BoardName,EBardName,BMaster,Attrib,Orders) values (?,?,?,?,?,?)";
static final String UPDATE_BOARD = "update board set BoardName=?,EBardName=?,BMaster=?,Attrib=?,Orders=? where ID = ?";
static final String DELETE_BOARD = "delete from board where ID = ?";
static final String LOAD_ORDERS = "select max(Orders)+5 as orders from board";
public DBBoard() {
}
public int getBoardOrders() {
int orders = 1;
TranContext myDBTrans = new TranContext();
try {
myDBTrans.prepareStatement(LOAD_ORDERS);
rs = myDBTrans.executeQuery();
if (rs.next()) {
orders = rs.getInt("orders");
}
if (orders == 0) {
orders = 5;
}
rs.close();
return orders;
}
catch (SQLException e) {
return Sys.RESULT_RIGHT;
}
finally {
try {
if (rs != null) {
rs.close();
}
}
catch (SQLException e) {
}
try {
myDBTrans.close();
}
catch (SQLException e) {
}
myDBTrans.freeCon();
}
}
public int createBoard(TranContext aTranContext) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
this.insertDB(myDBTrans);
this.setBoardList(myDBTrans);
UpMsg aUpMsg = new UpMsg(2);
ServerSession.upMsg(aUpMsg);
return Sys.RESULT_RIGHT;
}
catch (ObjectException e) {
logger.error(e);
return Sys.RESULT_OBJECTEXCEPTION;
}
finally {
if (aTranContext == null && myDBTrans != null) {
myDBTrans.freeCon();
}
}
}
public List getBoardList(TranContext aTranContext, String key) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
List alist = null;
try {
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 updateBoard(TranContext aTranContext) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
this.updateDB(myDBTrans, "ID");
this.setBoardList(myDBTrans);
UpMsg aUpMsg = new UpMsg(2);
ServerSession.upMsg(aUpMsg);
return Sys.RESULT_RIGHT;
}
catch (ObjectException e) {
logger.error(e);
return Sys.RESULT_OBJECTEXCEPTION;
}
finally {
if (aTranContext == null && myDBTrans != null) {
myDBTrans.freeCon();
}
}
}
public int getBoard(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 delBoard(TranContext aTranContext, String key) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
this.delDB(myDBTrans, "ID");
this.setBoardList(myDBTrans);
UpMsg aUpMsg = new UpMsg(2);
ServerSession.upMsg(aUpMsg);
return Sys.RESULT_RIGHT;
}
catch (ObjectException e) {
logger.error(e);
return Sys.RESULT_OBJECTEXCEPTION;
}
finally {
if (aTranContext == null && myDBTrans != null) {
myDBTrans.freeCon();
}
}
}
public synchronized void setBoardList(TranContext aTranContext) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
List alist = null;
try {
logger.info("整理一级版区信息静态列表");
alist = this.loadDBs(myDBTrans, "All");
Hashtable aht = new Hashtable();
BoardInfo aBoardInfo = null;
for (int i = 0; i < alist.size(); i++) {
aBoardInfo = (BoardInfo) alist.get(i);
aht.put(String.valueOf(aBoardInfo.getID()), aBoardInfo);
logger.info("加入一级版区静态列表:" + aBoardInfo.getID() + " " +
aBoardInfo.getBoardName());
}
BoardList.boardlist = aht;
}
catch (ObjectException e) {
logger.error(e);
}
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_BOARD);
myDB.setLong(1, this.myBoardInfo.getID());
}
if (key.equals("NAME")) {
myDB.prepareStatement(LOAD_BOARD_BYNAME);
myDB.setString(1, this.myBoardInfo.getBoardName());
}
if (key.equals("RENAME")) {
myDB.prepareStatement(LOAD_BOARD_RENAME);
myDB.setString(1, this.myBoardInfo.getBoardName());
myDB.setLong(2, this.myBoardInfo.getID());
}
if (key.equals("ENAME")) {
myDB.prepareStatement(LOAD_BOARD_NAME);
myDB.setString(1, this.myBoardInfo.getBoardName());
myDB.setString(2, this.myBoardInfo.getEBardName());
}
rs = myDB.executeQuery();
if (rs.next()) {
if (isLoad) {
this.myBoardInfo.setID(rs.getLong("ID"));
this.myBoardInfo.setBoardName(rs.getString("BoardName"));
this.myBoardInfo.setEBardName(rs.getString("EBardName"));
this.myBoardInfo.setBMaster(rs.getString("BMaster"));
this.myBoardInfo.setAttrib(rs.getInt("Attrib"));
this.myBoardInfo.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);
BoardInfo aBoardInfo = null;
try {
if (key.equals("All")) {
myDB.prepareStatement(LOAD_BOARDS);
rs = myDB.executeQuery();
}
while (rs.next()) {
aBoardInfo = new BoardInfo();
aBoardInfo.setID(rs.getLong("ID"));
aBoardInfo.setBoardName(rs.getString("BoardName"));
aBoardInfo.setEBardName(rs.getString("EBardName"));
aBoardInfo.setBMaster(rs.getString("BMaster"));
aBoardInfo.setAttrib(rs.getInt("Attrib"));
aBoardInfo.setOrders(rs.getInt("Orders"));
alist.add(aBoardInfo);
aBoardInfo = 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_BOARD);
myDB.setLong(1, this.myBoardInfo.getID());
myDB.setString(2, this.myBoardInfo.getBoardName());
myDB.setString(3, this.myBoardInfo.getEBardName());
myDB.setString(4, this.myBoardInfo.getBMaster());
myDB.setInt(5, this.myBoardInfo.getAttrib());
myDB.setInt(6, this.myBoardInfo.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_BOARD);
myDB.setString(1, this.myBoardInfo.getBoardName());
myDB.setString(2, this.myBoardInfo.getEBardName());
myDB.setString(3, this.myBoardInfo.getBMaster());
myDB.setInt(4, this.myBoardInfo.getAttrib());
myDB.setInt(5, this.myBoardInfo.getOrders());
myDB.setLong(6, this.myBoardInfo.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("ID")) {
myDB.prepareStatement(DELETE_BOARD);
myDB.setLong(1, this.myBoardInfo.getID());
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 + -