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.CpdProduct;
06: import com.completex.objective.persistency.examples.ex003a.domain.Product;
07:
08: import java.util.List;
09:
10: /**
11: * @author Gennady Krizhevsky
12: */
13: public class ProductDAO {
14: private Persistency persistency;
15:
16: public ProductDAO(Persistency persistency) {
17: this .persistency = persistency;
18: }
19:
20: public Product loadProduct(final Long productId)
21: throws ProductException {
22: try {
23: return (CpdProduct) persistency.load(new CpdProduct(
24: productId));
25: } catch (OdalPersistencyException e) {
26: throw new ProductException(e);
27: }
28: }
29:
30: public Product[] loadAllProducts() throws ProductException {
31: try {
32: List products = (List) persistency.select(new CpdProduct());
33: return (Product[]) products.toArray(new Product[products
34: .size()]);
35: } catch (OdalPersistencyException e) {
36: throw new ProductException(e);
37: }
38: }
39:
40: public void insertProduct(final Product product)
41: throws ProductException {
42: try {
43: persistency.insert(product);
44: } catch (OdalPersistencyException e) {
45: throw new ProductException(e);
46: }
47: }
48:
49: public void updateProduct(final Product product)
50: throws ProductException {
51: try {
52: persistency.update(product);
53: } catch (OdalPersistencyException e) {
54: throw new ProductException(e);
55: }
56: }
57:
58: }
|