1 6 package com.ibatis.jpetstore.persistence.sqlmapdao; 7 8 import com.ibatis.dao.client.DaoManager; 9 import com.ibatis.jpetstore.domain.LineItem; 10 import com.ibatis.jpetstore.domain.Order; 11 import com.ibatis.jpetstore.persistence.iface.OrderDao; 12 import com.ibatis.common.util.PaginatedList; 13 14 public class OrderSqlMapDao extends BaseSqlMapDao implements OrderDao { 15 16 public OrderSqlMapDao(DaoManager daoManager) { 17 super(daoManager); 18 } 19 20 public PaginatedList getOrdersByUsername(String username) { 21 return queryForPaginatedList("getOrdersByUsername", username, 10); 22 } 23 24 public Order getOrder(int orderId) { 25 Order order = null; 26 Object parameterObject = new Integer (orderId); 27 order = (Order) queryForObject("getOrder", parameterObject); 28 order.setLineItems(queryForList("getLineItemsByOrderId", new Integer (order.getOrderId()))); 29 return order; 30 } 31 32 public void insertOrder(Order order) { 33 update("insertOrder", order); 34 update("insertOrderStatus", order); 35 for (int i = 0; i < order.getLineItems().size(); i++) { 36 LineItem lineItem = (LineItem) order.getLineItems().get(i); 37 lineItem.setOrderId(order.getOrderId()); 38 update("insertLineItem", lineItem); 39 } 40 41 } 42 43 } 44 | Popular Tags |