jdbc.jsp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <%@page contentType="text/html;charset=UTF-8"%>
  2. <%@page import="java.io.*"%>
  3. <%@page import="java.util.*"%>
  4. <%@page import="javax.sql.*"%>
  5. <%@page import="org.springframework.context.ApplicationContext"%>
  6. <%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
  7. <%@page import="com.mossle.core.jdbc.DbcpDataSourceInfo"%>
  8. <%@page import="com.mossle.core.jdbc.DataSourceInfo"%>
  9. <%@page import="com.mossle.core.jdbc.DataSourceService"%>
  10. <%@page import="com.mossle.core.jdbc.DataSourceServiceFactoryBean"%>
  11. <%@page import="com.mossle.core.jdbc.DataSourceWrapper"%>
  12. <%
  13. ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(application);
  14. DataSourceService dataSourceService = (DataSourceService) ctx.getBean("dataSourceService");
  15. DataSourceServiceFactoryBean dataSourceServiceFactoryBean = (DataSourceServiceFactoryBean) ctx.getBean("&dataSourceService");
  16. String action = request.getParameter("action");
  17. if (action == null) {
  18. action = "list";
  19. }
  20. if ("close".equals(action)) {
  21. String name = request.getParameter("name");
  22. DataSourceWrapper dataSourceWrapper = dataSourceService.getDataSource(name);
  23. dataSourceWrapper.close();
  24. response.sendRedirect("jdbc.jsp");
  25. return;
  26. }
  27. if ("restart".equals(action)) {
  28. String name = request.getParameter("name");
  29. DataSourceWrapper dataSourceWrapper = dataSourceService.getDataSource(name);
  30. dataSourceWrapper.restart();
  31. response.sendRedirect("jdbc.jsp");
  32. return;
  33. }
  34. if ("edit".equals(action)) {
  35. String name = request.getParameter("name");
  36. DataSourceInfo dataSourceInfo = dataSourceService.getDataSourceInfo(name);
  37. pageContext.setAttribute("dataSourceInfo", dataSourceInfo);
  38. }
  39. if ("save".equals(action)) {
  40. String name = request.getParameter("name");
  41. String driverClassName = request.getParameter("driverClassName");
  42. String url = request.getParameter("url");
  43. String username = request.getParameter("username");
  44. String password = request.getParameter("password");
  45. String removeAbandoned = request.getParameter("removeAbandoned");
  46. String testWhileIdle = request.getParameter("testWhileIdle");
  47. String testOnBorrow = request.getParameter("testOnBorrow");
  48. String validationQuery = request.getParameter("validationQuery");
  49. DbcpDataSourceInfo dataSourceInfo = new DbcpDataSourceInfo();
  50. dataSourceInfo.setName(name);
  51. dataSourceInfo.setDriverClassName(driverClassName);
  52. dataSourceInfo.setUrl(url);
  53. dataSourceInfo.setUsername(username);
  54. dataSourceInfo.setRemoveAbandoned(Boolean.getBoolean(removeAbandoned));
  55. dataSourceInfo.setTestWhileIdle(Boolean.getBoolean(testWhileIdle));
  56. dataSourceInfo.setTestOnBorrow(Boolean.getBoolean(testOnBorrow));
  57. dataSourceInfo.setValidationQuery(validationQuery);
  58. dataSourceService.register(dataSourceInfo);
  59. response.sendRedirect("jdbc.jsp");
  60. return;
  61. }
  62. if ("remove".equals(action)) {
  63. String name = request.getParameter("name");
  64. DataSourceWrapper dataSourceWrapper = dataSourceService.getDataSource(name);
  65. dataSourceWrapper.close();
  66. dataSourceService.removeDataSource(name);
  67. dataSourceService.removeDataSourceInfo(name);
  68. response.sendRedirect("jdbc.jsp");
  69. return;
  70. }
  71. if ("toggle".equals(action)) {
  72. String name = request.getParameter("name");
  73. DataSourceWrapper dataSourceWrapper = dataSourceService.getDataSource(name);
  74. if (dataSourceWrapper.isLog4jdbcEnabled()) {
  75. dataSourceWrapper.disableLog4jdbc();
  76. } else {
  77. dataSourceWrapper.enableLog4jdbc();
  78. }
  79. response.sendRedirect("jdbc.jsp");
  80. return;
  81. }
  82. %>
  83. <html>
  84. <head>
  85. <meta charset="utf-8">
  86. <title>jdbc</title>
  87. <style>
  88. tbody tr:nth-child(odd) td,
  89. tbody tr:nth-child(odd) th {
  90. background-color: #f9f9f9;
  91. }
  92. </style>
  93. <script>
  94. function toggle(key) {
  95. if (key == "") {
  96. return;
  97. }
  98. var el = document.getElementById(key);
  99. if (el.style.display == 'none') {
  100. el.style.display = '';
  101. } else {
  102. el.style.display = 'none';
  103. }
  104. }
  105. </script>
  106. </head>
  107. <body>
  108. <table border="1">
  109. <thead>
  110. <tr>
  111. <th>name</th>
  112. <th>driverClassName</th>
  113. <th>url</th>
  114. <th>numActive</th>
  115. <th>numIdle</th>
  116. <th>closed</th>
  117. <th>log4jdbcEnabled</th>
  118. <th>error</th>
  119. <th>&nbsp;</th>
  120. </tr>
  121. </thead>
  122. <tbody>
  123. <%
  124. for (DataSourceInfo dataSourceInfo : dataSourceService.getDataSourceInfos()) {
  125. String name = dataSourceInfo.getName();
  126. DataSourceWrapper dataSourceWrapper = dataSourceService.getDataSource(name);
  127. pageContext.setAttribute("item", dataSourceInfo);
  128. pageContext.setAttribute("dataSource", dataSourceWrapper);
  129. %>
  130. <tr onclick="toggle('${item.name}')" style="${dataSourceService.throwable != null ? 'cursor:pointer' : ''}">
  131. <td>${item.name}</td>
  132. <td>${dataSource.basicDataSource.driverClassName}</td>
  133. <td>${dataSource.basicDataSource.url}</td>
  134. <td>${dataSource.basicDataSource.numActive}</td>
  135. <td>${dataSource.basicDataSource.numIdle}</td>
  136. <td>${dataSource.basicDataSource.closed}</td>
  137. <td>
  138. ${dataSource.log4jdbcEnabled}
  139. <button onclick="location.href='jdbc.jsp?action=toggle&name=${item.name}'">
  140. ${dataSource.log4jdbcEnabled ? 'disable' : 'enable'}
  141. </button>
  142. </td>
  143. <td>${dataSource.throwable != null}</td>
  144. <td>
  145. <a href="jdbc.jsp?action=close&name=${item.name}">close</a>
  146. <a href="jdbc.jsp?action=restart&name=${item.name}">restart</a>
  147. <a href="jdbc.jsp?action=edit&name=${item.name}">edit</a>
  148. <a href="jdbc.jsp?action=remove&name=${item.name}">remove</a>
  149. </td>
  150. </tr>
  151. <%
  152. if (dataSourceWrapper.getThrowable() != null) {
  153. %>
  154. <tr id="${item.name}" style="display:none;">
  155. <td colspan="9">
  156. <pre><%dataSourceWrapper.getThrowable().printStackTrace(new PrintWriter(out));%>
  157. </pre>
  158. </td>
  159. </tr>
  160. <%
  161. }
  162. }
  163. %>
  164. </tbody>
  165. </table>
  166. <br>
  167. <form action="jdbc.jsp" method="post">
  168. <input type="hidden" name="action" value="save">
  169. <fieldset>
  170. <table>
  171. <tr>
  172. <td>name</td>
  173. <td><input type="text" name="name" value="${dataSourceInfo.name}" size="100"></td>
  174. </tr>
  175. <tr>
  176. <td>driverClassName</td>
  177. <td><input type="text" name="driverClassName" value="${dataSourceInfo.driverClassName}" size="100"></td>
  178. </tr>
  179. <tr>
  180. <td>url</td>
  181. <td><input type="text" name="url" value="${dataSourceInfo.url}" size="100"></td>
  182. </tr>
  183. <tr>
  184. <td>username</td>
  185. <td><input type="text" name="username" value="${dataSourceInfo.username}" size="100"></td>
  186. </tr>
  187. <tr>
  188. <td>password</td>
  189. <td><input type="password" name="password" value="${dataSourceInfo.password}" size="100"></td>
  190. </tr>
  191. <tr>
  192. <td>removeAbandoned</td>
  193. <td><input type="text" name="removeAbandoned" value="${dataSourceInfo.removeAbandoned}" size="100"></td>
  194. </tr>
  195. <tr>
  196. <td>testWhileIdle</td>
  197. <td><input type="text" name="testWhileIdle" value="${dataSourceInfo.testWhileIdle}" size="100"></td>
  198. </tr>
  199. <tr>
  200. <td>testOnBorrow</td>
  201. <td><input type="text" name="testOnBorrow" value="${dataSourceInfo.testOnBorrow}" size="100"></td>
  202. </tr>
  203. <tr>
  204. <td>validationQuery</td>
  205. <td><input type="text" name="validationQuery" value="${dataSourceInfo.validationQuery}" size="100"></td>
  206. </tr>
  207. </table>
  208. <button>save</button>
  209. <a href="jdbc.jsp">clear</a>
  210. </fieldset>
  211. </form>
  212. <pre><%=dataSourceServiceFactoryBean.export()%></pre>
  213. </body>
  214. </html>