-->
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: Event with fine grained control=DB trigger independency
PostPosted: Mon Jun 20, 2005 9:04 am 
Regular
Regular

Joined: Mon Jun 14, 2004 1:42 pm
Posts: 80
Location: Brazil
Hibernate version:
3.05
--
Hi.
Currently an event listener is called to all classes mapped in the configuration of my hibernate application. This makes event system powerful to build audit, replication and that kind of general propose codification.
Well, but to create events to a specific class of objects, or maybe to move business logic commonly used in database triggers to the database independent level, how it will perform? Is it a good idea?
By the programming point of view it would be interesting to have a fine grained event mapping to do this.
Todays implementation would lead to that kind of code:
Code:

public class MyGeneralFlush extends DefaultFlushEntityEventListener {
   public void onFlushEntity(FlushEntityEvent evt) throws HibernateException {
      if (evt.getEntity() instanceof foo) {
        // do foo logic   
      } else if (evt.getEntity() instanceof foo2) {
            // do foo2 logic   
      } else if (evt.getEntity() instanceof foo3) {
            // do foo3 logic            
      }

Instead of each event being connected to the session, it could be connected with an specific Class (or set of classes or hierarchy of classes) in the hibernate mapping file.
Code:

public class FooFlush extends DefaultFlushEntityEventListener {
   public void onFlushEntity(FlushEntityEvent evt) throws HibernateException {
      if (evt.getEntity() instanceof foo) {
        // do foo logic   
      }
         }
}
public class Foo2Flush extends DefaultFlushEntityEventListener {
   public void onFlushEntity(FlushEntityEvent evt) throws HibernateException {
                 if (evt.getEntity() instanceof foo2) {
                 // do foo2 logic         
      }



I think it's a quite obvious idea, Any comments ?

_________________
Alexandre Torres
--------------------


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.