1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.taglib;
25
26 import org.dbforms.util.SqlUtil;
27
28 import java.sql.Connection;
29
30 import javax.servlet.jsp.JspException;
31 import javax.servlet.jsp.PageContext;
32
33
34
35 /***
36 * Grunikiewicz.philip 2001-12-18 Obtain a connection (from the connection
37 * pool) using same settings defined in dbForms-config.xml file
38 */
39 public class DbGetConnectionTag extends AbstractScriptHandlerTag
40 implements javax.servlet.jsp.tagext.TryCatchFinally {
41 private transient Connection conn;
42 private String dbConnectionName;
43
44 /***
45 * DOCUMENT ME!
46 *
47 * @param connection
48 */
49 public void setConn(Connection connection) {
50 conn = connection;
51 }
52
53
54 /***
55 * DOCUMENT ME!
56 *
57 * @return
58 */
59 public Connection getConn() {
60 return conn;
61 }
62
63
64 /***
65 * DOCUMENT ME!
66 *
67 * @param name DOCUMENT ME!
68 */
69 public void setDbConnectionName(String name) {
70 dbConnectionName = name;
71 }
72
73
74 /***
75 * DOCUMENT ME!
76 *
77 * @return DOCUMENT ME!
78 */
79 public String getDbConnectionName() {
80 return dbConnectionName;
81 }
82
83
84 /***
85 * DOCUMENT ME!
86 *
87 * @return DOCUMENT ME!
88 *
89 * @throws javax.servlet.jsp.JspException DOCUMENT ME!
90 * @throws JspException DOCUMENT ME!
91 */
92 public int doEndTag() throws javax.servlet.jsp.JspException {
93 try {
94
95 SqlUtil.closeConnection(this.getConn());
96 this.setConn(null);
97 pageContext.removeAttribute(getId(), PageContext.PAGE_SCOPE);
98 } catch (Exception e) {
99 throw new JspException("Connection error" + e.getMessage());
100 }
101
102 return EVAL_PAGE;
103 }
104
105
106 /***
107 * DOCUMENT ME!
108 */
109 public void doFinally() {
110 dbConnectionName = null;
111 }
112
113
114 /***
115 * DOCUMENT ME!
116 *
117 * @return DOCUMENT ME!
118 *
119 * @throws JspException DOCUMENT ME!
120 * @throws IllegalArgumentException DOCUMENT ME!
121 */
122 public int doStartTag() throws JspException {
123 try {
124
125 this.setConn(getConfig().getConnection(dbConnectionName));
126 pageContext.setAttribute(getId(), this.getConn(),
127 PageContext.PAGE_SCOPE);
128 } catch (Exception e) {
129 throw new JspException("Connection error" + e.getMessage());
130 }
131
132 return EVAL_BODY_INCLUDE;
133 }
134 }