1 16 package org.apache.juddi.datastore.jdbc; 17 18 import java.sql.Connection ; 19 import java.sql.PreparedStatement ; 20 import java.sql.ResultSet ; 21 import java.util.Vector ; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 import org.apache.juddi.datatype.Email; 26 27 30 class EmailTable 31 { 32 private static Log log = LogFactory.getLog(EmailTable.class); 34 35 static String insertSQL = null; 36 static String selectSQL = null; 37 static String deleteSQL = null; 38 39 static { 40 StringBuffer sql = null; 42 43 sql = new StringBuffer (150); 45 sql.append("INSERT INTO EMAIL ("); 46 sql.append("BUSINESS_KEY,"); 47 sql.append("CONTACT_ID,"); 48 sql.append("EMAIL_ID,"); 49 sql.append("USE_TYPE,"); 50 sql.append("EMAIL_ADDRESS) "); 51 sql.append("VALUES (?,?,?,?,?)"); 52 insertSQL = sql.toString(); 53 54 sql = new StringBuffer (200); 56 sql.append("SELECT "); 57 sql.append("USE_TYPE,"); 58 sql.append("EMAIL_ADDRESS, "); 59 sql.append("EMAIL_ID "); 60 sql.append("FROM EMAIL "); 61 sql.append("WHERE BUSINESS_KEY=? "); 62 sql.append("AND CONTACT_ID=? "); 63 sql.append("ORDER BY EMAIL_ID"); 64 selectSQL = sql.toString(); 65 66 sql = new StringBuffer (100); 68 sql.append("DELETE FROM EMAIL "); 69 sql.append("WHERE BUSINESS_KEY=?"); 70 deleteSQL = sql.toString(); 71 } 72 73 82 public static void insert( 83 String businessKey, 84 int contactID, 85 Vector emailList, 86 Connection connection) 87 throws java.sql.SQLException 88 { 89 if ((emailList == null) || (emailList.size() == 0)) 90 return; 92 PreparedStatement statement = null; 93 94 try 95 { 96 statement = connection.prepareStatement(insertSQL); 97 statement.setString(1, businessKey.toString()); 98 statement.setInt(2, contactID); 99 100 int listSize = emailList.size(); 101 for (int emailID = 0; emailID < listSize; emailID++) 102 { 103 Email email = (Email) emailList.elementAt(emailID); 104 105 statement.setInt(3, emailID); 106 statement.setString(4, email.getUseType()); 107 statement.setString(5, email.getValue()); 108 109 log.debug( 110 "insert into EMAIL table:\n\n\t" 111 + insertSQL 112 + "\n\t BUSINESS_KEY=" 113 + businessKey.toString() 114 + "\n\t CONTACT_ID=" 115 + contactID 116 + "\n\t EMAIL_ID=" 117 + emailID 118 + "\n\t USE_TYPE=" 119 + email.getUseType() 120 + "\n\t EMAIL_ADDRESS=" 121 + email.getValue() 122 + "\n"); 123 124 statement.executeUpdate(); 125 } 126 } 127 finally 128 { 129 try 130 { 131 statement.close(); 132 } 133 catch (Exception e) 134 { 135 } 136 } 137 } 138 139 147 public static Vector select( 148 String businessKey, 149 int contactID, 150 Connection connection) 151 throws java.sql.SQLException 152 { 153 Vector emailList = new Vector (); 154 PreparedStatement statement = null; 155 ResultSet resultSet = null; 156 157 try 158 { 159 statement = connection.prepareStatement(selectSQL); 161 statement.setString(1, businessKey.toString()); 162 statement.setInt(2, contactID); 163 164 log.debug( 165 "select from EMAIL table:\n\n\t" 166 + selectSQL 167 + "\n\t BUSINESS_KEY=" 168 + businessKey.toString() 169 + "\n\t CONTACT_ID=" 170 + contactID 171 + "\n"); 172 173 resultSet = statement.executeQuery(); 175 while (resultSet.next()) 176 { 177 Email email = new Email(); 178 email.setUseType(resultSet.getString(1)); email.setValue(resultSet.getString(2)); emailList.add(email); 181 } 182 183 return emailList; 184 } 185 finally 186 { 187 try 188 { 189 resultSet.close(); 190 statement.close(); 191 } 192 catch (Exception e) 193 { 194 } 195 } 196 } 197 198 206 public static void delete(String businessKey, Connection connection) 207 throws java.sql.SQLException 208 { 209 PreparedStatement statement = null; 210 211 try 212 { 213 statement = connection.prepareStatement(deleteSQL); 215 statement.setString(1, businessKey.toString()); 216 217 log.debug( 218 "delete from EMAIL table:\n\n\t" 219 + deleteSQL 220 + "\n\t BUSINESS_KEY=" 221 + businessKey.toString() 222 + "\n"); 223 224 statement.executeUpdate(); 226 } 227 finally 228 { 229 try 230 { 231 statement.close(); 232 } 233 catch (Exception e) 234 { 235 } 236 } 237 } 238 } 239 | Popular Tags |