📄 orderserviceimp.java
字号:
/*
* Copyright 2003-2005 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.jdon.framework.samples.jpetstore.service.bo;
import java.sql.SQLException;
import java.util.List;
import com.ibatis.dao.client.DaoManager;
import com.jdon.controller.events.EventModel;
import com.jdon.controller.model.PageIterator;
import com.jdon.controller.pool.Poolable;
import com.jdon.framework.samples.jpetstore.domain.Order;
import com.jdon.framework.samples.jpetstore.persistence.dao.DaoManagerFactory;
import com.jdon.framework.samples.jpetstore.persistence.dao.iface.ItemDao;
import com.jdon.framework.samples.jpetstore.persistence.dao.iface.OrderDao;
import com.jdon.framework.samples.jpetstore.persistence.dao.iface.SequenceDao;
import com.jdon.framework.samples.jpetstore.service.OrderService;
import com.jdon.util.Debug;
/**
* @author <a href="mailto:banqiao@jdon.com">banq</a>
*
*/
public class OrderServiceImp implements OrderService, Poolable {
private final static String module = OrderServiceImp.class.getName();
private OrderDao orderDao;
private SequenceDao sequenceDao;
private ItemDao itemDao;
private DaoManagerFactory daoManagerFactory;
/**
* @param orderDao
*/
public OrderServiceImp(OrderDao orderDao,
ItemDao itemDao,
SequenceDao sequenceDao,
DaoManagerFactory daoManagerFactory) {
this.orderDao = orderDao;
this.itemDao = itemDao;
this.sequenceDao = sequenceDao;
this.daoManagerFactory = daoManagerFactory;
}
/* (non-Javadoc)
* @see com.jdon.framework.samples.jpetstore.service.OrderService#insertOrder(com.jdon.framework.samples.jpetstore.domain.Order)
*/
public void insertOrder(EventModel em) {
Order order = (Order)em.getModel();
Debug.logVerbose(" insertOrder :" + order.getUsername());
DaoManager daoManager = daoManagerFactory.getDaomanager();
try {
// Get the next id within a separate transaction
order.setOrderId(getNextId("ordernum"));
daoManager.startTransaction();
itemDao.updateQuantity(order);
orderDao.insertOrder(order);
daoManager.commitTransaction();
}catch(Exception ex){
Debug.logError(" insertOrder error" + ex);
em.setErrors("db.error");
} finally {
daoManager.endTransaction();
}
}
public synchronized int getNextId(String key) {
try {
return sequenceDao.getNextId(key);
} catch (SQLException e) {
return 0;
}
}
/* (non-Javadoc)
* @see com.jdon.framework.samples.jpetstore.service.OrderService#getOrder(int)
*/
public Order getOrder(String orderId) {
Order Order = null;
try{
Order = orderDao.getOrder(Integer.parseInt(orderId));
//other business logic
}catch(Exception daoe){
Debug.logError(" Dao error : " + daoe, module);
}
return Order;
}
/* (non-Javadoc)
* @see com.jdon.framework.samples.jpetstore.service.OrderService#getOrdersByUsername(java.lang.String)
*/
public PageIterator getOrdersByUsername(String username, int start, int count) {
PageIterator pageIterator = null;
try {
List list = orderDao.getOrderIDsByUsername(username, start, count);
int allCount = orderDao.getOrderIDsByUsernameCount(username);
int currentCount = start + list.size();
pageIterator = new PageIterator(allCount, list.toArray(), start,
(currentCount < allCount)?true:false);
} catch (Exception daoe) {
Debug.logError(" Dao error : " + daoe, module);
}
return pageIterator;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -