package #{manager_impl_p};

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

import com.javapms.basic.hibernate3.Updater;
import com.javapms.basic.page.Pagination;
import #{dao_p}.#{Entity}Dao;
import #{entity_p}.#{Entity};
import #{manager_p}.#{Entity}Service;

@Service
@Transactional
public class #{Entity}ServiceImpl implements #{Entity}Service {
	@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);
		bean = dao.updateByUpdater(updater);
		return bean;
	}

	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;
	}
}