1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers.sql;
12
13 import jakarta.servlet.http.HttpServletRequest;
14 import jakarta.servlet.http.HttpServletResponse;
15 import jakarta.servlet.http.HttpSession;
16
17 import org.springframework.beans.factory.annotation.Value;
18 import org.springframework.stereotype.Controller;
19 import org.springframework.web.bind.annotation.RequestMapping;
20 import org.springframework.web.servlet.ModelAndView;
21 import org.springframework.web.servlet.mvc.ParameterizableViewController;
22
23 import psiprobe.model.sql.DataSourceTestInfo;
24 import psiprobe.tools.TimeExpression;
25
26
27
28
29
30 @Controller
31 public class DataSourceTestController extends ParameterizableViewController {
32
33
34 private int maxRows;
35
36
37 private int rowsPerPage;
38
39
40 private int historySize;
41
42
43 private String replacePattern;
44
45
46 private long collectionPeriod;
47
48 @RequestMapping(path = "/sql/datasourcetest.htm")
49 @Override
50 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
51 throws Exception {
52 return super.handleRequest(request, response);
53 }
54
55 @Override
56 protected ModelAndView handleRequestInternal(HttpServletRequest request,
57 HttpServletResponse response) throws Exception {
58
59 HttpSession sess = request.getSession(false);
60
61 DataSourceTestInfo sessData = null;
62
63 if (sess != null) {
64 sessData = (DataSourceTestInfo) sess.getAttribute(DataSourceTestInfo.DS_TEST_SESS_ATTR);
65 }
66
67 String referer = request.getHeader("Referer");
68 String backUrl;
69 if (referer != null) {
70 backUrl = referer.replaceAll(replacePattern, "");
71 } else {
72 backUrl = null;
73 }
74
75 return new ModelAndView(getViewName())
76 .addObject("maxRows",
77 String.valueOf(sessData == null ? getMaxRows() : sessData.getMaxRows()))
78 .addObject("rowsPerPage",
79 String.valueOf(sessData == null ? getRowsPerPage() : sessData.getRowsPerPage()))
80 .addObject("historySize",
81 String.valueOf(sessData == null ? getHistorySize() : sessData.getHistorySize()))
82 .addObject("backURL", backUrl).addObject("collectionPeriod", getCollectionPeriod());
83 }
84
85
86
87
88
89
90 public long getCollectionPeriod() {
91 return collectionPeriod;
92 }
93
94
95
96
97
98
99 public void setCollectionPeriod(long collectionPeriod) {
100 this.collectionPeriod = collectionPeriod;
101 }
102
103
104
105
106
107
108 @Value("${psiprobe.beans.stats.collectors.connector.period}")
109 public void setCollectionPeriod(String collectionPeriod) {
110 this.collectionPeriod = TimeExpression.inSeconds(collectionPeriod);
111 }
112
113
114
115
116
117
118 public int getMaxRows() {
119 return maxRows;
120 }
121
122
123
124
125
126
127 @Value("1000")
128 public void setMaxRows(int maxRows) {
129 this.maxRows = maxRows;
130 }
131
132
133
134
135
136
137 public int getRowsPerPage() {
138 return rowsPerPage;
139 }
140
141
142
143
144
145
146 @Value("50")
147 public void setRowsPerPage(int rowsPerPage) {
148 this.rowsPerPage = rowsPerPage;
149 }
150
151
152
153
154
155
156 public int getHistorySize() {
157 return historySize;
158 }
159
160
161
162
163
164
165 @Value("30")
166 public void setHistorySize(int historySize) {
167 this.historySize = historySize;
168 }
169
170
171
172
173
174
175 public String getReplacePattern() {
176 return replacePattern;
177 }
178
179
180
181
182
183
184 @Value("^http(s)?://[a-zA-Z\\-\\.0-9]+(:[0-9]+)?")
185 public void setReplacePattern(String replacePattern) {
186 this.replacePattern = replacePattern;
187 }
188
189 @Value("datasourcetest")
190 @Override
191 public void setViewName(String viewName) {
192 super.setViewName(viewName);
193 }
194
195 }