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

📄 mobusinessdao.java

📁 采用JAVA开发
💻 JAVA
字号:
package com.gctech.sms.dao;

import com.gctech.sms.vo.MOBusinessVO;
import java.sql.Connection;
import java.sql.PreparedStatement;
import com.gctech.sms.util.ConnectionManager;
import org.apache.log4j.Logger;
import java.util.Collection;
import java.util.Vector;
import java.sql.Statement;
import java.sql.ResultSet;
import com.gctech.sms.core.CommandStatus;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 * <p>Title: 上行业务。</p>
 * <p>Description: 一个上行业务对应一个上行类,
 * 一个上行类有对应的ProductId,回复消息。
 * 回复消息格式是:第一段话^第二段话^第三段话</p>
 * 内容中如果有变量使用{0},{1}来替换。
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: gctech</p>
 * @author 王红宝
 * @version $Id: MOBusinessDao.java,v 1.3 2004/05/09 05:13:52 wengjl Exp $
 */

public class MOBusinessDao {
  public MOBusinessDao() {
  }
  /**
   * 找到所有状态正常的指令。
   * */
  public static Collection findAllValidCmd(){
    Collection rt = new Vector();
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;
    try{
      con = ConnectionManager.getInstance().getConnection(MOBusinessDao.class);
      stmt = con.createStatement();
      String sql = "SELECT * FROM MOHANDLER WHERE STATUS = "+
                             CommandStatus.STATUS_ONLINE.getValue();
      logger.debug(sql);
      rs = stmt.executeQuery(sql);

      while ( rs.next() ){
        MOBusinessVO cmd = new MOBusinessVO();
        cmd.setClassName(rs.getString("CLASSNAME"));
        cmd.setIsAbstract(rs.getInt("IsAbstract"));
        cmd.setProductId(rs.getString("ProductId"));
        cmd.setRetMsg(rs.getString("retMsg"));
        cmd.setStatus(rs.getInt("STATUS"));
        rt.add(cmd);
      }
    }catch( Throwable e ){
      logger.error(e, e);
    }finally{
      if ( rs != null ){
        try {
          rs.close();
        }
        catch (Throwable ex) {
          logger.error(ex, ex);
        }
      }
      if ( stmt != null ){
        try {
          stmt.close();
        }
        catch (Throwable ex) {
          logger.error(ex, ex);
        }
      }
      if ( con != null ){
        try {
          con.close();
        }
        catch (Throwable ex) {
          logger.error(ex, ex);
        }
      }
      return rt;
    }

  }


  /**
   * 增加一个MOHandler。
   * */
  public static int add(MOBusinessVO obj){
    int rt = -1;
    Connection con = null;
    PreparedStatement pstmt = null;
    try{
      logger.debug("增加数据");
      con = ConnectionManager.getInstance().getConnection(MOBusinessDao.class);
      pstmt = con.prepareStatement(
          "insert into MOHandler(ID,STATUS,CLASSNAME,IsAbstract,ProductId,retMsg)values(?,?,?,?,?,?)");
      pstmt.setString(1, IDGenerator.nextId(con));
      pstmt.setInt(2, obj.getStatus());
      pstmt.setString(3, obj.getClassName());
      pstmt.setInt(4, obj.getIsAbstract());
      pstmt.setString(5, obj.getProductId());
      pstmt.setString(6, obj.getRetMsg());
      rt = pstmt.executeUpdate();
    }catch( Throwable e ){
      logger.error(e, e);
    }finally{
      if ( pstmt != null ){
        try {
          pstmt.close();
        }
        catch (Throwable ex) {
          logger.error(ex, ex);
        }
      }
      if ( con != null ){
        try {
          con.close();
        }
        catch (Throwable ex) {
          logger.error(ex, ex);
        }
      }
      return rt;
    }
  }
  public MOBusinessVO[] getAllMoBusiness(MOBusinessVO infovalue) throws SQLException {//查询所有数据
        Connection con = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        ArrayList list = new ArrayList();
        try{
          con = ConnectionManager.getInstance().getConnection(MOBusinessDao.class);
          StringBuffer sql = new StringBuffer("select a.id,a.STATUS,a.CLASSNAME,");
          sql.append( "a.IsAbstract,a.ProductId,a.retMsg,b.BUSINESSNAME ");
          sql.append( " from MOHandler a,spbusiness b ");
          sql.append(" where 1=1 and a.ProductId = b.id");
          if (infovalue!=null && infovalue.getId()!=null && !infovalue.getId().equals("")){
              sql.append(" and a.id = '" + infovalue.getId() + "'");
          }

          logger.debug(sql.toString());

          pstmt = con.prepareStatement(sql.toString());
          rs = pstmt.executeQuery();
          while (rs.next()){
            MOBusinessVO model = new MOBusinessVO();
            String id = rs.getString("id");
            if (!rs.wasNull()) model.setId(id);
            int status = rs.getInt("status");
            if (!rs.wasNull()) model.setStatus(status);
            String classname = rs.getString("classname");
            if (!rs.wasNull()) model.setClassName(classname);
            int isabstract = rs.getInt("isAbstract");
            if (!rs.wasNull()) model.setIsAbstract(isabstract);
            String productid = rs.getString("ProductId");
            if (!rs.wasNull()) model.setProductId(productid);
            String retmsg = rs.getString("retMsg");
            if (!rs.wasNull()) model.setRetMsg(retmsg);
            String bname = rs.getString("BUSINESSNAME");
            if (!rs.wasNull()) model.setBusinessname(bname);

            list.add(model);
          }
        }catch( Throwable e ){
          logger.error(e, e);
        }finally{
          if ( rs != null ){
            try {
              rs.close();
            }
            catch (Throwable ex) {
              logger.error(ex, ex);
            }
          }
          if ( pstmt != null ){
            try {
              pstmt.close();
            }
            catch (Throwable ex) {
              logger.error(ex, ex);
            }
          }
          if ( con != null ){
            try {
              con.close();
            }
            catch (Throwable ex) {
              logger.error(ex, ex);
            }
          }
        }
        //返回数据
        logger.debug("12313123");
        return (MOBusinessVO[])list.toArray(new MOBusinessVO[list.size()]);
  }
  public int deleteMoBusiness(MOBusinessVO infovalue) throws SQLException {//删除数据
        Connection con = null;
        PreparedStatement pstmt = null;
        int rs = 0 ;
        try{
          con = ConnectionManager.getInstance().getConnection(MOBusinessDao.class);
          StringBuffer sql = new StringBuffer("delete from MOHandler where 1=1 ");
          sql.append( "and MOHandler.id = '" + infovalue.getId() + "'");

          pstmt = con.prepareStatement(sql.toString());
          rs = pstmt.executeUpdate();

        }catch( Throwable e ){
          logger.error(e, e);
        }finally{
          if ( pstmt != null ){
            try {
              pstmt.close();
            }
            catch (Throwable ex) {
              logger.error(ex, ex);
            }
          }
          if ( con != null ){
            try {
              con.close();
            }
            catch (Throwable ex) {
              logger.error(ex, ex);
            }
          }
        }
        //返回数据
        return rs;
  }
  public int updateMoBusiness(MOBusinessVO infovalue) throws SQLException {//更新数据
    Connection con = null;
    PreparedStatement pstmt = null;
    int rs = 0 ;
    try{
      con = ConnectionManager.getInstance().getConnection(MOBusinessDao.class);
      StringBuffer sql = new StringBuffer("update MOHandler set ");

      sql.append( " MOHandler.classname = '" + infovalue.getClassName()+ "',");
      sql.append( " MOHandler.IsAbstract = '" + infovalue.getIsAbstract() + "',");
      sql.append( " MOHandler.ProductId = '" + infovalue.getProductId()+ "',");
      sql.append( " MOHandler.retmsg = '" + infovalue.getRetMsg()+ "',");
      sql.append( " MOHandler.status = '" + infovalue.getStatus()+ "',");

      sql.setLength(sql.length()-1);
      sql.append( " where 1=1");
      if (infovalue.getId()!=null){
        sql.append(" and MOHandler.id = '" + infovalue.getId() + "'");
      }
      logger.debug(sql.toString());
      pstmt = con.prepareStatement(sql.toString());
      rs = pstmt.executeUpdate();

    }catch( Throwable e ){
      logger.error(e, e);
    }finally{
      if ( pstmt != null ){
        try {
          pstmt.close();
        }
        catch (Throwable ex) {
          logger.error(ex, ex);
        }
      }
      if ( con != null ){
        try {
          con.close();
        }
        catch (Throwable ex) {
          logger.error(ex, ex);
        }
      }
    }
    //返回数据
    return rs;

  }

  static final Logger logger = Logger.getLogger(MOBusinessDao.class);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -