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

📄 userprofileutil.java.svn-base

📁 一个timesheet程序,用来统计开发人员的度量衡web在线程序.用于软件行业
💻 SVN-BASE
字号:
package com.nsi.components.util;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.nsi.components.userprofile.UserProfile;
import com.nsi.constants.AppConstants;
import com.nsi.control.exceptions.NsiEventException;
import com.nsi.persistence.DataSrcUtil;
import com.nsi.persistence.IsqlDataSource;
import com.nsi.util.ValHelper;

/**
 * @author Chris Ye, created on Oct 9, 2008
 *
 * UserProfileUtil
 */
public final class UserProfileUtil
{
	private static Log log = LogFactory.getLog(UserProfileUtil.class);
	/**
	 * private constructor of UserProfileUtil, prevent instantiation
	 */
	private UserProfileUtil()
	{
	}
	private static class UserProfileUtilHolder
	{
		static final UserProfileUtil userProfileUtil = new UserProfileUtil();
	}
	/**
	 * @return an instance of UserProfileUtil
	 */
	public static UserProfileUtil getInstance()
	{
		return UserProfileUtilHolder.userProfileUtil;
	}
	public void setUserprofile( UserProfile userprofile, String resourceid ) throws NsiEventException
	{
		Map<String,String> resultmap = new HashMap<String,String>();
		String sSql = 	"select userid, loginname, password, resourceid, userroleid, bactive " + 
							"from t_user where resourceid =" + resourceid + "";
		IsqlDataSource src = DataSrcUtil.getInstance().getDataSource();
		Connection conn = null;
		try
		{
			conn = src.getConnection();
			resultmap = src.retrieveSingleRow(conn, sSql);
		}
		catch(SQLException se)
		{
			log.error("setUserprofile() caught SQLException: " + se);
		}
		catch(Exception ex)
		{
			log.error("setUserprofile() caught Exception: " + ex);
		}
		finally
		{
			src.closeConn(conn);
		}
		if( !resultmap.isEmpty())
		{
			userprofile.setUserid(ValHelper.getInstance().getValue(resultmap, "userid"));
			userprofile.setLoginname(ValHelper.getInstance().getValue(resultmap, "loginname"));
			userprofile.setPwd(ValHelper.getInstance().getValue(resultmap, "password"));
			userprofile.setUserroleid(ValHelper.getInstance().getValue(resultmap, "userroleid"));
			userprofile.setActive(ValHelper.getInstance().getValue(resultmap, "bactive"));
		}
	}
	public void updateUserprofile( UserProfile userprofile, String loginuser ) throws NsiEventException
	{
		IsqlDataSource src = DataSrcUtil.getInstance().getDataSource();
		Connection conn = null;
		try
		{
			conn = src.getConnection();
			Statement stmt = conn.createStatement();
			String sSql = AppConstants.EMPTY_STRING;
			if( ValHelper.getInstance().isNotNullAndEmpty(userprofile.getUserid()))
			{
				sSql =	"update t_user set moduserid=" + loginuser.trim() + ", " + 
							"loginname='" + userprofile.getLoginname().trim() + "', " + 
							"bactive='" + userprofile.getActive().trim() + "', " + 
							"userroleid=" + userprofile.getUserroleid() + " " + 
							"where userid=" + userprofile.getUserid().trim() + "";
			}
			else
			{
				sSql =	"insert into t_user ( userid, loginname, password, bactive, resourceid, userroleid, moduserid ) " + 
							"values ( nextval('userid_seq'), '" + userprofile.getLoginname().trim() + "', " + "'" + AppConstants.DEFAULT_PASSWORD + "', " + 
							"'" + userprofile.getActive().trim() + "', " + userprofile.getResourceid().trim() + ", " + 
							userprofile.getUserroleid().trim() + ", " + loginuser.trim() + " )";
			}
			if( ValHelper.getInstance().isNotNullAndEmpty(sSql))
			{
				int resultCount = src.executeUpdate(stmt, sSql);
				if(resultCount != 1) throw new NsiEventException("ERROR update userprofile from t_user!!  resultCount = " + resultCount);
			}
		}
		catch( SQLException se )
		{
			log.error( "getDetaillist() caught SQLException: " + se );
		}
		catch( Exception ex )
		{
			log.error( "getDetaillist() caught Exception: " + ex );
		}
		finally
		{
			src.closeConn(conn);
		}
	}
	public void updateUserPwd( UserProfile userprofile, String loginuser ) throws NsiEventException
	{
		IsqlDataSource src = DataSrcUtil.getInstance().getDataSource();
		Connection conn = null;
		try
		{
			conn = src.getConnection();
			Statement stmt = conn.createStatement();
			String sSql =	"update t_user set moduserid=" + loginuser.trim() + ", " + 
								"password= '" + userprofile.getPwd().trim() + "' " + 
								"where userid=" + userprofile.getUserid().trim();
			int resultCount = src.executeUpdate(stmt, sSql);
			if(resultCount != 1) throw new NsiEventException("ERROR update user password from t_user!!  resultCount = " + resultCount);
		}
		catch( SQLException se )
		{
			log.error( "getDetaillist() caught SQLException: " + se );
		}
		catch( Exception ex )
		{
			log.error( "getDetaillist() caught Exception: " + ex );
		}
		finally
		{
			src.closeConn(conn);
		}
	}
	public void updUserPassword( String newpwd, String loginname ) throws NsiEventException
	{
		IsqlDataSource src = DataSrcUtil.getInstance().getDataSource();
		Connection conn = null;
		try
		{
			conn = src.getConnection();
			Statement stmt = conn.createStatement();
			String sSql =	"update t_user set password='" + newpwd + "' " + 
								"where loginname='" + loginname.trim() + "'";
			int resultCount = src.executeUpdate(stmt, sSql);
			if(resultCount != 1) throw new NsiEventException("ERROR update user password from t_user!!  resultCount = " + resultCount);
		}
		catch( SQLException se )
		{
			log.error( "getDetaillist() caught SQLException: " + se );
		}
		catch( Exception ex )
		{
			log.error( "getDetaillist() caught Exception: " + ex );
		}
		finally
		{
			src.closeConn(conn);
		}
	}
}

⌨️ 快捷键说明

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