01: package com.odal.petstore.persistence.dao;
02:
03: import com.completex.objective.components.persistency.MappingPersistency;
04: import com.completex.objective.components.persistency.OdalPersistencyException;
05: import com.completex.objective.components.persistency.Page;
06: import com.completex.objective.components.persistency.Query;
07: import com.odal.petstore.OdalPetstoreException;
08: import com.odal.petstore.domain.Order;
09: import com.odal.petstore.persistence.gen.cmp.CmpOrder;
10: import com.odal.petstore.persistence.iface.OrderDao;
11:
12: import java.util.List;
13:
14: /**
15: * @author Gennady Krizhevsky
16: */
17: public class OrderDaoImpl implements OrderDao {
18: private MappingPersistency persistency;
19:
20: public OrderDaoImpl(MappingPersistency persistency) {
21: this .persistency = persistency;
22: }
23:
24: public List getOrdersByUsername(String username, int pageNumber)
25: throws OdalPetstoreException {
26: try {
27: CmpOrder order = new CmpOrder();
28: order.setUserId(username);
29: Query query = persistency.getQueryFactory()
30: .newQueryByCompoundExample(order);
31: query.setDisconnectedPageQuery(true);
32: query.setPage(new Page(pageNumber, 10));
33: return (List) persistency.select(query);
34: } catch (OdalPersistencyException e) {
35: throw new OdalPetstoreException(e);
36: }
37: }
38:
39: public Order getOrder(long orderId) throws OdalPetstoreException {
40: try {
41: return (Order) persistency.load(new CmpOrder(orderId));
42: } catch (OdalPersistencyException e) {
43: throw new OdalPetstoreException(e);
44: }
45: }
46:
47: public void insertOrder(Order order) throws OdalPetstoreException {
48: try {
49: persistency.insert(order);
50: } catch (OdalPersistencyException e) {
51: throw new OdalPetstoreException(e);
52: }
53: }
54: }
|