contentserviceimp.java

来自「使用WEBWORK,SPRING,HIBERNATE编写的简单的添加」· Java 代码 · 共 150 行

JAVA
150
字号
/**
 *文件功能:文件管理; InnoDB free: 0 kB 
 */
package com.tech.service.imp;

import java.util.List;
import com.common.dao.DaoSupport;
import com.common.exception.BusinessException;
import com.common.util.BeanUtils;
import com.tech.model.Content;
import com.tech.service.ContentService;

/**
 *文件管理; InnoDB free: 0 kB
 * @作者 徐建协
 * @日期 2009-03-06
 */
public class ContentServiceImp implements ContentService {
  private DaoSupport<Content,Long> contentDao;

  public void setContentDao(DaoSupport<Content,Long> contentDao) {
    this.contentDao = contentDao;
  }

  /* (non-Javadoc)
   * @see com.common.service.BaseService#getEntity(java.io.Serializable)
   */
  public Content getEntity(Long id) throws BusinessException {
    try {
      return contentDao.getEntity(id);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("ContentServiceImp 不能获取主键为:" + id
          + "的数据" + e.toString());
    }
  }

  /* (non-Javadoc)
   * @see com.common.service.BaseService#loadEntity(java.io.Serializable)
   */
  public Content loadEntity(Long id) throws BusinessException {
    try {
      return contentDao.loadEntity(id);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("ContentServiceImp 不能获取主键为:" + id
          + "的数据" + e.toString());
    }
  }

  /* (non-Javadoc)
   * @see com.common.service.BaseService#removeEntity(java.lang.Object)
   */
  public void removeEntity(Content entity) throws BusinessException {
    try {
      contentDao.removeEntity(entity);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("删除异常:"
          + e.getMessage());
    }

  }

  /* (non-Javadoc)
   * @see com.common.service.BaseService#removeEntity(T[])
   */
  public void removeEntity(Content[] array) throws BusinessException {
    try {
      contentDao.removeEntity(array);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("删除异常:"
          + e.getMessage());
    }

  }

  /* (non-Javadoc)
   * @see com.common.service.BaseService#saveEntity(java.lang.Object)
   */
  public void saveEntity(Content entity) throws BusinessException {
    try {
      contentDao.saveEntity(entity);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("添加异常:"
          + e.getMessage());
    }

  }

  /* (non-Javadoc)
   * @see com.common.service.BaseService#saveEntity(T[])
   */
  public void saveEntity(Content[] array) throws BusinessException {
    try {
      contentDao.saveEntity(array);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("添加异常:"
          + e.getMessage());
    }

  }

  /* (non-Javadoc)
   * @see com.common.service.BaseService#updateEntity(java.lang.Object)
   */
  public void updateEntity(Content entity) throws BusinessException {
    try {
      
      Content entityLoad = contentDao.getEntity(entity.getId());
      // 拷贝不需要更新的字段内容
      //PropertyUtils.copyProperties(entityLoad,entity);
      BeanUtils.copyProperties(entityLoad,entity);
      contentDao.updateEntity(entityLoad);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("更新异常:"
          + e.getMessage());
    }

  }

  /* (non-Javadoc)
   * @see com.common.service.BaseService#updateEntity(T[])
   */
  public void updateEntity(Content[] array) throws BusinessException {
    try {
      contentDao.updateEntity(array);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("更新异常:"
          + e.getMessage());
    }

  }
  
  public boolean isExists(Content t,List<String> names) throws BusinessException{
    try {
      return contentDao.isExists(t,names);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException("查找异常:"
          + e.getMessage());
    } 
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?