KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > contineo > communication > dao > AttachmentDAO


1 /*
2  * Created on 01.04.2004
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */

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 /**
20  * @author Michael Scholz
21  *
22  * To change the template for this generated type comment go to
23  * Window>Preferences>Java>Code Generation>Code and Comments
24  */

25 public class AttachmentDAO {
26
27     /**
28      * @uml.property name="broker"
29      * @uml.associationEnd
30      */

31     private PersistenceBroker broker = null;
32
33     /**
34      * @uml.property name="pbkey"
35      * @uml.associationEnd
36      */

37     PBKey pbkey;
38
39     /**
40      * @uml.property name="logger"
41      * @uml.associationEnd
42      */

43     private Logger logger;
44
45     
46
47     /**
48      *
49      */

50     public AttachmentDAO() {
51         logger = LoggingManager.getLogger(this.getClass());
52         pbkey = new PBKey("contineo");
53     }
54     
55     /**
56      * This method finds an attachment by its id.
57      */

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 JavaDoc(messageId));
64             crit.addEqualTo("co_partid", new Integer JavaDoc(partId));
65             Query query = new QueryByCriteria(org.contineo.communication.Attachment.class, crit);
66             attachment = (Attachment)broker.getObjectByQuery(query);
67         } catch (Exception JavaDoc 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