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

📄 userpersistenceprovider.java

📁 OpenReports是一个完整的基于Web的报表方案
💻 JAVA
字号:
/*
 * Copyright (C) 2002 Erik Swenson - eswenson@opensourcesoft.net
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307, USA.
 *  
 */

package org.efs.openreports.providers.persistence;

import java.util.List;

import net.sf.hibernate.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.efs.openreports.objects.ReportUser;
import org.efs.openreports.providers.ProviderException;

public class UserPersistenceProvider extends HibernateProvider
{
	protected static Log log =
		LogFactory.getLog(UserPersistenceProvider.class.getName());

	public UserPersistenceProvider() throws ProviderException
	{
		super();

		log.info("UserPersistenceProvider Created.");
	}

	public ReportUser getUser(String name) throws ProviderException
	{
		try
		{
			Session session = openSession();
			Transaction tx = null;

			try
			{
				tx = session.beginTransaction();

				List list =
					session.find(
						"from org.efs.openreports.objects.ReportUser as user "
							+ "where user.name = ?",
						name,
						Hibernate.STRING);

				if (list.size() == 0)
					return null;

				ReportUser user = (ReportUser) list.get(0);

				tx.commit();

				return user;
			}
			catch (HibernateException he)
			{
				if (tx != null)
					tx.rollback();
				throw he;
			}
			finally
			{
				session.close();
			}
		}
		catch (HibernateException he)
		{
			throw new ProviderException(he);
		}
	}

	public ReportUser getUser(Integer id) throws ProviderException
	{
		return (ReportUser) load(ReportUser.class, id);
	}

	public List getUsers() throws ProviderException
	{
		String fromClause =
			"from org.efs.openreports.objects.ReportUser reportUser order by reportUser.name ";

		return query(fromClause);
	}

	public ReportUser insertUser(ReportUser user) throws ProviderException
	{
		return (ReportUser) save(user);
	}

	public void updateUser(ReportUser user) throws ProviderException
	{
		update(user);
	}

	public void deleteUser(ReportUser user) throws ProviderException
	{
		try
		{
			delete(user);
		}
		catch (ConstraintException ce)
		{
			throw new ProviderException(ce);
		}
	}
}

⌨️ 快捷键说明

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