📄 mocommanddao.java
字号:
package com.gctech.sms.dao;
import java.util.Collection;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import org.apache.log4j.Logger;
import com.gctech.sms.util.ConnectionManager;
import java.util.Vector;
import com.gctech.sms.core.CommandStatus;
import com.gctech.sms.vo.MoCommandObject;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.sql.*;
/**
* <p>Title: MO指令的访问类。</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: gctech</p>
* @author 王红宝
* @version $Id: MOCommandDao.java,v 1.3 2004/04/22 01:46:30 wanghb Exp $
*/
public class MOCommandDao {
public MOCommandDao() {
}
/**
* 找到所有状态正常的指令。
* */
public static Collection findAllValidCmd(){
Collection rt = new Vector();
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try{
con = ConnectionManager.getInstance().getConnection(MOCommandDao.class);
stmt = con.createStatement();
String sql = "SELECT ID,ClassName,LongCode,KeyWord,STATUS,LEV,GATEWAY "+
"FROM MOCommand WHERE STATUS != "+
CommandStatus.STATUS_FORBID.getValue()+
" ORDER BY LEV DESC,LongCode DESC,KeyWord DESC";
logger.debug(sql);
rs = stmt.executeQuery(sql);
while ( rs.next() ){
MoCommandObject cmd = new MoCommandObject();
cmd.setID(rs.getString(1));
cmd.setClassName(rs.getString(2));
cmd.setLongCode(rs.getString(3));
cmd.setKeyWord(rs.getString(4));
cmd.setStatus(rs.getInt(5));
cmd.setLevel(rs.getInt(6));
cmd.setGateway(rs.getInt(7));
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;
}
}
/**
* 增加一个指令。
* */
public static int add(MoCommandObject obj){
int rt = -1;
Connection con = null;
PreparedStatement pstmt = null;
try{
con = ConnectionManager.getInstance().getConnection(MOCommandDao.class);
pstmt = con.prepareStatement(
"insert into MOCommand(ID,STATUS,CLASSNAME,LONGCODE,KEYWORD,LEV,GATEWAY)values(?,?,?,?,?,?,?)");
pstmt.setString(1, IDGenerator.nextId(con));
pstmt.setInt(2, obj.getStatus());
pstmt.setString(3, obj.getClassName());
pstmt.setString(4, obj.getLongCode());
pstmt.setString(5, obj.getKeyWord());
pstmt.setInt(6, obj.getLevel());
pstmt.setInt(7, obj.getGateway());
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 MoCommandObject[] getAllMo(MoCommandObject infovalue) throws SQLException {//查询所有数据
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ArrayList list = new ArrayList();
try{
con = ConnectionManager.getInstance().getConnection(SmsServiceDao.class);
StringBuffer sql = new StringBuffer("select a.id,a.status,a.classname,");
sql.append( "a.longcode,a.keyword,a.lev,a.GATEWAY");
sql.append( " from mocommand a");
sql.append( " where 1=1 ");
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()){
MoCommandObject model = new MoCommandObject();
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);
String longcode = rs.getString("longcode");
if (!rs.wasNull()) model.setLongCode(longcode);
String keyword = rs.getString("keyword");
if (!rs.wasNull()) model.setKeyWord(keyword);
int lev = rs.getInt("lev");
if (!rs.wasNull()) model.setLevel(lev);
int gateway = rs.getInt("GATEWAY");
model.setGateway(gateway);
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);
}
}
}
//返回数据
return (MoCommandObject[])list.toArray(new MoCommandObject[list.size()]);
}
public int deleteMo(MoCommandObject infovalue) throws SQLException {//删除数据
Connection con = null;
PreparedStatement pstmt = null;
int rs = 0 ;
try{
con = ConnectionManager.getInstance().getConnection(SmsServiceDao.class);
StringBuffer sql = new StringBuffer("delete from mocommand where 1=1 ");
sql.append( "and mocommand.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 updateMo(MoCommandObject infovalue) throws SQLException {//更新数据
Connection con = null;
PreparedStatement pstmt = null;
int rs = 0 ;
try{
con = ConnectionManager.getInstance().getConnection(SmsServiceDao.class);
StringBuffer sql = new StringBuffer("update mocommand set ");
sql.append( " mocommand.status = '" + infovalue.getStatus() + "',");
sql.append( " mocommand.classname = '" + infovalue.getClassName() + "',");
sql.append( " mocommand.longcode = '" + infovalue.getLongCode() + "',");
sql.append( " mocommand.keyword = '" + infovalue.getKeyWord() + "',");
sql.append( " mocommand.lev = '" + infovalue.getLevel() + "',");
sql.append( " mocommand.GATEWAY = '" + infovalue.getGateway() + "',");
sql.setLength(sql.length()-1);
sql.append( " where 1=1");
if (infovalue.getID()!=null){
sql.append(" and mocommand.id = '" + infovalue.getID() + "'");
}
pstmt = con.prepareStatement(sql.toString());
logger.debug(sql.toString() + " rs返回");
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 MoCommandObject[] getByIdandStatus(MoCommandObject infovalue) throws SQLException {//查询所有数据
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ArrayList list = new ArrayList();
try{
con = ConnectionManager.getInstance().getConnection(SmsServiceDao.class);
StringBuffer sql = new StringBuffer("select a.id,a.status,a.classname,");
sql.append( "a.longcode,a.keyword,a.lev,a.GATEWAY");
sql.append( " from mocommand a");
sql.append( " where 1=1 ");
if (infovalue!=null && infovalue.getID()!=null && !infovalue.getID().equals("")){
sql.append( " and a.id = '" + infovalue.getID() + "'");
}
sql.append( " and a.status = '" + infovalue.getStatus() + "'");
logger.debug(sql.toString());
pstmt = con.prepareStatement(sql.toString());
rs = pstmt.executeQuery();
while (rs.next()){
MoCommandObject model = new MoCommandObject();
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);
String longcode = rs.getString("longcode");
if (!rs.wasNull()) model.setLongCode(longcode);
String keyword = rs.getString("keyword");
if (!rs.wasNull()) model.setKeyWord(keyword);
int lev = rs.getInt("lev");
if (!rs.wasNull()) model.setLevel(lev);
int gateway = rs.getInt("GATEWAY");
model.setGateway(gateway);
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);
}
}
}
//返回数据
return (MoCommandObject[])list.toArray(new MoCommandObject[list.size()]);
}
public static void main(String[] args) {
MOCommandDao MOCommandDao1 = new MOCommandDao();
}
static final Logger logger = Logger.getLogger(MOCommandDao.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -