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.DiscoveryURL; 26 27 30 class DiscoveryURLTable 31 { 32 private static Log log = LogFactory.getLog(DiscoveryURLTable.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 DISCOVERY_URL ("); 46 sql.append("BUSINESS_KEY,"); 47 sql.append("DISCOVERY_URL_ID,"); 48 sql.append("USE_TYPE,"); 49 sql.append("URL) "); 50 sql.append("VALUES (?,?,?,?)"); 51 insertSQL = sql.toString(); 52 53 sql = new StringBuffer (200); 55 sql.append("SELECT "); 56 sql.append("USE_TYPE,"); 57 sql.append("URL, "); 58 sql.append("DISCOVERY_URL_ID "); 59 sql.append("FROM DISCOVERY_URL "); 60 sql.append("WHERE BUSINESS_KEY=? "); 61 sql.append("ORDER BY DISCOVERY_URL_ID"); 62 selectSQL = sql.toString(); 63 64 sql = new StringBuffer (100); 66 sql.append("DELETE FROM DISCOVERY_URL "); 67 sql.append("WHERE BUSINESS_KEY=?"); 68 deleteSQL = sql.toString(); 69 } 70 71 80 public static void insert( 81 String businessKey, 82 Vector urlList, 83 Connection connection) 84 throws java.sql.SQLException 85 { 86 if ((urlList == null) || (urlList.size() == 0)) 87 return; 89 PreparedStatement statement = null; 90 91 try 92 { 93 statement = connection.prepareStatement(insertSQL); 94 statement.setString(1, businessKey.toString()); 95 96 int listSize = urlList.size(); 97 for (int urlID = 0; urlID < listSize; urlID++) 98 { 99 DiscoveryURL url = (DiscoveryURL) urlList.elementAt(urlID); 100 String urlValue = url.getValue(); 101 102 log.debug( 103 "insert into DISCOVERY_URL table:\n\n\t" 104 + insertSQL 105 + "\n\t BUSINESS_KEY=" 106 + businessKey.toString() 107 + "\n\t DISCOVERY_URL_ID=" 108 + urlID 109 + "\n\t USE_TYPE=" 110 + url.getUseType() 111 + "\n\t URL=" 112 + urlValue 113 + "\n"); 114 115 statement.setInt(2, urlID); 116 statement.setString(3, url.getUseType()); 117 statement.setString(4, urlValue); 118 statement.executeUpdate(); 119 } 120 } 121 finally 122 { 123 try 124 { 125 statement.close(); 126 } 127 catch (Exception e) 128 { 129 } 130 } 131 } 132 133 140 public static Vector select(String businessKey, Connection connection) 141 throws java.sql.SQLException 142 { 143 Vector urlList = new Vector (); 144 PreparedStatement statement = null; 145 ResultSet resultSet = null; 146 147 try 148 { 149 statement = connection.prepareStatement(selectSQL); 151 statement.setString(1, businessKey.toString()); 152 153 log.debug( 154 "select from DISCOVERY_URL table:\n\n\t" 155 + selectSQL 156 + "\n\t BUSINESS_KEY=" 157 + businessKey.toString() 158 + "\n"); 159 160 resultSet = statement.executeQuery(); 162 while (resultSet.next()) 163 { 164 DiscoveryURL url = new DiscoveryURL(); 165 url.setUseType(resultSet.getString(1)); url.setValue(resultSet.getString(2)); urlList.add(url); 168 } 169 170 return urlList; 171 } 172 finally 173 { 174 try 175 { 176 resultSet.close(); 177 statement.close(); 178 } 179 catch (Exception e) 180 { 181 } 182 } 183 } 184 185 193 public static void delete(String businessKey, Connection connection) 194 throws java.sql.SQLException 195 { 196 PreparedStatement statement = null; 197 198 try 199 { 200 statement = connection.prepareStatement(deleteSQL); 202 statement.setString(1, businessKey.toString()); 203 204 log.debug( 205 "delete from DISCOVERY_URL table:\n\n\t" 206 + deleteSQL 207 + "\n\t BUSINESS_KEY=" 208 + businessKey.toString() 209 + "\n"); 210 211 statement.executeUpdate(); 213 } 214 finally 215 { 216 try 217 { 218 statement.close(); 219 } 220 catch (Exception e) 221 { 222 } 223 } 224 } 225 } 226 | Popular Tags |