BaseService BaseServiceImpl


package com.web.base;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.poi.ss.usermodel.Cell;
import org.hibernate.Session;

/**
* Generic Manager that talks to GenericDao to CRUD POJOs.
*
* <p>Extend this interface if you want typesafe (no casting necessary) managers
* for your domain objects.
*
* @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
* @param <T> a type variable
* @param <PK> the primary key for that type
*/
public interface BaseService<T, PK extends Serializable> {

/**
* Generic method used to get all objects of a particular type. This
* is the same as lookup up all rows in a table.
* @return List of populated objects
*/
List<T> getAll();

/**
* Generic method to get an object based on class and identifier. An
* ObjectRetrievalFailureException Runtime Exception is thrown if
* nothing is found.
*
* @param id the identifier (primary key) of the object to get
* @return a populated object
* @see org.springframework.orm.ObjectRetrievalFailureException
*/
T get(PK id);

/**
* Checks for existence of an object of type T using the id arg.
* @param id the identifier (primary key) of the object to get
* @return - true if it exists, false if it doesn't
*/
boolean exists(PK id);

/**
* Generic method to save an object - handles both update and insert.
* @param object the object to save
* @return the updated object
*/
T save(T object);

/**
* Generic method to delete an object based on class and id
* @param id the identifier (primary key) of the object to remove
*/
void remove(PK id);

public void removes(PK[] ids);

void remove1(PK id);

public void removes1(PK[] ids);
public List<T> getByHql(String hql,Object[] objs);

public List getAllByHql(String hql,Object[] objs);

public void updateQuery(final String hql,final Map map);

public List<T> getPageData(String hql, Map map, int pageIndex, int pageSize);

public List<T> getPageData(String hql, Map map);

public int getPageSize(String hql, Map map);

public BigDecimal getTotalCount(String hql, Map map);

public String getCellValue(Cell cell);

public void removes2(PK[] ids, Map session);
}





package com.web.base;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.usermodel.Cell;

public class BaseServiceImpl<T, PK extends Serializable> implements BaseService<T, PK> {
/**
* Log variable for all child classes. Uses LogFactory.getLog(getClass()) from Commons Logging
*/
protected final Log log = LogFactory.getLog(getClass());

/**
* GenericDao instance, set by constructor of this class
*/
protected BaseDao<T, PK> baseDao;

/**
* Public constructor for creating a new GenericManagerImpl.
* @param genericDao the GenericDao to use for persistence
*/
public BaseServiceImpl(final BaseDao<T, PK> baseDao) {
this.baseDao = baseDao;
}

/**
* {@inheritDoc}
*/
public List<T> getAll() {
return baseDao.getAll();
}

/**
* {@inheritDoc}
*/
public T get(PK id) {
return baseDao.get(id);
}

/**
* {@inheritDoc}
*/
public boolean exists(PK id) {
return baseDao.exists(id);
}

/**
* {@inheritDoc}
*/
public T save(T object) {
return baseDao.save(object);
}

/**
* {@inheritDoc}
*/
public void remove(PK id) {
baseDao.remove1(id);
}

public void removes(PK[] ids){
baseDao.removes1(ids);
}

public void remove1(PK id) {
baseDao.remove(id);
}

public void removes1(PK[] ids){
baseDao.removes(ids);
}

public List<T> getPageData(String hql, Map map, int pageIndex, int pageSize) {
return baseDao.getPageData(hql, map, pageIndex, pageSize);
}

public List<T> getPageData(String hql, Map map) {
return baseDao.getPageData(hql, map);
}

public int getPageSize(String hql, Map map) {
return baseDao.getPageSize(hql,map);
}

public BigDecimal getTotalCount(String hql, Map map){
return baseDao.getTotalCount(hql,map);
}

public List<T> getByHql(String hql, Object[] objs) {
return baseDao.getByHql(hql, objs);
}

public void updateQuery(String hql, Map map) {
baseDao.updateQuery(hql, map);
}

public List getAllByHql(String hql, Object[] objs) {
return baseDao.getAllByHql(hql, objs);
}

public String getCellValue(Cell cell){
if(cell!=null){
if(cell.getCellType()==HSSFCell.CELL_TYPE_NUMERIC)
return String.valueOf(cell.getNumericCellValue());
else return cell.getRichStringCellValue().toString().trim();
}else return null;
}

public void removes2(PK[] ids,Map session) {
baseDao.removes2(ids,session);
}


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值