1 package org.hibernate.ce.auction.persistence.audit; 2 3 import org.hibernate.*; 4 5 import java.io.Serializable ; 6 import java.sql.Connection ; 7 8 import org.hibernate.ce.auction.persistence.HibernateUtil; 9 import org.hibernate.ce.auction.model.Auditable; 10 11 21 public class AuditLog { 22 23 public static void logEvent( 24 String message, 25 Auditable entity, 26 Long userId, 27 Connection connection) 28 throws CallbackException { 29 30 Session tempSession = 31 HibernateUtil.getSessionFactory().openSession(connection); 32 33 try { 34 AuditLogRecord record = 35 new AuditLogRecord(message, 36 entity.getId(), 37 entity.getClass(), 38 userId ); 39 40 tempSession.save(record); 41 tempSession.flush(); 42 43 } catch (Exception ex) { 44 throw new CallbackException(ex); 45 46 } finally { 47 try { 48 tempSession.close(); 49 } catch (HibernateException ex) { 50 throw new CallbackException(ex); 51 } 52 } 53 } 54 } 55 | Popular Tags |