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 java.sql.ResultSet; 14 import java.sql.SQLException; 15 import java.sql.Statement; 16 import java.util.ArrayList; 17 import java.util.Iterator; 18 19 import org.oasis.ebxml.registry.bindings.query.ResponseOption; 20 import org.oasis.ebxml.registry.bindings.rim.ExternalLink; 21 import org.oasis.ebxml.registry.bindings.rim.User; 22 23 import com.sun.ebxml.registry.RegistryException; 24 import com.sun.ebxml.registry.lcm.InvalidURLsException; 25 import com.sun.ebxml.registry.lcm.ObjectsNotFoundException; 26 import com.sun.ebxml.registry.security.authorization.AuthorizationServiceImpl; 27 import com.sun.ebxml.registry.util.BindingUtility; 28 import com.sun.ebxml.registry.util.RegistryProperties; 29 import com.sun.ebxml.registry.util.Utility; 30 31 /*** 32 * 33 * @see <{RegistryEntry}> 34 * @author Farrukh S. Najmi 35 * @author Adrian Chong 36 */ 37 public class ExternalLinkDAO extends RegistryObjectDAO { 38 protected ExternalLinkDAO(){} 39 40 static BindingUtility bu = BindingUtility.getInstance(); 41 42 public static String getTableNameStatic() { 43 return "ExternalLink"; 44 } 45 46 public String getTableName() { 47 return getTableNameStatic(); 48 } 49 50 /*** 51 * Does a bulk insert of a Collection of objects that match the type for this persister. 52 * Throw InvalidURLsException if any ExternalLink pointing to any unresolvable Http URL. 53 * Those URLs with response code < 200 or > 299 are considered invalid. 54 */ 55 public void insert(User user, java.sql.Connection connection, ArrayList extLinks) throws RegistryException { 56 57 if (extLinks.size()==0) { 58 return; 59 } 60 61 String extLinkId = null; 62 Statement stmt = null; 63 try { 64 // Update the exisitng ExternalLink 65 extLinks = updateExistingObjects(user, connection , extLinks); 66 if (extLinks.size()==0) { 67 return; 68 } 69 70 System.err.println("Inserting " + extLinks.size() + " ExternalLinks"); 71 72 // check those ExternalLink with http url 73 String check = RegistryProperties.getInstance().getProperty("ebxmlrr.persistence.rdb.ExternalLinkDAO.checkURLs"); 74 75 if (check.equalsIgnoreCase("true")) { 76 ArrayList invalidExtLinks = Utility.getInstance() 77 .validateURIs(extLinks); 78 if (invalidExtLinks.size() > 0) { 79 throw new InvalidURLsException(invalidExtLinks); 80 } 81 } 82 83 stmt = connection.createStatement(); 84 85 Iterator iter = extLinks.iterator(); 86 while (iter.hasNext()) { 87 ExternalLink extLink = (ExternalLink)iter.next(); 88 extLinkId = extLink.getId(); 89 //Log.print(Log.TRACE, 8, "\tDATABASE EVENT: storing ExternalLink " ); 90 91 String extURI = extLink.getExternalURI(); 92 93 String str = "INSERT INTO ExternalLink " + 94 "VALUES(null, " + //AccessControlPolicy 95 "'" + extLink.getId() + "', " + 96 "'ExternalLink', " + 97 "'" + extURI + "' )"; 98 99 System.err.println("stmt = " + str); 100 stmt.addBatch(str); 101 } 102 103 if (extLinks.size() > 0) { 104 int [] updateCounts = stmt.executeBatch(); 105 //stmt.close(); 106 super.insert(user, connection, extLinks); 107 // Now generate the AE for inserting ExternalLink 108 generateAuditbleEvent(connection, extLinks, "Created", user); 109 } 110 } 111 catch (java.sql.SQLException e) { 112 e.printStackTrace(); 113 RegistryException exception = new RegistryException(e); 114 throw exception; 115 } finally { 116 try { 117 if (stmt != null) 118 stmt.close(); 119 } catch (SQLException sqle) { 120 sqle.printStackTrace(); 121 } 122 } 123 } 124 125 public void update(User user, java.sql.Connection connection 126 , ArrayList extLinks) throws RegistryException { 127 /* 128 We do not need to check whether the user is authorized to update because the authorization is expected to be checked by higher level. 129 Should we move the authorization to persistance layer?????? 130 */ 131 update(user, connection, extLinks, true, false); 132 133 } 134 135 public void update(User user, java.sql.Connection connection, ArrayList extLinks, 136 boolean checkExistence, boolean checkAuthorization) throws RegistryException { 137 if (extLinks.size()==0) { 138 return; 139 } 140 System.err.println("Updating " + extLinks.size() + " ExternalLinks"); 141 String extLinkId = null; 142 Statement stmt = null; 143 try { 144 // Check whether the user can update the objects 145 if (checkAuthorization) { 146 AuthorizationServiceImpl authorization = AuthorizationServiceImpl.getInstance(); 147 authorization.checkAuthorization(user, bu.getIdsFromRegistryObjects(extLinks), AuthorizationServiceImpl.UPDATE_OBJECTS_REQUEST); 148 } 149 // check those ExternalLink with http url 150 String check = RegistryProperties.getInstance().getProperty("ebxmlrr.persistence.rdb.ExternalLinkDAO.checkURLs"); 151 if (check.equalsIgnoreCase("true")) { 152 ArrayList invalidExtLinks = Utility.getInstance() 153 .validateURIs(extLinks); 154 if (invalidExtLinks.size() > 0) { 155 throw new InvalidURLsException(invalidExtLinks); 156 } 157 } 158 159 stmt = connection.createStatement(); 160 161 Iterator iter = extLinks.iterator(); 162 while (iter.hasNext()) { 163 ExternalLink extLink = (ExternalLink)iter.next(); 164 extLinkId = extLink.getId(); 165 //Log.print(Log.TRACE, 8, "\tDATABASE EVENT: updating ExternalLink " ); 166 167 // checking whether it exists 168 if (checkExistence && !registryObjectExist(connection, extLinkId, getTableName())) { 169 ArrayList idList = new ArrayList(); 170 idList.add(extLinkId); 171 throw new ObjectsNotFoundException(idList); 172 } 173 174 String extURI = extLink.getExternalURI(); 175 176 String str = "UPDATE " + getTableName() + 177 " SET accessControlPolicy=null" + 178 ", externalURI='" + extURI + "'" + 179 " WHERE id='" + extLinkId + "'"; 180 181 System.err.println("stmt = " + str); 182 stmt.addBatch(str); 183 } 184 if (extLinks.size() > 0) { 185 int [] updateCounts = stmt.executeBatch(); 186 //stmt.close(); 187 // Updated composed Name, Descrption, Slot, ExternalIdentifier and Classification 188 super.update(user, connection, extLinks); 189 // Now generate the AE for inserting ExternalLink 190 generateAuditbleEvent(connection, extLinks, "Updated", user); 191 } 192 193 } 194 catch (java.sql.SQLException e) { 195 e.printStackTrace(); 196 RegistryException exception = new RegistryException(e); 197 throw exception; 198 } finally { 199 try { 200 if (stmt != null) 201 stmt.close(); 202 } catch (SQLException sqle) { 203 sqle.printStackTrace(); 204 } 205 } 206 } 207 208 public void loadObjectFromResultSet(java.sql.Connection conn, Object obj, ResultSet rs, ResponseOption responseOption, ArrayList objectRefs) throws RegistryException { 209 try { 210 if (!(obj instanceof org.oasis.ebxml.registry.bindings.rim.ExternalLink)) { 211 throw new RegistryException("Unexpected object " + obj + ". Was expecting org.oasis.ebxml.registry.bindings.rim.ExternalLink."); 212 } 213 214 ExternalLink el = (ExternalLink)obj; 215 super.loadObjectFromResultSet(conn, obj, rs, responseOption, objectRefs); 216 217 String externalURI = rs.getString("externalURI"); 218 el.setExternalURI(externalURI); 219 } 220 catch (SQLException e) { 221 e.printStackTrace(); 222 throw new RegistryException(e); 223 } 224 } 225 226 public ArrayList getLeafObjectList(java.sql.Connection conn, ResultSet rs, ResponseOption responseOption, ArrayList objectRefs) throws RegistryException { 227 ArrayList res = new ArrayList(); 228 229 try { 230 while(rs.next()) { 231 ExternalLink obj = new ExternalLink(); 232 loadObjectFromResultSet(conn, obj, rs, responseOption, objectRefs); 233 234 res.add(obj); 235 } 236 } 237 catch (SQLException e) { 238 e.printStackTrace(); 239 throw new RegistryException(e); 240 } 241 242 243 return res; 244 } 245 } 246

This page was automatically generated by Maven