[jboss-cvs] jboss-seam/src/main/org/jboss/seam ...

Gavin King gavin.king at jboss.com
Mon Jun 18 01:57:35 EDT 2007


  User: gavin   
  Date: 07/06/18 01:57:35

  Modified:    src/main/org/jboss/seam  Entity.java
  Log:
  JBSEAM-942, optimistic locking for passivated entities
  
  Revision  Changes    Path
  1.7       +41 -0     jboss-seam/src/main/org/jboss/seam/Entity.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Entity.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/Entity.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- Entity.java	17 May 2007 21:44:09 -0000	1.6
  +++ Entity.java	18 Jun 2007 05:57:35 -0000	1.7
  @@ -9,6 +9,7 @@
   import javax.persistence.PrePersist;
   import javax.persistence.PreRemove;
   import javax.persistence.PreUpdate;
  +import javax.persistence.Version;
   
   import org.jboss.seam.contexts.Contexts;
   import org.jboss.seam.util.Reflections;
  @@ -31,6 +32,8 @@
      private Method postLoadMethod;
      private Method identifierGetter;
      private Field identifierField;
  +   private Method versionGetter;
  +   private Field versionField;
   
      public Entity(Class<?> beanClass)
      {
  @@ -63,6 +66,10 @@
               {
                  identifierGetter = method;
               }
  +            if ( method.isAnnotationPresent(Version.class) )
  +            {
  +               versionGetter = method;
  +            }
               
               if ( !method.isAccessible() )
               {
  @@ -82,6 +89,14 @@
                        field.setAccessible(true);
                     }
                  }
  +               if ( field.isAnnotationPresent(Version.class) )
  +               {
  +                  versionField = field;
  +                  if ( !field.isAccessible() )
  +                  {
  +                     field.setAccessible(true);
  +                  }
  +               }
               }
            }
            
  @@ -119,6 +134,16 @@
         return identifierGetter;
      }
      
  +   public Field getVersionField()
  +   {
  +      return versionField;
  +   }
  +
  +   public Method getVersionGetter()
  +   {
  +      return versionGetter;
  +   }
  +   
      public Object getIdentifier(Object entity)
      {
         if (identifierGetter!=null)
  @@ -135,6 +160,22 @@
         }
      }
   
  +   public Object getVersion(Object entity)
  +   {
  +      if (versionGetter!=null)
  +      {
  +         return Reflections.invokeAndWrap(versionGetter, entity);
  +      }
  +      else if (versionField!=null)
  +      {
  +         return Reflections.getAndWrap(versionField, entity);
  +      }
  +      else
  +      {
  +         return null;
  +      }
  +   }
  +
      public static Entity forClass(Class clazz)
      {
         if ( !Contexts.isApplicationContextActive() )
  
  
  



More information about the jboss-cvs-commits mailing list