hibernateapplicationdao.java

来自「OBPM是一个开源」· Java 代码 · 共 100 行

JAVA
100
字号
package cn.myapps.core.deploy.application.dao;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.hibernate.Session;

import cn.myapps.base.action.ParamsTable;
import cn.myapps.base.dao.DataPackage;
import cn.myapps.base.dao.HibernateBaseDAO;
import cn.myapps.base.dao.ValueObject;
import cn.myapps.core.deploy.application.ejb.ApplicationVO;
import cn.myapps.core.user.action.WebUser;

public class HibernateApplicationDAO extends HibernateBaseDAO implements
		ApplicationDAO {

	private static Map AppDomain_Cache = null;

	public HibernateApplicationDAO(String voClassName) {
		super(voClassName);
	}

	public ApplicationVO getApplicationByDomainName(String domainName)
			throws Exception {
		String hql = "FROM " + _voClazzName + " vo WHERE vo.domainName = '"
				+ domainName + "'";
		return (ApplicationVO) getData(hql);
	}

	public DataPackage query(ParamsTable params, WebUser user) throws Exception {
		String hql = "FROM " + _voClazzName + " order by sortId";
		int _pagelines = Integer.MAX_VALUE;
		int _currpage = 1;
		if (params.getParameter("_pagelines") != null)
			_pagelines = Integer.parseInt((String) params
					.getParameter("_pagelines"));
		if (params.getParameter("_currpage") != null)
			_currpage = Integer.parseInt((String) params
					.getParameter("_currpage"));
		return getDatapackage(hql, _currpage, _pagelines);
	}

	public Collection getAllApplication() throws Exception {
		String hql = "FROM " + _voClazzName;
		return getDatas(hql);
	}

	public void create(ValueObject vo) throws Exception {
		try {
			Session session = currentSession();
			session.save(vo);
			refreshCache();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public void remove(String id) throws Exception {
		Session session = currentSession();
		ValueObject vo = find(id);
		if (vo != null)
			session.delete(vo);
		refreshCache();
	}

	public void update(ValueObject vo) throws Exception {
		Session session = currentSession();
		session.merge(vo);
		refreshCache();
	}

	public void refreshCache() throws Exception {
		if (AppDomain_Cache != null)
			AppDomain_Cache.clear();
		else
			AppDomain_Cache = new HashMap();
		Collection rs = getAllApplication();
		if (rs != null) {
			for (Iterator iter = rs.iterator(); iter.hasNext();) {
				ApplicationVO vo = (ApplicationVO) iter.next();
				if (vo.getDomainName() != null
						&& vo.getDomainName().trim().length() > 0
						&& vo.getWelcomePage() != null
						&& vo.getWelcomePage().trim().length() > 0)
					AppDomain_Cache.put(vo.getDomainName(), vo);
			}
		}

	}

	public Map getAppDomain_Cache() throws Exception {
		if (AppDomain_Cache == null)
			refreshCache();
		return AppDomain_Cache;
	}

}

⌨️ 快捷键说明

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