KickJava   Java API By Example, From Geeks To Geeks.

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


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  * MethodEndAccessObjectImpl.java
26  *
27  * Created on July 14, 2005, 11:09 AM
28  */

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

43 public class MethodEndAccessObjectImpl extends AbstractTableAccessObject{
44     private static final Logger JavaDoc logger =
45             Logger.getLogger(AdminConstants.kLoggerName);
46
47     private static MethodEndAccessObjectImpl _singletonME;
48     
49     /**
50      * Creates a new instance of MethodEndAccessObjectImpl
51      */

52     private MethodEndAccessObjectImpl() {
53         String JavaDoc serverName = super.getServerInstanceName();
54         super.tableName = TableInfo.METHOD_END_TABLE_NAME +
55                 serverName.toUpperCase();
56     }
57     
58     public boolean dropTable(Connection JavaDoc connection) {
59         super.con = connection;
60         return super.createStatmentAndExecuteUpdate(
61                 TableInfo.DROP_TABLE_METHOD_END_SQL,
62                 TableInfo.METHOD_END_TABLE_NAME);
63     }
64     
65     public boolean createTable(Connection JavaDoc connection) {
66         super.con = connection;
67         return super.createTable(
68                 TableInfo.CREATE_TABLE_METHOD_END_SQL,
69                 TableInfo.METHOD_END_TABLE_NAME);
70         
71     }
72     
73     public static TableAccessObject getInstance() {
74         if(_singletonME == null)
75             _singletonME = new MethodEndAccessObjectImpl();
76         
77         return _singletonME;
78     }
79     
80     public boolean insert(java.sql.PreparedStatement JavaDoc pstmt, TransferObject[] transferObject) {
81         // sanity
82
if (pstmt == null)
83             return false;
84         boolean result = false;
85         try{
86             
87             for (int i = 0 ; i<transferObject.length; i++) {
88                 MethodEndTO methodEndTO = (MethodEndTO)transferObject[i];
89                 pstmt.setString(1, methodEndTO.getRequestId());
90                 pstmt.setLong(2, methodEndTO.getTimeStamp());
91                 pstmt.setString(3, methodEndTO.getException());
92                 pstmt.addBatch();
93                 
94             }
95             int[] updated = pstmt.executeBatch();
96             result = (updated.length == transferObject.length)? true : false;
97         } catch(BatchUpdateException JavaDoc bue) {
98             // log it
99
logger.log(Level.FINE, "Error inserting data into CallFlow tables", bue);
100             result = false;
101         }catch (SQLException JavaDoc se) {
102             // log it
103
logger.log(Level.FINE, "Error inserting data into CallFlow tables", se);
104             result = false;
105         }
106         return result;
107     }
108
109       public String JavaDoc getInsertSQL() {
110         String JavaDoc newsql = super.updateSqlWithTableName(
111                 TableInfo.INSERT_INTO_TABLE_METHOD_END_SQL,
112                 TableInfo.METHOD_END_TABLE_NAME);
113         return newsql;
114     }
115
116       public String JavaDoc getDeleteSQL () {
117         String JavaDoc newsql = super.updateSqlWithTableName (
118                 TableInfo.DELETE_FROM_TABLE_METHOD_END_SQL,
119                 TableInfo.METHOD_END_TABLE_NAME);
120         return newsql;
121     }
122     
123 }
124
Popular Tags