-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Optimizing the AuditInterceptor
PostPosted: Fri Jan 26, 2007 1:37 pm 
Newbie

Joined: Wed May 18, 2005 4:50 am
Posts: 18
In the Hibernate Core reference documentation there is a sample implementation of an AuditInterceptor class.

In its onFlushDirty() and onSave() methods a for loop over all the properties of the entity class is used to find the properties "lastUpdateTimestamp" and "createUser". The code looks like this

Code:
for ( int i=0; i < propertyNames.length; i++ ) {
   if ( "lastUpdateTimestamp".equals( propertyNames[i] ) ) {
      currentState[i] = new Date();
      return true;
   }
}


Is this sample code something one would use in practice? Iterating over all the propertyNames each time an object is saved or updated seems kind of slow.

Is the order of the properties in the arrays something that can change while a system is running? Or can I rely on the order of the properties in the arrays being the same as the order in the mapping files or at least being fixed during runtime.

I would like to either use fixed indexes (something like the last property index etc.) or run through this loop once and store the correct indexes for each entity class in a HashMap.

I'd appreciate your input on this.[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 26, 2007 3:33 pm 
Newbie

Joined: Mon Aug 15, 2005 10:02 am
Posts: 7
Hi,

I've been looking throgth the sources and it looks like the implementation depends on dom4j implementaion of node.elementIterator() (Hibernate uses an ArrayList to store those properities, so I think they will be in the xml reading order). Since I don't have dom4j sources I can't be certain but you could run some tests, but the original order will only change if you create a new instance of SessionFactory.

EugĂȘnio.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 26, 2007 4:52 pm 
Regular
Regular

Joined: Wed Dec 07, 2005 4:19 pm
Posts: 53
Quote:
Iterating over all the propertyNames each time an object is saved or updated seems kind of slow.

slow ... Compared to WHAT? SQL query? IMHO, I would not worry about 'slow'. Besides, how many properties do you have? Twenty? I'd be more concerned about the fact that some of the interceptor methods (onFlushDirty) get called quite often...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.