KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > taglib > DbGetConnection


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbGetConnection.java,v 1.19 2004/08/18 12:26:07 hkollmann Exp $
3  * $Revision: 1.19 $
4  * $Date: 2004/08/18 12:26:07 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23
24 package org.dbforms.taglib;
25
26 import org.dbforms.util.SqlUtil;
27
28 import java.sql.Connection JavaDoc;
29
30 import javax.servlet.jsp.JspException JavaDoc;
31 import javax.servlet.jsp.PageContext JavaDoc;
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 DbGetConnection extends TagSupportWithScriptHandler
40    implements javax.servlet.jsp.tagext.TryCatchFinally JavaDoc {
41    private transient Connection JavaDoc conn;
42    private String JavaDoc dbConnectionName;
43
44    /**
45     * DOCUMENT ME!
46     *
47     * @param connection
48     */

49    public void setConn(Connection JavaDoc connection) {
50       conn = connection;
51    }
52
53
54    /**
55     * DOCUMENT ME!
56     *
57     * @return
58     */

59    public Connection JavaDoc getConn() {
60       return conn;
61    }
62
63
64    /**
65     * DOCUMENT ME!
66     *
67     * @param name DOCUMENT ME!
68     */

69    public void setDbConnectionName(String JavaDoc name) {
70       dbConnectionName = name;
71    }
72
73
74    /**
75     * DOCUMENT ME!
76     *
77     * @return DOCUMENT ME!
78     */

79    public String JavaDoc getDbConnectionName() {
80       return dbConnectionName;
81    }
82
83
84    /**
85     * @see javax.servlet.jsp.tagext.TryCatchFinally#doCatch(java.lang.Throwable)
86     */

87    public void doCatch(Throwable JavaDoc t) throws Throwable JavaDoc {
88       throw t;
89    }
90
91
92    /**
93     * DOCUMENT ME!
94     *
95     * @return DOCUMENT ME!
96     *
97     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
98     * @throws JspException DOCUMENT ME!
99     */

100    public int doEndTag() throws javax.servlet.jsp.JspException JavaDoc {
101       try {
102          // get the connection and place it in attribute;
103
SqlUtil.closeConnection(this.getConn());
104          this.setConn(null);
105          pageContext.removeAttribute(getId(), PageContext.PAGE_SCOPE);
106       } catch (Exception JavaDoc e) {
107          throw new JspException JavaDoc("Connection error" + e.getMessage());
108       }
109
110       return EVAL_PAGE;
111    }
112
113
114    /**
115     * DOCUMENT ME!
116     */

117    public void doFinally() {
118       dbConnectionName = null;
119    }
120
121
122    /**
123     * DOCUMENT ME!
124     *
125     * @return DOCUMENT ME!
126     *
127     * @throws JspException DOCUMENT ME!
128     * @throws IllegalArgumentException DOCUMENT ME!
129     */

130    public int doStartTag() throws JspException JavaDoc {
131       try {
132          // get the connection and place it in attribute;
133
this.setConn(getConfig().getConnection(dbConnectionName));
134          pageContext.setAttribute(getId(), this.getConn(),
135                                   PageContext.PAGE_SCOPE);
136       } catch (Exception JavaDoc e) {
137          throw new JspException JavaDoc("Connection error" + e.getMessage());
138       }
139
140       return EVAL_BODY_INCLUDE;
141    }
142 }
143
Popular Tags