/
NonPreLoader.java
74 lines (53 loc) · 1.32 KB
/
NonPreLoader.java
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
package io;
import java.util.List;
import utils.Dao;
import bean.User;
import bean.UserLoginLog;
import bean.UserRole;
public class NonPreLoader {
public static void main(String[] args) {
try {
long start = System.currentTimeMillis();
NonPreLoader nonPreLoader = new NonPreLoader();
for(int i=0;i<1000;i++){
nonPreLoader.checkUserIsActivate(i);
}
long end = System.currentTimeMillis();
System.out.println(end - start);
} catch (Exception e) {
e.printStackTrace();
}
}
public boolean checkUserIsActivate(long user_id) throws Exception{
boolean success = false;
Dao dao = null;
try {
dao = new Dao();
User user = dao.findUser(user_id);
if(user != null && user.isActivate()){
List<UserRole> roles = dao.getUserRole(user_id);
if(hasUserRole(roles, "WebUser")){
List<UserLoginLog> loginList = dao.getUserLoginLog(user_id);
if(loginList.size() >0){
success = true;
}
}
}
} catch (Exception e) {
throw e;
}finally{
if(dao != null) dao.close();
}
return success;
}
public boolean hasUserRole(List<UserRole> list, String roleName){
boolean success = false;
for(UserRole role : list){
if(roleName.equals(role.getName())){
success = false;
break;
}
}
return success;
}
}