KickJava   Java API By Example, From Geeks To Geeks.

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


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  * MethodStartAccessObjectImpl.java
26  *
27  * Created on July 14, 2005, 1:56 PM
28  */

29
30 package com.sun.enterprise.admin.monitor.callflow;
31
32 import java.sql.BatchUpdateException JavaDoc;
33 import java.sql.Connection JavaDoc;
34 import java.sql.SQLException JavaDoc;
35 import java.util.logging.Level JavaDoc;
36 import java.util.logging.Logger JavaDoc;
37 import com.sun.enterprise.admin.common.constant.AdminConstants;
38 /**
39  *
40  * @author Harpreet Singh
41  */

42 public class MethodStartAccessObjectImpl extends AbstractTableAccessObject{
43     private static final Logger JavaDoc logger =
44             Logger.getLogger(AdminConstants.kLoggerName);
45
46     private static MethodStartAccessObjectImpl _singletonMS;
47     
48     /** Creates a new instance of MethodStartAccessObjectImpl */
49     private MethodStartAccessObjectImpl() {
50         String JavaDoc serverName = super.getServerInstanceName();
51         super.tableName = TableInfo.METHOD_START_TABLE_NAME +
52                 serverName.toUpperCase();
53     }
54
55     public boolean createTable(Connection JavaDoc connection) {
56         super.con = connection;
57         return super.createTable(
58                 TableInfo.CREATE_TABLE_METHOD_START_SQL,
59                 TableInfo.METHOD_START_TABLE_NAME);
60     }
61
62     public boolean dropTable(Connection JavaDoc connection) {
63         super.con = connection;
64         return super.createStatmentAndExecuteUpdate(
65                 TableInfo.DROP_TABLE_METHOD_START_SQL,
66                 TableInfo.METHOD_START_TABLE_NAME);
67     }
68    
69     public static TableAccessObject getInstance() {
70         if(_singletonMS == null)
71             _singletonMS = new MethodStartAccessObjectImpl ();
72         
73         return _singletonMS;
74     }
75
76     public boolean insert(java.sql.PreparedStatement JavaDoc pstmt, TransferObject[] transferObject) {
77       // sanity
78
if (pstmt == null)
79             return false;
80         boolean result = false;
81         try{
82             
83             for (int i = 0 ; i<transferObject.length; i++) {
84                 MethodStartTO methodStartTO = (MethodStartTO)transferObject[i];
85                 pstmt.setString(1, methodStartTO.getRequestId());
86                 pstmt.setLong(2, methodStartTO.getTimeStamp());
87                 
88                 if (methodStartTO.getComponentType() != null)
89                     pstmt.setString(3, methodStartTO.getComponentType().toString());
90                 else
91                     pstmt.setString(3, null);
92
93                 pstmt.setString(4, methodStartTO.getComponentName());
94                 pstmt.setString(5, methodStartTO.getAppName());
95                 pstmt.setString(6, methodStartTO.getMethodName());
96
97                 pstmt.setString(7, methodStartTO.getModuleName());
98                 pstmt.setString(8, methodStartTO.getThreadId());
99                 pstmt.setString(9, methodStartTO.getTransactionId());
100
101                 pstmt.setString(10, methodStartTO.getSecurityId());
102                 pstmt.addBatch();
103             }
104             int[] updated = pstmt.executeBatch();
105             result = (updated.length == transferObject.length)? true : false;
106         } catch(BatchUpdateException JavaDoc bue) {
107             // log it
108
logger.log(Level.FINE, "Error inserting data into CallFlow tables", bue);
109             result = false;
110         }catch (SQLException JavaDoc se) {
111             // log it
112
logger.log(Level.FINE, "Error inserting data into CallFlow tables", se);
113             result = false;
114         }
115         return result; }
116
117       public String JavaDoc getInsertSQL() {
118         String JavaDoc newsql = super.updateSqlWithTableName(
119                 TableInfo.INSERT_INTO_TABLE_METHOD_START_SQL,
120                 TableInfo.METHOD_START_TABLE_NAME);
121         return newsql;
122     }
123
124       public String JavaDoc getDeleteSQL () {
125         String JavaDoc newsql = super.updateSqlWithTableName (
126                 TableInfo.DELETE_FROM_TABLE_METHOD_START_SQL,
127                 TableInfo.METHOD_START_TABLE_NAME);
128         return newsql;
129     }
130       
131 }
132
Popular Tags