📄 dbbookmark.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 com.laoer.bbscs.util.*;
import com.laoer.bbscs.sysinfo.*;
import org.apache.log4j.*;
/**
* <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 DBBookMark
extends BookMark
implements DBInf {
ResultSet rs = null;
String SQL = "";
static Logger logger = Logger.getLogger(DBBookMark.class.getName());
public DBBookMark() {
}
public int delBookMark(TranContext aTranContext) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
this.delDB(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 int createBookMark(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 List getBookMarkList(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 getBookMark(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 getBookMarkNum(TranContext aTranContext) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
int total = 0;
SQL = "select count(*) as total from " + this.myBookMarkInfo.getTablename() +
" where UserID = ?";
myDBTrans.prepareStatement(SQL);
myDBTrans.setLong(1, this.myBookMarkInfo.getUserID());
rs = myDBTrans.executeQuery();
if (rs.next()) {
total = rs.getInt("total");
}
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 updateBookMark(TranContext aTranContext, String key) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
this.updateDB(myDBTrans, key);
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("reBookMark")) {
SQL = "select * from " + this.myBookMarkInfo.getTablename() +
" where BookMarkName = ? and UserID = ?";
myDB.prepareStatement(SQL);
myDB.setString(1, this.myBookMarkInfo.getBookMarkName());
myDB.setLong(2, this.myBookMarkInfo.getUserID());
rs = myDB.executeQuery();
}
if (key.equals("ID")) {
SQL = "select * from " + this.myBookMarkInfo.getTablename() +
" where ID= ? and UserID = ?";
myDB.prepareStatement(SQL);
myDB.setString(1, this.myBookMarkInfo.getID());
myDB.setLong(2, this.myBookMarkInfo.getUserID());
rs = myDB.executeQuery();
}
if (rs.next()) {
if (isLoad) {
this.myBookMarkInfo.setID(rs.getString("ID"));
this.myBookMarkInfo.setUserID(rs.getLong("UserID"));
this.myBookMarkInfo.setBookMarkName(rs.getString("BookMarkName"));
this.myBookMarkInfo.setUrl(rs.getString("Url"));
this.myBookMarkInfo.setAlt(rs.getString("Alt"));
}
}
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);
BookMarkInfo aBookMarkInfo = null;
try {
if (key.equals("myBookMarkList")) {
String SQLStr = "select * from " + this.myBookMarkInfo.getTablename() +
" where UserID = " + this.myBookMarkInfo.getUserID();
this.pages.setTotals(this.getBookMarkNum(myDB));
this.pages.doPageBreak();
this.sListPageBreak = this.pages.getListPageBreak();
this.pages.setSQL(SQLStr);
rs = this.pages.getRs(myDB, "ID");
}
while (rs.next()) {
aBookMarkInfo = new BookMarkInfo();
aBookMarkInfo.setID(rs.getString("ID"));
aBookMarkInfo.setUserID(rs.getLong("UserID"));
aBookMarkInfo.setBookMarkName(rs.getString("BookMarkName"));
aBookMarkInfo.setUrl(rs.getString("Url"));
aBookMarkInfo.setAlt(rs.getString("Alt"));
alist.add(aBookMarkInfo);
}
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 {
SQL = "insert into " + this.myBookMarkInfo.getTablename() +
" (ID,UserID,BookMarkName,Url,Alt) values (?,?,?,?,?)";
myDB.prepareStatement(SQL);
myDB.setString(1,
String.valueOf(Util.getaLongTime()) +
String.valueOf(myBookMarkInfo.getUserID()));
myDB.setLong(2, this.myBookMarkInfo.getUserID());
myDB.setString(3, this.myBookMarkInfo.getBookMarkName());
myDB.setString(4, this.myBookMarkInfo.getUrl());
myDB.setString(5, this.myBookMarkInfo.getAlt());
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")) {
SQL = "update " + this.myBookMarkInfo.getTablename() +
" set BookMarkName = ?,Url = ?,Alt = ? where ID = ? and UserID = ?";
myDB.prepareStatement(SQL);
myDB.setString(1, this.myBookMarkInfo.getBookMarkName());
myDB.setString(2, this.myBookMarkInfo.getUrl());
myDB.setString(3, this.myBookMarkInfo.getAlt());
myDB.setString(4, this.myBookMarkInfo.getID());
myDB.setLong(5, this.myBookMarkInfo.getUserID());
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")) {
SQL = "delete from " + this.myBookMarkInfo.getTablename() +
" where ID = ? and UserID = ?";
myDB.prepareStatement(SQL);
myDB.setString(1, this.myBookMarkInfo.getID());
myDB.setLong(2, this.myBookMarkInfo.getUserID());
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 + -