package com.yihu.hos.resource.dao.impl;

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

import java.util.List;

/**
 * Created by chenweida on 2016/1/25.
 */
@Repository("rsAppResourceDao")
public class RsAppResourceDaoImpl extends SQLGeneralDAO implements IRsAppResourceDao {
    @Override
    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;
    }

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

    @Override
    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);
    }

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

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