View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2001 - 2003 freebxml.org. All rights reserved. 7 * 8 * ==================================================================== 9 */ 10 11 package com.sun.ebxml.registry.persistence.rdb; 12 13 import com.sun.ebxml.registry.RegistryException; 14 15 import java.sql.Connection; 16 import java.sql.SQLException; 17 import java.util.ArrayList; 18 import org.oasis.ebxml.registry.bindings.rim.Slot; 19 import org.oasis.ebxml.registry.bindings.rim.SpecificationLink; 20 import org.oasis.ebxml.registry.bindings.rim.User; 21 22 /*** 23 * Represents a link or reference to a technical specification used within a SpecificationLinkBinding. 24 * It serves the same purpose as the union of tModelInstanceInfo and instanceDetails in 25 * UDDI. 26 * 27 * <p><DL><DT><B>Capability Level: 0 </B><DD>This interface is required to be implemented by JAXR Providers at or above capability level 0.</DL> 28 * 29 * @see <{Concept}> 30 * @author Farrukh S. Najmi 31 */ 32 public class SpecificationLinkDAO extends RegistryObjectDAO { 33 protected SpecificationLinkDAO(){} 34 35 public static String getTableNameStatic() { 36 return "SpecificationLink"; 37 } 38 39 public String getTableName() { 40 return getTableNameStatic(); 41 } 42 43 /*** 44 * Does a bulk insert of a Collection of objects that match the type for this persister. 45 * 46 */ 47 public void insert(User user, Connection connection, ArrayList specLinks) throws RegistryException { 48 49 if(specLinks.size()==0) { 50 return; 51 } 52 53 String specLinkId = null; 54 java.sql.Statement stmt = null; 55 try { 56 57 //Version 2.1 is missing serviceBinding attribute on SPecificationLink 58 59 stmt = connection.createStatement(); 60 61 java.util.Iterator iter = specLinks.iterator(); 62 UsageDescriptionDAO usageDescriptionDAO = new UsageDescriptionDAO(); 63 UsageParameterDAO usageParameterDAO = new UsageParameterDAO(); 64 while (iter.hasNext()) { 65 SpecificationLink specLink = (SpecificationLink)iter.next(); 66 67 //Using special slots to pass the service and binding ids. 68 String serviceId = null; 69 String serviceBindingId = null; 70 Slot[] slots = specLink.getSlot(); 71 Slot serviceSlot = null; 72 Slot bindingSlot = null; 73 for (int i=0; i< slots.length; i++) { 74 Slot slot = slots[i]; 75 String name = slot.getName(); 76 77 if (name.equals("urn:ebxmlrr:SpecificationLink:service")) { 78 serviceSlot = slot; 79 org.oasis.ebxml.registry.bindings.rim.ValueList values = slot.getValueList(); 80 org.oasis.ebxml.registry.bindings.rim.ValueListTypeItem item = values.getValueListTypeItem(0); 81 serviceId = item.getValue(); 82 } 83 else if (name.equals("urn:ebxmlrr:SpecificationLink:serviceBinding")) { 84 bindingSlot = slot; 85 org.oasis.ebxml.registry.bindings.rim.ValueList values = slot.getValueList(); 86 org.oasis.ebxml.registry.bindings.rim.ValueListTypeItem item = values.getValueListTypeItem(0); 87 serviceBindingId = item.getValue(); 88 } 89 90 specLink.removeSlot(serviceSlot); 91 specLink.removeSlot(bindingSlot); 92 } 93 94 95 specLinkId = specLink.getId(); 96 97 String specificationObjectId = com.sun.ebxml.registry.util.BindingUtility.getInstance().getObjectId(specLink.getSpecificationObject()); 98 99 String str = "INSERT INTO SpecificationLink " + 100 "VALUES(null, " + //AccessControlPolicy 101 "'" + specLinkId + "', " + 102 "'SpecificationLink', " + // objectType 103 "'" + serviceId + "', " + 104 "'" + serviceBindingId + "', " + 105 "'" + specificationObjectId + "' ) "; 106 107 stmt.addBatch(str); 108 109 //insert the UsageParameters 110 String[] usageParams = specLink.getUsageParameter(); 111 ArrayList usageParamsAL = new ArrayList(); 112 for (int i=0; i<usageParams.length; i++) { 113 usageParamsAL.add(usageParams[i]); 114 } 115 if (usageParamsAL.size() > 0) { 116 usageParameterDAO.insert(connection, specLinkId, usageParamsAL); 117 } 118 119 //Process UsageDescription atribute 120 org.oasis.ebxml.registry.bindings.rim.InternationalStringType desc = specLink.getUsageDescription(); 121 122 if (desc != null) { 123 usageDescriptionDAO.insert(user, connection, specLinkId, desc); 124 } 125 126 } 127 128 if (specLinks.size() > 0) { 129 int [] updateCounts = stmt.executeBatch(); 130 //stmt.close(); 131 super.insert(user, connection, specLinks); 132 // Now generate the AE for inserting SpecificationLink 133 generateAuditbleEvent(connection, specLinks, "Created", user); 134 } 135 } 136 catch (SQLException e) { 137 e.printStackTrace(); 138 // It is trying to find out whether the SQLException is because 139 // the SpecificationLink already exist 140 if (specLinkId != null && registryObjectExist(connection, specLinkId)) { 141 throw new com.sun.ebxml.registry.lcm.RegistryObjectExistsException(specLinkId); 142 } 143 RegistryException exception = new RegistryException(e); 144 throw exception; 145 } finally { 146 try { 147 if (stmt != null) 148 stmt.close(); 149 } catch (SQLException sqle) { 150 sqle.printStackTrace(); 151 } 152 } 153 } 154 155 public void update(User user, Connection connection, ArrayList specLinks) throws RegistryException { 156 /* 157 * We do not need to check whether the user is authorized to update because the authorization is expected to be checked by higher level. 158 * Should we move the authorization to persistance layer?????? 159 */ 160 update(user, connection, specLinks, true, false); 161 } 162 163 public void update(User user, Connection connection, ArrayList specLinks, boolean checkExistence, boolean checkAuthorization) throws RegistryException { 164 String specLinkId = null; 165 java.sql.Statement stmt = null; 166 try { 167 stmt = connection.createStatement(); 168 169 java.util.Iterator iter = specLinks.iterator(); 170 //UsageDescriptionDAO usageDescriptionDAO = new UsageDescriptionDAO(); 171 //UsageParameterDAO usageParameterDAO = new UsageParameterDAO(); 172 while (iter.hasNext()) { 173 SpecificationLink specLink = (SpecificationLink)iter.next(); 174 175 //Using special slots to pass the service and binding ids. 176 String serviceId = null; 177 String serviceBindingId = null; 178 Slot[] slots = specLink.getSlot(); 179 Slot serviceSlot = null; 180 Slot bindingSlot = null; 181 for (int i=0; i< slots.length; i++) { 182 Slot slot = slots[i]; 183 String name = slot.getName(); 184 185 if (name.equals("urn:ebxmlrr:SpecificationLink:service")) { 186 serviceSlot = slot; 187 org.oasis.ebxml.registry.bindings.rim.ValueList values = slot.getValueList(); 188 org.oasis.ebxml.registry.bindings.rim.ValueListTypeItem item = values.getValueListTypeItem(0); 189 serviceId = item.getValue(); 190 } 191 else if (name.equals("urn:ebxmlrr:SpecificationLink:serviceBinding")) { 192 bindingSlot = slot; 193 org.oasis.ebxml.registry.bindings.rim.ValueList values = slot.getValueList(); 194 org.oasis.ebxml.registry.bindings.rim.ValueListTypeItem item = values.getValueListTypeItem(0); 195 serviceBindingId = item.getValue(); 196 } 197 198 specLink.removeSlot(serviceSlot); 199 specLink.removeSlot(bindingSlot); 200 } 201 202 specLinkId = specLink.getId(); 203 204 // checking whether it exists 205 if (!registryObjectExist(connection, specLinkId, getTableName())) { 206 ArrayList idList = new ArrayList(); 207 idList.add(specLinkId); 208 throw new com.sun.ebxml.registry.lcm.ObjectsNotFoundException(idList); 209 } 210 211 String specificationObjectId = com.sun.ebxml.registry.util.BindingUtility.getInstance().getObjectId(specLink.getSpecificationObject()); 212 213 String str = "UPDATE " + getTableName() + 214 " SET accessControlPolicy=null" + 215 ", service='" + serviceId + "'" + 216 ", serviceBinding='" + serviceBindingId + "'" + 217 ", specificationObject='" + specificationObjectId + "'" + 218 " WHERE id='" + specLinkId + "'"; 219 220 stmt.addBatch(str); 221 222 // Now generate the AE for inserting SpecificationLink 223 generateAuditbleEvent(connection, specLink, "Updated", user); 224 225 //insert the UsageParameters 226 String[] usageParams = specLink.getUsageParameter(); 227 ArrayList usageParamsAL = new ArrayList(); 228 for (int i=0; i<usageParams.length; i++) { 229 usageParamsAL.add(usageParams[i]); 230 } 231 if (usageParamsAL.size() > 0) { 232 // update usageParameters here???? 233 } 234 235 //Process UsageDescription atribute 236 org.oasis.ebxml.registry.bindings.rim.InternationalStringType desc = specLink.getUsageDescription(); 237 238 if (desc != null) { 239 // update usageDescription here???? 240 } 241 242 } // end looping specLinks 243 if (specLinks.size() > 0) { 244 int [] updateCounts = stmt.executeBatch(); 245 // Updated composed Name, Descrption, Slot, ExternalIdentifier and Classification 246 super.update(user, connection, specLinks); 247 } 248 } 249 catch (SQLException e) { 250 e.printStackTrace(); 251 RegistryException exception = new RegistryException(e); 252 throw exception; 253 } finally { 254 try { 255 if (stmt != null) 256 stmt.close(); 257 } catch (SQLException sqle) { 258 sqle.printStackTrace(); 259 } 260 } 261 } 262 /*** 263 * Does a bulk delete of a Collection of objects that match the type for this persister. 264 * 265 */ 266 public void delete(User user, Connection connection, ArrayList registryObjectIds) throws RegistryException { 267 super.delete(user, connection, registryObjectIds); 268 269 //Delete description atribute for the specified objects 270 UsageDescriptionDAO usageDescriptionDAO = new UsageDescriptionDAO(); 271 usageDescriptionDAO.deleteByParentIds(connection, registryObjectIds); 272 UsageParameterDAO usageParameterDAO = new UsageParameterDAO(); 273 usageParameterDAO.delete(connection, registryObjectIds); 274 } 275 276 /*** 277 * Does a bulk delete of objects for specified parentIds 278 * 279 */ 280 public void deleteByParentIds(User user, Connection connection, ArrayList parentIds) throws RegistryException { 281 java.sql.Statement stmt = null; 282 try { 283 stmt = connection.createStatement(); 284 java.sql.ResultSet rs = null; 285 286 ArrayList ids = new ArrayList(); 287 288 java.util.Iterator iter = parentIds.iterator(); 289 while (iter.hasNext()) { 290 String parentId = (String)iter.next(); 291 292 rs = stmt.executeQuery("SELECT id from " + getTableName() + " WHERE serviceBinding = '" + 293 parentId + "' "); 294 295 while (rs.next()) { 296 String id = rs.getString(1); 297 ids.add(id); 298 } 299 } 300 301 if (ids.size() > 0) { 302 delete(user, connection, ids); 303 } 304 //stmt.close(); 305 } 306 catch (SQLException e) { 307 RegistryException exception = new RegistryException(e); 308 throw exception; 309 } finally { 310 try { 311 if (stmt != null) 312 stmt.close(); 313 } catch (SQLException sqle) { 314 sqle.printStackTrace(); 315 } 316 } 317 } 318 319 /*** 320 * Gets objects for specified parentIds 321 * 322 */ 323 public ArrayList getByParentId(Connection connection, String parentId, ArrayList objectRefs) throws RegistryException { 324 ArrayList specLinks = new ArrayList(); 325 java.sql.Statement stmt = null; 326 try { 327 stmt = connection.createStatement(); 328 java.sql.ResultSet rs = null; 329 330 331 rs = stmt.executeQuery("SELECT * from " + getTableName() + " WHERE serviceBinding = '" + 332 parentId + "' "); 333 334 while (rs.next()) { 335 SpecificationLink obj = new SpecificationLink(); 336 337 org.oasis.ebxml.registry.bindings.query.ResponseOption responseOption = new org.oasis.ebxml.registry.bindings.query.ResponseOption(); 338 339 responseOption.setReturnComposedObjects(true); 340 loadObjectFromResultSet(connection, obj, rs, responseOption, objectRefs); 341 specLinks.add(obj); 342 } 343 } 344 catch (SQLException e) { 345 throw new RegistryException(e); 346 } finally { 347 try { 348 if (stmt != null) 349 stmt.close(); 350 } catch (SQLException sqle) { 351 sqle.printStackTrace(); 352 } 353 } 354 355 return specLinks; 356 } 357 358 public void loadObjectFromResultSet(Connection conn, Object obj, java.sql.ResultSet rs, org.oasis.ebxml.registry.bindings.query.ResponseOption responseOption, ArrayList objectRefs) throws RegistryException { 359 if (!(obj instanceof SpecificationLink)) { 360 throw new RegistryException("Unexpected object " + obj + ". Was expecting org.oasis.ebxml.registry.bindings.rim.SpecificationLink."); 361 } 362 363 SpecificationLink specLink = (SpecificationLink)obj; 364 365 super.loadObjectFromResultSet(conn, specLink, rs, responseOption, objectRefs); 366 367 try { 368 String specificationObjectId = rs.getString("specificationObject"); 369 org.oasis.ebxml.registry.bindings.rim.ObjectRef or = new org.oasis.ebxml.registry.bindings.rim.ObjectRef(); 370 or.setId(specificationObjectId); 371 specLink.setSpecificationObject(or); 372 } 373 catch (SQLException e) { 374 e.printStackTrace(); 375 throw new RegistryException(e); 376 } 377 } 378 379 public ArrayList getLeafObjectList(Connection conn, java.sql.ResultSet rs, org.oasis.ebxml.registry.bindings.query.ResponseOption responseOption, ArrayList objectRefs) throws RegistryException { 380 ArrayList res = new ArrayList(); 381 382 try { 383 while(rs.next()) { 384 SpecificationLink obj = new SpecificationLink(); 385 loadObjectFromResultSet(conn, obj, rs, responseOption, objectRefs); 386 387 res.add(obj); 388 } 389 } 390 catch (SQLException e) { 391 e.printStackTrace(); 392 throw new RegistryException(e); 393 } 394 395 396 return res; 397 } 398 }

This page was automatically generated by Maven