📄 dbbulletin.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 java.sql.*;
import org.apache.log4j.*;
import com.laoer.bbscs.sysinfo.*;
import com.laoer.bbscs.util.*;
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 DBBulletin
extends Bulletin
implements DBInf {
ResultSet rs = null;
String SQL = "";
static Logger logger = Logger.getLogger(DBBulletin.class.getName());
//Pages pages;
private static final String LOAD_NUM =
"select count(ID) as total from bulletin where isBull = ?";
private static final String LOAD_BULLETINS =
"select * from bulletin where isBull = ? order by AddTime desc,ID desc";
private static final String LOAD_BULLETINSBYID =
"select * from bulletin where ID = ?";
private static final String INSERT_BULLETINS =
"insert into bulletin (ID,ID2,Bid,Title,isBull,BoardName,AddTime) values (?,?,?,?,?,?,?)";
private static final String DEL_BULLETIN =
"delete from bulletin where ID = ?";
public DBBulletin() {
}
public void createBullFile(TranContext aTranContext) {
List myList = null;
this.pages = PagesFactory.getInstance();
this.pages.setPages(1);
this.pages.setPerPageNum(10);
myList = this.getBulletinList(aTranContext, "isBull");
int len = myList.size();
StringBuffer sb = new StringBuffer();
BulletinInfo aBulletinInfo;
for (int i = 0; i < len; i++) {
aBulletinInfo = (BulletinInfo) myList.get(i);
if (this.myBulletinInfo.getIsBull() == 0) {
sb.append("<tr><td><a href='" + Sys.getURL() +
"readAction.do?sid=###&bid=" + aBulletinInfo.getBid() +
"&recid=" + aBulletinInfo.getID2() + "&pages=1' title='" +
aBulletinInfo.getTitle() + "'>" +
Util.getCutString(aBulletinInfo.getTitle(), 8) +
"</a></td></tr>");
}
else if (this.myBulletinInfo.getIsBull() == 1) {
sb.append("<tr><td><a href='" + Sys.getURL() +
"readAction.do?sid=###&bid=" +
aBulletinInfo.getBid() +
"&recid=" + aBulletinInfo.getID2() + "&pages=1'>" +
aBulletinInfo.getTitle() +
"</a> <font color=#ff0000>[" +
aBulletinInfo.getBoardName() + "]</font></td></tr>");
}
}
String filepath = Util.getPubFilePath();
try {
if (this.myBulletinInfo.getIsBull() == 0) {
File file = new File(filepath + "bulletin.htm");
if (file.exists()) {
file.delete();
}
FileOutputStream wf = new FileOutputStream(filepath + "bulletin.htm");
if (Sys.isLocale()) {
wf.write(sb.toString().getBytes());
}
else {
wf.write(sb.toString().getBytes("UTF8"));
}
wf.close();
}
else if (this.myBulletinInfo.getIsBull() == 1) {
File file = new File(filepath + "commend.htm");
if (file.exists()) {
file.delete();
}
FileOutputStream wf = new FileOutputStream(filepath + "commend.htm");
if (Sys.isLocale()) {
wf.write(sb.toString().getBytes());
}
else {
wf.write(sb.toString().getBytes("UTF8"));
}
wf.close();
}
}
catch (IOException e) {
logger.error(e);
}
}
public int createBulletin(TranContext aTranContext) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
this.insertDB(myDBTrans);
this.createBullFile(myDBTrans);
return Sys.RESULT_RIGHT;
}
catch (ObjectException e) {
logger.error(e);
return Sys.RESULT_OBJECTEXCEPTION;
}
finally {
if (aTranContext == null && myDBTrans != null) {
myDBTrans.freeCon();
}
}
}
public int getBulletin(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 getBulletinNum(TranContext aTranContext) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
int total = 0;
myDBTrans.prepareStatement(LOAD_NUM);
myDBTrans.setInt(1, this.myBulletinInfo.getIsBull());
rs = myDBTrans.executeQuery();
if (rs.next()) {
total = rs.getInt("total");
}
rs.close();
return total;
}
catch (SQLException e) {
logger.error(e);
return Sys.RESULT_ZERO;
}
finally {
try {
if (rs != null) {
rs.close();
}
}
catch (SQLException e) {
}
try {
if (myDBTrans != null) {
myDBTrans.close();
}
}
catch (SQLException e) {
}
if (aTranContext == null && myDBTrans != null) {
myDBTrans.freeCon();
}
}
}
public int delBulletin(TranContext aTranContext, String key) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
this.delDB(myDBTrans, "ID");
this.createBullFile(myDBTrans);
return Sys.RESULT_RIGHT;
}
catch (ObjectException e) {
logger.error(e);
return Sys.RESULT_OBJECTEXCEPTION;
}
finally {
if (aTranContext == null && myDBTrans != null) {
myDBTrans.freeCon();
}
}
}
public List getBulletinList(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 void loadDB(TranContext myDB, String key, boolean isLoad) throws
ObjectException, ObjectNoExistException {
try {
if (key.equals("ID")) {
myDB.prepareStatement(LOAD_BULLETINSBYID);
myDB.setLong(1, this.myBulletinInfo.getID());
}
rs = myDB.executeQuery();
if (rs.next()) {
if (isLoad) {
this.myBulletinInfo.setID(rs.getLong("ID"));
this.myBulletinInfo.setID2(rs.getLong("ID2"));
this.myBulletinInfo.setBid(rs.getLong("Bid"));
this.myBulletinInfo.setTitle(rs.getString("Title"));
this.myBulletinInfo.setIsBull(rs.getInt("isBull"));
this.myBulletinInfo.setBoardName(rs.getString("BoardName"));
}
}
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);
BulletinInfo aBulletinInfo = null;
try {
if (key.equals("isBull")) {
String SQLStr = "select * from bulletin where isBull = " +
this.myBulletinInfo.getIsBull() +
" order by AddTime desc,ID desc";
this.pages.setTotals(this.getBulletinNum(myDB));
this.pages.doPageBreak();
this.sListPageBreak = this.pages.getListPageBreak();
this.pages.setSQL(SQLStr);
rs = this.pages.getRs(myDB, "ID");
}
while (rs.next()) {
aBulletinInfo = new BulletinInfo();
aBulletinInfo.setID(rs.getLong("ID"));
aBulletinInfo.setID2(rs.getLong("ID2"));
aBulletinInfo.setBid(rs.getLong("Bid"));
aBulletinInfo.setTitle(rs.getString("Title"));
aBulletinInfo.setIsBull(rs.getInt("isBull"));
aBulletinInfo.setBoardName(rs.getString("BoardName"));
alist.add(aBulletinInfo);
aBulletinInfo = 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_BULLETINS);
myDB.setLong(1, this.myBulletinInfo.getID());
myDB.setLong(2, this.myBulletinInfo.getID2());
myDB.setLong(3, this.myBulletinInfo.getBid());
myDB.setString(4, this.myBulletinInfo.getTitle());
myDB.setInt(5, this.myBulletinInfo.getIsBull());
myDB.setString(6, this.myBulletinInfo.getBoardName());
myDB.setLong(7, Util.getaLongTime());
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 {
}
public void delDB(TranContext myDB, String key) throws ObjectException {
try {
if (key.equals("ID")) {
myDB.prepareStatement(DEL_BULLETIN);
myDB.setLong(1, this.myBulletinInfo.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 + -