|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| package org.globus.cas.impl.databaseAccess; |
|
12 |
| |
|
13 |
| import java.sql.Connection; |
|
14 |
| import java.sql.ResultSet; |
|
15 |
| import java.sql.Statement; |
|
16 |
| import java.sql.SQLException; |
|
17 |
| |
|
18 |
| import java.util.Vector; |
|
19 |
| |
|
20 |
| import org.apache.commons.logging.Log; |
|
21 |
| import org.apache.commons.logging.LogFactory; |
|
22 |
| |
|
23 |
| import org.globus.cas.impl.CasConstants; |
|
24 |
| |
|
25 |
| import org.globus.util.I18n; |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| public class ServiceTypeActionHandler { |
|
31 |
| |
|
32 |
| static Log logger = |
|
33 |
| LogFactory.getLog(ServiceTypeActionHandler.class.getName() ); |
|
34 |
| |
|
35 |
| private static I18n i18n = |
|
36 |
| I18n.getI18n("org.globus.cas.impl.databaseAccess.errors", |
|
37 |
| ServiceTypeActionHandler.class.getClassLoader()); |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
0
| public static String addServiceActionMapping(String serviceName,
|
|
44 |
| String actionName) |
|
45 |
| throws CasDBException { |
|
46 |
| |
|
47 |
0
| logger.debug("addServiceActionMapping " + serviceName + " "
|
|
48 |
| + actionName); |
|
49 |
0
| String result = null;
|
|
50 |
0
| String query = "insert into" + CasDBConstants.TABLE_SERVICETYPE_ACTION
|
|
51 |
| + " (" + CasDBConstants.COL_SERVICETYPE_NAME + "," |
|
52 |
| + CasDBConstants.COL_ACTION_NAME + ") values ('" |
|
53 |
| + serviceName.trim() + "','" + actionName.trim() + "')"; |
|
54 |
0
| CasDBStorage.runUpdateQuery(query);
|
|
55 |
0
| int id = getServiceActionId(serviceName, actionName);
|
|
56 |
0
| if (id == -1) {
|
|
57 |
0
| String err = i18n.getMessage("serviceActionRetrId");
|
|
58 |
0
| logger.error(err);
|
|
59 |
0
| throw new CasDBException(err);
|
|
60 |
| } |
|
61 |
| else |
|
62 |
0
| result = Integer.toString(id);
|
|
63 |
0
| return result;
|
|
64 |
| } |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
0
| public static String[] listServiceActionMappings() throws CasDBException {
|
|
70 |
| |
|
71 |
0
| String query = "select * from" +
|
|
72 |
| CasDBConstants.TABLE_SERVICETYPE_ACTION; |
|
73 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
74 |
0
| Vector serviceAction = null;
|
|
75 |
0
| Statement statement = null;
|
|
76 |
0
| ResultSet resultSet = null;
|
|
77 |
0
| try {
|
|
78 |
0
| statement = connection.createStatement();
|
|
79 |
0
| resultSet = statement.executeQuery(query);
|
|
80 |
0
| if ((resultSet!=null) && (resultSet.next())) {
|
|
81 |
0
| serviceAction = new Vector(resultSet.getFetchSize());
|
|
82 |
0
| do {
|
|
83 |
0
| String service =
|
|
84 |
| resultSet.getString( |
|
85 |
| CasDBConstants.COL_SERVICETYPE_NAME.trim()); |
|
86 |
0
| String action =
|
|
87 |
| resultSet.getString( |
|
88 |
| CasDBConstants.COL_ACTION_NAME.trim()); |
|
89 |
0
| serviceAction.add(service
|
|
90 |
| + CasConstants.SERVICEACTION_DELIMITER |
|
91 |
| + action); |
|
92 |
0
| } while (resultSet.next());
|
|
93 |
| } |
|
94 |
| } |
|
95 |
| catch (SQLException exp) { |
|
96 |
0
| logger.error(i18n.getMessage("serviceActionList", query),
|
|
97 |
| exp); |
|
98 |
0
| throw new CasDBException(i18n.getMessage("serviceActionList",
|
|
99 |
| exp.getMessage()), exp); |
|
100 |
| } |
|
101 |
| finally { |
|
102 |
| |
|
103 |
| |
|
104 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
105 |
0
| try {
|
|
106 |
0
| if (resultSet != null)
|
|
107 |
0
| resultSet.close();
|
|
108 |
0
| if (statement != null)
|
|
109 |
0
| statement.close();
|
|
110 |
| } |
|
111 |
| catch (SQLException exp) { |
|
112 |
0
| logger.warn(i18n.getMessage("serviceActionListClose"), exp);
|
|
113 |
| } |
|
114 |
| } |
|
115 |
0
| return CasDBStorage.vectorToStringArray(serviceAction);
|
|
116 |
| } |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
0
| public static String[] retrieveServiceActionMappings(String serviceName)
|
|
124 |
| throws CasDBException { |
|
125 |
0
| String query = "select * from" + CasDBConstants.TABLE_SERVICETYPE_ACTION
|
|
126 |
| + " where" + CasDBConstants.COL_SERVICETYPE_NAME + "='" |
|
127 |
| + serviceName.trim() + "'"; |
|
128 |
0
| logger.debug("Query to retrieve service/action mappings is " + query);
|
|
129 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
130 |
0
| Vector actionNames = null;
|
|
131 |
0
| Statement statement = null;
|
|
132 |
0
| ResultSet resultSet = null;
|
|
133 |
0
| try {
|
|
134 |
0
| statement = connection.createStatement();
|
|
135 |
0
| resultSet = statement.executeQuery(query);
|
|
136 |
0
| if ((resultSet!=null) && (resultSet.next())) {
|
|
137 |
0
| actionNames = new Vector(resultSet.getFetchSize());
|
|
138 |
0
| do {
|
|
139 |
0
| actionNames.add(resultSet.getString(
|
|
140 |
| CasDBConstants.COL_ACTION_NAME.trim())); |
|
141 |
0
| } while (resultSet.next());
|
|
142 |
| } |
|
143 |
| } |
|
144 |
| catch (SQLException exp) { |
|
145 |
0
| logger.error(i18n.getMessage("retrieveErr", new Object[] {
|
|
146 |
| "service/action mappings", query }), exp); |
|
147 |
0
| throw new CasDBException(i18n.getMessage("retrieveErr",
|
|
148 |
| new Object[] { "service/action mappings", |
|
149 |
| exp.getMessage() }), exp); |
|
150 |
| } |
|
151 |
| finally { |
|
152 |
| |
|
153 |
| |
|
154 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
155 |
0
| try {
|
|
156 |
0
| if (resultSet != null)
|
|
157 |
0
| resultSet.close();
|
|
158 |
0
| if (statement != null)
|
|
159 |
0
| statement.close();
|
|
160 |
| } |
|
161 |
| catch (SQLException exp) { |
|
162 |
0
| logger.warn(i18n.getMessage("retrieveErrClose",
|
|
163 |
| "service/action mapping"), exp); |
|
164 |
| } |
|
165 |
| } |
|
166 |
0
| return CasDBStorage.vectorToStringArray(actionNames);
|
|
167 |
| } |
|
168 |
| |
|
169 |
| |
|
170 |
| |
|
171 |
| |
|
172 |
| |
|
173 |
| |
|
174 |
0
| public static String[] retrieveServiceActionIds(String serviceName)
|
|
175 |
| throws CasDBException { |
|
176 |
0
| String query = "select * from"
|
|
177 |
| + CasDBConstants.TABLE_SERVICETYPE_ACTION |
|
178 |
| + " where" + CasDBConstants.COL_SERVICETYPE_NAME + "='" |
|
179 |
| + serviceName.trim() + "'"; |
|
180 |
0
| logger.debug("Query to retrieve service/action mappings is " + query);
|
|
181 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
182 |
0
| String serviceActionId[] = null;
|
|
183 |
0
| Statement statement = null;
|
|
184 |
0
| ResultSet resultSet = null;
|
|
185 |
0
| try {
|
|
186 |
0
| statement = connection.createStatement();
|
|
187 |
0
| resultSet = statement.executeQuery(query);
|
|
188 |
0
| if ((resultSet!=null) && (resultSet.next())) {
|
|
189 |
0
| int i =0;
|
|
190 |
0
| serviceActionId = new String[resultSet.getFetchSize()];
|
|
191 |
0
| do {
|
|
192 |
0
| serviceActionId[i] =
|
|
193 |
| resultSet.getString( |
|
194 |
| CasDBConstants.COL_SERVICEACTION_ID.trim()); |
|
195 |
0
| i++;
|
|
196 |
0
| } while (resultSet.next());
|
|
197 |
| } |
|
198 |
| } |
|
199 |
| catch (SQLException exp) { |
|
200 |
0
| logger.error(i18n.getMessage("retrieveErr", new Object [] {
|
|
201 |
| "service action ids", query }), exp); |
|
202 |
0
| throw new CasDBException(i18n.getMessage("retrieveErr",
|
|
203 |
| new Object [] { |
|
204 |
| "service action ids", |
|
205 |
| exp.getMessage() }), |
|
206 |
| exp); |
|
207 |
| } |
|
208 |
| finally { |
|
209 |
| |
|
210 |
| |
|
211 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
212 |
0
| try {
|
|
213 |
0
| if (resultSet != null)
|
|
214 |
0
| resultSet.close();
|
|
215 |
0
| if (statement != null)
|
|
216 |
0
| statement.close();
|
|
217 |
| } |
|
218 |
| catch (SQLException exp) { |
|
219 |
0
| logger.warn(i18n.getMessage("retrieveErrClose",
|
|
220 |
| "service action id"), exp); |
|
221 |
| } |
|
222 |
| } |
|
223 |
0
| return serviceActionId;
|
|
224 |
| } |
|
225 |
| |
|
226 |
| |
|
227 |
| |
|
228 |
| |
|
229 |
| |
|
230 |
0
| public static void removeServiceActionMapping(String serviceName,
|
|
231 |
| String actionName) |
|
232 |
| throws CasDBException { |
|
233 |
| |
|
234 |
0
| logger.debug("removeServiceAction " + serviceName + " " + actionName);
|
|
235 |
0
| String query = "delete from" + CasDBConstants.TABLE_SERVICETYPE_ACTION
|
|
236 |
| + " where (" + CasDBConstants.COL_SERVICETYPE_NAME + "='" |
|
237 |
| + serviceName.trim() + "') and (" + CasDBConstants.COL_ACTION_NAME |
|
238 |
| + "='" + actionName.trim() + "')"; |
|
239 |
0
| int result = CasDBStorage.runUpdateQuery(query);
|
|
240 |
0
| if (result <=0) {
|
|
241 |
0
| String err = i18n.getMessage("serviceActionDelError", new Object[]
|
|
242 |
| { serviceName, actionName }); |
|
243 |
0
| logger.error(err);
|
|
244 |
0
| throw new CasDBException(err);
|
|
245 |
| } |
|
246 |
| } |
|
247 |
| |
|
248 |
| |
|
249 |
| |
|
250 |
| |
|
251 |
| |
|
252 |
0
| public static void removeServiceActionMapping(String serviceActionId)
|
|
253 |
| throws CasDBException { |
|
254 |
| |
|
255 |
0
| String query = "delete from" + CasDBConstants.TABLE_SERVICETYPE_ACTION
|
|
256 |
| + " where (" + CasDBConstants.COL_SERVICEACTION_ID + "=" |
|
257 |
| + Integer.parseInt(serviceActionId.trim()) + ")"; |
|
258 |
0
| int result = CasDBStorage.runUpdateQuery(query);
|
|
259 |
0
| if (result <=0) {
|
|
260 |
0
| String err = i18n.getMessage("serviceActionIdDelError",
|
|
261 |
| serviceActionId); |
|
262 |
0
| logger.error(err);
|
|
263 |
0
| throw new CasDBException(err);
|
|
264 |
| } |
|
265 |
| } |
|
266 |
| |
|
267 |
| |
|
268 |
| |
|
269 |
| |
|
270 |
0
| public static String[] retrieveServiceActionGroups(String serviceActionId)
|
|
271 |
| throws CasDBException { |
|
272 |
| |
|
273 |
0
| String query = "select" + CasDBConstants.COL_SERVICEACTIONGP_NAME +
|
|
274 |
| " from " + CasDBConstants.TABLE_SERVICEACTIONGP_ENTRY + " where" |
|
275 |
| + CasDBConstants.COL_SERVICEACTION_ID + "='" + serviceActionId |
|
276 |
| + "'"; |
|
277 |
0
| Vector gpNames = null;
|
|
278 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
279 |
0
| Statement statement = null;
|
|
280 |
0
| ResultSet resultSet = null;
|
|
281 |
0
| try {
|
|
282 |
0
| statement = connection.createStatement();
|
|
283 |
0
| resultSet = statement.executeQuery(query);
|
|
284 |
0
| if ((resultSet!=null) && (resultSet.next())) {
|
|
285 |
0
| gpNames = new Vector(resultSet.getFetchSize());
|
|
286 |
0
| do {
|
|
287 |
0
| gpNames.add(resultSet.getString(
|
|
288 |
| CasDBConstants.COL_SERVICEACTIONGP_NAME.trim())); |
|
289 |
0
| } while (resultSet.next());
|
|
290 |
| } |
|
291 |
| } |
|
292 |
| catch (SQLException exp) { |
|
293 |
0
| logger.error(i18n.getMessage("retrieveErr", new Object[] {
|
|
294 |
| "service action groups", query }), exp); |
|
295 |
0
| throw new CasDBException(i18n.getMessage("retrieveErr",
|
|
296 |
| new Object[] { "service action groups", exp.getMessage()}), |
|
297 |
| exp); |
|
298 |
| } |
|
299 |
| finally { |
|
300 |
| |
|
301 |
| |
|
302 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
303 |
0
| try {
|
|
304 |
0
| if (resultSet != null)
|
|
305 |
0
| resultSet.close();
|
|
306 |
0
| if (statement != null)
|
|
307 |
0
| statement.close();
|
|
308 |
| } |
|
309 |
| catch (SQLException exp) { |
|
310 |
0
| logger.warn(i18n.getMessage("retrieveErrClose",
|
|
311 |
| "service action groups"), exp); |
|
312 |
| } |
|
313 |
| } |
|
314 |
0
| return CasDBStorage.vectorToStringArray(gpNames);
|
|
315 |
| } |
|
316 |
| |
|
317 |
| |
|
318 |
| |
|
319 |
| |
|
320 |
| |
|
321 |
0
| public static void createServiceActionGroup(String serviceGroupName)
|
|
322 |
| throws CasDBException { |
|
323 |
| |
|
324 |
0
| String query = "insert into" + CasDBConstants.TABLE_SERVICEACTIONGP
|
|
325 |
| + " (" + CasDBConstants.COL_SERVICEACTIONGP_NAME + ") values ('" |
|
326 |
| + serviceGroupName.trim() + "')"; |
|
327 |
0
| CasDBStorage.runUpdateQuery(query);
|
|
328 |
| } |
|
329 |
| |
|
330 |
| |
|
331 |
| |
|
332 |
| |
|
333 |
| |
|
334 |
0
| public static void addServiceActionGpEntry(String serviceGroupName,
|
|
335 |
| String serviceName, |
|
336 |
| String actionName) |
|
337 |
| throws CasDBException { |
|
338 |
| |
|
339 |
0
| logger.debug("addServiceActionGpEntry " + serviceGroupName + " "
|
|
340 |
| + serviceName + " " + actionName); |
|
341 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
342 |
| |
|
343 |
| |
|
344 |
| |
|
345 |
| |
|
346 |
| |
|
347 |
| |
|
348 |
| |
|
349 |
| |
|
350 |
| |
|
351 |
| |
|
352 |
| |
|
353 |
| |
|
354 |
| |
|
355 |
0
| int serviceActionId = getServiceActionId(connection, serviceName,
|
|
356 |
| actionName); |
|
357 |
0
| if (serviceActionId == -1) {
|
|
358 |
0
| String err = i18n.getMessage("doesNotExist", new Object[] {
|
|
359 |
| "service/action mapping ", serviceName + "/" + actionName }); |
|
360 |
0
| logger.error(err);
|
|
361 |
0
| throw new CasDBException(err);
|
|
362 |
| } |
|
363 |
| |
|
364 |
0
| String query = "insert into "
|
|
365 |
| + CasDBConstants.TABLE_SERVICEACTIONGP_ENTRY + " (" |
|
366 |
| + CasDBConstants.COL_SERVICEACTIONGP_NAME + "," |
|
367 |
| + CasDBConstants.COL_SERVICEACTION_ID + " ) values ('" |
|
368 |
| + serviceGroupName.trim() + "','" |
|
369 |
| + Integer.toString(serviceActionId) + "')"; |
|
370 |
0
| runUpdateQuery(connection, query);
|
|
371 |
| |
|
372 |
| |
|
373 |
| |
|
374 |
| |
|
375 |
| |
|
376 |
| |
|
377 |
| |
|
378 |
| |
|
379 |
| |
|
380 |
| |
|
381 |
| |
|
382 |
| |
|
383 |
| |
|
384 |
| |
|
385 |
| |
|
386 |
| |
|
387 |
| |
|
388 |
| |
|
389 |
| |
|
390 |
| |
|
391 |
| |
|
392 |
| |
|
393 |
| |
|
394 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
395 |
| } |
|
396 |
| |
|
397 |
| |
|
398 |
| |
|
399 |
| |
|
400 |
0
| public static String[] listServiceActionGroups() throws CasDBException {
|
|
401 |
| |
|
402 |
0
| String query = "select" + CasDBConstants.COL_SERVICEACTIONGP_NAME
|
|
403 |
| + " from" + CasDBConstants.TABLE_SERVICEACTIONGP; |
|
404 |
0
| return CasDBStorage.runListQuery(query,
|
|
405 |
| CasDBConstants.COL_SERVICEACTIONGP_NAME); |
|
406 |
| } |
|
407 |
| |
|
408 |
| |
|
409 |
| |
|
410 |
| |
|
411 |
| |
|
412 |
0
| public static String[]
|
|
413 |
| retrieveServiceActionGpEntriesAsId(String serviceGroupName) |
|
414 |
| throws CasDBException { |
|
415 |
| |
|
416 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
417 |
0
| try {
|
|
418 |
0
| return retrieveServiceActionGpEntriesAsId(connection,
|
|
419 |
| serviceGroupName); |
|
420 |
| } finally { |
|
421 |
| |
|
422 |
| |
|
423 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
424 |
| } |
|
425 |
| } |
|
426 |
| |
|
427 |
0
| public static String[]
|
|
428 |
| retrieveServiceActionGpEntriesAsId(Connection connection, |
|
429 |
| String serviceGroupName) |
|
430 |
| throws CasDBException { |
|
431 |
| |
|
432 |
0
| Vector serviceAction = null;
|
|
433 |
0
| String query = "select * from"
|
|
434 |
| + CasDBConstants.TABLE_SERVICEACTIONGP_ENTRY + " where" |
|
435 |
| + CasDBConstants.COL_SERVICEACTIONGP_NAME + "='" |
|
436 |
| + serviceGroupName.trim() + "'"; |
|
437 |
| |
|
438 |
0
| Statement statement = null;
|
|
439 |
0
| ResultSet resultSet = null;
|
|
440 |
0
| try {
|
|
441 |
0
| statement = connection.createStatement();
|
|
442 |
0
| resultSet = statement.executeQuery(query);
|
|
443 |
0
| if ((resultSet!=null) && (resultSet.next())) {
|
|
444 |
0
| serviceAction = new Vector(resultSet.getFetchSize());
|
|
445 |
0
| do {
|
|
446 |
0
| serviceAction.add(resultSet.getString(
|
|
447 |
| CasDBConstants.COL_SERVICEACTION_ID.trim())); |
|
448 |
0
| } while (resultSet.next());
|
|
449 |
| } |
|
450 |
| } |
|
451 |
| catch (SQLException exp) { |
|
452 |
0
| logger.error(i18n.getMessage("retrieveErr", new Object[] {
|
|
453 |
| "action group ids", query }), exp); |
|
454 |
0
| throw new CasDBException(i18n.getMessage("retrieveErr",
|
|
455 |
| new Object[] { |
|
456 |
| "action group ids", |
|
457 |
| exp.getMessage() }), |
|
458 |
| exp); |
|
459 |
| } |
|
460 |
| finally { |
|
461 |
0
| try {
|
|
462 |
0
| if (resultSet != null)
|
|
463 |
0
| resultSet.close();
|
|
464 |
0
| if (statement != null)
|
|
465 |
0
| statement.close();
|
|
466 |
| } |
|
467 |
| catch (SQLException exp) { |
|
468 |
0
| logger.warn(i18n.getMessage("retrieveErrClose",
|
|
469 |
| "service action groups id"), exp); |
|
470 |
| } |
|
471 |
| } |
|
472 |
0
| return CasDBStorage.vectorToStringArray(serviceAction);
|
|
473 |
| } |
|
474 |
| |
|
475 |
| |
|
476 |
| |
|
477 |
| |
|
478 |
| |
|
479 |
0
| public static String[]
|
|
480 |
| retrieveServiceActionGpEntries(String serviceGroupName) |
|
481 |
| throws CasDBException { |
|
482 |
0
| logger.debug("retrieve service action gp entries " + serviceGroupName);
|
|
483 |
0
| String serviceActionId[] =
|
|
484 |
| retrieveServiceActionGpEntriesAsId(serviceGroupName); |
|
485 |
0
| if (serviceActionId != null) {
|
|
486 |
0
| String serviceAction[] = new String[serviceActionId.length];
|
|
487 |
0
| for (int i=0; i<serviceActionId.length; i++) {
|
|
488 |
0
| serviceAction[i] =
|
|
489 |
| getServiceActionMapping(new Integer( |
|
490 |
| serviceActionId[i]).intValue()); |
|
491 |
| } |
|
492 |
0
| return serviceAction;
|
|
493 |
| } |
|
494 |
0
| return null;
|
|
495 |
| } |
|
496 |
| |
|
497 |
| |
|
498 |
| |
|
499 |
| |
|
500 |
| |
|
501 |
0
| public static void removeServiceActionGpEntry(String serviceGroupName,
|
|
502 |
| String serviceName, |
|
503 |
| String actionName) throws |
|
504 |
| CasDBException { |
|
505 |
| |
|
506 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
507 |
| |
|
508 |
| |
|
509 |
| |
|
510 |
| |
|
511 |
| |
|
512 |
| |
|
513 |
| |
|
514 |
| |
|
515 |
| |
|
516 |
| |
|
517 |
| |
|
518 |
| |
|
519 |
0
| int serviceActionId = getServiceActionId(connection, serviceName,
|
|
520 |
| actionName); |
|
521 |
0
| if (serviceActionId == -1) {
|
|
522 |
0
| String err = i18n.getMessage("doesNotExist", new Object[] {
|
|
523 |
| "service/action mapping", serviceName + "/" + actionName }); |
|
524 |
0
| logger.error(err);
|
|
525 |
0
| throw new CasDBException(err);
|
|
526 |
| } |
|
527 |
| |
|
528 |
0
| String query = "delete from " +
|
|
529 |
| CasDBConstants.TABLE_SERVICEACTIONGP_ENTRY + " where (" |
|
530 |
| + CasDBConstants.COL_SERVICEACTIONGP_NAME + "='" + |
|
531 |
| serviceGroupName.trim() + "') and (" |
|
532 |
| + CasDBConstants.COL_SERVICEACTION_ID + "='" |
|
533 |
| + (Integer.toString(serviceActionId)) + "')"; |
|
534 |
0
| int result = runUpdateQuery(connection, query);
|
|
535 |
0
| if (result <= 0) {
|
|
536 |
0
| String err = i18n.getMessage("serviceActionMemDelError",
|
|
537 |
| new Object[] { serviceGroupName, |
|
538 |
| serviceName, |
|
539 |
| actionName }); |
|
540 |
0
| logger.error(err);
|
|
541 |
0
| throw new CasDBException(err);
|
|
542 |
| } |
|
543 |
| |
|
544 |
| |
|
545 |
| |
|
546 |
| |
|
547 |
| |
|
548 |
| |
|
549 |
| |
|
550 |
| |
|
551 |
| |
|
552 |
| |
|
553 |
| |
|
554 |
| |
|
555 |
| |
|
556 |
| |
|
557 |
| |
|
558 |
| |
|
559 |
| |
|
560 |
| |
|
561 |
| |
|
562 |
| |
|
563 |
| |
|
564 |
| |
|
565 |
| |
|
566 |
| |
|
567 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
568 |
| } |
|
569 |
| |
|
570 |
| |
|
571 |
| |
|
572 |
| |
|
573 |
0
| public static void deleteServiceActionGroup(String serviceGroupName)
|
|
574 |
| throws CasDBException { |
|
575 |
| |
|
576 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
577 |
0
| String query = "delete from" + CasDBConstants.TABLE_SERVICEACTIONGP
|
|
578 |
| + " where" + CasDBConstants.COL_SERVICEACTIONGP_NAME + "='" |
|
579 |
| + serviceGroupName + "'"; |
|
580 |
0
| int result = runUpdateQuery(connection, query);
|
|
581 |
0
| if (result <=0) {
|
|
582 |
0
| String err = i18n.getMessage("serviceActionGpDelError",
|
|
583 |
| serviceGroupName); |
|
584 |
0
| logger.error(err);
|
|
585 |
0
| throw new CasDBException(err);
|
|
586 |
| } |
|
587 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
588 |
| } |
|
589 |
| |
|
590 |
0
| public static String getServiceActionMapping(String serviceActionId)
|
|
591 |
| throws CasDBException { |
|
592 |
0
| return getServiceActionMapping(Integer.parseInt(serviceActionId));
|
|
593 |
| } |
|
594 |
| |
|
595 |
| |
|
596 |
0
| public static String getServiceActionMapping(int serviceActionId)
|
|
597 |
| throws CasDBException { |
|
598 |
| |
|
599 |
0
| String serviceTypeAction = null;
|
|
600 |
0
| Connection conn = CasDBStorage.getDBConnection();
|
|
601 |
| |
|
602 |
0
| String query = "select * from"
|
|
603 |
| + CasDBConstants.TABLE_SERVICETYPE_ACTION + " where" |
|
604 |
| + CasDBConstants.COL_SERVICEACTION_ID + "=" + serviceActionId; |
|
605 |
0
| Statement statement = null;
|
|
606 |
0
| ResultSet resultSet = null;
|
|
607 |
0
| try {
|
|
608 |
0
| statement = conn.createStatement();
|
|
609 |
0
| resultSet = statement.executeQuery(query);
|
|
610 |
0
| if (resultSet==null) {
|
|
611 |
0
| String err =
|
|
612 |
| i18n.getMessage("doesNotExistTable", |
|
613 |
| new Object[] { "Service action id", |
|
614 |
| "serviceAction" }); |
|
615 |
0
| logger.error(err);
|
|
616 |
0
| throw new CasDBException(err);
|
|
617 |
| } |
|
618 |
| else { |
|
619 |
0
| if (resultSet.next()) {
|
|
620 |
0
| String temp = resultSet.getString(
|
|
621 |
| CasDBConstants.COL_SERVICETYPE_NAME.trim()); |
|
622 |
0
| String temp1 = resultSet.getString(
|
|
623 |
| CasDBConstants.COL_ACTION_NAME.trim()); |
|
624 |
0
| serviceTypeAction = temp
|
|
625 |
| + CasConstants.SERVICEACTION_DELIMITER + temp1; |
|
626 |
| } |
|
627 |
| } |
|
628 |
| } |
|
629 |
| catch (SQLException exp) { |
|
630 |
0
| logger.error(i18n.getMessage("retrieveErr", new Object[] {
|
|
631 |
| "service action mapping", query }), exp); |
|
632 |
0
| throw new CasDBException(i18n
|
|
633 |
| .getMessage("retrieveErr", new Object[] { |
|
634 |
| "service action mapping", exp.getMessage()}), exp); |
|
635 |
| } |
|
636 |
| finally { |
|
637 |
| |
|
638 |
| |
|
639 |
0
| CasDBStorage.returnDBConnection(conn);
|
|
640 |
0
| try {
|
|
641 |
0
| if (resultSet != null)
|
|
642 |
0
| resultSet.close();
|
|
643 |
0
| if (statement != null)
|
|
644 |
0
| statement.close();
|
|
645 |
| } |
|
646 |
| catch (SQLException exp) { |
|
647 |
0
| logger.warn(i18n.getMessage("retrieveErrClose",
|
|
648 |
| "service action mapping"), exp); |
|
649 |
| } |
|
650 |
| } |
|
651 |
0
| return serviceTypeAction;
|
|
652 |
| } |
|
653 |
| |
|
654 |
| |
|
655 |
| |
|
656 |
| |
|
657 |
| |
|
658 |
0
| public static int getServiceActionId(String serviceName, String actionName)
|
|
659 |
| throws CasDBException { |
|
660 |
0
| Connection conn = CasDBStorage.getDBConnection();
|
|
661 |
0
| int id = getServiceActionId(conn, serviceName, actionName);
|
|
662 |
0
| CasDBStorage.returnDBConnection(conn);
|
|
663 |
0
| return id;
|
|
664 |
| } |
|
665 |
| |
|
666 |
| |
|
667 |
0
| private static int getServiceActionId(Connection conn, String serviceName,
|
|
668 |
| String actionName) |
|
669 |
| throws CasDBException { |
|
670 |
0
| int serviceId = -1;
|
|
671 |
| |
|
672 |
0
| String query = "select" + CasDBConstants.COL_SERVICEACTION_ID + " from"
|
|
673 |
| + CasDBConstants.TABLE_SERVICETYPE_ACTION + " where" |
|
674 |
| + CasDBConstants.COL_SERVICETYPE_NAME + "='" + serviceName.trim() |
|
675 |
| + "' and " + CasDBConstants.COL_ACTION_NAME + "='" |
|
676 |
| + actionName.trim() + "'"; |
|
677 |
0
| logger.debug("getServiceActionId " + query);
|
|
678 |
0
| Statement statement = null;
|
|
679 |
0
| ResultSet resultSet = null;
|
|
680 |
0
| try {
|
|
681 |
0
| statement = conn.createStatement();
|
|
682 |
0
| resultSet = statement.executeQuery(query);
|
|
683 |
0
| if ((resultSet!=null) && (resultSet.next())) {
|
|
684 |
0
| serviceId = resultSet.getInt(
|
|
685 |
| CasDBConstants.COL_SERVICEACTION_ID.trim()); |
|
686 |
| } |
|
687 |
| } |
|
688 |
| catch (SQLException exp) { |
|
689 |
0
| CasDBStorage.returnDBConnection(conn);
|
|
690 |
0
| logger.error(i18n.getMessage("retrieveErr", new Object[] {
|
|
691 |
| "service action id", query }), exp); |
|
692 |
0
| throw new CasDBException("Error getting service action id " +
|
|
693 |
| exp.getMessage(), exp); |
|
694 |
| } |
|
695 |
| finally { |
|
696 |
0
| try {
|
|
697 |
0
| if (resultSet != null)
|
|
698 |
0
| resultSet.close();
|
|
699 |
0
| if (statement != null)
|
|
700 |
0
| statement.close();
|
|
701 |
| } |
|
702 |
| catch (SQLException exp) { |
|
703 |
0
| logger.warn(i18n.getMessage("retrieveErrClose",
|
|
704 |
| "service action id "), exp); |
|
705 |
| } |
|
706 |
| } |
|
707 |
0
| return serviceId;
|
|
708 |
| } |
|
709 |
| |
|
710 |
| |
|
711 |
0
| private static int runUpdateQuery(Connection conn, String query)
|
|
712 |
| throws CasDBException { |
|
713 |
0
| Statement statement = null;
|
|
714 |
0
| int result = -1;
|
|
715 |
0
| try {
|
|
716 |
0
| statement = conn.createStatement();
|
|
717 |
0
| result = statement.executeUpdate(query);
|
|
718 |
| } |
|
719 |
| catch (SQLException exp) { |
|
720 |
0
| CasDBStorage.returnDBConnection(conn);
|
|
721 |
0
| logger.error(i18n.getMessage("stmtExecErr",query), exp);
|
|
722 |
0
| throw new CasDBException(i18n.getMessage("stmtExecErr",
|
|
723 |
| exp.getMessage()), exp); |
|
724 |
| } |
|
725 |
| finally { |
|
726 |
0
| try {
|
|
727 |
0
| if (statement != null)
|
|
728 |
0
| statement.close();
|
|
729 |
| } |
|
730 |
| catch (SQLException exp) { |
|
731 |
0
| logger.warn(i18n.getMessage("stmtExecErrClose"), exp);
|
|
732 |
| } |
|
733 |
| } |
|
734 |
0
| return result;
|
|
735 |
| } |
|
736 |
| } |