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.binding.AccessPoint; 27 import org.apache.juddi.datatype.binding.BindingTemplate; 28 import org.apache.juddi.datatype.binding.HostingRedirector; 29 30 33 class BindingTemplateTable 34 { 35 private static Log log = LogFactory.getLog(BindingTemplateTable.class); 37 38 static String insertSQL = null; 39 static String deleteSQL = null; 40 static String selectSQL = null; 41 static String selectByServiceKeySQL = null; 42 static String deleteByServiceKeySQL = null; 43 static String verifyOwnershipSQL = null; 44 45 static 46 { 47 StringBuffer sql = null; 49 50 sql = new StringBuffer (150); 52 sql.append("INSERT INTO BINDING_TEMPLATE ("); 53 sql.append("SERVICE_KEY,"); 54 sql.append("BINDING_KEY,"); 55 sql.append("ACCESS_POINT_TYPE,"); 56 sql.append("ACCESS_POINT_URL,"); 57 sql.append("HOSTING_REDIRECTOR,"); 58 sql.append("LAST_UPDATE) "); 59 sql.append("VALUES (?,?,?,?,?,?)"); 60 insertSQL = sql.toString(); 61 62 sql = new StringBuffer (100); 64 sql.append("DELETE FROM BINDING_TEMPLATE "); 65 sql.append("WHERE BINDING_KEY=?"); 66 deleteSQL = sql.toString(); 67 68 sql = new StringBuffer (200); 70 sql.append("SELECT "); 71 sql.append("SERVICE_KEY,"); 72 sql.append("ACCESS_POINT_TYPE,"); 73 sql.append("ACCESS_POINT_URL,"); 74 sql.append("HOSTING_REDIRECTOR "); 75 sql.append("FROM BINDING_TEMPLATE "); 76 sql.append("WHERE BINDING_KEY=?"); 77 selectSQL = sql.toString(); 78 79 sql = new StringBuffer (200); 81 sql.append("SELECT "); 82 sql.append("BINDING_KEY,"); 83 sql.append("ACCESS_POINT_TYPE,"); 84 sql.append("ACCESS_POINT_URL,"); 85 sql.append("HOSTING_REDIRECTOR "); 86 sql.append("FROM BINDING_TEMPLATE "); 87 sql.append("WHERE SERVICE_KEY=?"); 88 selectByServiceKeySQL = sql.toString(); 89 90 sql = new StringBuffer (100); 92 sql.append("DELETE FROM BINDING_TEMPLATE "); 93 sql.append("WHERE SERVICE_KEY=?"); 94 deleteByServiceKeySQL = sql.toString(); 95 96 sql = new StringBuffer (200); 98 sql.append("SELECT "); 99 sql.append("* "); 100 sql.append("FROM BUSINESS_ENTITY e, BUSINESS_SERVICE s, BINDING_TEMPLATE t "); 101 sql.append("WHERE s.SERVICE_KEY = t.SERVICE_KEY "); 102 sql.append("AND e.BUSINESS_KEY = s.BUSINESS_KEY "); 103 sql.append("AND t.BINDING_KEY=? "); 104 sql.append("AND e.PUBLISHER_ID=?"); 105 verifyOwnershipSQL = sql.toString(); 106 } 107 108 115 public static void insert(BindingTemplate binding,Connection connection) 116 throws java.sql.SQLException 117 { 118 PreparedStatement statement = null; 119 Timestamp timeStamp = new Timestamp (System.currentTimeMillis()); 120 121 try 122 { 123 String urlType = null; 125 String url = null; 126 AccessPoint accessPoint = binding.getAccessPoint(); 127 if (accessPoint != null) 128 { 129 urlType = accessPoint.getURLType(); 130 url = accessPoint.getURL(); 131 } 132 133 String redirectorKey = null; 135 HostingRedirector redirector = binding.getHostingRedirector(); 136 if (redirector != null) 137 { 138 if (redirector.getBindingKey() != null) 139 redirectorKey = redirector.getBindingKey(); 140 } 141 142 statement = connection.prepareStatement(insertSQL); 144 statement.setString(1,binding.getServiceKey().toString()); 145 statement.setString(2,binding.getBindingKey().toString()); 146 statement.setString(3,urlType); 147 statement.setString(4,url); 148 statement.setString(5,redirectorKey); 149 statement.setTimestamp(6,timeStamp); 150 151 log.debug("insert into BINDING_TEMPLATE table:\n\n\t" + insertSQL + 152 "\n\t SERVICE_KEY=" + binding.getServiceKey().toString() + 153 "\n\t BINDING_KEY=" + binding.getBindingKey().toString() + 154 "\n\t ACCESS_POINT_TYPE=" + urlType + 155 "\n\t ACCESS_POINT_URL=" + url + 156 "\n\t HOSTING_REDIRECTOR=" + redirectorKey + 157 "\n\t LAST_UPDATE=" + timeStamp.getTime() + "\n"); 158 159 statement.executeUpdate(); 160 } 161 finally 162 { 163 try { statement.close(); } catch (Exception e) { } 164 } 165 } 166 167 174 public static void delete(String bindingKey,Connection connection) 175 throws java.sql.SQLException 176 { 177 PreparedStatement statement = null; 178 179 try 180 { 181 statement = connection.prepareStatement(deleteSQL); 183 statement.setString(1,bindingKey); 184 185 log.debug("delete from BINDING_TEMPLATE table:\n\n\t" + deleteSQL + 186 "\n\t BINDING_KEY=" + bindingKey + "\n"); 187 188 statement.executeUpdate(); 190 } 191 finally 192 { 193 try { statement.close(); } catch (Exception e) { } 194 } 195 } 196 197 204 public static BindingTemplate select(String bindingKey,Connection connection) 205 throws java.sql.SQLException 206 { 207 BindingTemplate binding = null; 208 PreparedStatement statement = null; 209 ResultSet resultSet = null; 210 211 try 212 { 213 statement = connection.prepareStatement(selectSQL); 214 statement.setString(1,bindingKey.toString()); 215 216 log.debug("select from BINDING_TEMPLATE table:\n\n\t" + selectSQL + 217 "\n\t BINDING_KEY=" + bindingKey.toString() + "\n"); 218 219 resultSet = statement.executeQuery(); 220 if (resultSet.next()) 221 { 222 binding = new BindingTemplate(); 223 binding.setServiceKey(resultSet.getString(1)); binding.setBindingKey(bindingKey); 225 226 String urlType = resultSet.getString(2); String url = resultSet.getString(3); if ((urlType != null) && (url != null)) 229 binding.setAccessPoint(new AccessPoint(urlType,url)); 230 231 String redirectorKey = resultSet.getString(4); if (redirectorKey != null) 233 binding.setHostingRedirector(new HostingRedirector(redirectorKey)); 234 } 235 236 return binding; 237 } 238 finally 239 { 240 try { resultSet.close(); } catch (Exception e) { } 241 try { statement.close(); } catch (Exception e) { } 242 } 243 } 244 245 253 public static Vector selectByServiceKey(String serviceKey,Connection connection) 254 throws java.sql.SQLException 255 { 256 Vector bindList = new Vector (); 257 PreparedStatement statement = null; 258 ResultSet resultSet = null; 259 260 try 261 { 262 statement = connection.prepareStatement(selectByServiceKeySQL); 264 statement.setString(1,serviceKey.toString()); 265 266 log.debug("select from BINDING_TEMPLATE table:\n\n\t" + selectByServiceKeySQL + 267 "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); 268 269 resultSet = statement.executeQuery(); 271 272 BindingTemplate binding = null; 273 while (resultSet.next()) 274 { 275 binding = new BindingTemplate(); 276 binding.setServiceKey(serviceKey); 277 binding.setBindingKey(resultSet.getString(1)); 279 String urlType = resultSet.getString(2); String url = resultSet.getString(3); if ((urlType != null) && (url != null)) 282 binding.setAccessPoint(new AccessPoint(urlType,url)); 283 284 String redirectorKey = resultSet.getString(4); if (redirectorKey != null) 286 binding.setHostingRedirector(new HostingRedirector(redirectorKey)); 287 288 bindList.add(binding); 289 binding = null; 290 } 291 292 return bindList; 293 } 294 finally 295 { 296 try { resultSet.close(); } catch (Exception e) { } 297 try { statement.close(); } catch (Exception e) { } 298 } 299 } 300 301 309 public static void deleteByServiceKey(String serviceKey,Connection connection) 310 throws java.sql.SQLException 311 { 312 PreparedStatement statement = null; 313 314 try 315 { 316 statement = connection.prepareStatement(deleteByServiceKeySQL); 318 statement.setString(1,serviceKey.toString()); 319 320 log.debug("delete from BINDING_TEMPLATE table:\n\n\t" + deleteByServiceKeySQL + 321 "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); 322 323 int returnCode = statement.executeUpdate(); 325 326 log.info("delete was successful, rows deleted=" + returnCode); 327 } 328 finally 329 { 330 try { statement.close(); } catch (Exception e) { } 331 } 332 } 333 334 343 public static boolean verifyOwnership(String bindingKey,String publisherID,Connection connection) 344 throws java.sql.SQLException 345 { 346 if ((bindingKey == null) || (publisherID == null)) 347 return false; 348 349 boolean authorized = false; 350 PreparedStatement statement = null; 351 ResultSet resultSet = null; 352 353 try 354 { 355 statement = connection.prepareStatement(verifyOwnershipSQL); 356 statement.setString(1,bindingKey); 357 statement.setString(2,publisherID); 358 359 log.debug("checking ownership of BINDING_TEMPLATE:\n\n\t" + verifyOwnershipSQL + 360 "\n\t BINDNG_KEY=" + bindingKey + 361 "\n\t PUBLISHER_ID=" + publisherID + "\n"); 362 363 resultSet = statement.executeQuery(); 364 if (resultSet.next()) 365 authorized = true; 366 367 return authorized; 368 } 369 finally 370 { 371 try { resultSet.close(); } catch (Exception e) { } 372 try { statement.close(); } catch (Exception e) { } 373 } 374 } 375 } | Popular Tags |