1 package org.apache.jetspeed.om.apps.email; 2 3 4 import java.math.BigDecimal ; 5 import java.sql.Connection ; 6 import java.util.ArrayList ; 7 import java.util.Collections ; 8 import java.util.Date ; 9 import java.util.List ; 10 11 import org.apache.commons.lang.ObjectUtils; 12 import org.apache.torque.TorqueException; 13 import org.apache.torque.om.BaseObject; 14 import org.apache.torque.om.ComboKey; 15 import org.apache.torque.om.DateKey; 16 import org.apache.torque.om.NumberKey; 17 import org.apache.torque.om.ObjectKey; 18 import org.apache.torque.om.SimpleKey; 19 import org.apache.torque.om.StringKey; 20 import org.apache.torque.om.Persistent; 21 import org.apache.torque.util.Criteria; 22 import org.apache.torque.util.Transaction; 23 24 25 33 public abstract class BaseEmailInbox extends BaseObject 34 { 35 36 private static final EmailInboxPeer peer = 37 new EmailInboxPeer(); 38 39 40 41 private int emailInboxId; 42 43 44 private String messageId; 45 46 47 private String filename; 48 49 50 private byte[] attachment; 51 52 53 private int readflag; 54 55 56 60 public int getEmailInboxId() 61 { 62 return emailInboxId; 63 } 64 65 66 69 public void setEmailInboxId(int v ) 70 { 71 72 if (this.emailInboxId != v) 73 { 74 this.emailInboxId = v; 75 setModified(true); 76 } 77 78 79 } 80 81 82 86 public String getMessageId() 87 { 88 return messageId; 89 } 90 91 92 95 public void setMessageId(String v ) 96 { 97 98 if (!ObjectUtils.equals(this.messageId, v)) 99 { 100 this.messageId = v; 101 setModified(true); 102 } 103 104 105 } 106 107 108 112 public String getFilename() 113 { 114 return filename; 115 } 116 117 118 121 public void setFilename(String v ) 122 { 123 124 if (!ObjectUtils.equals(this.filename, v)) 125 { 126 this.filename = v; 127 setModified(true); 128 } 129 130 131 } 132 133 134 138 public byte[] getAttachment() 139 { 140 return attachment; 141 } 142 143 144 147 public void setAttachment(byte[] v ) 148 { 149 150 if (!ObjectUtils.equals(this.attachment, v)) 151 { 152 this.attachment = v; 153 setModified(true); 154 } 155 156 157 } 158 159 160 164 public int getReadflag() 165 { 166 return readflag; 167 } 168 169 170 173 public void setReadflag(int v ) 174 { 175 176 if (this.readflag != v) 177 { 178 this.readflag = v; 179 setModified(true); 180 } 181 182 183 } 184 185 186 187 188 private static List fieldNames = null; 189 190 193 public static synchronized List getFieldNames() 194 { 195 if (fieldNames == null) 196 { 197 fieldNames = new ArrayList (); 198 fieldNames.add("EmailInboxId"); 199 fieldNames.add("MessageId"); 200 fieldNames.add("Filename"); 201 fieldNames.add("Attachment"); 202 fieldNames.add("Readflag"); 203 fieldNames = Collections.unmodifiableList(fieldNames); 204 } 205 return fieldNames; 206 } 207 208 212 public Object getByName(String name) 213 { 214 if (name.equals("EmailInboxId")) 215 { 216 return new Integer (getEmailInboxId()); 217 } 218 if (name.equals("MessageId")) 219 { 220 return getMessageId(); 221 } 222 if (name.equals("Filename")) 223 { 224 return getFilename(); 225 } 226 if (name.equals("Attachment")) 227 { 228 return getAttachment(); 229 } 230 if (name.equals("Readflag")) 231 { 232 return new Integer (getReadflag()); 233 } 234 return null; 235 } 236 237 242 public Object getByPeerName(String name) 243 { 244 if (name.equals(EmailInboxPeer.EMAIL_INBOX_ID )) 245 { 246 return new Integer (getEmailInboxId()); 247 } 248 if (name.equals(EmailInboxPeer.MESSAGE_ID )) 249 { 250 return getMessageId(); 251 } 252 if (name.equals(EmailInboxPeer.FILENAME )) 253 { 254 return getFilename(); 255 } 256 if (name.equals(EmailInboxPeer.ATTACHMENT )) 257 { 258 return getAttachment(); 259 } 260 if (name.equals(EmailInboxPeer.READFLAG )) 261 { 262 return new Integer (getReadflag()); 263 } 264 return null; 265 } 266 267 271 public Object getByPosition(int pos) 272 { 273 if ( pos == 0 ) 274 { 275 return new Integer (getEmailInboxId()); 276 } 277 if ( pos == 1 ) 278 { 279 return getMessageId(); 280 } 281 if ( pos == 2 ) 282 { 283 return getFilename(); 284 } 285 if ( pos == 3 ) 286 { 287 return getAttachment(); 288 } 289 if ( pos == 4 ) 290 { 291 return new Integer (getReadflag()); 292 } 293 return null; 294 } 295 296 300 public void save() throws Exception 301 { 302 save(EmailInboxPeer.getMapBuilder() 303 .getDatabaseMap().getName()); 304 } 305 306 313 public void save(String dbName) throws TorqueException 314 { 315 Connection con = null; 316 try 317 { 318 con = Transaction.begin(dbName); 319 save(con); 320 Transaction.commit(con); 321 } 322 catch(TorqueException e) 323 { 324 Transaction.safeRollback(con); 325 throw e; 326 } 327 } 328 329 331 private boolean alreadyInSave = false; 332 339 public void save(Connection con) throws TorqueException 340 { 341 if (!alreadyInSave) 342 { 343 alreadyInSave = true; 344 345 346 347 if (isModified()) 349 { 350 if (isNew()) 351 { 352 EmailInboxPeer.doInsert((EmailInbox)this, con); 353 setNew(false); 354 } 355 else 356 { 357 EmailInboxPeer.doUpdate((EmailInbox)this, con); 358 } 359 360 if (isCacheOnSave()) 361 { 362 EmailInboxManager.putInstance(this); 363 } 364 } 365 366 alreadyInSave = false; 367 } 368 } 369 370 374 protected boolean isCacheOnSave() 375 { 376 return true; 377 } 378 379 380 385 public void setPrimaryKey(ObjectKey emailInboxId) 386 { 387 setEmailInboxId(((NumberKey)emailInboxId).intValue()); 388 } 389 390 393 public void setPrimaryKey(String key) 394 { 395 setEmailInboxId(Integer.parseInt(key)); 396 } 397 398 399 403 public ObjectKey getPrimaryKey() 404 { 405 return SimpleKey.keyFor(getEmailInboxId()); 406 } 407 408 409 414 public EmailInbox copy() throws TorqueException 415 { 416 EmailInbox copyObj = new EmailInbox(); 417 copyObj.setEmailInboxId(emailInboxId); 418 copyObj.setMessageId(messageId); 419 copyObj.setFilename(filename); 420 copyObj.setAttachment(attachment); 421 copyObj.setReadflag(readflag); 422 423 copyObj.setEmailInboxId(0); 424 425 return copyObj; 426 } 427 428 434 public EmailInboxPeer getPeer() 435 { 436 return peer; 437 } 438 } 439 | Popular Tags |