auditlog.java

来自「webwork in action 下载。」· Java 代码 · 共 55 行

JAVA
55
字号
package org.hibernate.auction.persistence.audit;import net.sf.hibernate.CallbackException;import net.sf.hibernate.HibernateException;import net.sf.hibernate.Session;import org.hibernate.auction.model.Auditable;import org.hibernate.auction.persistence.HibernateUtil;import java.sql.Connection;/** * The audit log helper that logs actual events. * <p> * The <tt>logEvent()</tt> method needs a JDBC connection, it will * open a new Hibernate <tt>Session</tt> on that connection and * persist the event. The temporary <tt>Session</tt> is then closed, * transaction handling is left to the client calling this method. * * @author Christian Bauer <christian@hibernate.org> */public class AuditLog {	public static void logEvent(		String message,		Auditable entity,		Long userId,		Connection connection)		throws CallbackException {		Session tempSession =		  HibernateUtil.getSessionFactory().openSession(connection);		try {			AuditLogRecord record =				new AuditLogRecord(message,								   entity.getId(),								   entity.getClass(),								   userId );			tempSession.save(record);			tempSession.flush();		} catch (Exception ex) {			throw new CallbackException(ex);		} finally {			try {				tempSession.close();			} catch (HibernateException ex) {				throw new CallbackException(ex);			}		}	}}

⌨️ 快捷键说明

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