KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > dao > CustomerExampleDAO


1 package test.dao;
2
3 import test.interfaces.CustomerPK;
4 import test.ejb.CustomerBMPBean;
5 import java.util.*;
6 import javax.ejb.*;
7
8 /**
9  * Example DAO implementation class
10  */

11 public class CustomerExampleDAO
12 implements CustomerDAO
13 {
14     
15     /**
16      * Initialise DAO
17      */

18     public void init()
19     {
20         // do JNDI lookup of Datasource resource ref
21
}
22     
23     /**
24      * Called by ejbLoad
25      */

26     public void load(CustomerPK pk, CustomerBMPBean bean)
27     {
28         // SELECT FROM datasource WHERE pkfields = pk.getX()
29
// bean.setX(read values)
30
}
31     
32     /**
33      * Called by ejbStore
34      */

35     public void store(CustomerBMPBean bean)
36     {
37         // UPDATE datasource SET values = bean.getX()
38
}
39     
40     /**
41      * Called by create method(s)
42      */

43     public CustomerPK create(CustomerBMPBean bean)
44     {
45         CustomerPK pk = null;
46         // INSERT INTO datasource (values) VALUES (bean.getX())
47
// pk = new CustomerPK(pkfields)
48
return pk;
49     }
50     
51     /**
52      * Called by ejbRemove
53      */

54     public void remove(CustomerPK pk)
55     {
56         // DELETE FROM datasource WHERE pkfields = pk.getX()
57
}
58     
59     /**
60      * Called by mandatory PK finder
61      */

62     public CustomerPK findByPrimaryKey(CustomerPK pk)
63     {
64         // SELECT FROM datasource WHERE pkfields = pk.getX()
65
// if not found
66
// throw new ObjectNotFoundException();
67
// pk = new CustomerPK(...);
68
return pk;
69     }
70     
71     /**
72      * Finder that returns all rows
73      */

74     public Collection findAll()
75     {
76         List ret = new ArrayList();
77         CustomerPK pk;
78         // SELECT FROM datasource
79
// for each resultset row
80
// pk = new CustomerPK(...);
81
// ret.add(pk);
82
return ret;
83     }
84     
85     /**
86      * Non-lifecycle business method delegate
87      */

88     public void backup(CustomerPK pk)
89     {
90         // INSERT INTO datasource.Archive (fields)
91
// SELECT fields FROM Customer WHERE pkfields = pk.getX();
92
}
93
94 }
95
Popular Tags