⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbsubscibe.java

📁 天乙代码src_531.rar 天乙代码src_531.rar 天乙代码src_531.rar 天乙代码src_531.rar
💻 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 org.apache.log4j.*;
import java.sql.*;
import com.laoer.bbscs.sysinfo.*;
import com.laoer.bbscs.util.*;

/**
 * <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 DBSubscibe
    extends Subscibe
    implements DBInf {

  ResultSet rs = null;
  String SQL = "";
  static Logger logger = Logger.getLogger(DBSubscibe.class.getName());

  public DBSubscibe() {
  }

  public int getSubscibeNum(TranContext aTranContext) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    try {
      int total = 0;
      String strSQL = "select count(*) as total from " +
          this.mySubscibeInfo.getTablename() + " where UserID = ? and BID = ?";
      myDBTrans.prepareStatement(strSQL);
      myDBTrans.setLong(1, this.mySubscibeInfo.getUserID());
      myDBTrans.setLong(2, this.mySubscibeInfo.getBID());
      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 getSubscibe(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 List getSubscibeList(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 delSubscibe(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 updateSubscibe(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 int createSubscibe(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("repeat")) {
        SQL = "select * from " + this.mySubscibeInfo.getTablename() +
            " where UserID = ? and RID = ?";
        myDB.prepareStatement(SQL);
        myDB.setLong(1, mySubscibeInfo.getUserID());
        myDB.setLong(2, mySubscibeInfo.getRID());
      }
      if (key.equals("ID")) {
        SQL = "select * from " + this.mySubscibeInfo.getTablename() +
            " where ID = ?";
        myDB.prepareStatement(SQL);
        myDB.setString(1, mySubscibeInfo.getID());
      }
      rs = myDB.executeQuery();
      if (rs.next()) {
        if (isLoad) {
          mySubscibeInfo.setID(rs.getString("ID"));
          mySubscibeInfo.setUserID(rs.getLong("UserID"));
          mySubscibeInfo.setUname(rs.getString("Uname"));
          mySubscibeInfo.setRID(rs.getLong("RID"));
          mySubscibeInfo.setPostTitle(rs.getString("PostTitle"));
          mySubscibeInfo.setBID(rs.getLong("BID"));
          mySubscibeInfo.setEmail_inform(rs.getInt("Email_inform"));
          mySubscibeInfo.setMsg_inform(rs.getInt("Msg_inform"));
        }
      }
      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);
    SubscibeInfo aSubscibeInfo = null;
    try {
      if (key.equals("sendlist")) {
        SQL = "select * from " + this.mySubscibeInfo.getTablename() +
            " where RID = ?";
        myDB.prepareStatement(SQL);
        myDB.setLong(1, mySubscibeInfo.getRID());
        rs = myDB.executeQuery();
      }
      if (key.equals("mySubscibe")) {
        String strSQL = "select * from " + this.mySubscibeInfo.getTablename() +
            " where UserID = " + this.mySubscibeInfo.getUserID() +
            " and BID = " + this.mySubscibeInfo.getBID();
        this.pages.setTotals(this.getSubscibeNum(myDB));
        this.pages.doPageBreak();
        this.sListPageBreak = this.pages.getListPageBreak();
        this.pages.setSQL(strSQL);
        myDB.prepareStatement(this.pages.getSQLString("ID"));
        rs = myDB.executeQuery();
      }
      while (rs.next()) {
        aSubscibeInfo = new SubscibeInfo();
        aSubscibeInfo.setID(rs.getString("ID"));
        aSubscibeInfo.setUserID(rs.getLong("UserID"));
        aSubscibeInfo.setUname(rs.getString("Uname"));
        aSubscibeInfo.setRID(rs.getLong("RID"));
        aSubscibeInfo.setPostTitle(rs.getString("PostTitle"));
        aSubscibeInfo.setBID(rs.getLong("BID"));
        aSubscibeInfo.setEmail_inform(rs.getInt("Email_inform"));
        aSubscibeInfo.setMsg_inform(rs.getInt("Msg_inform"));
        alist.add(aSubscibeInfo);
        aSubscibeInfo = 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 {
      SQL = "insert into " + this.mySubscibeInfo.getTablename() + " (ID,UserID,Uname,RID,PostTitle,BID,Email_inform,Msg_inform) values (?,?,?,?,?,?,?,?)";
      myDB.prepareStatement(SQL);
      myDB.setString(1, mySubscibeInfo.getID());
      myDB.setLong(2, mySubscibeInfo.getUserID());
      myDB.setString(3, mySubscibeInfo.getUname());
      myDB.setLong(4, mySubscibeInfo.getRID());
      myDB.setString(5, mySubscibeInfo.getPostTitle());
      myDB.setLong(6, mySubscibeInfo.getBID());
      myDB.setInt(7, mySubscibeInfo.getEmail_inform());
      myDB.setInt(8, mySubscibeInfo.getMsg_inform());
      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("dy")) {
        SQL = "update " + this.mySubscibeInfo.getTablename() +
            " set Email_inform = ?,Msg_inform = ? where ID = ?";
        myDB.prepareStatement(SQL);
        myDB.setInt(1, mySubscibeInfo.getEmail_inform());
        myDB.setInt(2, mySubscibeInfo.getMsg_inform());
        myDB.setString(3, mySubscibeInfo.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")) {
        SQL = "delete from " + this.mySubscibeInfo.getTablename() +
            " where ID = ?";
        myDB.prepareStatement(SQL);
        myDB.setString(1, mySubscibeInfo.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 + -