package #{manager_impl_p};

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeecms.common.hibernate4.Updater;
import com.jeecms.common.page.Pagination;
import #{dao_p}.#{Entity}Dao;
import #{entity_p}.#{Entity};
import #{manager_p}.#{Entity}Mng;

@Service
@Transactional
public class #{Entity}MngImpl implements #{Entity}Mng {
	@Transactional(readOnly = true)
	public Pagination getPage(int pageNo, int pageSize) {
		Pagination page = dao.getPage(pageNo, pageSize);
		return page;
	}

	@Transactional(readOnly = true)
	public #{Entity} findById(Integer id) {
		#{Entity} entity = dao.findById(id);
		return entity;
	}

	public #{Entity} save(#{Entity} bean) {
		dao.save(bean);
		return bean;
	}

	public #{Entity} update(#{Entity} bean) {
		Updater<#{Entity}> updater = new Updater<#{Entity}>(bean);
		#{Entity} entity = dao.updateByUpdater(updater);
		return entity;
	}

	public #{Entity} deleteById(Integer id) {
		#{Entity} bean = dao.deleteById(id);
		return bean;
	}
	
	public #{Entity}[] deleteByIds(Integer[] ids) {
		#{Entity}[] beans = new #{Entity}[ids.length];
		for (int i = 0,len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}

	private #{Entity}Dao dao;

	@Autowired
	public void setDao(#{Entity}Dao dao) {
		this.dao = dao;
	}
}