KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > monitor > callflow > DbAccessObjectImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * DbAccessObjectImpl.java
26  *
27  * Created on July 11, 2005, 10:40 AM
28  */

29
30 package com.sun.enterprise.admin.monitor.callflow;
31
32 import com.sun.enterprise.admin.monitor.callflow.DbAccessObject;
33 import java.sql.Connection JavaDoc;
34 import java.sql.DriverManager JavaDoc;
35 import java.sql.PreparedStatement JavaDoc;
36 import java.sql.ResultSet JavaDoc;
37 import java.sql.SQLException JavaDoc;
38 import java.sql.Statement JavaDoc;
39 import java.util.ArrayList JavaDoc;
40 import java.util.HashMap JavaDoc;
41 import java.util.List JavaDoc;
42 import java.util.Map JavaDoc;
43 import javax.naming.InitialContext JavaDoc;
44 import javax.naming.NamingException JavaDoc;
45 import javax.sql.DataSource JavaDoc;
46 import com.sun.enterprise.admin.monitor.callflow.RequestType;
47 import com.sun.appserv.management.monitor.CallFlowMonitor;
48 import java.util.logging.Level JavaDoc;
49 import java.util.logging.Logger JavaDoc;
50 import com.sun.enterprise.admin.common.constant.AdminConstants;
51 /**
52  *
53  * @author Harpreet Singh
54  */

55 public class DbAccessObjectImpl implements DbAccessObject {
56     private static final Logger JavaDoc logger =
57             Logger.getLogger(AdminConstants.kLoggerName);
58
59     private static DbAccessObject _singleton = null;
60     
61     private static final String JavaDoc CALLFLOW_POOL_JNDI_NAME = "jdbc/__CallFlowPool__pm";
62
63     private TableAccessObject reqStart = null;
64     private TableAccessObject reqEnd = null;
65     private TableAccessObject methStart = null;
66     private TableAccessObject methEnd = null;
67     private TableAccessObject startTime = null;
68     private TableAccessObject endTime = null;
69     
70     private Connection JavaDoc connection = null;
71     private PreparedStatement JavaDoc pstmtRS = null;
72     private PreparedStatement JavaDoc pstmtRE = null;
73     private PreparedStatement JavaDoc pstmtMS = null;
74     private PreparedStatement JavaDoc pstmtME = null;
75     private PreparedStatement JavaDoc pstmtST = null;
76     private PreparedStatement JavaDoc pstmtET = null;
77     
78     private String JavaDoc serverName = null;
79     
80     /** Creates a new instance of DbAccessObjectImpl */
81     private DbAccessObjectImpl() {
82         reqStart = RequestStartAccessObjectImpl.getInstance();
83         reqEnd = RequestEndAccessObjectImpl.getInstance();
84         methStart = MethodStartAccessObjectImpl.getInstance();
85         methEnd = MethodEndAccessObjectImpl.getInstance();
86         startTime = StartTimeAccessObjectImpl.getInstance();
87         endTime = EndTimeAccessObjectImpl.getInstance();
88     }
89     
90     //<editor-fold defaultstate="collapsed" desc="Enable & Disable">
91

92     public boolean enable () {
93         if(!setupConnection()){
94             logger.log(Level.SEVERE, "callflow.connection_obtain_failed");
95             logger.log(Level.SEVERE, "callflow.enable_failed");
96             throw new RuntimeException JavaDoc ("Error obtaining connection to callflow database");
97         }
98         boolean result = enable(connection);
99         if(result == true){
100             try{
101                 createPreparedStatements();
102             } catch (SQLException JavaDoc sqe){
103                 // log it
104
// if preparedStatements are not created. No point doing anything
105
// else.
106
logger.log(Level.SEVERE, "callflow.enable_failed", sqe);
107                 RuntimeException JavaDoc re = new RuntimeException JavaDoc ();
108                 re.initCause(sqe);
109                 throw re;
110             } finally {
111                 closeConnection();
112             }
113         } else if (result == false) { // as of now, we always return a true
114
// even if the table creation fails. This should never be exercised
115
// Keeping this code here such that if we change the semantics
116
// of enable(connection) that would not break the callflow code.
117
logger.log(Level.SEVERE, "callflow.enable_failed");
118              closeConnection ();
119              throw new RuntimeException JavaDoc ("Error creating tables");
120         }
121         return result;
122     }
123     private boolean enable (Connection JavaDoc connection) {
124         // even if 1 table create fails, go ahead and create the rest
125

126         boolean rs = reqStart.createTable(connection);
127         if (!rs)
128             return false;
129         boolean re = reqEnd.createTable(connection);
130         if (!re)
131             return false;
132         boolean ms = methStart.createTable(connection);
133         if (!ms)
134             return false;
135         boolean me = methEnd.createTable(connection);
136         if (!me)
137             return false;
138         boolean st = startTime.createTable(connection);
139         if (!st)
140             return false;
141         boolean et = endTime.createTable(connection);
142         if (!et)
143             return false;
144         return true;
145     }
146     public boolean disable() {
147         closePreparedStatements();
148         closeConnection();
149         return true;
150     }
151
152 //</editor-fold>
153

154     /**
155      * Factory Methodd to return DbAccessObject
156      * @return DbAccessObject
157      */

158     public static DbAccessObject getInstance() {
159         if(_singleton == null)
160             _singleton = new DbAccessObjectImpl ();
161         return _singleton;
162     }
163     
164     public boolean clearData () {
165         if(!setupConnection())
166             return false;
167         boolean result = clearData (connection);
168         closeConnection ();
169         return result;
170     }
171     private boolean clearData(Connection JavaDoc connection) {
172         // even if 1 table delete fails, go ahead and delete the rest
173

174         boolean rs = reqStart.dropTable(connection);
175         boolean re = reqEnd.dropTable(connection);
176         boolean ms = methStart.dropTable(connection);
177         boolean me = methEnd.dropTable(connection);
178         boolean st = startTime.dropTable(connection);
179         boolean et = endTime.dropTable(connection);
180         
181         if(rs == false || re == false || ms == false || me == false ||
182         st == false || et == false)
183             return false;
184         return true;
185         
186     }
187 //</editor-fold>
188

189     //<editor-fold defaultstate="collapsed" desc="Connection and Statement Manipulation">
190

191     // this method is temporarily used to setup connection to the database
192
// This should be modified to read the connection information from the
193
// domain.xml
194
private boolean setupConnection (){
195       try{
196                // TODO code application logic here
197
boolean standaloneDb =
198                   Boolean.valueOf(System.getProperty("callflow.db.standalone"));
199
200           if (!standaloneDb) {
201
202               InitialContext JavaDoc ic = new InitialContext JavaDoc ();
203               DataSource JavaDoc ds = (DataSource JavaDoc)ic.lookup (CALLFLOW_POOL_JNDI_NAME);
204               connection = ds.getConnection();
205           } else {
206             // TODO code application logic here
207
String JavaDoc url="jdbc:derby://localhost:1527/sun-callflow;retrieveMessagesFromServerOnGetMessage=true;create=true;";
208             Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
209             connection = DriverManager.getConnection(url, "APP", "APP");
210           }
211         } catch (Exception JavaDoc e){
212             logger.log(Level.SEVERE, "callflow.connection_obtain_failed", e);
213             return false;
214         }
215         return true;
216     }
217     private void closeConnection (){
218         try{
219             if(connection != null){
220                 connection.close();
221             }
222         } catch (Exception JavaDoc e){
223             logger.log(Level.WARNING, "Cannot close connection to CallFlow DB", e);
224         } finally {
225             connection = null;
226         }
227     }
228
229     private void createPreparedStatements () throws SQLException JavaDoc {
230         if(connection == null)
231             if(!setupConnection())
232                 return;
233
234         pstmtRS = connection.prepareStatement (reqStart.getInsertSQL());
235         pstmtRE = connection.prepareStatement(reqEnd.getInsertSQL());
236         pstmtMS = connection.prepareStatement(methStart.getInsertSQL());
237         pstmtME = connection.prepareStatement(methEnd.getInsertSQL());
238         pstmtST = connection.prepareStatement(startTime.getInsertSQL());
239         pstmtET = connection.prepareStatement(endTime.getInsertSQL());
240
241     }
242     private void closePreparedStatements () {
243         try{
244             if(pstmtRS != null)
245                 pstmtRS.close();
246         } catch (SQLException JavaDoc s){
247             // log it to fine.
248
logger.log(Level.FINE, "Could not close RequestStart SQL Statement", s);
249         }finally{
250             pstmtRS = null;
251         }
252         try{
253             if(pstmtRE != null)
254                 pstmtRE.close();
255         } catch (SQLException JavaDoc e){
256             // log it to fine
257
logger.log(Level.FINE, "Could not close RequestEnd SQL Statement", e);
258         }finally{
259             pstmtRE = null;
260         }
261         try{
262             if(pstmtMS != null)
263                 pstmtMS.close();
264         } catch (SQLException JavaDoc se){
265             // log it to fine
266
logger.log(Level.FINE, "Could not close MethodStart SQL Statement", se);
267         } finally{
268             pstmtMS = null;
269         }
270         try{
271             if(pstmtME != null)
272                 pstmtME.close();
273         } catch(SQLException JavaDoc sqe){
274             //log it to fine.
275
logger.log(Level.FINE, "Could not close MethodEnd SQL Statement", sqe);
276         }finally{
277             pstmtME = null;
278         }
279         try{
280             if(pstmtST != null)
281                 pstmtST.close();
282         } catch(SQLException JavaDoc sqe){
283             //log it to fine.
284
logger.log(Level.FINE, "Could not close StartTime SQL Statement", sqe);
285         }finally{
286             pstmtST = null;
287         }
288         try{
289             if(pstmtET != null)
290                 pstmtET.close();
291         } catch(SQLException JavaDoc sqe){
292             //log it to fine.
293
logger.log(Level.FINE, "Could not close EndTime SQL Statement", sqe);
294         }finally{
295             pstmtET = null;
296         }
297         
298     }
299     
300 //</editor-fold>
301

302     //<editor-fold defaultstate="collapsed" desc="getRequestInformation Query">
303
public java.util.List JavaDoc<java.util.Map JavaDoc<String JavaDoc, String JavaDoc>> getRequestInformation() {
304         if(connection == null)
305             if(!setupConnection())
306                 return null;
307         assert connection != null;
308         List JavaDoc<Map JavaDoc<String JavaDoc, String JavaDoc>> list = null;
309         Statement JavaDoc stmt = null;
310         try{
311             stmt = connection.createStatement();
312             stmt.executeQuery(
313                     generateQuerySQL(TableInfo.GET_REQUEST_INFORMATION_SQL));
314             ResultSet JavaDoc rs = stmt.getResultSet();
315             list = new ArrayList JavaDoc<Map JavaDoc<String JavaDoc, String JavaDoc>>();
316             while(rs.next()){
317                 Map JavaDoc<String JavaDoc, String JavaDoc> map = new HashMap JavaDoc<String JavaDoc, String JavaDoc> ();
318                 
319                 String JavaDoc request_id = rs.getString(TableInfo.REQUEST_ID);
320                 map.put (CallFlowMonitor.REQUEST_ID_KEY, request_id);
321                 // no need to return time stamp in nano.
322
long time_stamp = rs.getLong(TableInfo.TIME_STAMP_MILLIS);
323                 map.put (CallFlowMonitor.TIME_STAMP_MILLIS_KEY, String.valueOf(time_stamp));
324
325                 String JavaDoc ip_address = rs.getString(TableInfo.IP_ADDRESS);
326                 map.put (CallFlowMonitor.CLIENT_HOST_KEY, ip_address);
327                 
328                 String JavaDoc request_type = rs.getString(TableInfo.REQUEST_TYPE);
329                 map.put (CallFlowMonitor.REQUEST_TYPE_KEY, request_type);
330
331                 String JavaDoc method_name = rs.getString(TableInfo.METHOD_NAME);
332                 map.put (CallFlowMonitor.METHOD_NAME_KEY, method_name);
333                 
334                 String JavaDoc app_name = rs.getString(TableInfo.APP_NAME);
335                 map.put (CallFlowMonitor.APPLICATION_NAME_KEY, app_name);
336                 
337                 String JavaDoc security_id = rs.getString (TableInfo.SECURITY_ID);
338                 map.put (CallFlowMonitor.USER_KEY, security_id);
339                 
340                 String JavaDoc exception_name = rs.getString(TableInfo.EXCEPTION_NAME);
341                 map.put (CallFlowMonitor.EXCEPTION_KEY, exception_name);
342                 
343                 long time_taken = rs.getLong(10);
344                 map.put (CallFlowMonitor.RESPONSE_TIME_KEY, String.valueOf(time_taken));
345                 
346                 list.add(map);
347             }
348             
349         } catch (SQLException JavaDoc se){
350             // log it
351
logger.log(Level.WARNING, "callflow.error_get_request_info");
352             logger.log(Level.FINE, "callflow.error_sql_execute", se);
353         }
354         closeConnection();
355         return list;
356     }
357  //</editor-fold>
358

359     private String JavaDoc generateQuerySQL (String JavaDoc sql){
360         // append RS, RE , MS, ME table Name with __server name
361
String JavaDoc newsql = new String JavaDoc(sql);
362        // replace RS Table with RS__server
363
String JavaDoc table = TableInfo.REQUEST_START_TABLE_NAME;
364        String JavaDoc tableWithServerName = getTableWithServerName (table);
365        newsql = newsql.replaceAll(table, tableWithServerName);
366        // RE
367
table = TableInfo.REQUEST_END_TABLE_NAME;
368        tableWithServerName = getTableWithServerName (table);
369        newsql = newsql.replaceAll(table, tableWithServerName);
370        
371        // MS
372
table = TableInfo.METHOD_START_TABLE_NAME;
373        tableWithServerName = getTableWithServerName (table);
374        newsql = newsql.replaceAll(table, tableWithServerName);
375
376        // RE
377
table = TableInfo.METHOD_END_TABLE_NAME;
378        tableWithServerName = getTableWithServerName (table);
379        newsql = newsql.replaceAll(table, tableWithServerName);
380        return newsql;
381     }
382     
383     private String JavaDoc getTableWithServerName (String JavaDoc oldTableName) {
384         if (serverName == null)
385             serverName = reqStart.getServerInstanceName ();
386         
387         return oldTableName + serverName;
388     }
389    
390         
391     //<editor-fold defaultstate="collapsed" desc="GetCallStack Query">
392
public List JavaDoc<Map JavaDoc<String JavaDoc, String JavaDoc>> getCallStackInformation (String JavaDoc requestId) {
393        if(connection == null)
394             if(!setupConnection())
395                 return null;
396         assert connection != null;
397         List JavaDoc list = null;
398         PreparedStatement JavaDoc stmt = null;
399         try{
400             String JavaDoc sql = generateQuerySQL (TableInfo.GET_CALLSTACK_INFORMATION_SQL);
401             stmt = connection.prepareStatement(sql);
402             
403             stmt.setString(1, requestId);
404             stmt.setString(2, requestId);
405             stmt.setString(3, requestId);
406             stmt.setString(4, requestId);
407             ResultSet JavaDoc rs = stmt.executeQuery();
408             list = new ArrayList JavaDoc<Map JavaDoc<String JavaDoc, String JavaDoc>>();
409             while(rs.next()){
410                 Map JavaDoc<String JavaDoc, String JavaDoc> map = new HashMap JavaDoc<String JavaDoc, String JavaDoc> ();
411
412                 String JavaDoc table_type = rs.getString(TABLE_TYPE_INDEX_CSI);
413                 table_type = table_type.trim();
414                 map.put(CallFlowMonitor.CALL_STACK_ROW_TYPE_KEY, table_type);
415                 if (CallFlowMonitor.CALL_STACK_REQUEST_START.equals(table_type)){
416                     map = getCallStackRequestStartInformation(rs, map);
417                 } else if (CallFlowMonitor.CALL_STACK_REQUEST_END.equals(table_type)) {
418                     map = getCallStackRequestEndInformation(rs, map);
419                 } else if (CallFlowMonitor.CALL_STACK_METHOD_END.equals(table_type)){
420                     map = getCallStackMethodEndInformation(rs, map);
421                 } else if (CallFlowMonitor.CALL_STACK_METHOD_START.equals(table_type)){
422                     map = getCallStackMethodStartInformation(rs, map);
423                 }
424                 list.add(map);
425             }
426             stmt.close();
427         } catch (SQLException JavaDoc se){
428             // log it
429
logger.log(Level.FINE, "callflow.error_get_callstack_info", se);
430         }
431         closeConnection();
432         return list;
433     }
434     private Map JavaDoc<String JavaDoc, String JavaDoc> getCallStackCommonInformation (ResultSet JavaDoc rs,
435             Map JavaDoc<String JavaDoc, String JavaDoc> map) throws SQLException JavaDoc
436     {
437         
438         // get columns common across all tables
439
String JavaDoc request_id = rs.getString(TableInfo.REQUEST_ID);
440         map.put(CallFlowMonitor.REQUEST_ID_KEY, request_id);
441
442         long time_stamp = rs.getLong(TIMESTAMP_INDEX_CSI);
443         map.put(CallFlowMonitor.TIME_STAMP_KEY, String.valueOf(time_stamp));
444
445         long time_stamp_millis = rs.getLong (TIMESTAMP_MILLIS_INDEX_CSI);
446         map.put (CallFlowMonitor.TIME_STAMP_MILLIS_KEY, String.valueOf(time_stamp_millis));
447
448         return map;
449     }
450     
451     private Map JavaDoc<String JavaDoc, String JavaDoc> getCallStackRequestEndInformation (ResultSet JavaDoc rs,
452             Map JavaDoc<String JavaDoc, String JavaDoc> map) throws SQLException JavaDoc
453     {
454         map = getCallStackCommonInformation(rs, map);
455         return map;
456     }
457  
458     private Map JavaDoc<String JavaDoc, String JavaDoc> getCallStackRequestStartInformation (ResultSet JavaDoc rs,
459             Map JavaDoc<String JavaDoc, String JavaDoc> map) throws SQLException JavaDoc{
460         map = getCallStackCommonInformation(rs, map);
461         String JavaDoc request_type = rs.getString(REQUEST_TYPE_INDEX_CSI);
462         map.put (CallFlowMonitor.REQUEST_TYPE_KEY, request_type);
463         return map;
464     }
465     
466    private Map JavaDoc<String JavaDoc, String JavaDoc> getCallStackMethodEndInformation (ResultSet JavaDoc rs,
467             Map JavaDoc<String JavaDoc, String JavaDoc> map) throws SQLException JavaDoc{
468         map = getCallStackCommonInformation(rs, map);
469         String JavaDoc exception_name = rs.getString(EXCEPTION_NAME_INDEX_CSI);
470         map.put(CallFlowMonitor.EXCEPTION_KEY, exception_name);
471         String JavaDoc status =
472                 (exception_name == null)? String.valueOf(Boolean.TRUE) :
473                     String.valueOf(Boolean.FALSE);
474         map.put(CallFlowMonitor.STATUS_KEY, status);
475         return map;
476    
477    }
478    
479     private Map JavaDoc<String JavaDoc, String JavaDoc> getCallStackMethodStartInformation (ResultSet JavaDoc rs,
480             Map JavaDoc<String JavaDoc, String JavaDoc> map) throws SQLException JavaDoc{
481         map = getCallStackCommonInformation(rs, map);
482         String JavaDoc container_type = rs.getString(CONTAINER_TYPE_INDEX_CSI);
483         map.put(CallFlowMonitor.CONTAINER_TYPE_KEY, container_type);
484         
485         String JavaDoc component_name = rs.getString(COMPONENT_NAME_INDEX_CSI);
486         map.put(CallFlowMonitor.COMPONENT_NAME_KEY, component_name);
487         
488         String JavaDoc app_name = rs.getString(APP_NAME_INDEX_CSI);
489         map.put (CallFlowMonitor.APPLICATION_NAME_KEY, app_name);
490         
491         String JavaDoc method_name = rs.getString(METHOD_NAME_INDEX_CSI);
492         map.put (CallFlowMonitor.METHOD_NAME_KEY, method_name);
493
494         String JavaDoc module_name = rs.getString(MODULE_NAME_INDEX_CSI);
495         map.put(CallFlowMonitor.MODULE_NAME_KEY, module_name);
496         
497         String JavaDoc thread_id = rs.getString(THREAD_ID_INDEX_CSI);
498         map = getCallStackCommonInformation(rs, map);
499         String JavaDoc exception_name = rs.getString(EXCEPTION_NAME_INDEX_CSI);
500         map.put(CallFlowMonitor.EXCEPTION_KEY, exception_name);
501         String JavaDoc status =
502                 (exception_name == null)? String.valueOf(Boolean.TRUE) :
503                     String.valueOf(Boolean.FALSE);
504         map.put(CallFlowMonitor.STATUS_KEY, status);
505         return map;
506    
507    }
508 //</editor-fold>
509

510     //<editor-fold defaultstate="collapsed" desc="Insert method">
511
public boolean insert(TransferObject[] transferObject) {
512         boolean result = false;
513     
514         if (transferObject.length == 0) //sanity
515
return true;
516         
517         if (transferObject[0] instanceof RequestStartTO){
518             result =
519              (pstmtRS == null)? false: reqStart.insert(pstmtRS, transferObject);
520         } else if (transferObject[0] instanceof RequestEndTO){
521             result =
522               (pstmtRE == null)? false : reqEnd.insert(pstmtRE, transferObject);
523         } else if (transferObject[0] instanceof MethodStartTO){
524            result =
525            (pstmtMS == null)? false : methStart.insert(pstmtMS, transferObject);
526         } else if (transferObject[0] instanceof MethodEndTO){
527             result =
528              (pstmtME == null)? false : methEnd.insert(pstmtME, transferObject);
529         } else if (transferObject[0] instanceof StartTimeTO){
530         result =
531         (pstmtST == null)? false : startTime.insert(pstmtST, transferObject);
532     } else if (transferObject[0] instanceof EndTimeTO){
533         result =
534         (pstmtET == null)? false : endTime.insert(pstmtET, transferObject);
535     }
536         return result;
537     }
538 //</editor-fold>
539

540     //<editor-fold defaultstate="collapsed" desc="getPieInformation query">
541
public Map JavaDoc <String JavaDoc, String JavaDoc> getPieInformation(String JavaDoc requestId) {
542         closeConnection();
543         connection = null;
544         if(connection == null)
545             if(!setupConnection())
546                 return null;
547         Map JavaDoc<String JavaDoc, String JavaDoc> mapST = null;
548         Map JavaDoc<String JavaDoc, String JavaDoc> mapET = null;
549         Map JavaDoc<String JavaDoc, String JavaDoc> retMap = null;
550         PreparedStatement JavaDoc st = null;
551         PreparedStatement JavaDoc et = null;
552         try{
553             String JavaDoc startSql =
554                 generateQuerySQLForStartTimeAndEndTime (TableInfo.GET_PIE_INFORMATION_START_TIME_SQL);
555             st = connection.prepareStatement(startSql);
556             st.setString (1, requestId);
557             ResultSet JavaDoc rs = st.executeQuery();
558             mapST = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
559             while(rs.next()){
560                 String JavaDoc container_type = rs.getString(1);
561                 long time_taken = rs.getLong(2);
562                 mapST.put(container_type, String.valueOf(time_taken));
563             }
564             st.close();
565             String JavaDoc endSql =
566                 generateQuerySQLForStartTimeAndEndTime (TableInfo.GET_PIE_INFORMATION_END_TIME_SQL);
567             et = connection.prepareStatement(endSql);
568             et.setString (1, requestId);
569             rs = et.executeQuery();
570             mapET = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
571             while(rs.next()){
572                 String JavaDoc container_type = rs.getString(1);
573                 long time_taken = rs.getLong(2);
574                 mapET.put(container_type, String.valueOf(time_taken));
575             }
576             et.close();
577             retMap = new HashMap JavaDoc <String JavaDoc, String JavaDoc> ();
578             
579             for (String JavaDoc key : mapST.keySet()){
580                 String JavaDoc stime = mapST.get(key);
581                 if (stime == null)
582                     continue;
583                 long startTime = Long.valueOf(stime);
584                 String JavaDoc etime = mapET.get(key);
585                 if (etime == null )
586                     continue;
587                 long endTime = Long.valueOf(etime);
588                 long time_taken = endTime - startTime;
589                 retMap.put (key, String.valueOf (time_taken));
590             }
591             
592         } catch (SQLException JavaDoc se){
593             // log it
594
logger.log(Level.FINE, "callflow.error_get_pie_info", se);
595         }
596         closeConnection();
597         return retMap;
598     }
599     private String JavaDoc generateQuerySQLForStartTimeAndEndTime (String JavaDoc sql){
600         // append ST, ET table Name with __server name
601
String JavaDoc newsql = new String JavaDoc(sql);
602        // replace ST Table with ST__server
603
String JavaDoc table = TableInfo.START_TIME_TABLE_NAME;
604        String JavaDoc tableWithServerName = getTableWithServerName (table);
605        newsql = newsql.replaceAll(table, tableWithServerName);
606        // ET
607
table = TableInfo.END_TIME_TABLE_NAME;
608        tableWithServerName = getTableWithServerName (table);
609        newsql = newsql.replaceAll(table, tableWithServerName);
610        return newsql;
611     }
612     
613    //</editor-fold>
614

615     //<editor-fold defaultstate="collapsed" desc="References into Columns for getCallStackInformation query">
616
/**
617      * The following variables are used to reference into the columns that
618      * are returned by the getCallStackInformation Query
619      */

620     private int SECURITY_ID_INDEX_CSI = 13;
621
622     private int TRANSACTION_ID_INDEX_CSI = 12;
623
624     private int THREAD_ID_INDEX_CSI = 11;
625
626     private int MODULE_NAME_INDEX_CSI = 10;
627
628     private int METHOD_NAME_INDEX_CSI = 9;
629
630     private int APP_NAME_INDEX_CSI = 8;
631
632     private int COMPONENT_NAME_INDEX_CSI = 7;
633
634     private int CONTAINER_TYPE_INDEX_CSI = 6;
635
636     private int EXCEPTION_NAME_INDEX_CSI = 5;
637
638     private int REQUEST_TYPE_INDEX_CSI = 4;
639
640     private int TIMESTAMP_INDEX_CSI = 3;
641     
642     private int TABLE_TYPE_INDEX_CSI = 1;
643     
644     private int TIMESTAMP_MILLIS_INDEX_CSI = 14;
645 //</editor-fold>
646

647     public boolean deleteRequestIds (String JavaDoc[] requestIds) {
648         if (requestIds.length <=0 )
649             return true;
650         
651         boolean resultRS = false;
652         boolean resultRE = false;
653         boolean resultMS = false;
654         boolean resultME = false;
655         boolean resultCS = false;
656         boolean resultCE = false;
657         
658         PreparedStatement JavaDoc rs = null;
659         PreparedStatement JavaDoc re = null;
660         PreparedStatement JavaDoc ms = null;
661         PreparedStatement JavaDoc me = null;
662         PreparedStatement JavaDoc st = null;
663         PreparedStatement JavaDoc et = null;
664         
665         
666         if (connection == null)
667             if (!setupConnection())
668                 return false;
669         try {
670             rs = connection.prepareStatement(reqStart.getDeleteSQL());
671             resultRS = (rs == null)? false : reqStart.delete(rs, requestIds);
672             if (!resultRS)
673                  logger.log (Level.FINE, "Error deleting requests from Request Start Table");
674         } catch (SQLException JavaDoc se){
675             logger.log (Level.FINE, "Error deleting requests from Request Start Table", se);
676         }finally {
677             if (rs != null){
678                 try{
679                     rs.close();
680                 } catch (SQLException JavaDoc se){
681                     // ignore
682
} finally {
683                     rs = null;
684                 }
685             }
686         }
687         try{
688             re = connection.prepareStatement(reqEnd.getDeleteSQL());
689             resultRE = (re == null)? false : reqEnd.delete(re, requestIds);
690             if (!resultRE)
691                 logger.log (Level.FINE, "Error deleting requests from Request End Table");
692         } catch (SQLException JavaDoc se){
693             logger.log (Level.FINE, "Error deleting requests from Request End Table", se);
694         } finally {
695             if (re != null){
696                 try{
697                     re.close();
698                 } catch (SQLException JavaDoc se){
699                     // ignore
700
} finally {
701                     re = null;
702                 }
703             }
704         }
705         try{
706             ms = connection.prepareStatement(methStart.getDeleteSQL());
707             resultMS = (ms == null)? false : methStart.delete(ms, requestIds);
708             if (!resultMS)
709                 logger.log (Level.FINE, "Error deleting requests from Method Start Table");
710         } catch (SQLException JavaDoc se){
711             logger.log (Level.FINE, "Error deleting requests from Method Start Table", se);
712         }finally {
713             if (ms != null){
714                 try{
715                     ms.close();
716                 } catch (SQLException JavaDoc se){
717                     // ignore
718
} finally {
719                     ms = null;
720                 }
721             }
722         }
723         
724         try{
725             me = connection.prepareStatement(methEnd.getDeleteSQL());
726             resultME = (me == null)? false : methEnd.delete(me, requestIds);
727             if (!resultME)
728                 logger.log (Level.FINE, "Error deleting requests from Method End Table");
729         } catch (SQLException JavaDoc se){
730             logger.log (Level.FINE, "Error deleting requests from MethodEnd Table", se);
731         }finally {
732             if (me != null){
733                 try{
734                     me.close();
735                 } catch (SQLException JavaDoc se){
736                     // ignore
737
} finally {
738                     me = null;
739                 }
740             }
741         }
742         
743         try{
744             st = connection.prepareStatement(startTime.getDeleteSQL());
745             resultCS = (st == null)? false : startTime.delete(st, requestIds);
746             if (!resultCS)
747                 logger.log (Level.FINE, "Error deleting requests from Container Start Table");
748         } catch (SQLException JavaDoc se){
749             logger.log (Level.FINE, "Error deleting requests from Container Start Table", se);
750         }finally {
751             if (st != null){
752                 try{
753                     st.close();
754                 } catch (SQLException JavaDoc se){
755                     // ignore
756
} finally {
757                     st = null;
758                 }
759             }
760         }
761         try{
762             et =connection.prepareStatement(endTime.getDeleteSQL());
763             resultCE = (et == null)? false : endTime.delete(et, requestIds);
764             if (!resultCE)
765                 logger.log (Level.FINE, "Error deleting requests from Container End Table");
766         } catch (SQLException JavaDoc se){
767             logger.log (Level.FINE, "Error deleting requests from End time Table", se);
768         }finally {
769             if (et != null){
770                 try{
771                     et.close();
772                 } catch (SQLException JavaDoc se){
773                     // ignore
774
} finally {
775                     et = null;
776                 }
777             }
778         }
779         if (resultRS && resultRE && resultMS && resultME && resultCS && resultCE)
780             return true;
781         return false;
782     }
783 }
784
Popular Tags