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.AddressLine; 26 27 30 class AddressLineTable 31 { 32 private static Log log = LogFactory.getLog(AddressLineTable.class); 34 35 static String insertSQL = null; 36 static String selectSQL = null; 37 static String deleteSQL = null; 38 39 static 40 { 41 StringBuffer sql = null; 43 44 sql = new StringBuffer (150); 46 sql.append("INSERT INTO ADDRESS_LINE ("); 47 sql.append("BUSINESS_KEY,"); 48 sql.append("CONTACT_ID,"); 49 sql.append("ADDRESS_ID,"); 50 sql.append("ADDRESS_LINE_ID,"); 51 sql.append("LINE,"); 52 sql.append("KEY_NAME,"); 53 sql.append("KEY_VALUE) "); 54 sql.append("VALUES (?,?,?,?,?,?,?)"); 55 insertSQL = sql.toString(); 56 57 sql = new StringBuffer (200); 59 sql.append("SELECT "); 60 sql.append("LINE,"); 61 sql.append("KEY_NAME,"); 62 sql.append("KEY_VALUE, "); 63 sql.append("ADDRESS_LINE_ID "); 64 sql.append("FROM ADDRESS_LINE "); 65 sql.append("WHERE BUSINESS_KEY=? "); 66 sql.append("AND CONTACT_ID=? "); 67 sql.append("AND ADDRESS_ID=? "); 68 sql.append("ORDER BY ADDRESS_LINE_ID"); 69 selectSQL = sql.toString(); 70 71 sql = new StringBuffer (100); 73 sql.append("DELETE FROM ADDRESS_LINE "); 74 sql.append("WHERE BUSINESS_KEY=?"); 75 deleteSQL = sql.toString(); 76 } 77 78 88 public static void insert(String businessKey,int contactID,int addressID,Vector lineList,Connection connection) 89 throws java.sql.SQLException 90 { 91 if ((lineList == null) || (lineList.size() == 0)) 92 return; 94 PreparedStatement statement = null; 95 96 try 97 { 98 statement = connection.prepareStatement(insertSQL); 99 statement.setString(1,businessKey.toString()); 100 statement.setInt(2,contactID); 101 statement.setInt(3,addressID); 102 103 int listSize = lineList.size(); 104 for (int lineID=0; lineID<listSize; lineID++) 105 { 106 AddressLine line = (AddressLine)lineList.elementAt(lineID); 107 statement.setInt(4,lineID); 108 statement.setString(5,line.getLineValue()); 109 statement.setString(6,line.getKeyName()); 110 statement.setString(7,line.getKeyValue()); 111 112 log.debug("insert into ADDRESS_LINE table:\n\n\t" + insertSQL + 113 "\n\t BUSINESS_KEY=" + businessKey.toString() + 114 "\n\t CONTACT_ID=" + contactID + 115 "\n\t ADDRESS_ID=" + addressID + 116 "\n\t ADDRESS_LINE_ID=" + lineID + 117 "\n\t LINE=" + line.getLineValue() + 118 "\n\t KEY_NAME=" + line.getKeyName() + 119 "\n\t KEY_VALUE=" + line.getKeyValue() + "\n"); 120 121 statement.executeUpdate(); 122 } 123 } 124 finally 125 { 126 try { 127 statement.close(); 128 } 129 catch (Exception e) { } 130 } 131 } 132 133 141 public static Vector select(String businessKey,int contactID,int addressID,Connection connection) 142 throws java.sql.SQLException 143 { 144 Vector lineList = new Vector (); 145 PreparedStatement statement = null; 146 ResultSet resultSet = null; 147 148 try 149 { 150 statement = connection.prepareStatement(selectSQL); 152 statement.setString(1,businessKey.toString()); 153 statement.setInt(2,contactID); 154 statement.setInt(3,addressID); 155 156 log.debug("select from ADDRESS_LINE table:\n\n\t" + selectSQL + 157 "\n\t BUSINESS_KEY=" + businessKey.toString() + 158 "\n\t CONTACT_KEY=" + contactID + 159 "\n\t ADDRESS_ID=" + addressID + "\n"); 160 161 resultSet = statement.executeQuery(); 163 while (resultSet.next()) 164 { 165 AddressLine line = new AddressLine(); 166 line.setLineValue(resultSet.getString(1)); line.setKeyName(resultSet.getString(2)); line.setKeyValue(resultSet.getString(3)); lineList.add(line); 170 } 171 172 return lineList; 173 } 174 finally 175 { 176 try { 177 resultSet.close(); 178 statement.close(); 179 } 180 catch (Exception e) { } 181 } 182 } 183 184 192 public static void delete(String businessKey,Connection connection) 193 throws java.sql.SQLException 194 { 195 PreparedStatement statement = null; 196 197 try 198 { 199 statement = connection.prepareStatement(deleteSQL); 201 statement.setString(1,businessKey.toString()); 202 203 log.debug("delete from ADDRESS_LINE table:\n\n\t" + deleteSQL + 204 "\n\t BUSINESS_KEY=" + businessKey.toString() + "\n"); 205 206 statement.executeUpdate(); 208 } 209 finally 210 { 211 try { 212 statement.close(); 213 } 214 catch (Exception e) { } 215 } 216 } 217 } 218 | Popular Tags |