View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/ebxmlrr/src/share/com/sun/ebxml/registry/persistence/rdb/EmailAddressDAO.java,v 1.14 2003/05/30 22:42:36 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.rim.*; 11 import org.oasis.ebxml.registry.bindings.rim.types.*; 12 13 import com.sun.ebxml.registry.*; 14 15 /*** 16 * Represents an email address 17 * 18 * @see <{User}> 19 * @author Farrukh S. Najmi 20 * @author Adrian Chong 21 */ 22 public class EmailAddressDAO { 23 protected EmailAddressDAO(){} 24 25 public static String getTableNameStatic() { 26 return "EmailAddress"; 27 } 28 29 public String getTableName() { 30 return getTableNameStatic(); 31 } 32 33 public void insert(java.sql.Connection connection, ArrayList users) throws RegistryException { 34 // System.err.println("Inserting " + emailAddresss.size() + " EmailAddresss"); 35 36 if (users.size()==0) { 37 return; 38 } 39 40 Statement stmt = null; 41 42 try { 43 Iterator usersIter = users.iterator(); 44 stmt = connection.createStatement(); 45 46 while (usersIter.hasNext()) { 47 User user = (User)usersIter.next(); 48 String parentId = user.getId(); 49 EmailAddress emailAddresss [] = user.getEmailAddress(); 50 51 // Iterator iter = emailAddresss.iterator(); 52 for(int i=0; i < emailAddresss.length; i++) { 53 54 //Log.print(Log.TRACE, 8, "\tDATABASE EVENT: storing EmailAddress " ); 55 56 String address = emailAddresss[i].getAddress(); 57 58 String type = emailAddresss[i].getType(); 59 if (type != null) { 60 type = "'" + type + "'"; 61 } 62 63 64 stmt.addBatch("INSERT INTO " + getTableName() + 65 " VALUES( " + 66 "'" + address + "', " + 67 type + ", " + 68 "'" + parentId + "' )"); 69 } 70 } 71 72 if (users.size() > 0) { 73 int [] updateCounts = stmt.executeBatch(); 74 //stmt.close(); 75 } 76 } 77 catch (java.sql.SQLException e) { 78 RegistryException exception = new RegistryException(e); 79 throw exception; 80 } finally { 81 try { 82 if (stmt != null) 83 stmt.close(); 84 } catch (SQLException sqle) { 85 sqle.printStackTrace(); 86 } 87 } 88 89 90 } 91 92 /*** 93 * Does a bulk insert of a Collection of objects that match the type for this persister. 94 * 95 */ 96 public void insert(java.sql.Connection connection, String parentId, ArrayList emailAddresss) throws RegistryException { 97 System.err.println("Inserting " + emailAddresss.size() + " EmailAddresss"); 98 99 if (emailAddresss.size()==0) { 100 return; 101 } 102 103 Statement stmt = null; 104 try { 105 stmt = connection.createStatement(); 106 107 Iterator iter = emailAddresss.iterator(); 108 while (iter.hasNext()) { 109 EmailAddressType emailAddress = (EmailAddressType)iter.next(); 110 111 //Log.print(Log.TRACE, 8, "\tDATABASE EVENT: storing EmailAddress " ); 112 113 String address = emailAddress.getAddress(); 114 115 String type = emailAddress.getType(); 116 if (type != null) { 117 type = "'" + type + "'"; 118 } 119 120 121 stmt.addBatch("INSERT INTO EmailAddress " + 122 "VALUES( " + 123 "'" + address + "', " + 124 type + ", " + 125 "'" + parentId + "' )"); 126 } 127 128 if (emailAddresss.size() > 0) { 129 int [] updateCounts = stmt.executeBatch(); 130 //stmt.close(); 131 } 132 } 133 catch (java.sql.SQLException e) { 134 RegistryException exception = new RegistryException(e); 135 throw exception; 136 } finally { 137 try { 138 if (stmt != null) 139 stmt.close(); 140 } catch (SQLException sqle) { 141 sqle.printStackTrace(); 142 } 143 } 144 } 145 146 /*** 147 * Does a bulk update of a Collection of objects that match the type for this persister. 148 * 149 */ 150 public void update(java.sql.Connection connection, String parentId, ArrayList emailAddresss) throws RegistryException { 151 System.err.println("Updating " + emailAddresss.size() + " EmailAddresss"); 152 153 Statement stmt = null; 154 try 155 { 156 stmt = connection.createStatement(); 157 158 Iterator iter = emailAddresss.iterator(); 159 while (iter.hasNext()) 160 { 161 EmailAddress emailAddress = (EmailAddress)iter.next(); 162 163 164 String address = emailAddress.getAddress(); 165 166 String type = emailAddress.getType(); 167 if (type != null) { 168 type = "'" + type + "'"; 169 } 170 171 stmt.addBatch("UPDATE EmailAddress SET " + 172 //"accesControlPolicy = null, " + 173 "SET address = '" + address + "', " + 174 "SET type = " + type + 175 " WHERE parent = '" + parentId + "' "); 176 } 177 178 int [] updateCounts = stmt.executeBatch(); 179 //stmt.close(); 180 } 181 catch (java.sql.SQLException e) { 182 RegistryException exception = new RegistryException(e); 183 throw exception; 184 } finally { 185 try { 186 if (stmt != null) 187 stmt.close(); 188 } catch (SQLException sqle) { 189 sqle.printStackTrace(); 190 } 191 } 192 } 193 194 /*** 195 * Does a bulk delete of a Collection of objects that match the type for this persister. 196 * 197 */ 198 public void delete(java.sql.Connection connection, ArrayList parentIds) throws RegistryException { 199 System.err.println("Deleting " + parentIds.size() + " EmailAddresss"); 200 Statement stmt = null; 201 202 try 203 { 204 stmt = connection.createStatement(); 205 206 Iterator iter = parentIds.iterator(); 207 while (iter.hasNext()) { 208 String parentId = (String)iter.next(); 209 210 211 stmt.addBatch("DELETE from EmailAddress WHERE parent = '" + 212 parentId + "' "); 213 } 214 215 int [] updateCounts = stmt.executeBatch(); 216 //stmt.close(); 217 } 218 catch (java.sql.SQLException e) { 219 RegistryException exception = new RegistryException(e); 220 throw exception; 221 } finally { 222 try { 223 if (stmt != null) 224 stmt.close(); 225 } catch (SQLException sqle) { 226 sqle.printStackTrace(); 227 } 228 } 229 } 230 231 public void loadObjectFromResultSet(java.sql.Connection conn, Object obj, ResultSet rs) throws RegistryException { 232 try { 233 if (!(obj instanceof org.oasis.ebxml.registry.bindings.rim.EmailAddressType)) { 234 throw new RegistryException("Unexpected object " + obj + ". Was expecting org.oasis.ebxml.registry.bindings.rim.EmailAddressType."); 235 } 236 237 EmailAddressType addr = (EmailAddressType)obj; 238 239 String address = rs.getString("address"); 240 addr.setAddress(address); 241 242 String type = rs.getString("type"); 243 addr.setType(type); 244 245 } 246 catch (SQLException e) { 247 e.printStackTrace(); 248 throw new RegistryException(e); 249 } 250 } 251 252 ArrayList getEmailAddressesByParent(java.sql.Connection conn, String parentId) throws RegistryException { 253 ArrayList emails = new ArrayList(); 254 Statement stmt = null; 255 256 try { 257 stmt = conn.createStatement(); 258 ResultSet rs = stmt.executeQuery("SELECT * FROM EmailAddress WHERE parent = '" + parentId + "'"); 259 260 while (rs.next()) { 261 EmailAddress email = new EmailAddress(); 262 loadObjectFromResultSet(conn, email, rs); 263 emails.add(email); 264 } 265 } 266 catch (SQLException e) { 267 e.printStackTrace(); 268 throw new RegistryException(e); 269 } finally { 270 try { 271 if (stmt != null) 272 stmt.close(); 273 } catch (SQLException sqle) { 274 sqle.printStackTrace(); 275 } 276 } 277 278 return emails; 279 } 280 }

This page was automatically generated by Maven