User: oberg   
  Date: 00/10/09 13:14:28

  Modified:    src/main/org/jboss/ejb/plugins
                        EntitySynchronizationInterceptor.java
  Log:
  Added support for isModified bean flag
  
  Revision  Changes    Path
  1.21      +50 -4     
jboss/src/main/org/jboss/ejb/plugins/EntitySynchronizationInterceptor.java
  
  Index: EntitySynchronizationInterceptor.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/EntitySynchronizationInterceptor.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- EntitySynchronizationInterceptor.java     2000/10/08 05:30:17     1.20
  +++ EntitySynchronizationInterceptor.java     2000/10/09 20:14:27     1.21
  @@ -48,7 +48,7 @@
   *   @see <related>
   *   @author Rickard �berg ([EMAIL PROTECTED])
   *   @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
  -*   @version $Revision: 1.20 $
  +*   @version $Revision: 1.21 $
   */
   public class EntitySynchronizationInterceptor
   extends AbstractInterceptor
  @@ -87,6 +87,11 @@
        */
        protected EntityContainer container;
        
  +     /**
  +     *  Optional isModified method
  +     */
  +     protected Method isModified;
  +   
        // Static --------------------------------------------------------
        
        // Constructors --------------------------------------------------
  @@ -96,6 +101,21 @@
        { 
                this.container = (EntityContainer)container; 
        }
  +   
  +   public void init()
  +      throws Exception
  +   {
  +      // Check for isModified method
  +      try
  +      {
  +         isModified = container.getBeanClass().getMethod("isModified", new 
Class[0]);
  +         if (!isModified.getReturnType().equals(Boolean.TYPE))
  +            isModified = null; // Has to have "boolean" as return type!
  +      } catch (Exception e)
  +      {
  +         // Ignore
  +      }
  +   }
        
        public Container getContainer()
        {
  @@ -261,8 +281,19 @@
                                // And skip reads too ("get" methods)
                                // OSH FIXME: Isn't this startsWith("get") 
optimization a violation of
                                // the EJB specification? Think of 
SequenceBean.getNext().
  -                             if (ctx.getId() != null && 
!mi.getMethod().getName().startsWith("get"))
  -                                     
((EntityContainer)getContainer()).getPersistenceManager().storeEntity(ctx);
  +                             if (ctx.getId() != null)
  +                             {
  +               boolean dirty = true;
  +                                // Check isModified bean flag
  +                                if (isModified != null)
  +                                {
  +                                   dirty = 
((Boolean)isModified.invoke(ctx.getInstance(), new Object[0])).booleanValue();
  +                                }
  +            
  +               // Store entity
  +               if (dirty)
  +                                        
((EntityContainer)getContainer()).getPersistenceManager().storeEntity(ctx);
  +                             }
                                
                                return result;
                        } catch (Exception e) {
  @@ -319,8 +350,23 @@
                                                        //DEBUG 
Logger.debug("EntitySynchronization sync calling store on ctx "+ctx.hashCode());
                                                        
   //DEBUG                                                      
Logger.debug("EntitySynchronization sync calling store on ctx "+ctx.hashCode());
  +                                                     
  +                                                     // Check isModified bean flag
  +                                                     boolean dirty = true;
  +                                                     if (isModified != null)
  +                                                     {
  +                        try
  +                        {
  +                           dirty = ((Boolean)isModified.invoke(ctx.getInstance(), 
new Object[0])).booleanValue();
  +                        } catch (Exception e)
  +                        {
  +                           // Ignore
  +                           e.printStackTrace();
  +                        }
  +                                                     }
                                                        
  -                                                     
container.getPersistenceManager().storeEntity(ctx);
  +                     if (dirty)
  +                                                        
container.getPersistenceManager().storeEntity(ctx);
                                                }
                                        } catch (NoSuchEntityException e) {
                                                // Object has been removed -- ignore
  
  
  

Reply via email to