(We have very big system. When an order is created there are hundred of objects
created).We need to know all the objects created in one session.
If you are using interceptor you can put a call to logging on those methods.
Below code generates identifiers like this.
H:1967664672,T:43TH:http-bio-80-exec-7
H:1967664672
From session hashcode we can understand which objects created at same hibernate session.
T:43TH:http-bio-80-exec-7
T : Thread Number
H : Thread Name
with thread data, we can understand utilization of threads by server.
How many server threads are running at an interval?
Which users took which thread?
protected static void doEventLog( boolean flag, String event, Session session ) { if( flag ) { YEventLog elog = YEventLog.newInstanceWithStackTrace( event ) ; String sessIdent = YClientUtils.truncateStringNoElipsis( "H:" + session.hashCode( ) + ",T:" + Thread.currentThread( ).getId( ) + ";TH:" + Thread.currentThread( ).getName( ), 64 ) ; elog.setSessionIdentifier( sessIdent ) ; YDelayedPersisterService.delayedSave( elog ) ; } } //Put stacktrace of current Action public static YEventLog newInstanceWithStackTrace( String eventName ) { YEventLog elog = newInstance( eventName ) ; String trace = ExceptionUtils.stackTraceToString( null ) ; if( trace.length( ) > 25000 ) { trace = trace.substring( 0, 25000 ) ; } elog.setStringData( trace ) ; return elog ; } public class EventLog { private Integer id ; private Integer organization ; private Integer user ; private String sessionIdentifier ; private String eventName ; private Date time ; private BigDecimal decimalData ; private String stringData ; private int YVersion ; private Date YCreateDate ; private Date YUpdateDate ; }
I suggest you, to have 2 fields in database for holding The session id that object was created
and concatenated ids that object was updated or one concatenate all of these. (1st creator)
A better way will be having a separate table.(Our data is separated over tables)
Session Id, Bean Name, Date, Operation
No comments:
Post a Comment