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.sql.Timestamp ; 22 import java.util.Vector ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.juddi.datatype.service.BusinessService; 27 28 31 class BusinessServiceTable 32 { 33 private static Log log = LogFactory.getLog(BusinessServiceTable.class); 35 36 static String insertSQL = null; 37 static String deleteSQL = null; 38 static String selectSQL = null; 39 static String selectByBusinessKeySQL = null; 40 static String deleteByBusinessKeySQL = null; 41 static String verifyOwnershipSQL = null; 42 43 static 44 { 45 StringBuffer sql = null; 47 48 sql = new StringBuffer (100); 50 sql.append("INSERT INTO BUSINESS_SERVICE ("); 51 sql.append("BUSINESS_KEY,"); 52 sql.append("SERVICE_KEY,"); 53 sql.append("LAST_UPDATE) "); 54 sql.append("VALUES (?,?,?)"); 55 insertSQL = sql.toString(); 56 57 sql = new StringBuffer (100); 59 sql.append("DELETE FROM BUSINESS_SERVICE "); 60 sql.append("WHERE SERVICE_KEY=?"); 61 deleteSQL = sql.toString(); 62 63 sql = new StringBuffer (100); 65 sql.append("SELECT "); 66 sql.append("BUSINESS_KEY "); 67 sql.append("FROM BUSINESS_SERVICE "); 68 sql.append("WHERE SERVICE_KEY=?"); 69 selectSQL = sql.toString(); 70 71 sql = new StringBuffer (200); 73 sql.append("SELECT "); 74 sql.append("SERVICE_KEY "); 75 sql.append("FROM BUSINESS_SERVICE "); 76 sql.append("WHERE BUSINESS_KEY=?"); 77 selectByBusinessKeySQL = sql.toString(); 78 79 sql = new StringBuffer (100); 81 sql.append("DELETE FROM BUSINESS_SERVICE "); 82 sql.append("WHERE BUSINESS_KEY=?"); 83 deleteByBusinessKeySQL = sql.toString(); 84 85 sql = new StringBuffer (200); 87 sql.append("SELECT "); 88 sql.append("* "); 89 sql.append("FROM BUSINESS_ENTITY e, BUSINESS_SERVICE s "); 90 sql.append("WHERE e.BUSINESS_KEY = s.BUSINESS_KEY "); 91 sql.append("AND s.SERVICE_KEY=? "); 92 sql.append("AND e.PUBLISHER_ID=?"); 93 verifyOwnershipSQL = sql.toString(); 94 } 95 96 103 public static void insert(BusinessService service,Connection connection) 104 throws java.sql.SQLException 105 { 106 PreparedStatement statement = null; 107 Timestamp timeStamp = new Timestamp (System.currentTimeMillis()); 108 109 try 110 { 111 statement = connection.prepareStatement(insertSQL); 112 statement.setString(1,service.getBusinessKey().toString()); 113 statement.setString(2,service.getServiceKey().toString()); 114 statement.setTimestamp(3,timeStamp); 115 116 log.debug("insert into BUSINESS_SERVICE table:\n\n\t" + insertSQL + 117 "\n\t BUSINESS_KEY=" + service.getBusinessKey().toString() + 118 "\n\t SERVICE_KEY=" + service.getServiceKey().toString() + 119 "\n\t LAST_UPDATE=" + timeStamp.getTime() + "\n"); 120 121 statement.executeUpdate(); 122 } 123 finally 124 { 125 try { statement.close(); } catch (Exception e) { } 126 } 127 } 128 129 136 public static void delete(String serviceKey,Connection connection) 137 throws java.sql.SQLException 138 { 139 PreparedStatement statement = null; 140 141 try 142 { 143 statement = connection.prepareStatement(deleteSQL); 145 statement.setString(1,serviceKey.toString()); 146 147 log.debug("delete from BUSINESS_SERVICE table:\n\n\t" + deleteSQL + 148 "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); 149 150 statement.executeUpdate(); 152 } 153 finally 154 { 155 try { statement.close(); } catch (Exception e) { } 156 } 157 } 158 159 166 public static BusinessService select(String serviceKey,Connection connection) 167 throws java.sql.SQLException 168 { 169 BusinessService service = null; 170 PreparedStatement statement = null; 171 ResultSet resultSet = null; 172 173 try 174 { 175 statement = connection.prepareStatement(selectSQL); 176 statement.setString(1,serviceKey.toString()); 177 178 log.debug("select from BUSINESS_SERVICE table:\n\n\t" + selectSQL + 179 "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); 180 181 resultSet = statement.executeQuery(); 182 if (resultSet.next()) 183 { 184 service = new BusinessService(); 185 service.setBusinessKey(resultSet.getString(1)); service.setServiceKey(serviceKey); 187 } 188 189 return service; 190 } 191 finally 192 { 193 try { resultSet.close(); } catch (Exception e) { } 194 try { statement.close(); } catch (Exception e) { } 195 } 196 } 197 198 206 public static void deleteByBusinessKey(String businessKey,Connection connection) 207 throws java.sql.SQLException 208 { 209 PreparedStatement statement = null; 210 211 try 212 { 213 statement = connection.prepareStatement(deleteByBusinessKeySQL); 215 statement.setString(1,businessKey.toString()); 216 217 log.debug("delet from the BUSINESS_SERVICE table:\n\n\t" + deleteByBusinessKeySQL + 218 "\n\t BUSINESS_KEY=" + businessKey.toString() + "\n"); 219 220 statement.executeUpdate(); 222 } 223 finally 224 { 225 try { statement.close(); } catch (Exception e) { } 226 } 227 } 228 229 237 public static Vector selectByBusinessKey(String businessKey,Connection connection) 238 throws java.sql.SQLException 239 { 240 Vector serviceList = new Vector (); 241 PreparedStatement statement = null; 242 ResultSet resultSet = null; 243 244 try 245 { 246 statement = connection.prepareStatement(selectByBusinessKeySQL); 248 statement.setString(1,businessKey.toString()); 249 250 log.debug("select from BUSINESS_SERVICE table:\n\n\t" + selectByBusinessKeySQL + 251 "\n\t BUSINESS_KEY=" + businessKey.toString() + "\n"); 252 253 resultSet = statement.executeQuery(); 255 while (resultSet.next()) 256 { 257 BusinessService service = new BusinessService(); 258 service.setBusinessKey(businessKey); 259 service.setServiceKey(resultSet.getString(1)); serviceList.add(service); 261 } 262 263 return serviceList; 264 } 265 finally 266 { 267 try { resultSet.close(); } catch (Exception e) { } 268 try { statement.close(); } catch (Exception e) { } 269 } 270 } 271 272 281 public static boolean verifyOwnership(String serviceKey,String publisherID,Connection connection) 282 throws java.sql.SQLException 283 { 284 if ((serviceKey == null) || (publisherID == null)) 285 return false; 286 287 boolean authorized = false; 288 PreparedStatement statement = null; 289 ResultSet resultSet = null; 290 291 try 292 { 293 statement = connection.prepareStatement(verifyOwnershipSQL); 294 statement.setString(1,serviceKey); 295 statement.setString(2,publisherID); 296 297 log.debug("checking ownership of BUSINESS_SERVICE:\n\n\t" + verifyOwnershipSQL + 298 "\n\t SERVICE_KEY=" + serviceKey + 299 "\n\t PUBLISHER_ID=" + publisherID + "\n"); 300 301 resultSet = statement.executeQuery(); 302 if (resultSet.next()) 303 authorized = true; 304 305 return authorized; 306 } 307 finally 308 { 309 try { resultSet.close(); } catch (Exception e) { } 310 try { statement.close(); } catch (Exception e) { } 311 } 312 } 313 } 314 | Popular Tags |