01: package com.completex.objective.persistency.examples.ex003a.app;
02:
03: import com.completex.objective.components.persistency.OdalPersistencyException;
04: import com.completex.objective.components.persistency.Persistency;
05: import com.completex.objective.persistency.examples.ex003a.domain.Contact;
06: import com.completex.objective.persistency.examples.ex003a.domain.CpxCustomer;
07: import com.completex.objective.persistency.examples.ex003a.domain.Customer;
08:
09: import java.util.Collection;
10:
11: /**
12: * @author Gennady Krizhevsky
13: */
14: public class CustomerDAO {
15:
16: private Persistency persistency;
17:
18: public CustomerDAO(Persistency persistency) {
19: this .persistency = persistency;
20: }
21:
22: public void setPersistency(Persistency persistency) {
23: this .persistency = persistency;
24: }
25:
26: public void insertCustomer(final Customer customer)
27: throws CustomerException {
28: try {
29: persistency.insert(customer);
30: } catch (OdalPersistencyException e) {
31: throw new CustomerException(e);
32: }
33: }
34:
35: public void updateCustomer(final Customer customer)
36: throws CustomerException {
37: try {
38: persistency.update(customer);
39: } catch (OdalPersistencyException e) {
40: throw new CustomerException(e);
41: }
42: }
43:
44: public Customer loadCustomer(final Long customerId)
45: throws CustomerException {
46: try {
47: return (Customer) persistency.load(new CpxCustomer(
48: customerId));
49: } catch (OdalPersistencyException e) {
50: throw new CustomerException(e);
51: }
52: }
53:
54: public void insertContact(final Contact contact)
55: throws CustomerException {
56: try {
57: persistency.insert(contact);
58: } catch (OdalPersistencyException e) {
59: throw new CustomerException(e);
60: }
61: }
62:
63: public void updateContact(final Contact contact)
64: throws CustomerException {
65: try {
66: persistency.update(contact);
67: } catch (OdalPersistencyException e) {
68: throw new CustomerException(e);
69: }
70: }
71:
72: public Contact loadContact(final Long contactId)
73: throws CustomerException {
74: try {
75: return (Contact) persistency.load(new Contact(contactId));
76: } catch (OdalPersistencyException e) {
77: throw new CustomerException(e);
78: }
79: }
80:
81: public Contact[] loadCustomerContacts(final Long customerId)
82: throws CustomerException {
83: try {
84: Contact contactQuery = new Contact(customerId);
85: contactQuery.setCustomerId(customerId);
86: Collection collection = persistency.select(contactQuery);
87: return (Contact[]) collection
88: .toArray(new Contact[collection.size()]);
89: } catch (OdalPersistencyException e) {
90: throw new CustomerException(e);
91: }
92: }
93:
94: }
|