1 23 24 29 30 package com.sun.enterprise.admin.monitor.callflow; 31 32 import java.sql.BatchUpdateException ; 33 import java.sql.Connection ; 34 import java.sql.PreparedStatement ; 35 import java.sql.SQLException ; 36 import java.sql.Statement ; 37 import com.sun.enterprise.server.ApplicationServer; 38 import com.sun.enterprise.server.ServerContext; 39 import java.util.logging.Level ; 40 import java.util.logging.Logger ; 41 import com.sun.enterprise.admin.common.constant.AdminConstants; 42 46 public abstract class AbstractTableAccessObject implements TableAccessObject{ 47 48 private static final Logger logger = 49 Logger.getLogger(AdminConstants.kLoggerName); 50 53 private static final String TABLE_EXISTS_SQL_ERROR_CODE = "X0Y32"; 54 55 59 60 Connection con = null; 61 65 String tableName = null; 66 private static final String DEFAULT_SERVER_NAME = "server"; 67 68 abstract public boolean createTable(Connection connection); 69 abstract public boolean dropTable(Connection connection); 70 71 boolean createStatmentAndExecuteUpdate(String oldsql, 72 String tableNameWithoutServerInstance){ 73 74 String sql = updateSqlWithTableName (oldsql, tableNameWithoutServerInstance); 75 boolean result = false; 76 Statement stmt = null; 77 try{ 78 if (con != null){ 79 stmt = con.createStatement(); 80 stmt.executeUpdate(sql); 81 result = true; 82 } 83 } catch (java.sql.SQLException se) { 84 logger.log(Level.WARNING, "Error accessing CallFlow tables!", se); 86 result = false; 87 } finally { 88 if(stmt != null){ 89 try{ 90 stmt.close(); 91 }catch(java.sql.SQLException s){ 92 } 94 } 95 stmt = null; 96 } 97 return result; 98 } 99 100 107 boolean createTable(String oldsql, 108 String tableNameWithoutServerInstance){ 109 110 String sql = updateSqlWithTableName (oldsql, tableNameWithoutServerInstance); 111 boolean result = false; 112 Statement stmt = null; 113 try{ 114 if (con != null){ 115 stmt = con.createStatement(); 116 stmt.executeUpdate(sql); 117 result = true; 118 } 119 } catch (java.sql.SQLException se) { 120 if (se.getSQLState().equalsIgnoreCase (TABLE_EXISTS_SQL_ERROR_CODE)){ 122 logger.log (Level.FINE, "callflow.table_already_exists_error", 123 tableNameWithoutServerInstance); 124 } else { 125 logger.log(Level.WARNING, "callflow.table_creation_error", 126 tableNameWithoutServerInstance); 127 logger.log(Level.WARNING, "callflow.table_creation_error", se); 128 } 129 result = true; 130 } finally { 131 if(stmt != null){ 132 try{ 133 stmt.close(); 134 }catch(java.sql.SQLException s){ 135 } 137 } 138 stmt = null; 139 } 140 return result; 141 } 142 public String getServerInstanceName () { 143 String server = DEFAULT_SERVER_NAME; 145 ServerContext sc = ApplicationServer.getServerContext(); 146 if (sc != null) { 147 server = sc.getInstanceName (); 148 } 149 return "__" + server; 150 } 151 152 161 String updateSqlWithTableName (String oldsql, String table) { 162 String newsql = new String (oldsql); 163 newsql = newsql.replaceAll(table, tableName); 164 165 return newsql; 166 } 167 168 public boolean delete(PreparedStatement pstmt, String [] requestId) { 169 if (pstmt == null) 170 return false; 171 172 boolean result = false; 173 try{ 174 for (int i = 0 ; i<requestId.length; i++) { 175 pstmt.setString(1, requestId[i]); 176 pstmt.addBatch(); 177 } 178 int[] updated = pstmt.executeBatch(); 179 result = (updated.length == requestId.length)? true : false; 180 if (result == false){ 181 logger.log (Level.WARNING, "callflow.error_delete_row"); 182 } 183 } catch(BatchUpdateException bue) { 184 logger.log (Level.WARNING, "callflow.error_delete_row"); 186 logger.log(Level.FINE, "Error data into CallFlow tables", bue); 187 result = false; 188 }catch (SQLException se) { 189 logger.log (Level.WARNING, "callflow.error_delete_row"); 191 logger.log(Level.FINE, "Error inserting data into CallFlow tables", se); 192 result = false; 193 } 194 return result; 195 196 } 197 } 198 | Popular Tags |