-->
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.  [ 1 post ] 
Author Message
 Post subject: detecting dirty properties in PreUpdateEventListener
PostPosted: Wed Aug 31, 2005 5:53 pm 
Newbie

Joined: Thu Apr 28, 2005 8:16 pm
Posts: 9
I have implemented a PreUpdateEventListener to deny updates to a particular property under certain conditions.

I am unsatisfied with my current approach. I would be very grateful if somebody would suggest a more elegant approach for detecting exactly which properties are dirty in a PreUpdateEventListener (or an entirely different strategy for doing this kind of thing).

Code:
public class PreUpdateEventListener extends DefaultPreUpdateEventListener {

    public boolean onPreUpdate(PreUpdateEvent e) {

        // for a particular SMDP_TEMPLATE_COURSE, course_number updates are not
        // allowed if SMDP_RATE_CREDIT_COURSE records are present; the
        // course_number is at property index 1
        if(
            e.getEntity() instanceof TemplateCourse
            && ((TemplateCourse)e.getEntity()).getRateCreditCourses().size() > 0
            && !e.getPersister().getDatabaseSnapshot(e.getId(), e.getSession())[1]
                .equals(((TemplateCourse)e.getEntity()).getCourseNumber())
        ) {
            throw new RateCreditMaintenanceNotAllowedException();         
        }
           
        return super.onPreUpdate(e);

    }

}


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

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.