accountroledaoimpl.java

来自「一个完整的物流系统」· Java 代码 · 共 77 行

JAVA
77
字号
package jp.com.cost.dao.impl;

import java.util.List;

import jp.com.cost.common.Log;
import jp.com.cost.dao.AccountroleDao;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class AccountroleDaoImpl extends HibernateDaoSupport implements
		AccountroleDao {

	Query query;
	Session session;

	public boolean deleteAccountRole(int id) {
		// TODO Auto-generated method stub
		boolean bln = false;
		try {
			String SQL = "delete from accountrole where aid=" + id;
			session = getHibernateTemplate().getSessionFactory().openSession();
			query = session.createSQLQuery(SQL);
			query.executeUpdate();
			Log.insert("accountRole", "delete");
			bln = true;
			session.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return bln;
	}

	public boolean addAccountRole(String aid, String[] rid) {
		// TODO Auto-generated method stub
		boolean bln = false;
		for (int i = 0; i < rid.length; i++) {
			String SQL = "insert into accountrole(aid,rid) values("
					+ Integer.parseInt(aid) + "," + Integer.parseInt(rid[i])
					+ ")";
			session = getHibernateTemplate().getSessionFactory().openSession();
			query = session.createSQLQuery(SQL);
			query.executeUpdate();
			Log.insert("accountRole", "insert");
			bln = true;
			session.close();
		}
		return bln;
	}

	public boolean updateAccountRole(String aid, String[] rid) {
		// TODO Auto-generated method stub
		boolean bln = false;
		session = getHibernateTemplate().getSessionFactory().openSession();
		
		String SQL1 = "delete from accountrole where aid="
			+ Integer.parseInt(aid);
		query=session.createSQLQuery(SQL1);
		query.executeUpdate(); 
		for (int i = 0; i < rid.length; i++) {
			String SQL2 = "insert into accountrole(aid,rid) values("
					+ Integer.parseInt(aid) + "," + Integer.parseInt(rid[i])
					+ ")";
            query=session.createSQLQuery(SQL2);
            query.executeUpdate();
		}
		bln=true;
		Log.insert("accountRole", "modify");
		session.close();
		return bln;
	}

}

⌨️ 快捷键说明

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