SqlMapFactory.java
3.19 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
package com.sitech.util;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import java.io.Reader;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
public class SqlMapFactory {
private static Map<String, SqlMapClient> sqlMapClientMap = new HashMap<String, SqlMapClient>();
private static String defaultSqlMapConfig = "sqlmap.xml";
public static synchronized SqlMapClient getDefaultSqlMapClient() {
return getSqlMapClient(defaultSqlMapConfig);
}
public static synchronized SqlMapClient getOracleSqlMapClient(String mapConfig) {
return getSqlMapOracleClient(mapConfig);
}
public static synchronized SqlMapClient getSqlMapClient(String config) {
if (sqlMapClientMap.get(config) == null) {
String resource = config;
Reader reader;
SqlMapClient sqlMap = null;
try {
ResourceBundle LoginInfo = ResourceBundle.getBundle("LoginInfo");
String sClassforName = LoginInfo.getString("ClassforName");
String sUrl = LoginInfo.getString("url");
String sUserName = LoginInfo.getString("sqluser");
String sPassword = LoginInfo.getString("sqlpassword");
sPassword = DES3.decrypt(sPassword);
Properties properties = new Properties();
properties.put("SERVERDriver", sClassforName);
properties.put("SERVERConnectionURL", sUrl);
properties.put("SERVERUsername", sUserName);
properties.put("SERVERPassword", sPassword);
reader = Resources.getResourceAsReader(resource);
sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader, properties);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
}
sqlMapClientMap.put(config, sqlMap);
return sqlMap;
} else {
return (SqlMapClient) sqlMapClientMap.get(config);
}
}
public static synchronized SqlMapClient getSqlMapOracleClient(String config) {
if (sqlMapClientMap.get(config) == null) {
String resource = config;
Reader reader;
SqlMapClient sqlMap = null;
try {
ResourceBundle dbInfo = ResourceBundle.getBundle("db");
String sClassforName = dbInfo.getString("driver");
String sUrl = dbInfo.getString("url");
String sUserName = dbInfo.getString("sqluser");
String sPassword = dbInfo.getString("sqlpassword");
sPassword = DES3.decrypt(sPassword);
Properties properties = new Properties();
properties.put("SERVERDriver", sClassforName);
properties.put("SERVERConnectionURL", sUrl);
properties.put("SERVERUsername", sUserName);
properties.put("SERVERPassword", sPassword);
reader = Resources.getResourceAsReader(resource);
sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader, properties);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
}
sqlMapClientMap.put(config, sqlMap);
return sqlMap;
} else {
return (SqlMapClient) sqlMapClientMap.get(config);
}
}
}