1 7 package org.contineo.communication.dao; 8 9 import org.apache.log4j.Level; 10 import org.apache.log4j.Logger; 11 import org.apache.ojb.broker.PBKey; 12 import org.apache.ojb.broker.PersistenceBroker; 13 import org.apache.ojb.broker.PersistenceBrokerFactory; 14 import org.apache.ojb.broker.query.Criteria; 15 import org.apache.ojb.broker.query.Query; 16 import org.apache.ojb.broker.query.QueryByCriteria; 17 import org.contineo.communication.Attachment; 18 import org.contineo.core.LoggingManager; 19 25 public class AttachmentDAO { 26 27 31 private PersistenceBroker broker = null; 32 33 37 PBKey pbkey; 38 39 43 private Logger logger; 44 45 46 47 50 public AttachmentDAO() { 51 logger = LoggingManager.getLogger(this.getClass()); 52 pbkey = new PBKey("contineo"); 53 } 54 55 58 public Attachment findByPrimaryKey(int messageId, int partId) { 59 Attachment attachment = new Attachment(); 60 try { 61 broker = PersistenceBrokerFactory.createPersistenceBroker(pbkey); 62 Criteria crit = new Criteria(); 63 crit.addEqualTo("co_messageid", new Integer (messageId)); 64 crit.addEqualTo("co_partid", new Integer (partId)); 65 Query query = new QueryByCriteria(org.contineo.communication.Attachment.class, crit); 66 attachment = (Attachment)broker.getObjectByQuery(query); 67 } catch (Exception e) { 68 if (logger.isEnabledFor(Level.ERROR)) 69 logger.error(e.getMessage()); 70 } finally { 71 if (broker != null) broker.close(); 72 } 73 return attachment; 74 } 75 } 76 | Popular Tags |