Skip to content

Commit 6e9b6c8

Browse files
committed
remove druid
1 parent 9d465a6 commit 6e9b6c8

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies {
2525
compile 'org.nutz:nutz:1.r.65'
2626
compile 'com.alibaba:fastjson:1.2.28'
2727
compile 'com.h2database:h2:1.3.176'
28-
compile 'com.alibaba:druid:1.1.9'
28+
compile 'com.zaxxer:HikariCP:3.1.0'
2929
compile 'org.quartz-scheduler:quartz:2.2.1'
3030
compile 'javax.mail:mail:1.4.1'
3131
compile 'com.google.guava:guava:18.0'

src/main/java/org/nlpcn/jcoder/job/StatisticalJob.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.nlpcn.jcoder.job;
22

3-
import com.alibaba.druid.util.StringUtils;
43
import com.alibaba.fastjson.JSON;
54
import com.alibaba.fastjson.JSONObject;
65
import com.google.common.base.Strings;
@@ -119,11 +118,11 @@ public static void add(LogInfo log) {
119118
if (message.startsWith("Execute OK")) {
120119
// Execute OK ApiTest/test succesed ! use Time : 0
121120
(stats = new Stats()).successCount.set(1);
122-
duration = Integer.parseInt(StringUtils.subString(message, " succesed ! use Time : ", null).trim());
121+
duration = Integer.parseInt(StringUtil.subString(message, " succesed ! use Time : ", null).trim());
123122
} else if (message.startsWith("Execute ERR")) {
124123
// Execute ERR ApiTest/test useTime 0 erred : java.lang.reflect.InvocationTargetException...
125124
(stats = new Stats()).errorCount.set(1);
126-
duration = Integer.parseInt(StringUtils.subString(message, " useTime ", " erred : ").trim());
125+
duration = Integer.parseInt(StringUtil.subString(message, " useTime ", " erred : ").trim());
127126
} else {
128127
// 忽略其他日志信息
129128
return;

src/main/java/org/nlpcn/jcoder/server/H2Server.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.nlpcn.jcoder.server;
22

3-
import com.alibaba.druid.pool.DruidDataSource;
3+
import com.zaxxer.hikari.HikariDataSource;
44
import org.h2.tools.Server;
55
import org.nlpcn.jcoder.util.IOUtil;
66
import org.nlpcn.jcoder.util.StaticValue;
@@ -44,15 +44,11 @@ public static void startServer(NutConfig nc) {
4444
}
4545
}
4646

47-
DruidDataSource dds = new DruidDataSource();
47+
HikariDataSource dds = new HikariDataSource();
4848
dds.setDriverClassName("org.h2.Driver");
49-
dds.setUrl("jdbc:h2:" + h2db);
49+
dds.setJdbcUrl("jdbc:h2:" + h2db);
5050
dds.setUsername("sa");
5151
dds.setPassword("");
52-
dds.setInitialSize(10);
53-
dds.setMaxActive(100);
54-
dds.setTestOnReturn(true);
55-
dds.setValidationQuery("select 1");
5652
BasicDao basicDao = new BasicDao(dds);
5753

5854
StaticValue.systemDao = basicDao;

src/main/java/org/nlpcn/jcoder/util/StringUtil.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,28 @@ public static String trim(String value) {
8080
}
8181
return ((st > 0) || (len < value.length())) ? value.substring(st, len) : value;
8282
}
83+
84+
85+
/**
86+
* Example: subString("abcd","a","c")="b"
87+
*
88+
* @param src
89+
* @param start null while start from index=0
90+
* @param to null while to index=src.length
91+
* @return
92+
*/
93+
public static String subString(String src, String start, String to) {
94+
int indexFrom = start == null ? 0 : src.indexOf(start);
95+
int indexTo = to == null ? src.length() : src.indexOf(to);
96+
if (indexFrom < 0 || indexTo < 0 || indexFrom > indexTo) {
97+
return null;
98+
}
99+
100+
if (null != start) {
101+
indexFrom += start.length();
102+
}
103+
104+
return src.substring(indexFrom, indexTo);
105+
106+
}
83107
}

src/main/java/org/nlpcn/jcoder/util/dao/BasicDao.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.nlpcn.jcoder.util.dao;
22

3-
import com.alibaba.druid.pool.DruidDataSource;
3+
import com.zaxxer.hikari.HikariDataSource;
44
import org.nutz.castor.Castors;
55
import org.nutz.dao.*;
66
import org.nutz.dao.entity.Entity;
@@ -29,14 +29,13 @@ public class BasicDao {
2929

3030
@Inject
3131
protected Dao dao;
32-
private DruidDataSource ds;
32+
private HikariDataSource ds;
3333

3434
public BasicDao(String jdbcUrl, String username, String password) {
35-
ds = new DruidDataSource();
36-
ds.setUrl(jdbcUrl);
35+
ds = new HikariDataSource();
36+
ds.setJdbcUrl(jdbcUrl);
3737
ds.setUsername(username);
3838
ds.setPassword(password);
39-
ds.setMaxWait(60000);
4039
this.dao = new NutDao(ds);
4140
}
4241

0 commit comments

Comments
 (0)