0 Replies Latest reply on Mar 30, 2014 11:43 AM by tzman

    Managed beans and proxies 2

    tzman Newbie

      I tried to add a reply a few times yesterday and today to the previous discussion, but the forum kept giving me an error.

       

      I think the main confusion is my use of the term Proxy. In this particular case, I am talking about Javassit proxies, not derived types or wrapper objects coded specifically for the class being proxied.

       

      The use case is maintaining and updating persisted data in a very large object graph. Data, relational data and associations can be modified. We have strict workflow around when data is persisted as well as business rules around knowing that a particular attribute in the object graph has been modified. We do all of this by dynamically creating javassist proxies when a screen is going to be modifying the data. The modifications are stored in a context object attached to the proxy. Proxies are cached when created so if a proxy is requested again for the same object, the same proxy is returned, this works the same for collections.

       

      The problem with using a producer is that there are hundreds of classes that could be proxied. So I would need to do something like this"

       

      @MyProxy
      @Produces
      public <T> T produceMyProxy( T bean){
          // create a javassist proxy wrapping the bean
          return proxy
      }
      
      @MyProxy
      @Produces
      public <T> T produceMyProxy( Class<T> beanClass){
          // create a new javassist proxy wrapping the bean
          return proxy
      }
      
      @MyProxy
      @Produces
      public <T> T produceMyProxy( InjectionPoint ip){
           // get the information from the injection point   
           // create a javassist proxy wrapping the bean
           return proxy
      }
      
      

       

      We proxy any type of object, there is not an interface or a base class that must be implemented, just an annotation that says it is proxiable. The objects could have their own producers and qualifiers, so it seemed that the producer approach wouldnt work. If I am missing something please let me know.

       

      This is how I see it being used.

       

      public class SomeAction{
          @MyProxy
          @Inject
          private MyPojo pojo;       
      }
      

       

      I would like to hook into the process after the object is created and before it is injected and Cdi determines it needs to create a proxy. At this point I would want to see that the injection point is qualified with MyProxy and create a proxy to be injected. This would mean that any injection point is capable of being qualified with MyProxy, but no classes actually declare the annotation. It would also allow the developer to define producers without the extra complexity of a proxy.

       

      I am not sure if there is a simpler way of achieving this, but the main point is that the objects being proxied are not concerned with whether or not they are going to be proxied.

       

      Any help, insight or suggestions are greatly appreciated.