package com.yihu.hos.resource.dao;

import com.yihu.hos.resource.model.RsAppResource;
import com.yihu.hos.web.framework.dao.SQLGeneralDAO;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by chenweida on 2016/1/25.
 */
@Repository("rsAppResourceDao")
public class RsAppResourceDaoImpl extends SQLGeneralDAO {

    public static final String BEAN_ID = "rsAppResourceDao";

    
    public List<RsAppResource> getAppResourceByResourceId(String resourceid) throws Exception {
        List<RsAppResource> rs = (List<RsAppResource>) super.hibernateTemplate.find("from RsAppResource r where r.resourceId=?", resourceid);
        return rs;
    }

    
    public void deleteByResourceId(String resourceId) throws Exception {
        super.hibernateTemplate.deleteAll(super.hibernateTemplate.find("from RsAppResource r where r.resourceId=?", resourceId));
    }

    
    public RsAppResource getAppResourceByResourceIdAndAppId(String resourceId, String appId) {
        return (RsAppResource) super.hibernateTemplate.find("from RsAppResource r where r.resourceId=? and r.appId=? ", resourceId, appId).get(0);
    }

    
    public void deleteEntityList(List<RsAppResource> deleteList) throws Exception {
        super.hibernateTemplate.deleteAll(deleteList);
    }

    public void saveEntityList(List<RsAppResource> newList) throws Exception {
        for (RsAppResource r : newList)
            super.hibernateTemplate.save(r);
    }
}
