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

📄 loginvocationhandler.java

📁 《j2ee开发全程实录》随书源码
💻 JAVA
字号:
package com.cownew.PIS.framework.server.logMgr;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.Date;
import java.util.Properties;

import org.springframework.util.StringUtils;


import com.cownew.PIS.framework.server.helper.ServerSQLExecutorUtils;
import com.cownew.PIS.framework.server.helper.ThreadVariableManager;
import com.cownew.ctk.common.DateUtils;
import com.cownew.ctk.common.RandomGUID;

public class LogInvocationHandler implements InvocationHandler
{
	private ILogableService realObj;
	private Properties logAttributes;
	
	public LogInvocationHandler(ILogableService realObj)
	{
		super();
		this.realObj = realObj;
		logAttributes = realObj.getLogAttributes();
	}

	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable
	{
		String methodName = method.getName();

		Object result = method.invoke(realObj, args);
		
		//只有成功执行才记录日志
		if (logAttributes.containsKey(methodName))
		{
			String desc = method.getName() + ":"
					+ StringUtils.arrayToCommaDelimitedString(args);
			String oprtName = logAttributes.get(methodName).toString();
			writeLog(oprtName, desc);
		}
		return result;
	}
	

	private void writeLog(String oprtName, String desc)
			throws SQLException
	{
		String id = new RandomGUID().toString();
		Date now = DateUtils.getSQLNow();
		String userId = ThreadVariableManager.getInstance()
				.getCurrentServerUserContext().getCurUserId();
		ServerSQLExecutorUtils.execute(
				"insert into T_BS_LogItem(FId,FDate,FUserId,FOprtName,FDescription)\n"
						+ "values(?,?,?,?,?)", new Object[] { id, now, userId,
						oprtName, desc });
	}
}

⌨️ 快捷键说明

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