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.Address; 26 27 30 class AddressTable 31 { 32 private static Log log = LogFactory.getLog(AddressTable.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 ADDRESS ("); 46 sql.append("BUSINESS_KEY,"); 47 sql.append("CONTACT_ID,"); 48 sql.append("ADDRESS_ID,"); 49 sql.append("USE_TYPE,"); 50 sql.append("SORT_CODE,"); 51 sql.append("TMODEL_KEY) "); 52 sql.append("VALUES (?,?,?,?,?,?)"); 53 insertSQL = sql.toString(); 54 55 sql = new StringBuffer (200); 57 sql.append("SELECT "); 58 sql.append("USE_TYPE,"); 59 sql.append("SORT_CODE,"); 60 sql.append("TMODEL_KEY, "); 61 sql.append("ADDRESS_ID "); 62 sql.append("FROM ADDRESS "); 63 sql.append("WHERE BUSINESS_KEY=? "); 64 sql.append("AND CONTACT_ID=? "); 65 sql.append("ORDER BY ADDRESS_ID"); 66 selectSQL = sql.toString(); 67 68 sql = new StringBuffer (100); 70 sql.append("DELETE FROM ADDRESS "); 71 sql.append("WHERE BUSINESS_KEY=?"); 72 deleteSQL = sql.toString(); 73 } 74 75 84 public static void insert(String businessKey,int contactID,Vector addrList,Connection connection) 85 throws java.sql.SQLException 86 { 87 if ((addrList == null) || (addrList.size() == 0)) 88 return; 90 PreparedStatement statement = null; 91 92 try 93 { 94 statement = connection.prepareStatement(insertSQL); 95 statement.setString(1, businessKey.toString()); 96 statement.setInt(2, contactID); 97 98 int listSize = addrList.size(); 99 for (int addressID = 0; addressID < listSize; addressID++) 100 { 101 Address address = (Address) addrList.elementAt(addressID); 102 statement.setInt(3, addressID); 103 statement.setString(4, address.getUseType()); 104 statement.setString(5, address.getSortCode()); 105 statement.setString(6, address.getTModelKey()); 106 107 log.debug( 108 "insert into ADDRESS table:\n\n\t" 109 + insertSQL 110 + "\n\t BUSINESS_KEY=" 111 + businessKey.toString() 112 + "\n\t CONTACT_ID=" 113 + contactID 114 + "\n\t ADDRESS_ID=" 115 + addressID 116 + "\n\t USE_TYPE=" 117 + address.getUseType() 118 + "\n\t SORT_CODE=" 119 + address.getSortCode() 120 + "\n\t TMODEL_KEY=" 121 + address.getTModelKey() 122 + "\n"); 123 124 statement.executeUpdate(); 125 } 126 } 127 finally 128 { 129 try { 130 statement.close(); 131 } 132 catch (Exception e) { } 133 } 134 } 135 136 144 public static Vector select(String businessKey,int contactID,Connection connection) 145 throws java.sql.SQLException 146 { 147 Vector addrList = new Vector (); 148 PreparedStatement statement = null; 149 ResultSet resultSet = null; 150 151 try 152 { 153 statement = connection.prepareStatement(selectSQL); 155 statement.setString(1, businessKey.toString()); 156 statement.setInt(2, contactID); 157 158 log.debug( 159 "select from ADDRESS table:\n\n\t" 160 + selectSQL 161 + "\n\t BUSINESS_KEY=" 162 + businessKey.toString() 163 + "\n\t CONTACT_ID=" 164 + contactID 165 + "\n"); 166 167 resultSet = statement.executeQuery(); 169 while (resultSet.next()) 170 { 171 Address address = new Address(); 172 address.setUseType(resultSet.getString(1)); address.setSortCode(resultSet.getString(2)); address.setTModelKey(resultSet.getString(3)); addrList.add(address); 176 address = null; 177 } 178 179 return addrList; 180 } 181 finally 182 { 183 try { 184 resultSet.close(); 185 statement.close(); 186 } 187 catch (Exception e) { } 188 } 189 } 190 191 199 public static void delete(String businessKey, Connection connection) 200 throws java.sql.SQLException 201 { 202 PreparedStatement statement = null; 203 204 try 205 { 206 statement = connection.prepareStatement(deleteSQL); 208 statement.setString(1, businessKey.toString()); 209 210 log.debug( 211 "delete from ADDRESS table:\n\n\t" 212 + deleteSQL 213 + "\n\t BUSINESS_KEY=" 214 + businessKey.toString() 215 + "\n"); 216 217 statement.executeUpdate(); 219 } 220 finally 221 { 222 try { 223 statement.close(); 224 } 225 catch (Exception e) { } 226 } 227 } 228 } | Popular Tags |