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

📄 update.java

📁 MSN客服自动化机器人
💻 JAVA
字号:
package jm.form.msn.action;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.Statement;
import java.util.Properties;

import jm.JM;
import jm.entity.CommandOftenKeys;
import jm.form.msn.bean.BusinessUser;
import jm.form.msn.util.Command;
import jm.form.msn.util.Manager;

/**
 * 版本升级程序
 * 3版升级到4版、5版使用
 * 梦界家园MSNP15
 * @author ISHome
 * @version 0.4
 */
public class Update implements Command, CommandOftenKeys {

    public String getCommandHelp() {
	return "梦界机器人3版升级到4版数据库升级工具";
    }

    public String invoker(BusinessUser u, Manager manager) {
	try {
	    manager.showInfoMessageDialog("系统开始升级,请稍候。");
	    // 删除SM000600(表结构修改)
	    Connection conn = manager.getConnectionPool().getConnection();
	    conn.setAutoCommit(false);
	    Statement pstmt = conn.createStatement();
	    pstmt.executeUpdate("DROP TABLE SM000600");
	    pstmt.executeUpdate(creatTableSQL("SC000500.SQL"));
	    pstmt.executeUpdate(creatTableSQL("SC000700.SQL"));
	    pstmt.executeUpdate(creatTableSQL("SM000200.SQL"));
	    pstmt.executeUpdate(creatTableSQL("SM000300.SQL"));
	    pstmt.executeUpdate(creatTableSQL("SM000600.SQL"));
	    save(manager);
	    if (pstmt != null)
		pstmt.close();
	    if (conn != null) {
		conn.commit();
		conn.close();
	    }
	    manager.showInfoMessageDialog("系统升级成功。");
	} catch (Exception e) {
	    e.printStackTrace();
	    manager.showErrorMessageDialog("系统升级失败。");
	}
	return "";
    }

    /**
     * 获得建表语句
     * @param tablename
     * @return
     */
    private String creatTableSQL(String tablename) {
	StringBuffer sql = new StringBuffer(200);
	String dataline;
	try {
	    InputStream setdata = this.getClass().getClassLoader().getResourceAsStream(DATA_DB_SQL + tablename);
	    BufferedReader in = new BufferedReader(new InputStreamReader(setdata));
	    while ((dataline = in.readLine()) != null) {
		sql.append(dataline.intern());
	    }
	    in.close();
	} catch (Exception e) {
	    e.printStackTrace();
	}
	return "" + sql;
    }

    /**
     * 升级程序
     * 3版升级到4版、5版使用
     * @return
     */
    private boolean save(Manager manager) {
	try {
	    Properties prop = new Properties();
	    prop.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_SYSTEM));
	    prop.setProperty(SYSTEM_VER, JM.Ver);
	    File configOut = new File(this.getClass().getClassLoader().getSystemResource(CONFIG_SYSTEM).toURI());
	    FileOutputStream outfile = new FileOutputStream(configOut);
	    prop.store(outfile, CONFIG_SYSTEM);
	    outfile.close();
	    manager.loadConfigMap();
	} catch (Exception ex) {
	    ex.printStackTrace();
	    return false;
	}

	return true;
    }
}

⌨️ 快捷键说明

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