KickJava   Java API By Example, From Geeks To Geeks.

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


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  * RequestStartAccessObjectImpl.java
26  *
27  * Created on July 11, 2005, 11:15 AM
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 com.sun.enterprise.admin.monitor.callflow.TableInfo;
35 import java.sql.PreparedStatement JavaDoc;
36 import java.sql.SQLException JavaDoc;
37 import java.util.logging.Level JavaDoc;
38 import java.util.logging.Logger JavaDoc;
39 import com.sun.enterprise.admin.common.constant.AdminConstants;
40 /**
41  *
42  * @author Harpreet Singh
43  */

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

53     private RequestStartAccessObjectImpl() {
54         String JavaDoc serverName = super.getServerInstanceName();
55         super.tableName = TableInfo.REQUEST_START_TABLE_NAME +
56                 serverName.toUpperCase();
57     }
58
59     public String JavaDoc getInsertSQL () {
60         String JavaDoc newsql = super.updateSqlWithTableName(
61                 TableInfo.INSERT_INTO_TABLE_REQUEST_START_SQL,
62                 TableInfo.REQUEST_START_TABLE_NAME);
63         return newsql;
64     }
65
66     public String JavaDoc getDeleteSQL () {
67         String JavaDoc newsql = super.updateSqlWithTableName (
68                 TableInfo.DELETE_FROM_TABLE_REQUEST_START_SQL,
69                 TableInfo.REQUEST_START_TABLE_NAME);
70         return newsql;
71     }
72     
73     public boolean dropTable(Connection JavaDoc connection) {
74         super.con = connection;
75         return super.createStatmentAndExecuteUpdate(TableInfo.
76                 DROP_TABLE_REQUEST_START_SQL, TableInfo.REQUEST_START_TABLE_NAME);
77                 
78
79     }
80
81     public boolean createTable (Connection JavaDoc connection){
82         super.con = connection;
83         return super.createTable(TableInfo.
84                 CREATE_TABLE_REQUEST_START_SQL, TableInfo.REQUEST_START_TABLE_NAME);
85        
86     }
87     
88     
89     public static TableAccessObject getInstance() {
90         if(_singletonRS == null)
91             _singletonRS = new RequestStartAccessObjectImpl ();
92         
93         return _singletonRS;
94     }
95
96     public boolean insert(PreparedStatement JavaDoc pstmt, TransferObject[] requestStart) {
97         // sanity
98
if (pstmt == null)
99             return false;
100             
101         boolean result = false;
102         try{
103             for (int i = 0 ; i<requestStart.length; i++) {
104                 RequestStartTO request = (RequestStartTO)requestStart[i];
105                 pstmt.setString(1, request.getRequestId());
106                 pstmt.setLong(2, request.getTimeStamp());
107                 pstmt.setLong (3, request.getTimeStampMillis());
108                 if(request.getRequestType() != null)
109                     pstmt.setString(4, request.getRequestType().toString());
110                 else
111                     pstmt.setString(4, null);
112                 if (request.getIpAddress() != null)
113                     pstmt.setString(5, request.getIpAddress());
114                 else
115                     pstmt.setString (5, null);
116                 
117                 pstmt.addBatch();
118             }
119             int[] updated = pstmt.executeBatch();
120             result = (updated.length == requestStart.length)? true : false;
121             if (result == false){
122                 logger.log(Level.WARNING, "callflow.error_insert_row");
123             }
124         } catch(BatchUpdateException JavaDoc bue) {
125             // log it
126
logger.log(Level.FINE, "Error inserting data into CallFlow tables", bue);
127             result = false;
128         }catch (SQLException JavaDoc se) {
129             // log it
130
logger.log(Level.FINE, "Error inserting data into CallFlow tables", se);
131             result = false;
132         }
133         return result;
134     }
135   
136
137 }
138
Popular Tags