MigrationSettingOperation.jsp
6.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.upgradetool.dbupgrade.upgrade.DBUtil" %>
<%@ page import="weaver.upgradetool.dbupgrade.upgrade.UpgradeRecordSet" %>
<%@ page import="java.io.BufferedWriter" %>
<%@ page import="java.io.FileOutputStream" %>
<%@ page import="java.io.FileReader" %>
<%@ page import="java.io.OutputStreamWriter" %>
<%@ page import="java.sql.Connection" %>
<%@ include file="/system/upgradetoe9/MigrationOperation.jsp"%>
<%
String sqlFilePath = GCONST.getSqlPath() ;
String dbserver = Util.null2String(request.getParameter("dbserver"));
String dbport = Util.null2String(request.getParameter("dbport"));
String dbname = Util.null2String(request.getParameter("dbname"));
String username = Util.null2String(request.getParameter("username"));
String password = Util.null2String(request.getParameter("password"));
String dbtype = Util.null2String(request.getParameter("dbtype"));
String verifycode = Util.null2String(request.getParameter("verifycode"));
String sourcepath = Util.null2String(request.getParameter("sourcepath"));
String method = Util.null2String(request.getParameter("method"));
Prop prop = Prop.getInstance();
String ecologydburl = prop.getPropValue(GCONST.getConfigFile(), "ecology.url");
String ecologydbuser = prop.getPropValue(GCONST.getConfigFile(), "ecology.user");
char[] c_code=new char[16];
new FileReader(GCONST.getRootPath()+File.separator+"WEB-INF"+File.separator+"code.key").read(c_code);
String realcode=new String(c_code).trim();
JSONObject jsonObj = new JSONObject();
if(method.equals("testConnection")){
boolean res = PropUtil.editProp( dbserver, dbport, dbname, username, password, dbtype, sourcepath,"");
if(!realcode.equals(verifycode)){
jsonObj.put("status","fail");
jsonObj.put("message","验证码不正确!");
out.print(jsonObj.toString());
return;
}
if(ecologydburl.contains(dbserver)&&ecologydburl.contains(dbname)&&ecologydbuser.equalsIgnoreCase(username)){
jsonObj.put("status","fail");
jsonObj.put("message","该页面需要填写源数据库参数,而非当前E9数据库库参数!");
out.print(jsonObj.toString());
return;
}
UpgradeRecordSet rs = new UpgradeRecordSet();
String E9Dbtype = rs.getDBType();
String tmpE7DBType="";
if(dbtype.toLowerCase().indexOf("sqlserver")>-1){
tmpE7DBType="sqlserver";
}else if(dbtype.toLowerCase().indexOf("oracle")>-1){
tmpE7DBType="oracle";
}
if("".equals(tmpE7DBType)){
jsonObj.put("status","fail");
jsonObj.put("message","原OA数据库类型获取错误"+tmpE7DBType);
out.print(jsonObj.toString());
return;
}
if(!E9Dbtype.equalsIgnoreCase(tmpE7DBType)){
jsonObj.put("status","fail");
jsonObj.put("message","据库类型不一致!原OA数据库类型为:"+tmpE7DBType+",当前E9数据库类型为:"+E9Dbtype);
out.print(jsonObj.toString());
return;
}
if(!res){
jsonObj.put("status","fail");
jsonObj.put("message","数据库参数文件保存失败!");
out.print(jsonObj.toString());
return;
}
DBUtil dbutil = new DBUtil();
Connection conn = dbutil.getBeTransConnection(request);
if(conn==null ||conn.isClosed()){
jsonObj.put("status","fail");
jsonObj.put("message","数据库连接失败,请检查参数信息是否正确!");
out.print(jsonObj.toString());
return;
}
String beforeCharacter= dbutil.getBeforeDBCharacterSet(conn,tmpE7DBType);
String nowCharacter= dbutil.getNowDBCharacterSet();
DBUtil dbUtil=new DBUtil();
String beforeLicense = Util.null2String(dbUtil.getBeforeLicense());
String propFilePath=GCONST.getRootPath() +"system"+ File.separatorChar+"upgradetoe9"+ File.separatorChar+"resource"+ File.separatorChar+"weaver_source.properties";
File fout = new File(propFilePath);
BufferedWriter fileOut = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fout,true),"GBK"));
String tempstring = "";
if(!"".equals(Util.null2String(beforeLicense))){
tempstring = "beforeLicense = " + beforeLicense;
fileOut.write(tempstring);
fileOut.newLine();
}
fileOut.flush();
fileOut.close();
//prop文件的备份
String propBakFilePath=GCONST.getRootPath() +"system"+ File.separatorChar+"upgradetoe9"+ File.separatorChar+"resource"+ File.separatorChar+"weaver_source_bak.properties";
File foutBak = new File(propBakFilePath);
BufferedWriter fileOutBak = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(foutBak,true),"GBK"));
if(!"".equals(Util.null2String(beforeLicense))){
fileOutBak.write(tempstring);
fileOutBak.newLine();
}
fileOutBak.flush();
fileOutBak.close();
if(beforeCharacter!=null&&!beforeCharacter.equalsIgnoreCase(nowCharacter)){
if(dbtype.equalsIgnoreCase("sqlserver")){
if(beforeCharacter.equals("936")){
beforeCharacter="简体中文GBK";
}else if (beforeCharacter.equals("65001")){
beforeCharacter="unicode UFT-8";
}
if(nowCharacter.equals("936")){
nowCharacter="简体中文GBK";
}else if (nowCharacter.equals("65001")){
nowCharacter="unicode UFT-8";
}
}
conn.close();
jsonObj.put("status","fail");
jsonObj.put("message","数据库字符集不一致!原OA数据库字符集为:"+beforeCharacter+",当前E9数据库字符集为:"+nowCharacter);
out.print(jsonObj.toString());
return;
}
jsonObj.put("status","success");
jsonObj.put("message","测试通过!请点击“下一步”继续!");
out.print(jsonObj.toString());
return;
}else{
jsonObj.put("status","fail");
jsonObj.put("message","表单参数不合法");
out.print(jsonObj.toString());
}
%>