⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admdao.java

📁 达内培训时做的亚信的实战项目 包含数据库 struts+hibernate
💻 JAVA
字号:
package com.tarena.oos.DAO;


import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

import com.tarena.oos.model.Adm;
import com.tarena.oos.model.Module;

/**
 * Data access object (DAO) for domain model class Adm.
 * @see .Adm
  * @author MyEclipse Persistence Tools 
 */

public class AdmDAO extends BaseDAO  {
    private static final Log log = LogFactory.getLog(AdmDAO.class);
	//property constants
	public static final String NAME = "name";
	public static final String LOGIN_NAME = "loginName";
	public static final String LOGIN_PASSWORD = "loginPassword";
	public static final String PHONE = "phone";
	public static final String EMAIL = "email";


    
    public void save(Adm transientInstance) {
        log.debug("saving Adm instance");
        try {
            getSession().save(transientInstance);
            getSession().beginTransaction().commit();
            getSession().flush();
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(Adm persistentInstance) {
        log.debug("deleting Adm instance");
        try {
            getSession().delete(persistentInstance);
            getSession().beginTransaction().commit();
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
	public void deleteById(java.lang.Integer id) {
		String hql = "from Adm adm  where adm.id=:id";
		Adm adm = (Adm)getSession().createQuery(hql).setInteger("id", id)
								.uniqueResult();
        getSession().delete(adm);
        getSession().beginTransaction().commit();
	}
    public Adm findById( java.lang.Integer id) {
        log.debug("getting Adm instance with id: " + id);
        try {
            Adm instance = (Adm) getSession()
                    .get(Adm.class, id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(Adm instance) {
        log.debug("finding Adm instance by example");
        try {
            List results = getSession()
                    .createCriteria("Adm")
                    .add(Example.create(instance))
            .list();
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding Adm instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from Adm as model where model." 
         						+ propertyName + "= ?";
         Query queryObject = getSession().createQuery(queryString);
		 queryObject.setParameter(0, value);
		 return queryObject.list();
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}
	
	public List findByLoginName(Object loginName) {
		return findByProperty(LOGIN_NAME, loginName);
	}
	
	public List findByLoginPassword(Object loginPassword) {
		return findByProperty(LOGIN_PASSWORD, loginPassword);
	}
	
	public List findByPhone(Object phone) {
		return findByProperty(PHONE, phone);
	}
	
	public List findByEmail(Object email) {
		return findByProperty(EMAIL, email);
	}
	

	public List findAll() {
		log.debug("finding all Adm instances");
		try {
			String queryString = "from Adm";
	         Query queryObject = getSession().createQuery(queryString);
			 return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
    public Adm merge(Adm detachedInstance) {
        log.debug("merging Adm instance");
        try {
            Adm result = (Adm) getSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(Adm instance) {
        log.debug("attaching dirty Adm instance");
        try {
            getSession().saveOrUpdate(instance);
            getSession().beginTransaction().commit();
            getSession().flush();
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(Adm instance) {
        log.debug("attaching clean Adm instance");
        try {
            getSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    public Adm getModulesByIds(String[] rights,Adm adm) {
    	ModuleDAO dao=new ModuleDAO();
    	for(int i=0;i<rights.length;i++) {
    		int module_id=Integer.parseInt(rights[i]);
    		Module module=dao.findById(module_id);
    		adm.addModule(module);
    	}
    	return adm;
    }
    public void deleteAdmByIds(String[] ids) {
        AdmDAO dao=new AdmDAO();
        for(int i=0;i<ids.length;i++) {
        	int id=Integer.parseInt(ids[i]);
        	dao.deleteById(id);
        }
    }
}

⌨️ 快捷键说明

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