01: package com.completex.objective.persistency.examples.ex004a.app;
02:
03: import com.completex.objective.components.persistency.AbstractPersistentObject;
04: import com.completex.objective.components.persistency.MappingPersistency;
05: import com.completex.objective.components.persistency.OdalPersistencyException;
06: import com.completex.objective.components.persistency.core.impl.BasicLifeCycleController;
07: import com.completex.objective.persistency.examples.ex004a.cpxpos.CpxCustomerPO;
08: import com.completex.objective.persistency.examples.ex004a.domain.CpxCustomer;
09:
10: import java.sql.SQLException;
11: import java.util.List;
12:
13: /**
14: * @author Gennady Krizhevsky
15: */
16: public class CustomerDAO {
17:
18: private MappingPersistency persistency;
19:
20: public CustomerDAO(MappingPersistency persistency) {
21: this .persistency = persistency;
22: }
23:
24: public void setPersistency(MappingPersistency persistency) {
25: this .persistency = persistency;
26: }
27:
28: public void insertCustomer(final CpxCustomer customer)
29: throws CustomerException {
30: try {
31: persistency.insert(customer);
32: } catch (OdalPersistencyException e) {
33: throw new CustomerException(e);
34: }
35: }
36:
37: public void updateCustomer(final CpxCustomer customer)
38: throws CustomerException {
39: try {
40: persistency.update(customer);
41: } catch (OdalPersistencyException e) {
42: throw new CustomerException(e);
43: }
44: }
45:
46: public void deleteCustomer(final CpxCustomer customer)
47: throws CustomerException {
48: try {
49: persistency.delete(customer);
50: } catch (SQLException e) {
51: throw new CustomerException(e);
52: }
53: }
54:
55: public CpxCustomer loadCustomer(final Long customerId)
56: throws CustomerException {
57: try {
58: return (CpxCustomer) persistency.load(new CpxCustomerPO(
59: customerId));
60: } catch (OdalPersistencyException e) {
61: throw new CustomerException(e);
62: }
63: }
64:
65: /**
66: * Load all the customers. Utilizes BasicLifeCycleController.afterCompositeSelect method
67: * to pre-load otherwise lazily loadable Contact.
68: *
69: * @return list of customers
70: * @throws CustomerException
71: */
72: public List loadAllCustomers() throws CustomerException {
73: try {
74: return (List) persistency.select(new CpxCustomerPO(),
75: new BasicLifeCycleController() {
76: public Object afterCompositeSelect(
77: AbstractPersistentObject po) {
78: ((CpxCustomerPO) po).getContact();
79: return po;
80: }
81: });
82: } catch (OdalPersistencyException e) {
83: throw new CustomerException(e);
84: }
85: }
86:
87: }
|