1 /*
2 * PROJECT : DAR Runtime and Tools
3 * COPYRIGHT : Copyright (C) 1999-2004 tim.stephenson@enableit.org
4 * LICENSE : GNU LESSER GENERAL PUBLIC LICENSE
5 * Version 2.1, February 1999
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 package org.enableit.db.isql;
22
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.List;
26
27 import javax.naming.Binding;
28 import javax.naming.Context;
29 import javax.naming.InitialContext;
30 import javax.naming.NamingEnumeration;
31 import javax.servlet.http.HttpServletRequest;
32
33 import org.apache.log4j.Category;
34 import org.apache.struts.action.ActionForm;
35 import org.apache.struts.action.ActionMapping;
36
37
38 /***
39 * Struts action form.
40 * @struts:form name="IsqlForm"
41 */
42 public class IsqlForm extends ActionForm {
43 /*
44 * Member Properties
45 */
46
47 /***
48 * Define a static Category variable for logging
49 * Use category per package
50 */
51 private static Category logger = Category.getInstance(IsqlForm.class);
52
53 /***
54 * query
55 */
56 private String query;
57
58 /***
59 * dataSource
60 */
61 private String dataSource;
62
63 /***
64 * Collection of available dataSource values.
65 */
66 private Collection dataSourceValues;
67
68 /***
69 * Collection of available dataSource ids.
70 */
71 private Collection dataSourceIds;
72
73 /***
74 * Response
75 */
76 private String dbResponse;
77
78 /***
79 * Results of a query
80 */
81 private List results;
82
83 /*
84 * Constructors
85 */
86
87 /***
88 * Default constructor
89 */
90 public IsqlForm() {
91 dataSourceIds = new ArrayList();
92 dataSourceValues = new ArrayList();
93 initDataSourceCollections();
94 }
95
96 /*
97 * Set methods
98 */
99
100 /***
101 * Sets query
102 */
103 public void setQuery(String query) {
104 logger.info("METHOD_ENTRY: setQuery");
105 logger.info("... param: query = " + query);
106
107 this.query = query.trim();
108
109 logger.info("METHOD_EXIT: setQuery");
110 }
111
112 /***
113 * Sets dataSource name.
114 * @param dataSource The dataSource name to run the query through.
115 */
116 public void setDataSource(String dataSource) {
117 logger.info("METHOD_ENTRY: setDataSource");
118 logger.info("... param: dataSource = " + dataSource);
119
120 this.dataSource = dataSource;
121
122 logger.info("METHOD_EXIT: setDataSource");
123 }
124
125 /***
126 * Sets dataSource name.
127 * @param dataSourceIds The available Data Source Id collection.
128 */
129 public void setDataSourceIds(Collection dataSourceIds) {
130 logger.info("METHOD_ENTRY: setDataSourceIds");
131 logger.info("... param: dataSourceIds = " + dataSourceIds);
132
133 this.dataSourceIds = dataSourceIds;
134
135 logger.info("METHOD_EXIT: setDataSourceIds");
136 }
137
138 /***
139 * Sets dataSource name.
140 * @param dataSourceValues The available Data Source Values collection.
141 */
142 public void setDataSourceValues(Collection dataSourceValues) {
143 logger.info("METHOD_ENTRY: setDataSourceValues");
144 logger.info("... param: dataSourceValues = " + dataSourceValues);
145
146 this.dataSourceValues = dataSourceValues;
147
148 logger.info("METHOD_EXIT: setDataSourceValues");
149 }
150
151 /***
152 * Sets database response
153 */
154 public void setResponse(String dbResponse) {
155 logger.info("METHOD_ENTRY: setDBResponse");
156 logger.info("... param: dbResponse = " + dbResponse);
157
158 this.dbResponse = dbResponse;
159 }
160
161 /***
162 * Sets the query results
163 */
164 public void setResults(List results) {
165 logger.debug("METHOD_ENTRY: setResults");
166 logger.debug("... param: results = " + results);
167
168 this.results = results;
169 }
170
171 /*
172 * Get methods
173 */
174
175 /***
176 * Returns query
177 */
178 public String getQuery() {
179 return this.query;
180 }
181
182 /***
183 * Returns dataSource
184 */
185 public String getDataSource() {
186 return this.dataSource;
187 }
188
189 /***
190 * @return Data Source Id Collection
191 */
192 public Collection getDataSourceIdCollection() {
193 return this.dataSourceIds;
194 }
195
196 /***
197 * @return Data Source Values Collection
198 */
199 public Collection getDataSourceValueCollection() {
200 return this.dataSourceValues;
201 }
202
203 /***
204 * Returns the database response
205 */
206 public String getResponse() {
207 return this.dbResponse;
208 }
209
210 /***
211 * Returns query results
212 */
213 public List getResults() {
214 return this.results;
215 }
216
217 /*
218 * Other methods
219 */
220
221 /***
222 * Populate the list of file types that may be uploaded.
223 */
224 private void initDataSourceCollections() {
225 dataSourceIds.clear();
226 dataSourceValues.clear();
227
228 try {
229 Context ctx = new InitialContext();
230 NamingEnumeration enum = ctx.listBindings("java:comp/env/jdbc");
231
232 while (enum.hasMore()) {
233 Binding binding = (Binding) enum.nextElement();
234
235 dataSourceIds.add("jdbc/" + binding.getName());
236 dataSourceValues.add("jdbc/" + binding.getName());
237 logger.warn("DataSource: [" + binding.getName() + "]");
238 }
239 } catch (Exception e) {
240 logger.error("Exception reading JDBC data sources");
241 }
242 }
243
244 /***
245 * Reset all properties to their default values.
246 *
247 * @param mapping The mapping used to select this instance
248 * @param request The servlet request we are processing
249 */
250 public void reset(ActionMapping mapping, HttpServletRequest request) {
251 query = null;
252 dataSource = null;
253 }
254 }
This page was automatically generated by Maven