View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/ebxmlrr/src/share/com/sun/ebxml/registry/persistence/rdb/RegistryEntryDAO.java,v 1.15 2003/05/30 22:42:37 waikei Exp $ 3 */ 4 5 package com.sun.ebxml.registry.persistence.rdb; 6 7 import java.util.*; 8 import java.sql.*; 9 10 import org.oasis.ebxml.registry.bindings.rs.RegistryError; 11 import org.oasis.ebxml.registry.bindings.rs.RegistryErrorList; 12 import org.oasis.ebxml.registry.bindings.rs.types.ErrorType; 13 import org.oasis.ebxml.registry.bindings.rim.*; 14 import org.oasis.ebxml.registry.bindings.rim.types.*; 15 import org.oasis.ebxml.registry.bindings.query.*; 16 import org.oasis.ebxml.registry.bindings.query.types.*; 17 18 import com.sun.ebxml.registry.*; 19 import com.sun.ebxml.registry.lcm.*; 20 21 /*** 22 * 23 * @author Farrukh S. Najmi 24 */ 25 public class RegistryEntryDAO extends RegistryObjectDAO { 26 27 public static String getTableNameStatic() { 28 return "RegistryEntry"; 29 } 30 31 public String getTableName() { 32 return getTableNameStatic(); 33 } 34 35 /*** 36 * Update the status of specified objects (homogenous collection) to the specified status. 37 * @param statusUnchanged if an id in registryObjectIds is in this ArrayList, no AuditableEvent 38 * generated for that RegistryEntry 39 */ 40 public void updateStatus(User user, java.sql.Connection connection, ArrayList registryObjectIds 41 , StatusType status, ArrayList statusUnchanged) throws RegistryException { 42 43 Statement stmt = null; 44 if (registryObjectIds.size()==0) { 45 return; 46 } 47 try 48 { 49 stmt = connection.createStatement(); 50 51 String str = "UPDATE " + getTableName() + 52 " SET status = '" + status + "' WHERE id IN ( "; 53 54 Iterator iter = registryObjectIds.iterator(); 55 while (iter.hasNext()) 56 { 57 String id = (String)iter.next(); 58 // Generate AuditableEvents 59 RegistryObject ro = new RegistryObject(); 60 ro.setId(id); 61 if (status.getType() == StatusType.APPROVED.getType()) { 62 /*It is incorrect! We should generate Approved event. 63 But EventTypeType.valueOf("Approved") throws IllegalArgumentException 64 */ 65 if (!statusUnchanged.contains(id)) { 66 generateAuditbleEvent(connection, ro, "Updated", user); 67 } 68 } 69 else if (status.getType() == StatusType.DEPRECATED.getType()) { 70 if (!statusUnchanged.contains(id)) { 71 generateAuditbleEvent(connection, ro, "Deprecated", user); 72 } 73 } 74 if (iter.hasNext()) { 75 str += "'" + id + "', "; 76 } 77 else { 78 str += "'" + id + "' ) "; 79 } 80 } 81 82 System.err.println("stmt = " + str); 83 stmt.execute(str); 84 //stmt.close(); 85 } 86 catch (java.sql.SQLException e) { 87 RegistryException exception = new RegistryException(e); 88 throw exception; 89 } finally { 90 try { 91 if (stmt != null) 92 stmt.close(); 93 } catch (SQLException sqle) { 94 sqle.printStackTrace(); 95 } 96 } 97 } 98 99 /*** 100 @param idStatus The HashMap storing id String as key and Status String as value 101 @param objectTypeIds The HashMap storing objectType as key and ArrayList of Id as value. 102 All the objectType in database not ClassificationScheme or RegistryPackage the 103 key is stored as "ExtrinsicObject" 104 */ 105 private void getIdStatusAndObjectTypeIdsMap(java.sql.Connection connection, ArrayList ids 106 , HashMap idStatus, HashMap objectTypeIds) throws RegistryException { 107 if (ids.size()==0) { 108 return; 109 } 110 ArrayList classSchemesIds = new ArrayList(); 111 ArrayList pkgsIds = new ArrayList(); 112 ArrayList extObjectsIds = new ArrayList(); 113 Statement stmt = null; 114 try { 115 stmt = connection.createStatement(); 116 String sql = "SELECT id, objectType, status FROM RegistryEntry WHERE id IN ("; 117 Iterator idsIter = ids.iterator(); 118 while (idsIter.hasNext()) { 119 String id = (String)idsIter.next(); 120 if (idsIter.hasNext()) { 121 sql += "'" + id + "', "; 122 } 123 else { 124 sql += "'" + id + "' ) "; 125 } 126 } 127 ResultSet rs = stmt.executeQuery(sql); 128 String id = null; 129 String objectType = null; 130 String status = null; 131 while(rs.next()) { 132 id = rs.getString("id"); 133 objectType = rs.getString("objectType"); 134 status = rs.getString("status"); 135 idStatus.put(id, status); 136 if (objectType.equalsIgnoreCase("ClassificationScheme")) { 137 classSchemesIds.add(id); 138 } 139 else if (objectType.equalsIgnoreCase("RegistryPackage")) { 140 pkgsIds.add(id); 141 } 142 else { 143 // All the remaining objectType are considered as ExtrinsicObject 144 extObjectsIds.add(id); 145 } 146 } // end looping the ResultSet 147 if (classSchemesIds.size() > 0) { 148 objectTypeIds.put("ClassificationScheme", classSchemesIds); 149 } 150 if (pkgsIds.size() > 0) { 151 objectTypeIds.put("RegistryPackage", pkgsIds); 152 } 153 if (extObjectsIds.size() > 0) { 154 objectTypeIds.put("ExtrinsicObject", extObjectsIds); 155 } 156 } 157 catch(SQLException e) { 158 RegistryException exception = new RegistryException(e); 159 throw exception; 160 } finally { 161 try { 162 if (stmt != null) 163 stmt.close(); 164 } catch (SQLException sqle) { 165 sqle.printStackTrace(); 166 } 167 } 168 169 } 170 171 /*** 172 * Update the status of specified objects (heterogeneous collection) to the specified status. 173 * 174 */ 175 public void updateStatusForHeterogeneousObjects(User user, java.sql.Connection connection, ArrayList registryObjectsIds 176 , org.oasis.ebxml.registry.bindings.rim.types.StatusType status, RegistryErrorList el) throws RegistryException { 177 178 if (registryObjectsIds.size() > 0) { 179 180 HashMap idStatus = new HashMap(); 181 HashMap objectTypeIds = new HashMap(); 182 getIdStatusAndObjectTypeIdsMap(connection, registryObjectsIds, idStatus, objectTypeIds); 183 184 Iterator idsIter = registryObjectsIds.iterator(); 185 // Storing the id of RE whose status kept unchanged 186 ArrayList statusUnchanged = new ArrayList(); 187 while(idsIter.hasNext()) { 188 String id = (String)idsIter.next(); 189 if (!idStatus.containsKey(id)) { 190 // Either object not exist or the object not a RE 191 if (registryObjectExist(connection, id)) { 192 throw new NonRegistryEntryFoundException(id); 193 } 194 else { 195 ArrayList notExistIds = new ArrayList(); 196 notExistIds.add(id); 197 // Should we make ObjectNotFoundException later??? 198 throw new ObjectsNotFoundException(notExistIds); 199 } 200 } 201 202 String oldStatus = (String) idStatus.get(id); 203 if (oldStatus != null) { 204 if (StatusType.valueOf(oldStatus).getType() == status.getType()) { 205 // we are going to approve/deprecated a RE already approved/deprecated 206 statusUnchanged.add(id); 207 RegistryError re = new RegistryError(); 208 re.setSeverity(ErrorType.WARNING); 209 re.setErrorCode("unknown"); 210 if (status.getType()==StatusType.APPROVED.getType()) { 211 re.setContent("The RegistryEntry " + id + " has been already approved"); 212 re.setCodeContext("LifeCycleManagerImpl.approveObjects"); 213 } 214 if (status.getType()==StatusType.DEPRECATED.getType()) { 215 re.setContent("The RegistryEntry " + id + " has been already deprecated"); 216 re.setCodeContext("LifeCycleManagerImpl.deprecateObjects"); 217 } 218 el.addRegistryError(re); 219 } 220 } 221 } // end looping all the ids 222 223 Iterator objectTypesIter = objectTypeIds.keySet().iterator(); 224 while(objectTypesIter.hasNext()) { 225 String objectType = (String)objectTypesIter.next(); 226 if (objectType.equalsIgnoreCase("ClassificationScheme")) { 227 ClassificationSchemeDAO classificationSchemeDAO = new ClassificationSchemeDAO(); 228 classificationSchemeDAO.updateStatus(user, connection, (ArrayList)(objectTypeIds.get(objectType)), status, statusUnchanged); 229 } 230 else if (objectType.equalsIgnoreCase("ExtrinsicObject")) { 231 ExtrinsicObjectDAO extrinsicObjectDAO = new ExtrinsicObjectDAO(); 232 extrinsicObjectDAO.updateStatus(user, connection, (ArrayList)(objectTypeIds.get(objectType)), status, statusUnchanged); 233 } 234 else if (objectType.equalsIgnoreCase("RegistryPackage")) { 235 RegistryPackageDAO registryPackageDAO = new RegistryPackageDAO(); 236 registryPackageDAO.updateStatus(user, connection, (ArrayList)(objectTypeIds.get(objectType)), status, statusUnchanged); 237 } 238 else { 239 throw new RegistryException("Unexpected objectType " + objectType); 240 } 241 } // end looping all objectTypes 242 } 243 } 244 245 ArrayList getRegistryEntryList(java.sql.Connection conn, ResultSet rs, ResponseOption responseOption) throws RegistryException { 246 ArrayList res = new ArrayList(); 247 248 try { 249 while(rs.next()) { 250 RegistryEntry re = new RegistryEntry(); 251 loadObjectFromResultSet(conn, re, rs, responseOption, new ArrayList()); 252 253 res.add(re); 254 } 255 } 256 catch (SQLException e) { 257 e.printStackTrace(); 258 throw new RegistryException(e); 259 } 260 261 return res; 262 } 263 264 public void loadObjectFromResultSet(java.sql.Connection conn, Object obj, ResultSet rs, ResponseOption responseOption, ArrayList objectRefs) throws RegistryException { 265 try { 266 if (!(obj instanceof org.oasis.ebxml.registry.bindings.rim.RegistryEntryType)) { 267 throw new RegistryException("Unexpected object " + obj + ". Was expecting org.oasis.ebxml.registry.bindings.rim.RegistryEntryType."); 268 } 269 270 RegistryEntryType re = (RegistryEntryType)obj; 271 272 super.loadObjectFromResultSet(conn, re, rs, responseOption, objectRefs); 273 274 java.sql.Timestamp expiration = null; 275 276 //Need to work around a bug in PostgreSQL and loading of ClassificationScheme data from NIST tests 277 try { 278 rs.getTimestamp("expiration"); 279 re.setExpiration(expiration); 280 } 281 catch (StringIndexOutOfBoundsException e) { 282 e.printStackTrace(); 283 String id = rs.getString("id"); 284 System.err.println("RegistryEntry id = '" + id + "'"); 285 } 286 287 int majorVersion = rs.getInt("majorVersion"); 288 re.setMajorVersion(majorVersion); 289 290 int minorVersion = rs.getInt("minorVersion"); 291 re.setMinorVersion(minorVersion); 292 293 String stabilityStr = rs.getString("stability"); 294 if (stabilityStr != null) { 295 re.setStability(StabilityType.valueOf(stabilityStr)); 296 } 297 298 String statusStr = rs.getString("status"); 299 re.setStatus(StatusType.valueOf(statusStr)); 300 301 String userVersion = rs.getString("userVersion"); 302 re.setUserVersion(userVersion); 303 } 304 catch (SQLException e) { 305 e.printStackTrace(); 306 throw new RegistryException(e); 307 } 308 } 309 }

This page was automatically generated by Maven